diff --git a/main/tests/test_gdscript.cpp b/main/tests/test_gdscript.cpp index 5c7633a0cf2..5f3a2c1dc8c 100644 --- a/main/tests/test_gdscript.cpp +++ b/main/tests/test_gdscript.cpp @@ -193,14 +193,6 @@ static String _parser_expr(const GDScriptParser::Node *p_expr) { case GDScriptParser::OperatorNode::OP_BIT_INVERT: { txt = "~" + _parser_expr(c_node->arguments[0]); } break; - case GDScriptParser::OperatorNode::OP_PREINC: { - } break; - case GDScriptParser::OperatorNode::OP_PREDEC: { - } break; - case GDScriptParser::OperatorNode::OP_INC: { - } break; - case GDScriptParser::OperatorNode::OP_DEC: { - } break; case GDScriptParser::OperatorNode::OP_IN: { txt = _parser_expr(c_node->arguments[0]) + " in " + _parser_expr(c_node->arguments[1]); } break; @@ -455,10 +447,9 @@ static void _parser_show_class(const GDScriptParser::ClassNode *p_class, int p_i print_line("\n"); } - for (int i = 0; i < p_class->constant_expressions.size(); i++) { - - const GDScriptParser::ClassNode::Constant &constant = p_class->constant_expressions[i]; - _print_indent(p_indent, "const " + String(constant.identifier) + "=" + _parser_expr(constant.expression)); + for (Map::Element *E = p_class->constant_expressions.front(); E; E = E->next()) { + const GDScriptParser::ClassNode::Constant &constant = E->get(); + _print_indent(p_indent, "const " + String(E->key()) + "=" + _parser_expr(constant.expression)); } for (int i = 0; i < p_class->variables.size(); i++) { diff --git a/modules/gdscript/gdscript.h b/modules/gdscript/gdscript.h index d1c57a0330c..5c6cda09937 100644 --- a/modules/gdscript/gdscript.h +++ b/modules/gdscript/gdscript.h @@ -64,6 +64,7 @@ class GDScript : public Script { StringName setter; StringName getter; MultiplayerAPI::RPCMode rpc_mode; + GDScriptDataType data_type; }; friend class GDScriptInstance; @@ -145,6 +146,10 @@ public: const Map > &get_subclasses() const { return subclasses; } const Map &get_constants() const { return constants; } const Set &get_members() const { return members; } + const GDScriptDataType &get_member_type(const StringName &p_member) const { + ERR_FAIL_COND_V(!member_indices.has(p_member), GDScriptDataType()); + return member_indices[p_member].data_type; + } const Map &get_member_functions() const { return member_functions; } const Ref &get_native() const { return native; } diff --git a/modules/gdscript/gdscript_compiler.cpp b/modules/gdscript/gdscript_compiler.cpp index f15b4b83b9a..d65b22cc8c2 100644 --- a/modules/gdscript/gdscript_compiler.cpp +++ b/modules/gdscript/gdscript_compiler.cpp @@ -777,14 +777,6 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser:: case GDScriptParser::OperatorNode::OP_BIT_INVERT: { if (!_create_unary_operator(codegen, on, Variant::OP_BIT_NEGATE, p_stack_level)) return -1; } break; - case GDScriptParser::OperatorNode::OP_PREINC: { - } break; //? - case GDScriptParser::OperatorNode::OP_PREDEC: { - } break; - case GDScriptParser::OperatorNode::OP_INC: { - } break; - case GDScriptParser::OperatorNode::OP_DEC: { - } break; //binary operators (in precedence order) case GDScriptParser::OperatorNode::OP_IN: { if (!_create_binary_operator(codegen, on, Variant::OP_IN, p_stack_level)) return -1; @@ -1520,6 +1512,7 @@ Error GDScriptCompiler::_parse_function(GDScript *p_script, const GDScriptParser if (p_func) { gdfunc->_static = p_func->_static; gdfunc->rpc_mode = p_func->rpc_mode; + gdfunc->argument_types.resize(p_func->argument_types.size()); } #ifdef TOOLS_ENABLED @@ -1770,24 +1763,24 @@ Error GDScriptCompiler::_parse_class_level(GDScript *p_script, GDScript *p_owner #endif } - for (int i = 0; i < p_class->constant_expressions.size(); i++) { + for (Map::Element *E = p_class->constant_expressions.front(); E; E = E->next()) { - StringName name = p_class->constant_expressions[i].identifier; + StringName name = E->key(); - ERR_CONTINUE(p_class->constant_expressions[i].expression->type != GDScriptParser::Node::TYPE_CONSTANT); + ERR_CONTINUE(E->get().expression->type != GDScriptParser::Node::TYPE_CONSTANT); if (_is_class_member_property(p_script, name)) { _set_error("Member '" + name + "' already exists as a class property.", p_class); return ERR_ALREADY_EXISTS; } - GDScriptParser::ConstantNode *constant = static_cast(p_class->constant_expressions[i].expression); + GDScriptParser::ConstantNode *constant = static_cast(E->get().expression); p_script->constants.insert(name, constant->value); //p_script->constants[constant->value].make_const(); #ifdef TOOLS_ENABLED - p_script->member_lines[name] = p_class->constant_expressions[i].expression->line; + p_script->member_lines[name] = E->get().expression->line; #endif } diff --git a/modules/gdscript/gdscript_editor.cpp b/modules/gdscript/gdscript_editor.cpp index c8d2d2e3e86..8389f57761c 100644 --- a/modules/gdscript/gdscript_editor.cpp +++ b/modules/gdscript/gdscript_editor.cpp @@ -1236,15 +1236,11 @@ static bool _guess_identifier_type(GDScriptCompletionContext &context, int p_lin } //guess type in constant + if (context._class->constant_expressions.has(p_identifier)) { - for (int i = 0; i < context._class->constant_expressions.size(); i++) { - - if (context._class->constant_expressions[i].identifier == p_identifier) { - - ERR_FAIL_COND_V(context._class->constant_expressions[i].expression->type != GDScriptParser::Node::TYPE_CONSTANT, false); - r_type = _get_type_from_variant(static_cast(context._class->constant_expressions[i].expression)->value); - return true; - } + ERR_FAIL_COND_V(context._class->constant_expressions[p_identifier].expression->type != GDScriptParser::Node::TYPE_CONSTANT, false); + r_type = _get_type_from_variant(static_cast(context._class->constant_expressions[p_identifier].expression)->value); + return true; } if (!(context.function && context.function->_static)) { @@ -1372,8 +1368,8 @@ static void _find_identifiers_in_class(GDScriptCompletionContext &context, bool } if (!p_only_functions) { - for (int i = 0; i < context._class->constant_expressions.size(); i++) { - result.insert(context._class->constant_expressions[i].identifier); + for (Map::Element *E = context._class->constant_expressions.front(); E; E = E->next()) { + result.insert(E->key()); } for (int i = 0; i < context._class->subclasses.size(); i++) { @@ -2320,9 +2316,8 @@ Error GDScriptLanguage::complete_code(const String &p_code, const String &p_base options.insert(String(cl->variables[i].identifier)); } - for (int i = 0; i < cl->constant_expressions.size(); i++) { - - options.insert(String(cl->constant_expressions[i].identifier)); + for (Map::Element *E = cl->constant_expressions.front(); E; E = E->next()) { + options.insert(String(E->key())); } } @@ -2816,13 +2811,10 @@ Error GDScriptLanguage::lookup_code(const String &p_code, const String &p_symbol //guess in class constants - for (int i = 0; i < context._class->constant_expressions.size(); i++) { - - if (context._class->constant_expressions[i].identifier == p_symbol) { - r_result.type = ScriptLanguage::LookupResult::RESULT_SCRIPT_LOCATION; - r_result.location = context._class->constant_expressions[i].expression->line; - return OK; - } + if (context._class->constant_expressions.has(p_symbol)) { + r_result.type = ScriptLanguage::LookupResult::RESULT_SCRIPT_LOCATION; + r_result.location = context._class->constant_expressions[p_symbol].expression->line; + return OK; } //guess in class variables diff --git a/modules/gdscript/gdscript_function.cpp b/modules/gdscript/gdscript_function.cpp index 10599f0c38b..319400bbbe5 100644 --- a/modules/gdscript/gdscript_function.cpp +++ b/modules/gdscript/gdscript_function.cpp @@ -1370,6 +1370,15 @@ int GDScriptFunction::get_default_argument_addr(int p_idx) const { return default_arguments[p_idx]; } +GDScriptDataType GDScriptFunction::get_return_type() const { + return return_type; +} + +GDScriptDataType GDScriptFunction::get_argument_type(int p_idx) const { + ERR_FAIL_INDEX_V(p_idx, argument_types.size(), GDScriptDataType()); + return argument_types[p_idx]; +} + StringName GDScriptFunction::get_name() const { return name; diff --git a/modules/gdscript/gdscript_function.h b/modules/gdscript/gdscript_function.h index 770d5c8733c..62b6871b767 100644 --- a/modules/gdscript/gdscript_function.h +++ b/modules/gdscript/gdscript_function.h @@ -42,6 +42,22 @@ class GDScriptInstance; class GDScript; +struct GDScriptDataType { + bool has_type; + enum { + BUILTIN, + NATIVE, + SCRIPT, + GDSCRIPT + } kind; + Variant::Type builtin_type; + StringName native_type; + Ref