diff options
Diffstat (limited to 'modules/gdscript/gdscript_parser.cpp')
-rw-r--r-- | modules/gdscript/gdscript_parser.cpp | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/modules/gdscript/gdscript_parser.cpp b/modules/gdscript/gdscript_parser.cpp index af07457750..0967f74285 100644 --- a/modules/gdscript/gdscript_parser.cpp +++ b/modules/gdscript/gdscript_parser.cpp @@ -94,6 +94,10 @@ Variant::Type GDScriptParser::get_builtin_type(const StringName &p_type) { return Variant::VARIANT_MAX; } +void GDScriptParser::cleanup() { + builtin_types.clear(); +} + GDScriptFunctions::Function GDScriptParser::get_builtin_function(const StringName &p_name) { for (int i = 0; i < GDScriptFunctions::FUNC_MAX; i++) { if (p_name == GDScriptFunctions::get_func_name(GDScriptFunctions::Function(i))) { @@ -2005,7 +2009,6 @@ GDScriptParser::ExpressionNode *GDScriptParser::parse_binary_operator(Expression push_error(vformat(R"(Expected expression after "%s" operator.")", op.get_name())); } - // TODO: Store the Variant operator here too (in the node). // TODO: Also for unary, ternary, and assignment. switch (op.type) { case GDScriptTokenizer::Token::PLUS: @@ -2167,39 +2170,50 @@ GDScriptParser::ExpressionNode *GDScriptParser::parse_assignment(ExpressionNode switch (previous.type) { case GDScriptTokenizer::Token::EQUAL: assignment->operation = AssignmentNode::OP_NONE; + assignment->variant_op = Variant::OP_MAX; #ifdef DEBUG_ENABLED has_operator = false; #endif break; case GDScriptTokenizer::Token::PLUS_EQUAL: assignment->operation = AssignmentNode::OP_ADDITION; + assignment->variant_op = Variant::OP_ADD; break; case GDScriptTokenizer::Token::MINUS_EQUAL: assignment->operation = AssignmentNode::OP_SUBTRACTION; + assignment->variant_op = Variant::OP_SUBTRACT; break; case GDScriptTokenizer::Token::STAR_EQUAL: assignment->operation = AssignmentNode::OP_MULTIPLICATION; + assignment->variant_op = Variant::OP_MULTIPLY; break; case GDScriptTokenizer::Token::SLASH_EQUAL: assignment->operation = AssignmentNode::OP_DIVISION; + assignment->variant_op = Variant::OP_DIVIDE; break; case GDScriptTokenizer::Token::PERCENT_EQUAL: assignment->operation = AssignmentNode::OP_MODULO; + assignment->variant_op = Variant::OP_MODULE; break; case GDScriptTokenizer::Token::LESS_LESS_EQUAL: assignment->operation = AssignmentNode::OP_BIT_SHIFT_LEFT; + assignment->variant_op = Variant::OP_SHIFT_LEFT; break; case GDScriptTokenizer::Token::GREATER_GREATER_EQUAL: assignment->operation = AssignmentNode::OP_BIT_SHIFT_RIGHT; + assignment->variant_op = Variant::OP_SHIFT_RIGHT; break; case GDScriptTokenizer::Token::AMPERSAND_EQUAL: assignment->operation = AssignmentNode::OP_BIT_AND; + assignment->variant_op = Variant::OP_BIT_AND; break; case GDScriptTokenizer::Token::PIPE_EQUAL: assignment->operation = AssignmentNode::OP_BIT_OR; + assignment->variant_op = Variant::OP_BIT_OR; break; case GDScriptTokenizer::Token::CARET_EQUAL: assignment->operation = AssignmentNode::OP_BIT_XOR; + assignment->variant_op = Variant::OP_BIT_XOR; break; default: break; // Unreachable. @@ -2328,7 +2342,11 @@ GDScriptParser::ExpressionNode *GDScriptParser::parse_dictionary(ExpressionNode GDScriptParser::ExpressionNode *GDScriptParser::parse_grouping(ExpressionNode *p_previous_operand, bool p_can_assign) { ExpressionNode *grouped = parse_expression(false); pop_multiline(); - consume(GDScriptTokenizer::Token::PARENTHESIS_CLOSE, R"*(Expected closing ")" after grouping expression.)*"); + if (grouped == nullptr) { + push_error(R"(Expected grouping expression.)"); + } else { + consume(GDScriptTokenizer::Token::PARENTHESIS_CLOSE, R"*(Expected closing ")" after grouping expression.)*"); + } return grouped; } @@ -2419,7 +2437,9 @@ GDScriptParser::ExpressionNode *GDScriptParser::parse_call(ExpressionNode *p_pre } else { call->callee = p_previous_operand; - if (call->callee->type == Node::IDENTIFIER) { + if (call->callee == nullptr) { + push_error(R"*(Cannot call on an expression. Use ".call()" if it's a Callable.)*"); + } else if (call->callee->type == Node::IDENTIFIER) { call->function_name = static_cast<IdentifierNode *>(call->callee)->name; make_completion_context(COMPLETION_METHOD, call->callee); } else if (call->callee->type == Node::SUBSCRIPT) { |