MCPcopy Create free account
hub / github.com/Redot-Engine/redot-engine / parse_binary_operator

Method parse_binary_operator

modules/gdscript/gdscript_parser.cpp:2890–2994  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2888}
2889
2890GDScriptParser::ExpressionNode *GDScriptParser::parse_binary_operator(ExpressionNode *p_previous_operand, bool p_can_assign) {
2891 GDScriptTokenizer::Token op = previous;
2892 BinaryOpNode *operation = alloc_node<BinaryOpNode>();
2893 reset_extents(operation, p_previous_operand);
2894 update_extents(operation);
2895
2896 Precedence precedence = (Precedence)(get_rule(op.type)->precedence + 1);
2897 operation->left_operand = p_previous_operand;
2898 operation->right_operand = parse_precedence(precedence, false);
2899 complete_extents(operation);
2900
2901 if (operation->right_operand == nullptr) {
2902 push_error(vformat(R"(Expected expression after "%s" operator.)", op.get_name()));
2903 }
2904
2905 /// @todo Also for unary, ternary, and assignment.
2906 switch (op.type) {
2907 case GDScriptTokenizer::Token::PLUS:
2908 operation->operation = BinaryOpNode::OP_ADDITION;
2909 operation->variant_op = Variant::OP_ADD;
2910 break;
2911 case GDScriptTokenizer::Token::MINUS:
2912 operation->operation = BinaryOpNode::OP_SUBTRACTION;
2913 operation->variant_op = Variant::OP_SUBTRACT;
2914 break;
2915 case GDScriptTokenizer::Token::STAR:
2916 operation->operation = BinaryOpNode::OP_MULTIPLICATION;
2917 operation->variant_op = Variant::OP_MULTIPLY;
2918 break;
2919 case GDScriptTokenizer::Token::SLASH:
2920 operation->operation = BinaryOpNode::OP_DIVISION;
2921 operation->variant_op = Variant::OP_DIVIDE;
2922 break;
2923 case GDScriptTokenizer::Token::PERCENT:
2924 operation->operation = BinaryOpNode::OP_MODULO;
2925 operation->variant_op = Variant::OP_MODULE;
2926 break;
2927 case GDScriptTokenizer::Token::STAR_STAR:
2928 operation->operation = BinaryOpNode::OP_POWER;
2929 operation->variant_op = Variant::OP_POWER;
2930 break;
2931 case GDScriptTokenizer::Token::LESS_LESS:
2932 operation->operation = BinaryOpNode::OP_BIT_LEFT_SHIFT;
2933 operation->variant_op = Variant::OP_SHIFT_LEFT;
2934 break;
2935 case GDScriptTokenizer::Token::GREATER_GREATER:
2936 operation->operation = BinaryOpNode::OP_BIT_RIGHT_SHIFT;
2937 operation->variant_op = Variant::OP_SHIFT_RIGHT;
2938 break;
2939 case GDScriptTokenizer::Token::AMPERSAND:
2940 operation->operation = BinaryOpNode::OP_BIT_AND;
2941 operation->variant_op = Variant::OP_BIT_AND;
2942 break;
2943 case GDScriptTokenizer::Token::PIPE:
2944 operation->operation = BinaryOpNode::OP_BIT_OR;
2945 operation->variant_op = Variant::OP_BIT_OR;
2946 break;
2947 case GDScriptTokenizer::Token::CARET:

Callers

nothing calls this directly

Calls 2

vformatFunction · 0.85
get_nameMethod · 0.45

Tested by

no test coverage detected