@@ -312,15 +312,6 @@ Error GDScriptAnalyzer::resolve_class_inheritance(GDScriptParser::ClassNode *p_c
312
312
p_source = p_class;
313
313
}
314
314
315
- Ref<GDScriptParserRef> parser_ref = ensure_cached_parser_for_class (p_class, nullptr , vformat (R"( Trying to resolve class inheritance of "%s" from "%s")" , p_class->fqcn , parser->script_path ), p_source);
316
- Finally finally ([&]() {
317
- GDScriptParser::ClassNode *look_class = p_class;
318
- do {
319
- ensure_cached_parser_for_class (look_class->base_type .class_type , look_class, vformat (R"( Trying to resolve class inheritance of "%s" from "%s")" , p_class->fqcn , parser->script_path ), p_source);
320
- look_class = look_class->base_type .class_type ;
321
- } while (look_class != nullptr );
322
- });
323
-
324
315
if (p_class->base_type .is_resolving ()) {
325
316
push_error (vformat (R"( Could not resolve class "%s": Cyclic reference.)" , type_from_metatype (p_class->get_datatype ()).to_string ()), p_source);
326
317
return ERR_PARSE_ERROR;
@@ -332,17 +323,21 @@ Error GDScriptAnalyzer::resolve_class_inheritance(GDScriptParser::ClassNode *p_c
332
323
}
333
324
334
325
if (!parser->has_class (p_class)) {
326
+ String script_path = p_class->get_datatype ().script_path ;
327
+ Ref<GDScriptParserRef> parser_ref = parser->get_depended_parser_for (script_path);
335
328
if (parser_ref.is_null ()) {
336
- // Error already pushed.
329
+ push_error ( vformat ( R"( Could not find script "%s". )" , script_path), p_source);
337
330
return ERR_PARSE_ERROR;
338
331
}
339
332
340
333
Error err = parser_ref->raise_status (GDScriptParserRef::PARSED);
341
334
if (err) {
342
- push_error (vformat (R"( Could not parse script "%s": %s.)" , p_class-> get_datatype (). script_path , error_names[err]), p_source);
335
+ push_error (vformat (R"( Could not parse script "%s": %s.)" , script_path, error_names[err]), p_source);
343
336
return ERR_PARSE_ERROR;
344
337
}
345
338
339
+ ERR_FAIL_COND_V_MSG (!parser_ref->get_parser ()->has_class (p_class), ERR_PARSE_ERROR, R"( Parser bug: Mismatched external parser.)" );
340
+
346
341
GDScriptAnalyzer *other_analyzer = parser_ref->get_analyzer ();
347
342
GDScriptParser *other_parser = parser_ref->get_parser ();
348
343
@@ -888,11 +883,6 @@ void GDScriptAnalyzer::resolve_class_member(GDScriptParser::ClassNode *p_class,
888
883
p_source = member.get_source_node ();
889
884
}
890
885
891
- Ref<GDScriptParserRef> parser_ref = ensure_cached_parser_for_class (p_class, nullptr , vformat (R"( Trying to resolve class member "%s" of "%s" from "%s")" , member.get_name (), p_class->fqcn , parser->script_path ), p_source);
892
- Finally finally ([&]() {
893
- ensure_cached_parser_for_class (member.get_datatype ().class_type , p_class, vformat (R"( Trying to resolve class member "%s" of "%s" from "%s")" , member.get_name (), p_class->fqcn , parser->script_path ), p_source);
894
- });
895
-
896
886
if (member.get_datatype ().is_resolving ()) {
897
887
push_error (vformat (R"( Could not resolve member "%s": Cyclic reference.)" , member.get_name ()), p_source);
898
888
return ;
@@ -902,39 +892,42 @@ void GDScriptAnalyzer::resolve_class_member(GDScriptParser::ClassNode *p_class,
902
892
return ;
903
893
}
904
894
905
- // If it's already resolving, that's ok.
906
- if (!p_class->base_type .is_resolving ()) {
907
- Error err = resolve_class_inheritance (p_class);
908
- if (err) {
909
- return ;
910
- }
911
- }
912
-
913
895
if (!parser->has_class (p_class)) {
896
+ String script_path = p_class->get_datatype ().script_path ;
897
+ Ref<GDScriptParserRef> parser_ref = parser->get_depended_parser_for (script_path);
914
898
if (parser_ref.is_null ()) {
915
- // Error already pushed.
899
+ push_error ( vformat ( R"( Could not find script "%s" (While resolving "%s"). )" , script_path, member. get_name ()), p_source);
916
900
return ;
917
901
}
918
902
919
903
Error err = parser_ref->raise_status (GDScriptParserRef::PARSED);
920
904
if (err) {
921
- push_error (vformat (R"( Could not parse script "%s": %s (While resolving member "%s").)" , p_class-> get_datatype (). script_path , error_names[err], member.get_name ()), p_source);
905
+ push_error (vformat (R"( Could not resolve script "%s": %s (While resolving "%s").)" , script_path, error_names[err], member.get_name ()), p_source);
922
906
return ;
923
907
}
924
908
909
+ ERR_FAIL_COND_MSG (!parser_ref->get_parser ()->has_class (p_class), R"( Parser bug: Mismatched external parser.)" );
910
+
925
911
GDScriptAnalyzer *other_analyzer = parser_ref->get_analyzer ();
926
912
GDScriptParser *other_parser = parser_ref->get_parser ();
927
913
928
914
int error_count = other_parser->errors .size ();
929
915
other_analyzer->resolve_class_member (p_class, p_index);
930
916
if (other_parser->errors .size () > error_count) {
931
917
push_error (vformat (R"( Could not resolve member "%s".)" , member.get_name ()), p_source);
932
- return ;
933
918
}
934
919
935
920
return ;
936
921
}
937
922
923
+ // If it's already resolving, that's ok.
924
+ if (!p_class->base_type .is_resolving ()) {
925
+ Error err = resolve_class_inheritance (p_class);
926
+ if (err) {
927
+ return ;
928
+ }
929
+ }
930
+
938
931
GDScriptParser::ClassNode *previous_class = parser->current_class ;
939
932
parser->current_class = p_class;
940
933
@@ -1177,33 +1170,34 @@ void GDScriptAnalyzer::resolve_class_interface(GDScriptParser::ClassNode *p_clas
1177
1170
p_source = p_class;
1178
1171
}
1179
1172
1180
- Ref<GDScriptParserRef> parser_ref = ensure_cached_parser_for_class (p_class, nullptr , vformat (R"( Trying to resolve class interface of "%s" from "%s")" , p_class->fqcn , parser->script_path ), p_source);
1181
-
1182
1173
if (!p_class->resolved_interface ) {
1183
1174
#ifdef DEBUG_ENABLED
1184
1175
bool has_static_data = p_class->has_static_data ;
1185
1176
#endif
1186
1177
1187
1178
if (!parser->has_class (p_class)) {
1179
+ String script_path = p_class->get_datatype ().script_path ;
1180
+ Ref<GDScriptParserRef> parser_ref = parser->get_depended_parser_for (script_path);
1188
1181
if (parser_ref.is_null ()) {
1189
- // Error already pushed.
1182
+ push_error ( vformat ( R"( Could not find script "%s". )" , script_path), p_source);
1190
1183
return ;
1191
1184
}
1192
1185
1193
1186
Error err = parser_ref->raise_status (GDScriptParserRef::PARSED);
1194
1187
if (err) {
1195
- push_error (vformat (R"( Could not parse script "%s": %s.)" , p_class-> get_datatype (). script_path , error_names[err]), p_source);
1188
+ push_error (vformat (R"( Could not resolve script "%s": %s.)" , script_path, error_names[err]), p_source);
1196
1189
return ;
1197
1190
}
1198
1191
1192
+ ERR_FAIL_COND_MSG (!parser_ref->get_parser ()->has_class (p_class), R"( Parser bug: Mismatched external parser.)" );
1193
+
1199
1194
GDScriptAnalyzer *other_analyzer = parser_ref->get_analyzer ();
1200
1195
GDScriptParser *other_parser = parser_ref->get_parser ();
1201
1196
1202
1197
int error_count = other_parser->errors .size ();
1203
1198
other_analyzer->resolve_class_interface (p_class);
1204
1199
if (other_parser->errors .size () > error_count) {
1205
1200
push_error (vformat (R"( Could not resolve class "%s".)" , p_class->fqcn ), p_source);
1206
- return ;
1207
1201
}
1208
1202
1209
1203
return ;
@@ -1267,32 +1261,33 @@ void GDScriptAnalyzer::resolve_class_body(GDScriptParser::ClassNode *p_class, co
1267
1261
p_source = p_class;
1268
1262
}
1269
1263
1270
- Ref<GDScriptParserRef> parser_ref = ensure_cached_parser_for_class (p_class, nullptr , vformat (R"( Trying to resolve class body of "%s" from "%s")" , p_class->fqcn , parser->script_path ), p_source);
1271
-
1272
1264
if (p_class->resolved_body ) {
1273
1265
return ;
1274
1266
}
1275
1267
1276
1268
if (!parser->has_class (p_class)) {
1269
+ String script_path = p_class->get_datatype ().script_path ;
1270
+ Ref<GDScriptParserRef> parser_ref = parser->get_depended_parser_for (script_path);
1277
1271
if (parser_ref.is_null ()) {
1278
- // Error already pushed.
1272
+ push_error ( vformat ( R"( Could not find script "%s". )" , script_path), p_source);
1279
1273
return ;
1280
1274
}
1281
1275
1282
1276
Error err = parser_ref->raise_status (GDScriptParserRef::PARSED);
1283
1277
if (err) {
1284
- push_error (vformat (R"( Could not parse script "%s": %s.)" , p_class-> get_datatype (). script_path , error_names[err]), p_source);
1278
+ push_error (vformat (R"( Could not resolve script "%s": %s.)" , script_path, error_names[err]), p_source);
1285
1279
return ;
1286
1280
}
1287
1281
1282
+ ERR_FAIL_COND_MSG (!parser_ref->get_parser ()->has_class (p_class), R"( Parser bug: Mismatched external parser.)" );
1283
+
1288
1284
GDScriptAnalyzer *other_analyzer = parser_ref->get_analyzer ();
1289
1285
GDScriptParser *other_parser = parser_ref->get_parser ();
1290
1286
1291
1287
int error_count = other_parser->errors .size ();
1292
1288
other_analyzer->resolve_class_body (p_class);
1293
1289
if (other_parser->errors .size () > error_count) {
1294
1290
push_error (vformat (R"( Could not resolve class "%s".)" , p_class->fqcn ), p_source);
1295
- return ;
1296
1291
}
1297
1292
1298
1293
return ;
@@ -3650,81 +3645,12 @@ GDScriptParser::DataType GDScriptAnalyzer::make_global_class_meta_type(const Str
3650
3645
}
3651
3646
}
3652
3647
3653
- Ref<GDScriptParserRef> GDScriptAnalyzer::ensure_cached_parser_for_class (const GDScriptParser::ClassNode *p_class, const GDScriptParser::ClassNode *p_from_class, const String &p_context, const GDScriptParser::Node *p_source) {
3654
- if (p_class == nullptr ) {
3655
- return nullptr ;
3656
- }
3657
-
3658
- if (parser->has_class (p_class)) {
3659
- return nullptr ;
3660
- }
3661
-
3662
- {
3663
- HashMap<const GDScriptParser::ClassNode *, Ref<GDScriptParserRef>>::Iterator E = external_class_parser_cache.find (p_class);
3664
- if (E) {
3665
- return E->value ;
3666
- }
3667
- }
3668
-
3669
- Ref<GDScriptParserRef> parser_ref;
3670
- Ref<GDScriptParserRef> dependant_parser_ref;
3671
- GDScriptParser *dependant_parser = parser;
3672
- do {
3673
- if (HashMap<const GDScriptParser::ClassNode *, Ref<GDScriptParserRef>>::Iterator E = external_class_parser_cache.find (p_from_class)) {
3674
- dependant_parser_ref = E->value ;
3675
- dependant_parser = E->value ->get_parser ();
3676
-
3677
- // Silently ensure it's parsed.
3678
- dependant_parser_ref->raise_status (GDScriptParserRef::PARSED);
3679
- }
3680
-
3681
- if (dependant_parser == nullptr ) {
3682
- continue ;
3683
- }
3684
-
3685
- if (dependant_parser_ref.is_valid () && dependant_parser->has_class (p_class)) {
3686
- external_class_parser_cache.insert (p_class, dependant_parser_ref);
3687
- parser_ref = dependant_parser_ref;
3688
- break ;
3689
- }
3690
-
3691
- String script_path = p_class->get_datatype ().script_path ;
3692
- HashMap<String, Ref<GDScriptParserRef>>::Iterator E = dependant_parser->depended_parsers .find (script_path);
3693
- if (E) {
3694
- // Silently ensure it's parsed.
3695
- E->value ->raise_status (GDScriptParserRef::PARSED);
3696
- if (E->value ->get_parser ()->has_class (p_class)) {
3697
- external_class_parser_cache.insert (p_class, E->value );
3698
- parser_ref = E->value ;
3699
- break ;
3700
- }
3701
- }
3702
-
3703
- dependant_parser_ref = Ref<GDScriptParserRef>();
3704
- dependant_parser = nullptr ;
3705
- p_from_class = p_from_class->base_type .class_type ;
3706
- } while (p_from_class != nullptr );
3707
-
3708
- if (parser_ref.is_null ()) {
3709
- push_error (vformat (R"( Parser bug: Could not find external parser. (%s))" , p_context), p_source);
3710
- }
3711
-
3712
- return parser_ref;
3713
- }
3714
-
3715
- Ref<GDScript> GDScriptAnalyzer::get_depended_shallow_script (const String &p_path, Error &r_error) {
3716
- // To keep a local cache of the parser for resolving external nodes later.
3717
- parser->get_depended_parser_for (p_path);
3718
- Ref<GDScript> scr = GDScriptCache::get_shallow_script (p_path, r_error, parser->script_path );
3719
- return scr;
3720
- }
3721
-
3722
3648
void GDScriptAnalyzer::reduce_identifier_from_base_set_class (GDScriptParser::IdentifierNode *p_identifier, GDScriptParser::DataType p_identifier_datatype) {
3723
3649
ERR_FAIL_NULL (p_identifier);
3724
3650
3725
3651
p_identifier->set_datatype (p_identifier_datatype);
3726
3652
Error err = OK;
3727
- Ref<GDScript> scr = get_depended_shallow_script (p_identifier_datatype.script_path , err);
3653
+ Ref<GDScript> scr = GDScriptCache::get_shallow_script (p_identifier_datatype.script_path , err, parser-> script_path );
3728
3654
if (err) {
3729
3655
push_error (vformat (R"( Error while getting cache for script "%s".)" , p_identifier_datatype.script_path ), p_identifier);
3730
3656
return ;
@@ -4414,7 +4340,7 @@ void GDScriptAnalyzer::reduce_preload(GDScriptParser::PreloadNode *p_preload) {
4414
4340
const String &res_type = ResourceLoader::get_resource_type (p_preload->resolved_path );
4415
4341
if (res_type == " GDScript" ) {
4416
4342
Error err = OK;
4417
- Ref<GDScript> res = get_depended_shallow_script (p_preload->resolved_path , err);
4343
+ Ref<GDScript> res = GDScriptCache::get_shallow_script (p_preload->resolved_path , err, parser-> script_path );
4418
4344
p_preload->resource = res;
4419
4345
if (err != OK) {
4420
4346
push_error (vformat (R"( Could not preload resource script "%s".)" , p_preload->resolved_path ), p_preload->path );
@@ -4990,7 +4916,7 @@ Array GDScriptAnalyzer::make_array_from_element_datatype(const GDScriptParser::D
4990
4916
Ref<Script> script_type = p_element_datatype.script_type ;
4991
4917
if (p_element_datatype.kind == GDScriptParser::DataType::CLASS && script_type.is_null ()) {
4992
4918
Error err = OK;
4993
- Ref<GDScript> scr = get_depended_shallow_script (p_element_datatype.script_path , err);
4919
+ Ref<GDScript> scr = GDScriptCache::get_shallow_script (p_element_datatype.script_path , err, parser-> script_path );
4994
4920
if (err) {
4995
4921
push_error (vformat (R"( Error while getting cache for script "%s".)" , p_element_datatype.script_path ), p_source_node);
4996
4922
return array;
0 commit comments