diff options
author | George Marques <george@gmarqu.es> | 2019-03-03 16:36:42 -0300 |
---|---|---|
committer | George Marques <george@gmarqu.es> | 2019-03-03 16:51:54 -0300 |
commit | bda60bfa29a43315755bac92dc15fb0a1a30c22e (patch) | |
tree | 04b23f17700651850e109e43ca5b8187ff400af5 /modules/gdscript/gdscript_parser.cpp | |
parent | 4f0590338f0506b74a3a154112598fadb442e13d (diff) |
Add a dependency search mode for GDScript parser
- This mode avoids loading any other resource.
- Search for class_name now uses this mode, to avoid loading in the scan
thread.
- Implement get_dependencies() for GDScript loader, now exporting
dependencies only should include the preloaded resources.
Diffstat (limited to 'modules/gdscript/gdscript_parser.cpp')
-rw-r--r-- | modules/gdscript/gdscript_parser.cpp | 74 |
1 files changed, 46 insertions, 28 deletions
diff --git a/modules/gdscript/gdscript_parser.cpp b/modules/gdscript/gdscript_parser.cpp index 5ebf68177d..36b6a0dec6 100644 --- a/modules/gdscript/gdscript_parser.cpp +++ b/modules/gdscript/gdscript_parser.cpp @@ -473,29 +473,31 @@ GDScriptParser::Node *GDScriptParser::_parse_expression(Node *p_parent, bool p_s } Ref<Resource> res; - if (!validating) { + dependencies.push_back(path); + if (!dependencies_only) { + if (!validating) { - //this can be too slow for just validating code - if (for_completion && ScriptCodeCompletionCache::get_singleton() && FileAccess::exists(path)) { - res = ScriptCodeCompletionCache::get_singleton()->get_cached_resource(path); - } else if (!for_completion || FileAccess::exists(path)) { - res = ResourceLoader::load(path); - } - } else { + //this can be too slow for just validating code + if (for_completion && ScriptCodeCompletionCache::get_singleton() && FileAccess::exists(path)) { + res = ScriptCodeCompletionCache::get_singleton()->get_cached_resource(path); + } else if (!for_completion || FileAccess::exists(path)) { + res = ResourceLoader::load(path); + } + } else { - if (!FileAccess::exists(path)) { + if (!FileAccess::exists(path)) { + _set_error("Can't preload resource at path: " + path); + return NULL; + } else if (ScriptCodeCompletionCache::get_singleton()) { + res = ScriptCodeCompletionCache::get_singleton()->get_cached_resource(path); + } + } + if (!res.is_valid()) { _set_error("Can't preload resource at path: " + path); return NULL; - } else if (ScriptCodeCompletionCache::get_singleton()) { - res = ScriptCodeCompletionCache::get_singleton()->get_cached_resource(path); } } - if (!res.is_valid()) { - _set_error("Can't preload resource at path: " + path); - return NULL; - } - if (tokenizer->get_token() != GDScriptTokenizer::TK_PARENTHESIS_CLOSE) { _set_error("Expected ')' after 'preload' path"); return NULL; @@ -812,17 +814,19 @@ GDScriptParser::Node *GDScriptParser::_parse_expression(Node *p_parent, bool p_s bfn = true; } - // Check parents for the constant - if (!bfn && cln->extends_file != StringName()) { - Ref<GDScript> parent = ResourceLoader::load(cln->extends_file); - if (parent.is_valid() && parent->is_valid()) { - Map<StringName, Variant> parent_constants; - parent->get_constants(&parent_constants); - if (parent_constants.has(identifier)) { - ConstantNode *constant = alloc_node<ConstantNode>(); - constant->value = parent_constants[identifier]; - expr = constant; - bfn = true; + if (!dependencies_only) { + // Check parents for the constant + if (!bfn && cln->extends_file != StringName()) { + Ref<GDScript> parent = ResourceLoader::load(cln->extends_file); + if (parent.is_valid() && parent->is_valid()) { + Map<StringName, Variant> parent_constants; + parent->get_constants(&parent_constants); + if (parent_constants.has(identifier)) { + ConstantNode *constant = alloc_node<ConstantNode>(); + constant->value = parent_constants[identifier]; + expr = constant; + bfn = true; + } } } } @@ -3378,6 +3382,13 @@ void GDScriptParser::_parse_extends(ClassNode *p_class) { p_class->extends_file = constant; tokenizer->advance(); + // Add parent script as a dependency + String parent = constant; + if (parent.is_rel_path()) { + parent = base_path.plus_file(parent).simplify_path(); + } + dependencies.push_back(parent); + if (tokenizer->get_token() != GDScriptTokenizer::TK_PERIOD) { return; } else @@ -8149,6 +8160,10 @@ Error GDScriptParser::_parse(const String &p_base_path) { return ERR_PARSE_ERROR; } + if (dependencies_only) { + return OK; + } + _determine_inheritance(main_class); if (error_set) { @@ -8227,7 +8242,7 @@ Error GDScriptParser::parse_bytecode(const Vector<uint8_t> &p_bytecode, const St return ret; } -Error GDScriptParser::parse(const String &p_code, const String &p_base_path, bool p_just_validate, const String &p_self_path, bool p_for_completion, Set<int> *r_safe_lines) { +Error GDScriptParser::parse(const String &p_code, const String &p_base_path, bool p_just_validate, const String &p_self_path, bool p_for_completion, Set<int> *r_safe_lines, bool p_dependencies_only) { clear(); @@ -8237,6 +8252,7 @@ Error GDScriptParser::parse(const String &p_code, const String &p_base_path, boo validating = p_just_validate; for_completion = p_for_completion; + dependencies_only = p_dependencies_only; #ifdef DEBUG_ENABLED safe_lines = r_safe_lines; #endif // DEBUG_ENABLED @@ -8293,6 +8309,8 @@ void GDScriptParser::clear() { parenthesis = 0; current_export.type = Variant::NIL; check_types = true; + dependencies_only = false; + dependencies.clear(); error = ""; #ifdef DEBUG_ENABLED safe_lines = NULL; |