Browse Source

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

Juan Linietsky 9 years ago
parent
commit
e49b73e93a
2 changed files with 22 additions and 20 deletions
  1. 21 19
      modules/gdscript/gd_parser.cpp
  2. 1 1
      modules/gdscript/gd_parser.h

+ 21 - 19
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<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;
-					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 ) {
 			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);

+ 1 - 1
modules/gdscript/gd_parser.h

@@ -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);