summaryrefslogtreecommitdiffstats
path: root/modules/gdscript/gdscript_analyzer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'modules/gdscript/gdscript_analyzer.cpp')
-rw-r--r--modules/gdscript/gdscript_analyzer.cpp42
1 files changed, 37 insertions, 5 deletions
diff --git a/modules/gdscript/gdscript_analyzer.cpp b/modules/gdscript/gdscript_analyzer.cpp
index 0636ac5083..28a44357eb 100644
--- a/modules/gdscript/gdscript_analyzer.cpp
+++ b/modules/gdscript/gdscript_analyzer.cpp
@@ -562,6 +562,11 @@ Error GDScriptAnalyzer::resolve_class_inheritance(GDScriptParser::ClassNode *p_c
class_type.native_type = result.native_type;
p_class->set_datatype(class_type);
+ // Add base class to the list of dependencies.
+ if (result.kind == GDScriptParser::DataType::CLASS) {
+ parser->add_dependency(result.script_path);
+ }
+
// Apply annotations.
for (GDScriptParser::AnnotationNode *&E : p_class->annotations) {
resolve_annotation(E);
@@ -722,13 +727,32 @@ GDScriptParser::DataType GDScriptAnalyzer::resolve_datatype(GDScriptParser::Type
}
} else if (ProjectSettings::get_singleton()->has_autoload(first) && ProjectSettings::get_singleton()->get_autoload(first).is_singleton) {
const ProjectSettings::AutoloadInfo &autoload = ProjectSettings::get_singleton()->get_autoload(first);
- Ref<GDScriptParserRef> ref = parser->get_depended_parser_for(autoload.path);
+ String script_path;
+ if (ResourceLoader::get_resource_type(autoload.path) == "PackedScene") {
+ // Try to get script from scene if possible.
+ if (GDScriptLanguage::get_singleton()->has_any_global_constant(autoload.name)) {
+ Variant constant = GDScriptLanguage::get_singleton()->get_any_global_constant(autoload.name);
+ Node *node = Object::cast_to<Node>(constant);
+ if (node != nullptr) {
+ Ref<GDScript> scr = node->get_script();
+ if (scr.is_valid()) {
+ script_path = scr->get_script_path();
+ }
+ }
+ }
+ } else if (ResourceLoader::get_resource_type(autoload.path) == "GDScript") {
+ script_path = autoload.path;
+ }
+ if (script_path.is_empty()) {
+ return bad_type;
+ }
+ Ref<GDScriptParserRef> ref = parser->get_depended_parser_for(script_path);
if (ref.is_null()) {
- push_error(vformat(R"(The referenced autoload "%s" (from "%s") could not be loaded.)", first, autoload.path), p_type);
+ push_error(vformat(R"(The referenced autoload "%s" (from "%s") could not be loaded.)", first, script_path), p_type);
return bad_type;
}
if (ref->raise_status(GDScriptParserRef::INHERITANCE_SOLVED) != OK) {
- push_error(vformat(R"(Could not parse singleton "%s" from "%s".)", first, autoload.path), p_type);
+ push_error(vformat(R"(Could not parse singleton "%s" from "%s".)", first, script_path), p_type);
return bad_type;
}
result = ref->get_parser()->head->get_datatype();
@@ -849,6 +873,11 @@ GDScriptParser::DataType GDScriptAnalyzer::resolve_datatype(GDScriptParser::Type
}
p_type->set_datatype(result);
+
+ if (result.kind == GDScriptParser::DataType::CLASS || result.kind == GDScriptParser::DataType::SCRIPT) {
+ parser->add_dependency(result.script_path);
+ }
+
return result;
}
@@ -3769,7 +3798,7 @@ void GDScriptAnalyzer::reduce_identifier_from_base(GDScriptParser::IdentifierNod
} break;
case GDScriptParser::ClassNode::Member::FUNCTION: {
- if (is_base && (!base.is_meta_type || member.function->is_static)) {
+ if (is_base && (!base.is_meta_type || member.function->is_static || is_constructor)) {
p_identifier->set_datatype(make_callable_type(member.function->info));
p_identifier->source = GDScriptParser::IdentifierNode::MEMBER_FUNCTION;
return;
@@ -4063,6 +4092,7 @@ void GDScriptAnalyzer::reduce_identifier(GDScriptParser::IdentifierNode *p_ident
if (ScriptServer::is_global_class(name)) {
p_identifier->set_datatype(make_global_class_meta_type(name, p_identifier));
+ parser->add_dependency(p_identifier->get_datatype().script_path);
return;
}
@@ -4105,6 +4135,7 @@ void GDScriptAnalyzer::reduce_identifier(GDScriptParser::IdentifierNode *p_ident
}
result.is_constant = true;
p_identifier->set_datatype(result);
+ parser->add_dependency(autoload.path);
return;
}
}
@@ -4224,7 +4255,6 @@ void GDScriptAnalyzer::reduce_preload(GDScriptParser::PreloadNode *p_preload) {
push_error("Preloaded path must be a constant string.", p_preload->path);
} else {
p_preload->resolved_path = p_preload->path->reduced_value;
- // TODO: Save this as script dependency.
if (p_preload->resolved_path.is_relative_path()) {
p_preload->resolved_path = parser->script_path.get_base_dir().path_join(p_preload->resolved_path);
}
@@ -4255,6 +4285,8 @@ void GDScriptAnalyzer::reduce_preload(GDScriptParser::PreloadNode *p_preload) {
push_error(vformat(R"(Could not preload resource file "%s".)", p_preload->resolved_path), p_preload->path);
}
}
+
+ parser->add_dependency(p_preload->resolved_path);
}
}