summaryrefslogtreecommitdiff
path: root/modules/gdscript/gd_parser.cpp
diff options
context:
space:
mode:
authorJuan Linietsky <reduzio@gmail.com>2016-06-30 10:40:13 -0300
committerJuan Linietsky <reduzio@gmail.com>2016-06-30 10:40:13 -0300
commite49b73e93a91ebd76671dfedd213ddf5b0ae7b56 (patch)
treebad33963885061bc8b9ca1dab10334cb5dcae42f /modules/gdscript/gd_parser.cpp
parentcf0fbe493ff8e2dd80859d75a9794d364a03551c (diff)
Only check for constants when parsing constants, should close #5497
Diffstat (limited to 'modules/gdscript/gd_parser.cpp')
-rw-r--r--modules/gdscript/gd_parser.cpp40
1 files changed, 21 insertions, 19 deletions
diff --git a/modules/gdscript/gd_parser.cpp b/modules/gdscript/gd_parser.cpp
index 6c6560efa6..c33bf00c7b 100644
--- a/modules/gdscript/gd_parser.cpp
+++ b/modules/gdscript/gd_parser.cpp
@@ -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<OperatorNode::Operator> operators;
@@ -244,7 +244,7 @@ GDParser::Node* GDParser::_parse_expression(Node *p_parent,bool p_static,bool p_
//subexpression ()
tokenizer->advance();
parenthesis++;
- Node* subexpr = _parse_expression(p_parent,p_static);
+ Node* subexpr = _parse_expression(p_parent,p_static,p_allow_assign,p_parsing_constant);
parenthesis--;
if (!subexpr)
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;
- bfn = true;
- break;
+ expr = cln->constant_expressions[i].expression;
+ bfn = true;
+ break;
+ }
}
- }
- if (GDScriptLanguage::get_singleton()->get_global_map().has(identifier)) {
- //check from constants
- ConstantNode *constant = alloc_node<ConstantNode>();
- constant->value = GDScriptLanguage::get_singleton()->get_global_array()[ GDScriptLanguage::get_singleton()->get_global_map()[identifier] ];
- expr=constant;
- bfn = true;
+ if (GDScriptLanguage::get_singleton()->get_global_map().has(identifier)) {
+ //check from constants
+ ConstantNode *constant = alloc_node<ConstantNode>();
+ constant->value = GDScriptLanguage::get_singleton()->get_global_array()[ GDScriptLanguage::get_singleton()->get_global_map()[identifier] ];
+ expr=constant;
+ bfn = true;
+ }
}
if ( !bfn ) {
@@ -576,7 +578,7 @@ GDParser::Node* GDParser::_parse_expression(Node *p_parent,bool p_static,bool p_
_set_error("',' or ']' expected");
return NULL;
}
- Node *n = _parse_expression(arr,p_static);
+ Node *n = _parse_expression(arr,p_static,p_allow_assign,p_parsing_constant);
if (!n)
return NULL;
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;
} else {
//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)
return NULL;
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) {
- Node *value = _parse_expression(dict,p_static);
+ Node *value = _parse_expression(dict,p_static,p_allow_assign,p_parsing_constant);
if (!value)
return NULL;
expecting=DICT_EXPECT_COMMA;
@@ -842,7 +844,7 @@ GDParser::Node* GDParser::_parse_expression(Node *p_parent,bool p_static,bool p_
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) {
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) {
- 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)
return NULL;
expr = _reduce_expression(expr,p_reduce_const);