Only check for constants when parsing constants, should close #5497

This commit is contained in:
Juan Linietsky 2016-06-30 10:40:13 -03:00
parent cf0fbe493f
commit e49b73e93a
2 changed files with 22 additions and 20 deletions

View file

@ -217,7 +217,7 @@ bool GDParser::_get_completable_identifier(CompletionType p_type,StringName& ide
} }
GDParser::Node* GDParser::_parse_expression(Node *p_parent,bool p_static,bool p_allow_assign) { GDParser::Node* GDParser::_parse_expression(Node *p_parent,bool p_static,bool p_allow_assign,bool p_parsing_constant) {
// Vector<Node*> expressions; // Vector<Node*> expressions;
// Vector<OperatorNode::Operator> operators; // Vector<OperatorNode::Operator> operators;
@ -244,7 +244,7 @@ GDParser::Node* GDParser::_parse_expression(Node *p_parent,bool p_static,bool p_
//subexpression () //subexpression ()
tokenizer->advance(); tokenizer->advance();
parenthesis++; parenthesis++;
Node* subexpr = _parse_expression(p_parent,p_static); Node* subexpr = _parse_expression(p_parent,p_static,p_allow_assign,p_parsing_constant);
parenthesis--; parenthesis--;
if (!subexpr) if (!subexpr)
return NULL; return NULL;
@ -485,22 +485,24 @@ GDParser::Node* GDParser::_parse_expression(Node *p_parent,bool p_static,bool p_
} }
for( int i=0; i<cln->constant_expressions.size(); ++i ) { if (p_parsing_constant) {
for( int i=0; i<cln->constant_expressions.size(); ++i ) {
if( cln->constant_expressions[i].identifier == identifier ) { if( cln->constant_expressions[i].identifier == identifier ) {
expr = cln->constant_expressions[i].expression; expr = cln->constant_expressions[i].expression;
bfn = true; bfn = true;
break; break;
}
} }
}
if (GDScriptLanguage::get_singleton()->get_global_map().has(identifier)) { if (GDScriptLanguage::get_singleton()->get_global_map().has(identifier)) {
//check from constants //check from constants
ConstantNode *constant = alloc_node<ConstantNode>(); ConstantNode *constant = alloc_node<ConstantNode>();
constant->value = GDScriptLanguage::get_singleton()->get_global_array()[ GDScriptLanguage::get_singleton()->get_global_map()[identifier] ]; constant->value = GDScriptLanguage::get_singleton()->get_global_array()[ GDScriptLanguage::get_singleton()->get_global_map()[identifier] ];
expr=constant; expr=constant;
bfn = true; bfn = true;
}
} }
if ( !bfn ) { if ( !bfn ) {
@ -576,7 +578,7 @@ GDParser::Node* GDParser::_parse_expression(Node *p_parent,bool p_static,bool p_
_set_error("',' or ']' expected"); _set_error("',' or ']' expected");
return NULL; return NULL;
} }
Node *n = _parse_expression(arr,p_static); Node *n = _parse_expression(arr,p_static,p_allow_assign,p_parsing_constant);
if (!n) if (!n)
return NULL; return NULL;
arr->elements.push_back(n); arr->elements.push_back(n);
@ -683,7 +685,7 @@ GDParser::Node* GDParser::_parse_expression(Node *p_parent,bool p_static,bool p_
expecting=DICT_EXPECT_VALUE; expecting=DICT_EXPECT_VALUE;
} else { } else {
//python/js style more flexible //python/js style more flexible
key = _parse_expression(dict,p_static); key = _parse_expression(dict,p_static,p_allow_assign,p_parsing_constant);
if (!key) if (!key)
return NULL; return NULL;
expecting=DICT_EXPECT_COLON; expecting=DICT_EXPECT_COLON;
@ -691,7 +693,7 @@ GDParser::Node* GDParser::_parse_expression(Node *p_parent,bool p_static,bool p_
} }
if (expecting==DICT_EXPECT_VALUE) { if (expecting==DICT_EXPECT_VALUE) {
Node *value = _parse_expression(dict,p_static); Node *value = _parse_expression(dict,p_static,p_allow_assign,p_parsing_constant);
if (!value) if (!value)
return NULL; return NULL;
expecting=DICT_EXPECT_COMMA; expecting=DICT_EXPECT_COMMA;
@ -842,7 +844,7 @@ GDParser::Node* GDParser::_parse_expression(Node *p_parent,bool p_static,bool p_
tokenizer->advance(1); tokenizer->advance(1);
Node *subexpr = _parse_expression(op,p_static); Node *subexpr = _parse_expression(op,p_static,p_allow_assign,p_parsing_constant);
if (!subexpr) { if (!subexpr) {
return NULL; return NULL;
} }
@ -1441,7 +1443,7 @@ GDParser::Node* GDParser::_reduce_expression(Node *p_node,bool p_to_const) {
GDParser::Node* GDParser::_parse_and_reduce_expression(Node *p_parent,bool p_static,bool p_reduce_const,bool p_allow_assign) { GDParser::Node* GDParser::_parse_and_reduce_expression(Node *p_parent,bool p_static,bool p_reduce_const,bool p_allow_assign) {
Node* expr=_parse_expression(p_parent,p_static,p_allow_assign); Node* expr=_parse_expression(p_parent,p_static,p_allow_assign,p_reduce_const);
if (!expr || error_set) if (!expr || error_set)
return NULL; return NULL;
expr = _reduce_expression(expr,p_reduce_const); expr = _reduce_expression(expr,p_reduce_const);

View file

@ -435,7 +435,7 @@ private:
bool _parse_arguments(Node* p_parent, Vector<Node*>& p_args, bool p_static, bool p_can_codecomplete=false); bool _parse_arguments(Node* p_parent, Vector<Node*>& p_args, bool p_static, bool p_can_codecomplete=false);
bool _enter_indent_block(BlockNode *p_block=NULL); bool _enter_indent_block(BlockNode *p_block=NULL);
bool _parse_newline(); bool _parse_newline();
Node* _parse_expression(Node *p_parent,bool p_static,bool p_allow_assign=false); Node* _parse_expression(Node *p_parent, bool p_static, bool p_allow_assign=false, bool p_parsing_constant=false);
Node* _reduce_expression(Node *p_node,bool p_to_const=false); Node* _reduce_expression(Node *p_node,bool p_to_const=false);
Node* _parse_and_reduce_expression(Node *p_parent,bool p_static,bool p_reduce_const=false,bool p_allow_assign=false); Node* _parse_and_reduce_expression(Node *p_parent,bool p_static,bool p_reduce_const=false,bool p_allow_assign=false);