summaryrefslogtreecommitdiff
path: root/modules/gdscript
diff options
context:
space:
mode:
authorAaron Franke <arnfranke@yahoo.com>2021-07-15 23:45:57 -0400
committerAaron Franke <arnfranke@yahoo.com>2021-07-23 17:38:28 -0400
commit4e6efd1b07f1c6d53d226977ddc729333b74306a (patch)
treea52f672e7f622bb65e3b65f2a2edc9d19b1ecdcf /modules/gdscript
parentb918c4c3ce84af1f8af2d06ef31784f48a15551a (diff)
Use C++ iterators for Lists in many situations
Diffstat (limited to 'modules/gdscript')
-rw-r--r--modules/gdscript/editor/gdscript_highlighter.cpp36
-rw-r--r--modules/gdscript/gdscript.cpp61
-rw-r--r--modules/gdscript/gdscript_analyzer.cpp55
-rw-r--r--modules/gdscript/gdscript_byte_codegen.cpp16
-rw-r--r--modules/gdscript/gdscript_compiler.cpp3
-rw-r--r--modules/gdscript/gdscript_editor.cpp166
-rw-r--r--modules/gdscript/gdscript_function.cpp9
-rw-r--r--modules/gdscript/gdscript_parser.cpp21
-rw-r--r--modules/gdscript/gdscript_utility_functions.cpp4
-rw-r--r--modules/gdscript/language_server/gdscript_extend_parser.cpp10
-rw-r--r--modules/gdscript/language_server/gdscript_text_document.cpp15
-rw-r--r--modules/gdscript/language_server/gdscript_workspace.cpp10
-rw-r--r--modules/gdscript/tests/gdscript_test_runner.cpp14
-rw-r--r--modules/gdscript/tests/test_gdscript.cpp12
14 files changed, 205 insertions, 227 deletions
diff --git a/modules/gdscript/editor/gdscript_highlighter.cpp b/modules/gdscript/editor/gdscript_highlighter.cpp
index 9a4c22f49f..b19a57d56a 100644
--- a/modules/gdscript/editor/gdscript_highlighter.cpp
+++ b/modules/gdscript/editor/gdscript_highlighter.cpp
@@ -458,8 +458,8 @@ void GDScriptSyntaxHighlighter::_update_cache() {
const Color types_color = EDITOR_GET("text_editor/highlighting/engine_type_color");
List<StringName> types;
ClassDB::get_class_list(&types);
- for (List<StringName>::Element *E = types.front(); E; E = E->next()) {
- String n = E->get();
+ for (StringName &E : types) {
+ String n = E;
if (n.begins_with("_")) {
n = n.substr(1, n.length());
}
@@ -470,8 +470,8 @@ void GDScriptSyntaxHighlighter::_update_cache() {
const Color usertype_color = EDITOR_GET("text_editor/highlighting/user_type_color");
List<StringName> global_classes;
ScriptServer::get_global_class_list(&global_classes);
- for (List<StringName>::Element *E = global_classes.front(); E; E = E->next()) {
- keywords[String(E->get())] = usertype_color;
+ for (StringName &E : global_classes) {
+ keywords[String(E)] = usertype_color;
}
/* Autoloads. */
@@ -489,8 +489,8 @@ void GDScriptSyntaxHighlighter::_update_cache() {
const Color basetype_color = EDITOR_GET("text_editor/highlighting/base_type_color");
List<String> core_types;
gdscript->get_core_type_words(&core_types);
- for (List<String>::Element *E = core_types.front(); E; E = E->next()) {
- keywords[E->get()] = basetype_color;
+ for (String &E : core_types) {
+ keywords[E] = basetype_color;
}
/* Reserved words. */
@@ -498,11 +498,11 @@ void GDScriptSyntaxHighlighter::_update_cache() {
const Color control_flow_keyword_color = EDITOR_GET("text_editor/highlighting/control_flow_keyword_color");
List<String> keyword_list;
gdscript->get_reserved_words(&keyword_list);
- for (List<String>::Element *E = keyword_list.front(); E; E = E->next()) {
- if (gdscript->is_control_flow_keyword(E->get())) {
- keywords[E->get()] = control_flow_keyword_color;
+ for (String &E : keyword_list) {
+ if (gdscript->is_control_flow_keyword(E)) {
+ keywords[E] = control_flow_keyword_color;
} else {
- keywords[E->get()] = keyword_color;
+ keywords[E] = keyword_color;
}
}
@@ -510,8 +510,7 @@ void GDScriptSyntaxHighlighter::_update_cache() {
const Color comment_color = EDITOR_GET("text_editor/highlighting/comment_color");
List<String> comments;
gdscript->get_comment_delimiters(&comments);
- for (List<String>::Element *E = comments.front(); E; E = E->next()) {
- String comment = E->get();
+ for (String &comment : comments) {
String beg = comment.get_slice(" ", 0);
String end = comment.get_slice_count(" ") > 1 ? comment.get_slice(" ", 1) : String();
add_color_region(beg, end, comment_color, end == "");
@@ -521,8 +520,7 @@ void GDScriptSyntaxHighlighter::_update_cache() {
const Color string_color = EDITOR_GET("text_editor/highlighting/string_color");
List<String> strings;
gdscript->get_string_delimiters(&strings);
- for (List<String>::Element *E = strings.front(); E; E = E->next()) {
- String string = E->get();
+ for (String &string : strings) {
String beg = string.get_slice(" ", 0);
String end = string.get_slice_count(" ") > 1 ? string.get_slice(" ", 1) : String();
add_color_region(beg, end, string_color, end == "");
@@ -536,9 +534,9 @@ void GDScriptSyntaxHighlighter::_update_cache() {
if (instance_base != StringName()) {
List<PropertyInfo> plist;
ClassDB::get_property_list(instance_base, &plist);
- for (List<PropertyInfo>::Element *E = plist.front(); E; E = E->next()) {
- String name = E->get().name;
- if (E->get().usage & PROPERTY_USAGE_CATEGORY || E->get().usage & PROPERTY_USAGE_GROUP || E->get().usage & PROPERTY_USAGE_SUBGROUP) {
+ for (PropertyInfo &E : plist) {
+ String name = E.name;
+ if (E.usage & PROPERTY_USAGE_CATEGORY || E.usage & PROPERTY_USAGE_GROUP || E.usage & PROPERTY_USAGE_SUBGROUP) {
continue;
}
if (name.find("/") != -1) {
@@ -549,8 +547,8 @@ void GDScriptSyntaxHighlighter::_update_cache() {
List<String> clist;
ClassDB::get_integer_constant_list(instance_base, &clist);
- for (List<String>::Element *E = clist.front(); E; E = E->next()) {
- member_keywords[E->get()] = member_variable_color;
+ for (String &E : clist) {
+ member_keywords[E] = member_variable_color;
}
}
}
diff --git a/modules/gdscript/gdscript.cpp b/modules/gdscript/gdscript.cpp
index f7113674ec..79cc90b92f 100644
--- a/modules/gdscript/gdscript.cpp
+++ b/modules/gdscript/gdscript.cpp
@@ -291,8 +291,8 @@ void GDScript::_get_script_property_list(List<PropertyInfo> *r_list, bool p_incl
sptr = sptr->_base;
}
- for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) {
- r_list->push_back(E->get());
+ for (PropertyInfo &E : props) {
+ r_list->push_back(E);
}
}
@@ -401,8 +401,8 @@ void GDScript::_update_exports_values(Map<StringName, Variant> &values, List<Pro
values[E->key()] = E->get();
}
- for (List<PropertyInfo>::Element *E = members_cache.front(); E; E = E->next()) {
- propnames.push_back(E->get());
+ for (PropertyInfo &E : members_cache) {
+ propnames.push_back(E);
}
}
@@ -861,8 +861,8 @@ Error GDScript::reload(bool p_keep_state) {
}
}
#ifdef DEBUG_ENABLED
- for (const List<GDScriptWarning>::Element *E = parser.get_warnings().front(); E; E = E->next()) {
- const GDScriptWarning &warning = E->get();
+ for (const GDScriptWarning &E : parser.get_warnings()) {
+ const GDScriptWarning &warning = E;
if (EngineDebugger::is_active()) {
Vector<ScriptLanguage::StackInfo> si;
EngineDebugger::get_script_debugger()->send_error("", get_path(), warning.start_line, warning.get_name(), warning.get_message(), ERR_HANDLER_WARNING, si);
@@ -1445,8 +1445,8 @@ void GDScriptInstance::get_property_list(List<PropertyInfo> *p_properties) const
sptr = sptr->_base;
}
- for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) {
- p_properties->push_back(E->get());
+ for (PropertyInfo &E : props) {
+ p_properties->push_back(E);
}
}
@@ -1644,8 +1644,7 @@ void GDScriptLanguage::init() {
List<StringName> class_list;
ClassDB::get_class_list(&class_list);
- for (List<StringName>::Element *E = class_list.front(); E; E = E->next()) {
- StringName n = E->get();
+ for (StringName &n : class_list) {
String s = String(n);
if (s.begins_with("_")) {
n = s.substr(1, s.length());
@@ -1654,7 +1653,7 @@ void GDScriptLanguage::init() {
if (globals.has(n)) {
continue;
}
- Ref<GDScriptNativeClass> nc = memnew(GDScriptNativeClass(E->get()));
+ Ref<GDScriptNativeClass> nc = memnew(GDScriptNativeClass(n));
_add_global(n, nc);
}
@@ -1662,8 +1661,8 @@ void GDScriptLanguage::init() {
List<Engine::Singleton> singletons;
Engine::get_singleton()->get_singletons(&singletons);
- for (List<Engine::Singleton>::Element *E = singletons.front(); E; E = E->next()) {
- _add_global(E->get().name, E->get().ptr);
+ for (Engine::Singleton &E : singletons) {
+ _add_global(E.name, E.ptr);
}
#ifdef TESTS_ENABLED
@@ -1806,10 +1805,10 @@ void GDScriptLanguage::reload_all_scripts() {
scripts.sort_custom<GDScriptDepSort>(); //update in inheritance dependency order
- for (List<Ref<GDScript>>::Element *E = scripts.front(); E; E = E->next()) {
- print_verbose("GDScript: Reloading: " + E->get()->get_path());
- E->get()->load_source_code(E->get()->get_path());
- E->get()->reload(true);
+ for (Ref<GDScript> E : scripts) {
+ print_verbose("GDScript: Reloading: " + E->get_path());
+ E->load_source_code(E->get_path());
+ E->reload(true);
}
#endif
}
@@ -1838,21 +1837,21 @@ void GDScriptLanguage::reload_tool_script(const Ref<Script> &p_script, bool p_so
scripts.sort_custom<GDScriptDepSort>(); //update in inheritance dependency order
- for (List<Ref<GDScript>>::Element *E = scripts.front(); E; E = E->next()) {
- bool reload = E->get() == p_script || to_reload.has(E->get()->get_base());
+ for (Ref<GDScript> E : scripts) {
+ bool reload = E == p_script || to_reload.has(E->get_base());
if (!reload) {
continue;
}
- to_reload.insert(E->get(), Map<ObjectID, List<Pair<StringName, Variant>>>());
+ to_reload.insert(E, Map<ObjectID, List<Pair<StringName, Variant>>>());
if (!p_soft_reload) {
//save state and remove script from instances
- Map<ObjectID, List<Pair<StringName, Variant>>> &map = to_reload[E->get()];
+ Map<ObjectID, List<Pair<StringName, Variant>>> &map = to_reload[E];
- while (E->get()->instances.front()) {
- Object *obj = E->get()->instances.front()->get();
+ while (E->instances.front()) {
+ Object *obj = E->instances.front()->get();
//save instance info
List<Pair<StringName, Variant>> state;
if (obj->get_script_instance()) {
@@ -1865,8 +1864,8 @@ void GDScriptLanguage::reload_tool_script(const Ref<Script> &p_script, bool p_so
//same thing for placeholders
#ifdef TOOLS_ENABLED
- while (E->get()->placeholders.size()) {
- Object *obj = E->get()->placeholders.front()->get()->get_owner();
+ while (E->placeholders.size()) {
+ Object *obj = E->placeholders.front()->get()->get_owner();
//save instance info
if (obj->get_script_instance()) {
@@ -1876,13 +1875,13 @@ void GDScriptLanguage::reload_tool_script(const Ref<Script> &p_script, bool p_so
obj->set_script(Variant());
} else {
// no instance found. Let's remove it so we don't loop forever
- E->get()->placeholders.erase(E->get()->placeholders.front()->get());
+ E->placeholders.erase(E->placeholders.front()->get());
}
}
#endif
- for (Map<ObjectID, List<Pair<StringName, Variant>>>::Element *F = E->get()->pending_reload_state.front(); F; F = F->next()) {
+ for (Map<ObjectID, List<Pair<StringName, Variant>>>::Element *F = E->pending_reload_state.front(); F; F = F->next()) {
map[F->key()] = F->get(); //pending to reload, use this one instead
}
}
@@ -2025,8 +2024,8 @@ void GDScriptLanguage::get_reserved_words(List<String> *p_words) const {
List<StringName> functions;
GDScriptUtilityFunctions::get_function_list(&functions);
- for (const List<StringName>::Element *E = functions.front(); E; E = E->next()) {
- p_words->push_back(String(E->get()));
+ for (const StringName &E : functions) {
+ p_words->push_back(String(E));
}
}
@@ -2296,8 +2295,8 @@ void ResourceFormatLoaderGDScript::get_dependencies(const String &p_path, List<S
return;
}
- for (const List<String>::Element *E = parser.get_dependencies().front(); E; E = E->next()) {
- p_dependencies->push_back(E->get());
+ for (const String &E : parser.get_dependencies()) {
+ p_dependencies->push_back(E);
}
}
diff --git a/modules/gdscript/gdscript_analyzer.cpp b/modules/gdscript/gdscript_analyzer.cpp
index e7fb33a6a7..ab37e54cf1 100644
--- a/modules/gdscript/gdscript_analyzer.cpp
+++ b/modules/gdscript/gdscript_analyzer.cpp
@@ -115,8 +115,8 @@ static GDScriptParser::DataType make_native_enum_type(const StringName &p_native
StringName real_native_name = GDScriptParser::get_real_class_name(p_native_class);
ClassDB::get_enum_constants(real_native_name, p_enum_name, &enum_values);
- for (const List<StringName>::Element *E = enum_values.front(); E != nullptr; E = E->next()) {
- type.enum_values[E->get()] = ClassDB::get_integer_constant(real_native_name, E->get());
+ for (const StringName &E : enum_values) {
+ type.enum_values[E] = ClassDB::get_integer_constant(real_native_name, E);
}
return type;
@@ -573,8 +573,8 @@ void GDScriptAnalyzer::resolve_class_interface(GDScriptParser::ClassNode *p_clas
member.variable->set_datatype(datatype);
// Apply annotations.
- for (List<GDScriptParser::AnnotationNode *>::Element *E = member.variable->annotations.front(); E; E = E->next()) {
- E->get()->apply(parser, member.variable);
+ for (GDScriptParser::AnnotationNode *&E : member.variable->annotations) {
+ E->apply(parser, member.variable);
}
} break;
case GDScriptParser::ClassNode::Member::CONSTANT: {
@@ -622,8 +622,8 @@ void GDScriptAnalyzer::resolve_class_interface(GDScriptParser::ClassNode *p_clas
member.constant->set_datatype(datatype);
// Apply annotations.
- for (List<GDScriptParser::AnnotationNode *>::Element *E = member.constant->annotations.front(); E; E = E->next()) {
- E->get()->apply(parser, member.constant);
+ for (GDScriptParser::AnnotationNode *&E : member.constant->annotations) {
+ E->apply(parser, member.constant);
}
} break;
case GDScriptParser::ClassNode::Member::SIGNAL: {
@@ -641,8 +641,8 @@ void GDScriptAnalyzer::resolve_class_interface(GDScriptParser::ClassNode *p_clas
member.signal->set_datatype(signal_type);
// Apply annotations.
- for (List<GDScriptParser::AnnotationNode *>::Element *E = member.signal->annotations.front(); E; E = E->next()) {
- E->get()->apply(parser, member.signal);
+ for (GDScriptParser::AnnotationNode *&E : member.signal->annotations) {
+ E->apply(parser, member.signal);
}
} break;
case GDScriptParser::ClassNode::Member::ENUM: {
@@ -688,8 +688,8 @@ void GDScriptAnalyzer::resolve_class_interface(GDScriptParser::ClassNode *p_clas
member.m_enum->set_datatype(enum_type);
// Apply annotations.
- for (List<GDScriptParser::AnnotationNode *>::Element *E = member.m_enum->annotations.front(); E; E = E->next()) {
- E->get()->apply(parser, member.m_enum);
+ for (GDScriptParser::AnnotationNode *&E : member.m_enum->annotations) {
+ E->apply(parser, member.m_enum);
}
} break;
case GDScriptParser::ClassNode::Member::FUNCTION:
@@ -761,8 +761,8 @@ void GDScriptAnalyzer::resolve_class_body(GDScriptParser::ClassNode *p_class) {
resolve_function_body(member.function);
// Apply annotations.
- for (List<GDScriptParser::AnnotationNode *>::Element *E = member.function->annotations.front(); E; E = E->next()) {
- E->get()->apply(parser, member.function);
+ for (GDScriptParser::AnnotationNode *&E : member.function->annotations) {
+ E->apply(parser, member.function);
}
}
@@ -1927,9 +1927,7 @@ void GDScriptAnalyzer::reduce_call(GDScriptParser::CallNode *p_call, bool is_awa
Variant::get_constructor_list(builtin_type, &constructors);
bool match = false;
- for (const List<MethodInfo>::Element *E = constructors.front(); E != nullptr; E = E->next()) {
- const MethodInfo &info = E->get();
-
+ for (const MethodInfo &info : constructors) {
if (p_call->arguments.size() < info.arguments.size() - info.default_arguments.size()) {
continue;
}
@@ -2326,8 +2324,7 @@ void GDScriptAnalyzer::reduce_identifier_from_base(GDScriptParser::IdentifierNod
Variant::construct(base.builtin_type, dummy, nullptr, 0, temp);
List<PropertyInfo> properties;
dummy.get_property_list(&properties);
- for (const List<PropertyInfo>::Element *E = properties.front(); E != nullptr; E = E->next()) {
- const PropertyInfo &prop = E->get();
+ for (const PropertyInfo &prop : properties) {
if (prop.name == name) {
p_identifier->set_datatype(type_from_property(prop));
return;
@@ -3125,8 +3122,8 @@ GDScriptParser::DataType GDScriptAnalyzer::type_from_variant(const Variant &p_va
GDScriptParser::ClassNode *found = ref->get_parser()->head;
// It should be okay to assume this exists, since we have a complete script already.
- for (const List<StringName>::Element *E = class_chain.front(); E; E = E->next()) {
- found = found->get_member(E->get()).m_class;
+ for (const StringName &E : class_chain) {
+ found = found->get_member(E).m_class;
}
result.class_type = found;
@@ -3222,9 +3219,9 @@ bool GDScriptAnalyzer::get_function_signature(GDScriptParser::Node *p_source, GD
List<MethodInfo> methods;
dummy.get_method_list(&methods);
- for (const List<MethodInfo>::Element *E = methods.front(); E != nullptr; E = E->next()) {
- if (E->get().name == p_function) {
- return function_signature_from_info(E->get(), r_return_type, r_par_types, r_default_arg_count, r_static, r_vararg);
+ for (const MethodInfo &E : methods) {
+ if (E.name == p_function) {
+ return function_signature_from_info(E, r_return_type, r_par_types, r_default_arg_count, r_static, r_vararg);
}
}
@@ -3321,8 +3318,8 @@ bool GDScriptAnalyzer::function_signature_from_info(const MethodInfo &p_info, GD
r_default_arg_count = p_info.default_arguments.size();
r_vararg = (p_info.flags & METHOD_FLAG_VARARG) != 0;
- for (const List<PropertyInfo>::Element *E = p_info.arguments.front(); E != nullptr; E = E->next()) {
- r_par_types.push_back(type_from_property(E->get()));
+ for (const PropertyInfo &E : p_info.arguments) {
+ r_par_types.push_back(type_from_property(E));
}
return true;
}
@@ -3330,8 +3327,8 @@ bool GDScriptAnalyzer::function_signature_from_info(const MethodInfo &p_info, GD
bool GDScriptAnalyzer::validate_call_arg(const MethodInfo &p_method, const GDScriptParser::CallNode *p_call) {
List<GDScriptParser::DataType> arg_types;
- for (const List<PropertyInfo>::Element *E = p_method.arguments.front(); E != nullptr; E = E->next()) {
- arg_types.push_back(type_from_property(E->get()));
+ for (const PropertyInfo &E : p_method.arguments) {
+ arg_types.push_back(type_from_property(E));
}
return validate_call_arg(arg_types, p_method.default_arguments.size(), (p_method.flags & METHOD_FLAG_VARARG) != 0, p_call);
@@ -3658,11 +3655,11 @@ Error GDScriptAnalyzer::resolve_program() {
List<String> parser_keys;
depended_parsers.get_key_list(&parser_keys);
- for (const List<String>::Element *E = parser_keys.front(); E != nullptr; E = E->next()) {
- if (depended_parsers[E->get()].is_null()) {
+ for (const String &E : parser_keys) {
+ if (depended_parsers[E].is_null()) {
return ERR_PARSE_ERROR;
}
- depended_parsers[E->get()]->raise_status(GDScriptParserRef::FULLY_SOLVED);
+ depended_parsers[E]->raise_status(GDScriptParserRef::FULLY_SOLVED);
}
return parser->errors.is_empty() ? OK : ERR_PARSE_ERROR;
}
diff --git a/modules/gdscript/gdscript_byte_codegen.cpp b/modules/gdscript/gdscript_byte_codegen.cpp
index 9ff5a342ec..5958326315 100644
--- a/modules/gdscript/gdscript_byte_codegen.cpp
+++ b/modules/gdscript/gdscript_byte_codegen.cpp
@@ -1459,8 +1459,8 @@ void GDScriptByteCodeGenerator::write_endfor() {
}
// Patch break statements.
- for (const List<int>::Element *E = current_breaks_to_patch.back()->get().front(); E; E = E->next()) {
- patch_jump(E->get());
+ for (const int &E : current_breaks_to_patch.back()->get()) {
+ patch_jump(E);
}
current_breaks_to_patch.pop_back();
@@ -1494,8 +1494,8 @@ void GDScriptByteCodeGenerator::write_endwhile() {
while_jmp_addrs.pop_back();
// Patch break statements.
- for (const List<int>::Element *E = current_breaks_to_patch.back()->get().front(); E; E = E->next()) {
- patch_jump(E->get());
+ for (const int &E : current_breaks_to_patch.back()->get()) {
+ patch_jump(E);
}
current_breaks_to_patch.pop_back();
}
@@ -1506,8 +1506,8 @@ void GDScriptByteCodeGenerator::start_match() {
void GDScriptByteCodeGenerator::start_match_branch() {
// Patch continue statements.
- for (const List<int>::Element *E = match_continues_to_patch.back()->get().front(); E; E = E->next()) {
- patch_jump(E->get());
+ for (const int &E : match_continues_to_patch.back()->get()) {
+ patch_jump(E);
}
match_continues_to_patch.pop_back();
// Start a new list for next branch.
@@ -1516,8 +1516,8 @@ void GDScriptByteCodeGenerator::start_match_branch() {
void GDScriptByteCodeGenerator::end_match() {
// Patch continue statements.
- for (const List<int>::Element *E = match_continues_to_patch.back()->get().front(); E; E = E->next()) {
- patch_jump(E->get());
+ for (const int &E : match_continues_to_patch.back()->get()) {
+ patch_jump(E);
}
match_continues_to_patch.pop_back();
}
diff --git a/modules/gdscript/gdscript_compiler.cpp b/modules/gdscript/gdscript_compiler.cpp
index fbe791a109..3289f8978b 100644
--- a/modules/gdscript/gdscript_compiler.cpp
+++ b/modules/gdscript/gdscript_compiler.cpp
@@ -981,8 +981,7 @@ GDScriptCodeGenerator::Address GDScriptCompiler::_parse_expression(CodeGen &code
assigned = prev_base;
// Set back the values into their bases.
- for (List<ChainInfo>::Element *E = set_chain.front(); E; E = E->next()) {
- const ChainInfo &info = E->get();
+ for (ChainInfo &info : set_chain) {
if (!info.is_named) {
gen->write_set(info.base, info.key, assigned);
if (info.key.mode == GDScriptCodeGenerator::Address::TEMPORARY) {
diff --git a/modules/gdscript/gdscript_editor.cpp b/modules/gdscript/gdscript_editor.cpp
index 79023df284..3ac9db3645 100644
--- a/modules/gdscript/gdscript_editor.cpp
+++ b/modules/gdscript/gdscript_editor.cpp
@@ -141,8 +141,8 @@ bool GDScriptLanguage::validate(const String &p_script, const String &p_path, Li
}
#ifdef DEBUG_ENABLED
if (r_warnings) {
- for (const List<GDScriptWarning>::Element *E = parser.get_warnings().front(); E; E = E->next()) {
- const GDScriptWarning &warn = E->get();
+ for (const GDScriptWarning &E : parser.get_warnings()) {
+ const GDScriptWarning &warn = E;
ScriptLanguage::Warning w;
w.start_line = warn.start_line;
w.end_line = warn.end_line;
@@ -157,8 +157,8 @@ bool GDScriptLanguage::validate(const String &p_script, const String &p_path, Li
#endif
if (err) {
if (r_errors) {
- for (const List<GDScriptParser::ParserError>::Element *E = parser.get_errors().front(); E; E = E->next()) {
- const GDScriptParser::ParserError &pe = E->get();
+ for (const GDScriptParser::ParserError &E : parser.get_errors()) {
+ const GDScriptParser::ParserError &pe = E;
ScriptLanguage::ScriptError e;
e.line = pe.line;
e.column = pe.column;
@@ -319,9 +319,9 @@ void GDScriptLanguage::debug_get_stack_level_locals(int p_level, List<String> *p
List<Pair<StringName, int>> locals;
f->debug_get_stack_member_state(*_call_stack[l].line, &locals);
- for (List<Pair<StringName, int>>::Element *E = locals.front(); E; E = E->next()) {
- p_locals->push_back(E->get().first);
- p_values->push_back(_call_stack[l].stack[E->get().second]);
+ for (Pair<StringName, int> &E : locals) {
+ p_locals->push_back(E.first);
+ p_values->push_back(_call_stack[l].stack[E.second]);
}
}
@@ -421,8 +421,8 @@ void GDScriptLanguage::get_public_functions(List<MethodInfo> *p_functions) const
List<StringName> functions;
GDScriptUtilityFunctions::get_function_list(&functions);
- for (const List<StringName>::Element *E = functions.front(); E; E = E->next()) {
- p_functions->push_back(GDScriptUtilityFunctions::get_function_info(E->get()));
+ for (const StringName &E : functions) {
+ p_functions->push_back(GDScriptUtilityFunctions::get_function_info(E));
}
// Not really "functions", but show in documentation.
@@ -548,7 +548,7 @@ static String _make_arguments_hint(const MethodInfo &p_info, int p_arg_idx, bool
int def_args = p_info.arguments.size() - p_info.default_arguments.size();
int i = 0;
- for (const List<PropertyInfo>::Element *E = p_info.arguments.front(); E; E = E->next()) {
+ for (const PropertyInfo &E : p_info.arguments) {
if (i > 0) {
arghint += ", ";
}
@@ -556,7 +556,7 @@ static String _make_arguments_hint(const MethodInfo &p_info, int p_arg_idx, bool
if (i == p_arg_idx) {
arghint += String::chr(0xFFFF);
}
- arghint += E->get().name + ": " + _get_visual_datatype(E->get(), true);
+ arghint += E.name + ": " + _get_visual_datatype(E, true);
if (i - def_args >= 0) {
arghint += String(" = ") + p_info.default_arguments[i - def_args].get_construct_string();
@@ -662,11 +662,11 @@ static void _find_annotation_arguments(const GDScriptParser::AnnotationNode *p_a
r_result.insert(node.display, node);
List<StringName> node_types;
ClassDB::get_inheriters_from_class("Node", &node_types);
- for (const List<StringName>::Element *E = node_types.front(); E != nullptr; E = E->next()) {
- if (!ClassDB::is_class_exposed(E->get())) {
+ for (const StringName &E : node_types) {
+ if (!ClassDB::is_class_exposed(E)) {
continue;
}
- ScriptCodeCompletionOption option(E->get(), ScriptCodeCompletionOption::KIND_CLASS);
+ ScriptCodeCompletionOption option(E, ScriptCodeCompletionOption::KIND_CLASS);
r_result.insert(option.display, option);
}
}
@@ -675,9 +675,9 @@ static void _find_annotation_arguments(const GDScriptParser::AnnotationNode *p_a
static void _list_available_types(bool p_inherit_only, GDScriptParser::CompletionContext &p_context, Map<String, ScriptCodeCompletionOption> &r_result) {
List<StringName> native_types;
ClassDB::get_class_list(&native_types);
- for (const List<StringName>::Element *E = native_types.front(); E != nullptr; E = E->next()) {
- if (ClassDB::is_class_exposed(E->get()) && !Engine::get_singleton()->has_singleton(E->get())) {
- ScriptCodeCompletionOption option(E->get(), ScriptCodeCompletionOption::KIND_CLASS);
+ for (const StringName &E : native_types) {
+ if (ClassDB::is_class_exposed(E) && !Engine::get_singleton()->has_singleton(E)) {
+ ScriptCodeCompletionOption option(E, ScriptCodeCompletionOption::KIND_CLASS);
r_result.insert(option.display, option);
}
}
@@ -687,8 +687,8 @@ static void _list_available_types(bool p_inherit_only, GDScriptParser::Completio
// Native enums from base class
List<StringName> enums;
ClassDB::get_enum_list(p_context.current_class->base_type.native_type, &enums);
- for (const List<StringName>::Element *E = enums.front(); E != nullptr; E = E->next()) {
- ScriptCodeCompletionOption option(E->get(), ScriptCodeCompletionOption::KIND_ENUM);
+ for (const StringName &E : enums) {
+ ScriptCodeCompletionOption option(E, ScriptCodeCompletionOption::KIND_ENUM);
r_result.insert(option.display, option);
}
}
@@ -725,8 +725,8 @@ static void _list_available_types(bool p_inherit_only, GDScriptParser::Completio
// Global scripts
List<StringName> global_classes;
ScriptServer::get_global_class_list(&global_classes);
- for (const List<StringName>::Element *E = global_classes.front(); E != nullptr; E = E->next()) {
- ScriptCodeCompletionOption option(E->get(), ScriptCodeCompletionOption::KIND_CLASS);
+ for (const StringName &E : global_classes) {
+ ScriptCodeCompletionOption option(E, ScriptCodeCompletionOption::KIND_CLASS);
r_result.insert(option.display, option);
}
@@ -865,8 +865,8 @@ static void _find_identifiers_in_base(const GDScriptCompletionIdentifier &p_base
if (!_static) {
List<PropertyInfo> members;
scr->get_script_property_list(&members);
- for (List<PropertyInfo>::Element *E = members.front(); E; E = E->next()) {
- ScriptCodeCompletionOption option(E->get().name, ScriptCodeCompletionOption::KIND_MEMBER);
+ for (PropertyInfo &E : members) {
+ ScriptCodeCompletionOption option(E.name, ScriptCodeCompletionOption::KIND_MEMBER);
r_result.insert(option.display, option);
}
}
@@ -879,20 +879,20 @@ static void _find_identifiers_in_base(const GDScriptCompletionIdentifier &p_base
List<MethodInfo> signals;
scr->get_script_signal_list(&signals);
- for (List<MethodInfo>::Element *E = signals.front(); E; E = E->next()) {
- ScriptCodeCompletionOption option(E->get().name, ScriptCodeCompletionOption::KIND_SIGNAL);
+ for (MethodInfo &E : signals) {
+ ScriptCodeCompletionOption option(E.name, ScriptCodeCompletionOption::KIND_SIGNAL);
r_result.insert(option.display, option);
}
}
List<MethodInfo> methods;
scr->get_script_method_list(&methods);
- for (List<MethodInfo>::Element *E = methods.front(); E; E = E->next()) {
- if (E->get().name.begins_with("@")) {
+ for (MethodInfo &E : methods) {
+ if (E.name.begins_with("@")) {
continue;
}
- ScriptCodeCompletionOption option(E->get().name, ScriptCodeCompletionOption::KIND_FUNCTION);
- if (E->get().arguments.size()) {
+ ScriptCodeCompletionOption option(E.name, ScriptCodeCompletionOption::KIND_FUNCTION);
+ if (E.arguments.size()) {
option.insert_text += "(";
} else {
option.insert_text += "()";
@@ -920,22 +920,22 @@ static void _find_identifiers_in_base(const GDScriptCompletionIdentifier &p_base
if (!p_only_functions) {
List<String> constants;
ClassDB::get_integer_constant_list(type, &constants);
- for (List<String>::Element *E = constants.front(); E; E = E->next()) {
- ScriptCodeCompletionOption option(E->get(), ScriptCodeCompletionOption::KIND_CONSTANT);
+ for (String &E : constants) {
+ ScriptCodeCompletionOption option(E, ScriptCodeCompletionOption::KIND_CONSTANT);
r_result.insert(option.display, option);
}
if (!_static || Engine::get_singleton()->has_singleton(type)) {
List<PropertyInfo> pinfo;
ClassDB::get_property_list(type, &pinfo);
- for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) {
- if (E->get().usage & (PROPERTY_USAGE_GROUP | PROPERTY_USAGE_CATEGORY)) {
+ for (PropertyInfo &E : pinfo) {
+ if (E.usage & (PROPERTY_USAGE_GROUP | PROPERTY_USAGE_CATEGORY)) {
continue;
}
- if (E->get().name.find("/") != -1) {
+ if (E.name.find("/") != -1) {
continue;
}
- ScriptCodeCompletionOption option(E->get().name, ScriptCodeCompletionOption::KIND_MEMBER);
+ ScriptCodeCompletionOption option(E.name, ScriptCodeCompletionOption::KIND_MEMBER);
r_result.insert(option.display, option);
}
}
@@ -945,12 +945,12 @@ static void _find_identifiers_in_base(const GDScriptCompletionIdentifier &p_base
List<MethodInfo> methods;
bool is_autocompleting_getters = GLOBAL_GET("debug/gdscript/completion/autocomplete_setters_and_getters").booleanize();
ClassDB::get_method_list(type, &methods, false, !is_autocompleting_getters);
- for (List<MethodInfo>::Element *E = methods.front(); E; E = E->next()) {
- if (E->get().name.begins_with("_")) {
+ for (MethodInfo &E : methods) {
+ if (E.name.begins_with("_")) {
continue;
}
- ScriptCodeCompletionOption option(E->get().name, ScriptCodeCompletionOption::KIND_FUNCTION);
- if (E->get().arguments.size()) {
+ ScriptCodeCompletionOption option(E.name, ScriptCodeCompletionOption::KIND_FUNCTION);
+ if (E.arguments.size()) {
option.insert_text += "(";
} else {
option.insert_text += "()";
@@ -977,9 +977,9 @@ static void _find_identifiers_in_base(const GDScriptCompletionIdentifier &p_base
tmp.get_property_list(&members);
}
- for (List<PropertyInfo>::Element *E = members.front(); E; E = E->next()) {
- if (String(E->get().name).find("/") == -1) {
- ScriptCodeCompletionOption option(E->get().name, ScriptCodeCompletionOption::KIND_MEMBER);
+ for (PropertyInfo &E : members) {
+ if (String(E.name).find("/") == -1) {
+ ScriptCodeCompletionOption option(E.name, ScriptCodeCompletionOption::KIND_MEMBER);
r_result.insert(option.display, option);
}
}
@@ -987,9 +987,9 @@ static void _find_identifiers_in_base(const GDScriptCompletionIdentifier &p_base
List<MethodInfo> methods;
tmp.get_method_list(&methods);
- for (const List<MethodInfo>::Element *E = methods.front(); E; E = E->next()) {
- ScriptCodeCompletionOption option(E->get().name, ScriptCodeCompletionOption::KIND_FUNCTION);
- if (E->get().arguments.size()) {
+ for (const MethodInfo &E : methods) {
+ ScriptCodeCompletionOption option(E.name, ScriptCodeCompletionOption::KIND_FUNCTION);
+ if (E.arguments.size()) {
option.insert_text += "(";
} else {
option.insert_text += "()";
@@ -1019,9 +1019,9 @@ static void _find_identifiers(GDScriptParser::CompletionContext &p_context, bool
List<StringName> functions;
GDScriptUtilityFunctions::get_function_list(&functions);
- for (const List<StringName>::Element *E = functions.front(); E; E = E->next()) {
- MethodInfo function = GDScriptUtilityFunctions::get_function_info(E->get());
- ScriptCodeCompletionOption option(String(E->get()), ScriptCodeCompletionOption::KIND_FUNCTION);
+ for (const StringName &E : functions) {
+ MethodInfo function = GDScriptUtilityFunctions::get_function_info(E);
+ ScriptCodeCompletionOption option(String(E), ScriptCodeCompletionOption::KIND_FUNCTION);
if (function.arguments.size() || (function.flags & METHOD_FLAG_VARARG)) {
option.insert_text += "(";
} else {
@@ -1768,9 +1768,9 @@ static bool _guess_identifier_type(GDScriptParser::CompletionContext &p_context,
StringName real_native = GDScriptParser::get_real_class_name(base_type.native_type);
MethodInfo info;
if (ClassDB::get_method_info(real_native, p_context.current_function->identifier->name, &info)) {
- for (const List<PropertyInfo>::Element *E = info.arguments.front(); E; E = E->next()) {
- if (E->get().name == p_identifier) {
- r_type = _type_from_property(E->get());
+ for (const PropertyInfo &E : info.arguments) {
+ if (E.name == p_identifier) {
+ r_type = _type_from_property(E);
return true;
}
}
@@ -1932,8 +1932,7 @@ static bool _guess_identifier_type_from_base(GDScriptParser::CompletionContext &
if (!is_static) {
List<PropertyInfo> members;
scr->get_script_property_list(&members);
- for (const List<PropertyInfo>::Element *E = members.front(); E; E = E->next()) {
- const PropertyInfo &prop = E->get();
+ for (const PropertyInfo &prop : members) {
if (prop.name == p_identifier) {
r_type = _type_from_property(prop);
return true;
@@ -2096,8 +2095,7 @@ static bool _guess_method_return_type_from_base(GDScriptParser::CompletionContex
if (scr.is_valid()) {
List<MethodInfo> methods;
scr->get_script_method_list(&methods);
- for (List<MethodInfo>::Element *E = methods.front(); E; E = E->next()) {
- MethodInfo &mi = E->get();
+ for (MethodInfo &mi : methods) {
if (mi.name == p_method) {
r_type = _type_from_property(mi.return_val);
return true;
@@ -2137,8 +2135,7 @@ static bool _guess_method_return_type_from_base(GDScriptParser::CompletionContex
List<MethodInfo> methods;
tmp.get_method_list(&methods);
- for (List<MethodInfo>::Element *E = methods.front(); E; E = E->next()) {
- MethodInfo &mi = E->get();
+ for (MethodInfo &mi : methods) {
if (mi.name == p_method) {
r_type = _type_from_property(mi.return_val);
return true;
@@ -2183,8 +2180,8 @@ static void _find_enumeration_candidates(GDScriptParser::CompletionContext &p_co
List<StringName> enum_constants;
ClassDB::get_enum_constants(class_name, enum_name, &enum_constants);
- for (List<StringName>::Element *E = enum_constants.front(); E; E = E->next()) {
- String candidate = class_name + "." + E->get();
+ for (StringName &E : enum_constants) {
+ String candidate = class_name + "." + E;
ScriptCodeCompletionOption option(candidate, ScriptCodeCompletionOption::KIND_ENUM);
r_result.insert(option.display, option);
}
@@ -2228,8 +2225,8 @@ static void _find_call_arguments(GDScriptParser::CompletionContext &p_context, c
if (obj) {
List<String> options;
obj->get_argument_options(p_method, p_argidx, &options);
- for (List<String>::Element *F = options.front(); F; F = F->next()) {
- ScriptCodeCompletionOption option(F->get(), ScriptCodeCompletionOption::KIND_FUNCTION);
+ for (String &F : options) {
+ ScriptCodeCompletionOption option(F, ScriptCodeCompletionOption::KIND_FUNCTION);
r_result.insert(option.display, option);
}
}
@@ -2250,8 +2247,8 @@ static void _find_call_arguments(GDScriptParser::CompletionContext &p_context, c
List<PropertyInfo> props;
ProjectSettings::get_singleton()->get_property_list(&props);
- for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) {
- String s = E->get().name;
+ for (PropertyInfo &E : props) {
+ String s = E.name;
if (!s.begins_with("autoload/")) {
continue;
}
@@ -2266,8 +2263,8 @@ static void _find_call_arguments(GDScriptParser::CompletionContext &p_context, c
// Get input actions
List<PropertyInfo> props;
ProjectSettings::get_singleton()->get_property_list(&props);
- for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) {
- String s = E->get().name;
+ for (PropertyInfo &E : props) {
+ String s = E.name;
if (!s.begins_with("input/")) {
continue;
}
@@ -2291,9 +2288,9 @@ static void _find_call_arguments(GDScriptParser::CompletionContext &p_context, c
List<MethodInfo> methods;
base.get_method_list(&methods);
- for (List<MethodInfo>::Element *E = methods.front(); E; E = E->next()) {
- if (E->get().name == p_method) {
- r_arghint = _make_arguments_hint(E->get(), p_argidx);
+ for (MethodInfo &E : methods) {
+ if (E.name == p_method) {
+ r_arghint = _make_arguments_hint(E, p_argidx);
return;
}
}
@@ -2340,14 +2337,14 @@ static void _find_call_arguments(GDScriptParser::CompletionContext &p_context, c
Variant::get_constructor_list(GDScriptParser::get_builtin_type(call->function_name), &constructors);
int i = 0;
- for (List<MethodInfo>::Element *E = constructors.front(); E; E = E->next()) {
- if (p_argidx >= E->get().arguments.size()) {
+ for (MethodInfo &E : constructors) {
+ if (p_argidx >= E.arguments.size()) {
continue;
}
if (i > 0) {
r_arghint += "\n";
}
- r_arghint += _make_arguments_hint(E->get(), p_argidx);
+ r_arghint += _make_arguments_hint(E, p_argidx);
i++;
}
return;
@@ -2406,9 +2403,9 @@ static void _find_call_arguments(GDScriptParser::CompletionContext &p_context, c
case GDScriptParser::COMPLETION_ANNOTATION: {
List<MethodInfo> annotations;
parser.get_annotation_list(&annotations);
- for (const List<MethodInfo>::Element *E = annotations.front(); E != nullptr; E = E->next()) {
- ScriptCodeCompletionOption option(E->get().name.substr(1), ScriptCodeCompletionOption::KIND_PLAIN_TEXT);
- if (E->get().arguments.size() > 0) {
+ for (const MethodInfo &E : annotations) {
+ ScriptCodeCompletionOption option(E.name.substr(1), ScriptCodeCompletionOption::KIND_PLAIN_TEXT);
+ if (E.arguments.size() > 0) {
option.insert_text += "(";
}
options.insert(option.display, option);
@@ -2426,10 +2423,10 @@ static void _find_call_arguments(GDScriptParser::CompletionContext &p_context, c
case GDScriptParser::COMPLETION_BUILT_IN_TYPE_CONSTANT: {
List<StringName> constants;
Variant::get_constants_for_type(completion_context.builtin_type, &constants);
- for (const List<StringName>::Element *E = constants.front(); E != nullptr; E = E->next()) {
- ScriptCodeCompletionOption option(E->get(), ScriptCodeCompletionOption::KIND_CONSTANT);
+ for (const StringName &E : constants) {
+ ScriptCodeCompletionOption option(E, ScriptCodeCompletionOption::KIND_CONSTANT);
bool valid = false;
- Variant default_value = Variant::get_constant_value(completion_context.builtin_type, E->get(), &valid);
+ Variant default_value = Variant::get_constant_value(completion_context.builtin_type, E, &valid);
if (valid) {
option.default_value = default_value;
}
@@ -2606,8 +2603,7 @@ static void _find_call_arguments(GDScriptParser::CompletionContext &p_context, c
List<MethodInfo> virtual_methods;
ClassDB::get_virtual_methods(class_name, &virtual_methods);
- for (List<MethodInfo>::Element *E = virtual_methods.front(); E; E = E->next()) {
- MethodInfo &mi = E->get();
+ for (MethodInfo &mi : virtual_methods) {
String method_hint = mi.name;
if (method_hint.find(":") != -1) {
method_hint = method_hint.get_slice(":", 0);
@@ -2656,8 +2652,8 @@ static void _find_call_arguments(GDScriptParser::CompletionContext &p_context, c
List<String> opts;
p_owner->get_argument_options("get_node", 0, &opts);
- for (List<String>::Element *E = opts.front(); E; E = E->next()) {
- String opt = E->get().strip_edges();
+ for (String &E : opts) {
+ String opt = E.strip_edges();
if (opt.is_quoted()) {
r_forced = true;
String idopt = opt.unquote();
@@ -2841,8 +2837,8 @@ static Error _lookup_symbol_from_base(const GDScriptParser::DataType &p_base, co
List<MethodInfo> virtual_methods;
ClassDB::get_virtual_methods(class_name, &virtual_methods, true);
- for (List<MethodInfo>::Element *E = virtual_methods.front(); E; E = E->next()) {
- if (E->get().name == p_symbol) {
+ for (MethodInfo &E : virtual_methods) {
+ if (E.name == p_symbol) {
r_result.type = ScriptLanguage::LookupResult::RESULT_CLASS_METHOD;
r_result.class_name = base_type.native_type;
r_result.class_member = p_symbol;
@@ -2860,8 +2856,8 @@ static Error _lookup_symbol_from_base(const GDScriptParser::DataType &p_base, co
List<String> constants;
ClassDB::get_integer_constant_list(class_name, &constants, true);
- for (List<String>::Element *E = constants.front(); E; E = E->next()) {
- if (E->get() == p_symbol) {
+ for (String &E : constants) {
+ if (E == p_symbol) {
r_result.type = ScriptLanguage::LookupResult::RESULT_CLASS_CONSTANT;
r_result.class_name = base_type.native_type;
r_result.class_member = p_symbol;
diff --git a/modules/gdscript/gdscript_function.cpp b/modules/gdscript/gdscript_function.cpp
index f300d5a2c9..876c508689 100644
--- a/modules/gdscript/gdscript_function.cpp
+++ b/modules/gdscript/gdscript_function.cpp
@@ -94,8 +94,7 @@ struct _GDFKCS {
void GDScriptFunction::debug_get_stack_member_state(int p_line, List<Pair<StringName, int>> *r_stackvars) const {
int oc = 0;
Map<StringName, _GDFKC> sdmap;
- for (const List<StackDebug>::Element *E = stack_debug.front(); E; E = E->next()) {
- const StackDebug &sd = E->get();
+ for (const StackDebug &sd : stack_debug) {
if (sd.line > p_line) {
break;
}
@@ -131,10 +130,10 @@ void GDScriptFunction::debug_get_stack_member_state(int p_line, List<Pair<String
stackpositions.sort();
- for (List<_GDFKCS>::Element *E = stackpositions.front(); E; E = E->next()) {
+ for (_GDFKCS &E : stackpositions) {
Pair<StringName, int> p;
- p.first = E->get().id;
- p.second = E->get().pos;
+ p.first = E.id;
+ p.second = E.pos;
r_stackvars->push_back(p);
}
}
diff --git a/modules/gdscript/gdscript_parser.cpp b/modules/gdscript/gdscript_parser.cpp
index e103d86b15..9949d0db56 100644
--- a/modules/gdscript/gdscript_parser.cpp
+++ b/modules/gdscript/gdscript_parser.cpp
@@ -136,8 +136,8 @@ void GDScriptParser::cleanup() {
void GDScriptParser::get_annotation_list(List<MethodInfo> *r_annotations) const {
List<StringName> keys;
valid_annotations.get_key_list(&keys);
- for (const List<StringName>::Element *E = keys.front(); E != nullptr; E = E->next()) {
- r_annotations->push_back(valid_annotations[E->get()].info);
+ for (const StringName &E : keys) {
+ r_annotations->push_back(valid_annotations[E].info);
}
}
@@ -248,7 +248,7 @@ void GDScriptParser::push_warning(const Node *p_source, GDScriptWarning::Code p_
warning.rightmost_column = p_source->rightmost_column;
List<GDScriptWarning>::Element *before = nullptr;
- for (List<GDScriptWarning>::Element *E = warnings.front(); E != nullptr; E = E->next()) {
+ for (List<GDScriptWarning>::Element *E = warnings.front(); E; E = E->next()) {
if (E->get().start_line > warning.start_line) {
break;
}
@@ -1332,8 +1332,7 @@ GDScriptParser::AnnotationNode *GDScriptParser::parse_annotation(uint32_t p_vali
}
void GDScriptParser::clear_unused_annotations() {
- for (const List<AnnotationNode *>::Element *E = annotation_stack.front(); E != nullptr; E = E->next()) {
- AnnotationNode *annotation = E->get();
+ for (AnnotationNode *annotation : annotation_stack) {
push_error(vformat(R"(Annotation "%s" does not precedes a valid target, so it will have no effect.)", annotation->name), annotation);
}
@@ -1796,8 +1795,8 @@ GDScriptParser::MatchBranchNode *GDScriptParser::parse_match_branch() {
List<StringName> binds;
branch->patterns[0]->binds.get_key_list(&binds);
- for (List<StringName>::Element *E = binds.front(); E != nullptr; E = E->next()) {
- SuiteNode::Local local(branch->patterns[0]->binds[E->get()], current_function);
+ for (StringName &E : binds) {
+ SuiteNode::Local local(branch->patterns[0]->binds[E], current_function);
suite->add_local(local);
}
}
@@ -3993,8 +3992,8 @@ void GDScriptParser::TreePrinter::print_for(ForNode *p_for) {
}
void GDScriptParser::TreePrinter::print_function(FunctionNode *p_function, const String &p_context) {
- for (const List<AnnotationNode *>::Element *E = p_function->annotations.front(); E != nullptr; E = E->next()) {
- print_annotation(E->get());
+ for (AnnotationNode *E : p_function->annotations) {
+ print_annotation(E);
}
push_text(p_context);
push_text(" ");
@@ -4333,8 +4332,8 @@ void GDScriptParser::TreePrinter::print_unary_op(UnaryOpNode *p_unary_op) {
}
void GDScriptParser::TreePrinter::print_variable(VariableNode *p_variable) {
- for (const List<AnnotationNode *>::Element *E = p_variable->annotations.front(); E != nullptr; E = E->next()) {
- print_annotation(E->get());
+ for (AnnotationNode *E : p_variable->annotations) {
+ print_annotation(E);
}
push_text("Variable ");
diff --git a/modules/gdscript/gdscript_utility_functions.cpp b/modules/gdscript/gdscript_utility_functions.cpp
index 64c629662c..62531473c3 100644
--- a/modules/gdscript/gdscript_utility_functions.cpp
+++ b/modules/gdscript/gdscript_utility_functions.cpp
@@ -706,8 +706,8 @@ bool GDScriptUtilityFunctions::function_exists(const StringName &p_function) {
}
void GDScriptUtilityFunctions::get_function_list(List<StringName> *r_functions) {
- for (const List<StringName>::Element *E = utility_function_name_table.front(); E; E = E->next()) {
- r_functions->push_back(E->get());
+ for (const StringName &E : utility_function_name_table) {
+ r_functions->push_back(E);
}
}
diff --git a/modules/gdscript/language_server/gdscript_extend_parser.cpp b/modules/gdscript/language_server/gdscript_extend_parser.cpp
index e9a7bf3830..eb68e38840 100644
--- a/modules/gdscript/language_server/gdscript_extend_parser.cpp
+++ b/modules/gdscript/language_server/gdscript_extend_parser.cpp
@@ -39,8 +39,7 @@ void ExtendGDScriptParser::update_diagnostics() {
diagnostics.clear();
const List<ParserError> &errors = get_errors();
- for (const List<ParserError>::Element *E = errors.front(); E != nullptr; E = E->next()) {
- const ParserError &error = E->get();
+ for (const ParserError &error : errors) {
lsp::Diagnostic diagnostic;
diagnostic.severity = lsp::DiagnosticSeverity::Error;
diagnostic.message = error.message;
@@ -61,8 +60,7 @@ void ExtendGDScriptParser::update_diagnostics() {
}
const List<GDScriptWarning> &warnings = get_warnings();
- for (const List<GDScriptWarning>::Element *E = warnings.front(); E; E = E->next()) {
- const GDScriptWarning &warning = E->get();
+ for (const GDScriptWarning &warning : warnings) {
lsp::Diagnostic diagnostic;
diagnostic.severity = lsp::DiagnosticSeverity::Warning;
diagnostic.message = "(" + warning.get_name() + "): " + warning.get_message();
@@ -467,8 +465,8 @@ String ExtendGDScriptParser::parse_documentation(int p_line, bool p_docs_down) {
}
String doc;
- for (List<String>::Element *E = doc_lines.front(); E; E = E->next()) {
- doc += E->get() + "\n";
+ for (String &E : doc_lines) {
+ doc += E + "\n";
}
return doc;
}
diff --git a/modules/gdscript/language_server/gdscript_text_document.cpp b/modules/gdscript/language_server/gdscript_text_document.cpp
index 55aff618aa..69ddbe5d1e 100644
--- a/modules/gdscript/language_server/gdscript_text_document.cpp
+++ b/modules/gdscript/language_server/gdscript_text_document.cpp
@@ -157,8 +157,7 @@ Array GDScriptTextDocument::completion(const Dictionary &p_params) {
int i = 0;
arr.resize(options.size());
- for (const List<ScriptCodeCompletionOption>::Element *E = options.front(); E; E = E->next()) {
- const ScriptCodeCompletionOption &option = E->get();
+ for (const ScriptCodeCompletionOption &option : options) {
lsp::CompletionItem item;
item.label = option.display;
item.data = request_data;
@@ -294,8 +293,8 @@ Array GDScriptTextDocument::documentLink(const Dictionary &p_params) {
List<lsp::DocumentLink> links;
GDScriptLanguageProtocol::get_singleton()->get_workspace()->resolve_document_links(params.textDocument.uri, links);
- for (const List<lsp::DocumentLink>::Element *E = links.front(); E; E = E->next()) {
- ret.push_back(E->get().to_json());
+ for (const lsp::DocumentLink &E : links) {
+ ret.push_back(E.to_json());
}
return ret;
}
@@ -322,8 +321,8 @@ Variant GDScriptTextDocument::hover(const Dictionary &p_params) {
Array contents;
List<const lsp::DocumentSymbol *> list;
GDScriptLanguageProtocol::get_singleton()->get_workspace()->resolve_related_symbols(params, list);
- for (List<const lsp::DocumentSymbol *>::Element *E = list.front(); E; E = E->next()) {
- if (const lsp::DocumentSymbol *s = E->get()) {
+ for (const lsp::DocumentSymbol *&E : list) {
+ if (const lsp::DocumentSymbol *s = E) {
contents.push_back(s->render().value);
}
}
@@ -430,8 +429,8 @@ Array GDScriptTextDocument::find_symbols(const lsp::TextDocumentPositionParams &
} else if (GDScriptLanguageProtocol::get_singleton()->is_smart_resolve_enabled()) {
List<const lsp::DocumentSymbol *> list;
GDScriptLanguageProtocol::get_singleton()->get_workspace()->resolve_related_symbols(p_location, list);
- for (List<const lsp::DocumentSymbol *>::Element *E = list.front(); E; E = E->next()) {
- if (const lsp::DocumentSymbol *s = E->get()) {
+ for (const lsp::DocumentSymbol *&E : list) {
+ if (const lsp::DocumentSymbol *s = E) {
if (!s->uri.is_empty()) {
lsp::Location location;
location.uri = s->uri;
diff --git a/modules/gdscript/language_server/gdscript_workspace.cpp b/modules/gdscript/language_server/gdscript_workspace.cpp
index 1915c92cbf..eb60433859 100644
--- a/modules/gdscript/language_server/gdscript_workspace.cpp
+++ b/modules/gdscript/language_server/gdscript_workspace.cpp
@@ -119,8 +119,7 @@ const lsp::DocumentSymbol *GDScriptWorkspace::get_script_symbol(const String &p_
void GDScriptWorkspace::reload_all_workspace_scripts() {
List<String> paths;
list_script_files("res://", paths);
- for (List<String>::Element *E = paths.front(); E; E = E->next()) {
- const String &path = E->get();
+ for (String &path : paths) {
Error err;
String content = FileAccess::get_file_as_string(path, &err);
ERR_CONTINUE(err != OK);
@@ -559,8 +558,8 @@ const lsp::DocumentSymbol *GDScriptWorkspace::resolve_native_symbol(const lsp::N
void GDScriptWorkspace::resolve_document_links(const String &p_uri, List<lsp::DocumentLink> &r_list) {
if (const ExtendGDScriptParser *parser = get_parse_successed_script(get_file_path(p_uri))) {
const List<lsp::DocumentLink> &links = parser->get_document_links();
- for (const List<lsp::DocumentLink>::Element *E = links.front(); E; E = E->next()) {
- r_list.push_back(E->get());
+ for (const lsp::DocumentLink &E : links) {
+ r_list.push_back(E);
}
}
}
@@ -587,8 +586,7 @@ Error GDScriptWorkspace::resolve_signature(const lsp::TextDocumentPositionParams
GDScriptLanguageProtocol::get_singleton()->get_workspace()->resolve_related_symbols(text_pos, symbols);
}
- for (List<const lsp::DocumentSymbol *>::Element *E = symbols.front(); E; E = E->next()) {
- const lsp::DocumentSymbol *symbol = E->get();
+ for (const lsp::DocumentSymbol *symbol : symbols) {
if (symbol->kind == lsp::SymbolKind::Method || symbol->kind == lsp::SymbolKind::Function) {
lsp::SignatureInformation signature_info;
signature_info.label = symbol->detail;
diff --git a/modules/gdscript/tests/gdscript_test_runner.cpp b/modules/gdscript/tests/gdscript_test_runner.cpp
index b7faebb4ef..03a48bf071 100644
--- a/modules/gdscript/tests/gdscript_test_runner.cpp
+++ b/modules/gdscript/tests/gdscript_test_runner.cpp
@@ -295,7 +295,7 @@ void GDScriptTestRunner::handle_cmdline() {
String test_cmd = "--gdscript-test";
String gen_cmd = "--gdscript-generate-tests";
- for (List<String>::Element *E = cmdline_args.front(); E != nullptr; E = E->next()) {
+ for (List<String>::Element *E = cmdline_args.front(); E; E = E->next()) {
String &cmd = E->get();
if (cmd == test_cmd || cmd == gen_cmd) {
if (E->next() == nullptr) {
@@ -440,8 +440,8 @@ GDScriptTest::TestResult GDScriptTest::execute_test_code(bool p_is_generating) {
result.output = get_text_for_status(result.status) + "\n";
const List<GDScriptParser::ParserError> &errors = parser.get_errors();
- for (const List<GDScriptParser::ParserError>::Element *E = errors.front(); E; E = E->next()) {
- result.output += E->get().message + "\n"; // TODO: line, column?
+ for (const GDScriptParser::ParserError &E : errors) {
+ result.output += E.message + "\n"; // TODO: line, column?
break; // Only the first error since the following might be cascading.
}
if (!p_is_generating) {
@@ -459,8 +459,8 @@ GDScriptTest::TestResult GDScriptTest::execute_test_code(bool p_is_generating) {
result.output = get_text_for_status(result.status) + "\n";
const List<GDScriptParser::ParserError> &errors = parser.get_errors();
- for (const List<GDScriptParser::ParserError>::Element *E = errors.front(); E; E = E->next()) {
- result.output += E->get().message + "\n"; // TODO: line, column?
+ for (const GDScriptParser::ParserError &E : errors) {
+ result.output += E.message + "\n"; // TODO: line, column?
break; // Only the first error since the following might be cascading.
}
if (!p_is_generating) {
@@ -470,8 +470,8 @@ GDScriptTest::TestResult GDScriptTest::execute_test_code(bool p_is_generating) {
}
StringBuilder warning_string;
- for (const List<GDScriptWarning>::Element *E = parser.get_warnings().front(); E != nullptr; E = E->next()) {
- const GDScriptWarning warning = E->get();
+ for (const GDScriptWarning &E : parser.get_warnings()) {
+ const GDScriptWarning warning = E;
warning_string.append(">> WARNING");
warning_string.append("\n>> Line: ");
warning_string.append(itos(warning.start_line));
diff --git a/modules/gdscript/tests/test_gdscript.cpp b/modules/gdscript/tests/test_gdscript.cpp
index 7aa5895981..52e9d92223 100644
--- a/modules/gdscript/tests/test_gdscript.cpp
+++ b/modules/gdscript/tests/test_gdscript.cpp
@@ -113,8 +113,7 @@ static void test_parser(const String &p_code, const String &p_script_path, const
if (err != OK) {
const List<GDScriptParser::ParserError> &errors = parser.get_errors();
- for (const List<GDScriptParser::ParserError>::Element *E = errors.front(); E != nullptr; E = E->next()) {
- const GDScriptParser::ParserError &error = E->get();
+ for (const GDScriptParser::ParserError &error : errors) {
print_line(vformat("%02d:%02d: %s", error.line, error.column, error.message));
}
}
@@ -124,8 +123,7 @@ static void test_parser(const String &p_code, const String &p_script_path, const
if (err != OK) {
const List<GDScriptParser::ParserError> &errors = parser.get_errors();
- for (const List<GDScriptParser::ParserError>::Element *E = errors.front(); E != nullptr; E = E->next()) {
- const GDScriptParser::ParserError &error = E->get();
+ for (const GDScriptParser::ParserError &error : errors) {
print_line(vformat("%02d:%02d: %s", error.line, error.column, error.message));
}
}
@@ -143,8 +141,7 @@ static void test_compiler(const String &p_code, const String &p_script_path, con
if (err != OK) {
print_line("Error in parser:");
const List<GDScriptParser::ParserError> &errors = parser.get_errors();
- for (const List<GDScriptParser::ParserError>::Element *E = errors.front(); E != nullptr; E = E->next()) {
- const GDScriptParser::ParserError &error = E->get();
+ for (const GDScriptParser::ParserError &error : errors) {
print_line(vformat("%02d:%02d: %s", error.line, error.column, error.message));
}
return;
@@ -156,8 +153,7 @@ static void test_compiler(const String &p_code, const String &p_script_path, con
if (err != OK) {
print_line("Error in analyzer:");
const List<GDScriptParser::ParserError> &errors = parser.get_errors();
- for (const List<GDScriptParser::ParserError>::Element *E = errors.front(); E != nullptr; E = E->next()) {
- const GDScriptParser::ParserError &error = E->get();
+ for (const GDScriptParser::ParserError &error : errors) {
print_line(vformat("%02d:%02d: %s", error.line, error.column, error.message));
}
return;