From 8aab9a06d4db1106dc733022f951db979e39f97b Mon Sep 17 00:00:00 2001 From: George Marques Date: Tue, 29 May 2018 23:16:51 -0300 Subject: Add typing syntax --- modules/gdscript/gdscript.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'modules/gdscript/gdscript.cpp') diff --git a/modules/gdscript/gdscript.cpp b/modules/gdscript/gdscript.cpp index b3ebd4fe4b..f221aac5fe 100644 --- a/modules/gdscript/gdscript.cpp +++ b/modules/gdscript/gdscript.cpp @@ -1735,7 +1735,9 @@ void GDScriptLanguage::get_reserved_words(List *p_words) const { "NAN", "self", "true", + "void", // functions + "as", "assert", "breakpoint", "class", -- cgit v1.2.3 From b7a00aead039a988f9e224ef5ad19688a17c971c Mon Sep 17 00:00:00 2001 From: George Marques Date: Tue, 29 May 2018 23:16:52 -0300 Subject: Move inheritance resolution to the parser --- modules/gdscript/gdscript.cpp | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) (limited to 'modules/gdscript/gdscript.cpp') diff --git a/modules/gdscript/gdscript.cpp b/modules/gdscript/gdscript.cpp index f221aac5fe..ae8dcfc370 100644 --- a/modules/gdscript/gdscript.cpp +++ b/modules/gdscript/gdscript.cpp @@ -1826,8 +1826,40 @@ String GDScriptLanguage::get_global_class_name(const String &p_path, String *r_b if (parser.get_parse_tree() && parser.get_parse_tree()->type == GDScriptParser::Node::TYPE_CLASS) { const GDScriptParser::ClassNode *c = static_cast(parser.get_parse_tree()); - if (r_base_type && c->extends_used && c->extends_class.size() == 1) { - *r_base_type = c->extends_class[0]; //todo, should work much better + if (r_base_type) { + GDScriptParser::DataType base_type; + if (c->base_type.has_type) { + base_type = c->base_type; + while (base_type.has_type && base_type.kind != GDScriptParser::DataType::NATIVE) { + switch (base_type.kind) { + case GDScriptParser::DataType::CLASS: { + base_type = base_type.class_type->base_type; + } break; + case GDScriptParser::DataType::GDSCRIPT: { + Ref gds = base_type.script_type; + if (gds.is_valid()) { + base_type.kind = GDScriptParser::DataType::NATIVE; + base_type.native_type = gds->get_instance_base_type(); + } else { + base_type = GDScriptParser::DataType(); + } + } break; + default: { + base_type = GDScriptParser::DataType(); + } break; + } + } + } + if (base_type.has_type) { + *r_base_type = base_type.native_type; + } else { + // Fallback + if (c->extends_used && c->extends_class.size() == 1) { + *r_base_type = c->extends_class[0]; + } else if (!c->extends_used) { + *r_base_type = "Reference"; + } + } } return c->name; } -- cgit v1.2.3 From 4b18c4e448c93fbb44c80b89e744cfacea8d8bc4 Mon Sep 17 00:00:00 2001 From: George Marques Date: Tue, 29 May 2018 23:16:56 -0300 Subject: Add typed instructions to GDScript - Typed assignment (built-in, native, and script). - Cast (built-in conversion; native and script checks). - Check type of functions arguments on call. - Check type of members on set. --- modules/gdscript/gdscript.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'modules/gdscript/gdscript.cpp') diff --git a/modules/gdscript/gdscript.cpp b/modules/gdscript/gdscript.cpp index ae8dcfc370..a8916c2a2e 100644 --- a/modules/gdscript/gdscript.cpp +++ b/modules/gdscript/gdscript.cpp @@ -941,8 +941,12 @@ bool GDScriptInstance::set(const StringName &p_name, const Variant &p_value) { if (err.error == Variant::CallError::CALL_OK) { return true; //function exists, call was successful } - } else + } else { + if (!E->get().data_type.is_type(p_value)) { + return false; // Type mismatch + } members[E->get().index] = p_value; + } return true; } } -- cgit v1.2.3 From e3d72d14ff27af2b396397065ddc38f87685c694 Mon Sep 17 00:00:00 2001 From: George Marques Date: Tue, 29 May 2018 23:16:57 -0300 Subject: Use type information to enable GDScript introspection This makes the Script API provide accurate information when requesting property or method info. --- modules/gdscript/gdscript.cpp | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) (limited to 'modules/gdscript/gdscript.cpp') diff --git a/modules/gdscript/gdscript.cpp b/modules/gdscript/gdscript.cpp index a8916c2a2e..8bd29ffc55 100644 --- a/modules/gdscript/gdscript.cpp +++ b/modules/gdscript/gdscript.cpp @@ -220,16 +220,14 @@ void GDScript::_placeholder_erased(PlaceHolderScriptInstance *p_placeholder) { void GDScript::get_script_method_list(List *p_list) const { for (const Map::Element *E = member_functions.front(); E; E = E->next()) { + GDScriptFunction *func = E->get(); MethodInfo mi; mi.name = E->key(); - for (int i = 0; i < E->get()->get_argument_count(); i++) { - PropertyInfo arg; - arg.type = Variant::NIL; //variant - arg.name = E->get()->get_argument_name(i); - mi.arguments.push_back(arg); + for (int i = 0; i < func->get_argument_count(); i++) { + mi.arguments.push_back(func->get_argument_type(i)); } - mi.return_val.name = "Variant"; + mi.return_val = func->get_return_type(); p_list->push_back(mi); } } @@ -277,16 +275,14 @@ MethodInfo GDScript::get_method_info(const StringName &p_method) const { if (!E) return MethodInfo(); + GDScriptFunction *func = E->get(); MethodInfo mi; mi.name = E->key(); - for (int i = 0; i < E->get()->get_argument_count(); i++) { - PropertyInfo arg; - arg.type = Variant::NIL; //variant - arg.name = E->get()->get_argument_name(i); - mi.arguments.push_back(arg); + for (int i = 0; i < func->get_argument_count(); i++) { + mi.arguments.push_back(func->get_argument_type(i)); } - mi.return_val.name = "Variant"; + mi.return_val = func->get_return_type(); return mi; } -- cgit v1.2.3