MCPcopy Create free account
hub / github.com/Redot-Engine/redot-engine / is_shadowing

Method is_shadowing

modules/gdscript/gdscript_analyzer.cpp:5980–6057  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5978
5979#ifdef DEBUG_ENABLED
5980void GDScriptAnalyzer::is_shadowing(GDScriptParser::IdentifierNode *p_identifier, const String &p_context, const bool p_in_local_scope) {
5981 const StringName &name = p_identifier->name;
5982
5983 {
5984 List<MethodInfo> gdscript_funcs;
5985 GDScriptLanguage::get_singleton()->get_public_functions(&gdscript_funcs);
5986
5987 for (MethodInfo &info : gdscript_funcs) {
5988 if (info.name == name) {
5989 parser->push_warning(p_identifier, GDScriptWarning::SHADOWED_GLOBAL_IDENTIFIER, p_context, name, "built-in function");
5990 return;
5991 }
5992 }
5993 if (Variant::has_utility_function(name)) {
5994 parser->push_warning(p_identifier, GDScriptWarning::SHADOWED_GLOBAL_IDENTIFIER, p_context, name, "built-in function");
5995 return;
5996 } else if (class_exists(name)) {
5997 parser->push_warning(p_identifier, GDScriptWarning::SHADOWED_GLOBAL_IDENTIFIER, p_context, name, "native class");
5998 return;
5999 } else if (ScriptServer::is_global_class(name)) {
6000 String class_path = ScriptServer::get_global_class_path(name).get_file();
6001 parser->push_warning(p_identifier, GDScriptWarning::SHADOWED_GLOBAL_IDENTIFIER, p_context, name, vformat(R"(global class defined in "%s")", class_path));
6002 return;
6003 } else if (GDScriptParser::get_builtin_type(name) < Variant::VARIANT_MAX) {
6004 parser->push_warning(p_identifier, GDScriptWarning::SHADOWED_GLOBAL_IDENTIFIER, p_context, name, "built-in type");
6005 return;
6006 }
6007 }
6008
6009 const GDScriptParser::DataType current_class_type = parser->current_class->get_datatype();
6010 if (p_in_local_scope) {
6011 GDScriptParser::ClassNode *base_class = current_class_type.class_type;
6012
6013 if (base_class != nullptr) {
6014 if (base_class->has_member(name)) {
6015 parser->push_warning(p_identifier, GDScriptWarning::SHADOWED_VARIABLE, p_context, p_identifier->name, base_class->get_member(name).get_type_name(), itos(base_class->get_member(name).get_line()));
6016 return;
6017 }
6018 base_class = base_class->base_type.class_type;
6019 }
6020
6021 while (base_class != nullptr) {
6022 if (base_class->has_member(name)) {
6023 String base_class_name = base_class->get_global_name();
6024 if (base_class_name.is_empty()) {
6025 base_class_name = base_class->fqcn;
6026 }
6027
6028 parser->push_warning(p_identifier, GDScriptWarning::SHADOWED_VARIABLE_BASE_CLASS, p_context, p_identifier->name, base_class->get_member(name).get_type_name(), itos(base_class->get_member(name).get_line()), base_class_name);
6029 return;
6030 }
6031 base_class = base_class->base_type.class_type;
6032 }
6033 }
6034
6035 StringName native_base_class = current_class_type.native_type;
6036 while (native_base_class != StringName()) {
6037 ERR_FAIL_COND_MSG(!class_exists(native_base_class), "Non-existent native base class.");

Callers

nothing calls this directly

Calls 14

vformatFunction · 0.85
itosFunction · 0.85
has_methodFunction · 0.85
get_memberMethod · 0.80
StringNameClass · 0.50
get_public_functionsMethod · 0.45
push_warningMethod · 0.45
get_fileMethod · 0.45
get_datatypeMethod · 0.45
has_memberMethod · 0.45
get_type_nameMethod · 0.45
get_lineMethod · 0.45

Tested by

no test coverage detected