Skip to content

Commit

Permalink
Remove checks for underscores
Browse files Browse the repository at this point in the history
Pull godotengine#26990 makes them obsolete
  • Loading branch information
ptrojahn committed Jun 28, 2019
1 parent bd937ea commit 31905de
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 123 deletions.
8 changes: 0 additions & 8 deletions editor/doc/doc_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,6 @@ static void return_doc_from_retinfo(DocData::MethodDoc &p_method, const Property

if (p_retinfo.type == Variant::INT && p_retinfo.usage & PROPERTY_USAGE_CLASS_IS_ENUM) {
p_method.return_enum = p_retinfo.class_name;
if (p_method.return_enum.begins_with("_")) //proxy class
p_method.return_enum = p_method.return_enum.substr(1, p_method.return_enum.length());
p_method.return_type = "int";
} else if (p_retinfo.class_name != StringName()) {
p_method.return_type = p_retinfo.class_name;
Expand All @@ -190,8 +188,6 @@ static void argument_doc_from_arginfo(DocData::ArgumentDoc &p_argument, const Pr

if (p_arginfo.type == Variant::INT && p_arginfo.usage & PROPERTY_USAGE_CLASS_IS_ENUM) {
p_argument.enumeration = p_arginfo.class_name;
if (p_argument.enumeration.begins_with("_")) //proxy class
p_argument.enumeration = p_argument.enumeration.substr(1, p_argument.enumeration.length());
p_argument.type = "int";
} else if (p_arginfo.class_name != StringName()) {
p_argument.type = p_arginfo.class_name;
Expand Down Expand Up @@ -219,8 +215,6 @@ void DocData::generate(bool p_basic_types) {

String name = classes.front()->get();
String cname = name;
if (cname.begins_with("_")) //proxy class
cname = cname.substr(1, name.length());

class_list[cname] = ClassDoc();
ClassDoc &c = class_list[cname];
Expand Down Expand Up @@ -580,8 +574,6 @@ void DocData::generate(bool p_basic_types) {
pd.type = s.ptr->get_class();
while (String(ClassDB::get_parent_class(pd.type)) != "Object")
pd.type = ClassDB::get_parent_class(pd.type);
if (pd.type.begins_with("_"))
pd.type = pd.type.substr(1, pd.type.length());
c.properties.push_back(pd);
}
}
Expand Down
8 changes: 1 addition & 7 deletions editor/plugins/script_text_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,11 +316,7 @@ void ScriptTextEditor::_set_theme_for_script() {

for (List<StringName>::Element *E = types.front(); E; E = E->next()) {

String n = E->get();
if (n.begins_with("_"))
n = n.substr(1, n.length());

text_edit->add_keyword_color(n, colors_cache.type_color);
text_edit->add_keyword_color(E->get(), colors_cache.type_color);
}
_update_member_keywords();

Expand Down Expand Up @@ -779,8 +775,6 @@ void ScriptTextEditor::_lookup_symbol(const String &p_symbol, int p_row, int p_c

_goto_line(p_row);

result.class_name = result.class_name.trim_prefix("_");

switch (result.type) {
case ScriptLanguage::LookupResult::RESULT_SCRIPT_LOCATION: {

Expand Down
8 changes: 1 addition & 7 deletions modules/gdnative/nativescript/api_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,13 +202,7 @@ List<ClassAPI> generate_c_api_classes() {
class_api.api_type = ClassDB::get_api_type(e->get());
class_api.class_name = class_name;
class_api.super_class_name = ClassDB::get_parent_class(class_name);
{
String name = class_name;
if (name.begins_with("_")) {
name.remove(0);
}
class_api.is_singleton = Engine::get_singleton()->has_singleton(name);
}
class_api.is_singleton = Engine::get_singleton()->has_singleton(class_name);
class_api.is_instanciable = !class_api.is_singleton && ClassDB::can_instance(class_name);

{
Expand Down
2 changes: 0 additions & 2 deletions modules/gdscript/gdscript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1410,8 +1410,6 @@ void GDScriptLanguage::init() {

StringName n = E->get();
String s = String(n);
if (s.begins_with("_"))
n = s.substr(1, s.length());

if (globals.has(n))
continue;
Expand Down
110 changes: 27 additions & 83 deletions modules/gdscript/gdscript_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -782,10 +782,7 @@ static bool _guess_expression_type(GDScriptCompletionContext &p_context, const G
native_type.kind = GDScriptParser::DataType::NATIVE;
native_type.native_type = native_type.script_type->get_instance_base_type();
if (!ClassDB::class_exists(native_type.native_type)) {
native_type.native_type = String("_") + native_type.native_type;
if (!ClassDB::class_exists(native_type.native_type)) {
native_type.has_type = false;
}
native_type.has_type = false;
}
}
}
Expand Down Expand Up @@ -1337,38 +1334,24 @@ static bool _guess_identifier_type(GDScriptCompletionContext &p_context, const S
return false;
}

for (int i = 0; i < 2; i++) {
StringName target_id;
switch (i) {
case 0:
// Check ClassDB
target_id = p_identifier;
break;
case 1:
// ClassDB again for underscore-prefixed classes
target_id = String("_") + p_identifier;
break;
}

if (ClassDB::class_exists(target_id)) {
r_type.type.has_type = true;
r_type.type.kind = GDScriptParser::DataType::NATIVE;
r_type.type.native_type = target_id;
if (Engine::get_singleton()->has_singleton(target_id)) {
r_type.type.is_meta_type = false;
r_type.value = Engine::get_singleton()->get_singleton_object(target_id);
} else {
r_type.type.is_meta_type = true;
const Map<StringName, int>::Element *target_elem = GDScriptLanguage::get_singleton()->get_global_map().find(target_id);
// Check because classes like EditorNode are in ClassDB by now, but unknown to GDScript
if (!target_elem) {
return false;
}
int idx = target_elem->get();
r_type.value = GDScriptLanguage::get_singleton()->get_global_array()[idx];
if (ClassDB::class_exists(p_identifier)) {
r_type.type.has_type = true;
r_type.type.kind = GDScriptParser::DataType::NATIVE;
r_type.type.native_type = p_identifier;
if (Engine::get_singleton()->has_singleton(p_identifier)) {
r_type.type.is_meta_type = false;
r_type.value = Engine::get_singleton()->get_singleton_object(p_identifier);
} else {
r_type.type.is_meta_type = true;
const Map<StringName, int>::Element *target_elem = GDScriptLanguage::get_singleton()->get_global_map().find(p_identifier);
// Check because classes like EditorNode are in ClassDB by now, but unknown to GDScript
if (!target_elem) {
return false;
}
return true;
int idx = target_elem->get();
r_type.value = GDScriptLanguage::get_singleton()->get_global_array()[idx];
}
return true;
}

// Check autoload singletons
Expand Down Expand Up @@ -1482,10 +1465,7 @@ static bool _guess_identifier_type_from_base(GDScriptCompletionContext &p_contex
case GDScriptParser::DataType::NATIVE: {
StringName class_name = base_type.native_type;
if (!ClassDB::class_exists(class_name)) {
class_name = String("_") + class_name;
if (!ClassDB::class_exists(class_name)) {
return false;
}
return false;
}

// Skip constants since they're all integers. Type does not matter because int has no members
Expand Down Expand Up @@ -1669,10 +1649,7 @@ static bool _guess_method_return_type_from_base(GDScriptCompletionContext &p_con
case GDScriptParser::DataType::NATIVE: {
StringName native = base_type.native_type;
if (!ClassDB::class_exists(native)) {
native = String("_") + native;
if (!ClassDB::class_exists(native)) {
return false;
}
return false;
}
MethodBind *mb = ClassDB::get_method(native, p_method);
if (mb) {
Expand Down Expand Up @@ -1999,10 +1976,7 @@ static void _find_identifiers_in_base(const GDScriptCompletionContext &p_context
case GDScriptParser::DataType::NATIVE: {
StringName type = base_type.native_type;
if (!ClassDB::class_exists(type)) {
type = String("_") + type;
if (!ClassDB::class_exists(type)) {
return;
}
return;
}

if (!p_only_functions) {
Expand Down Expand Up @@ -2229,11 +2203,8 @@ static void _find_call_arguments(const GDScriptCompletionContext &p_context, con
case GDScriptParser::DataType::NATIVE: {
StringName class_name = base_type.native_type;
if (!ClassDB::class_exists(class_name)) {
class_name = String("_") + class_name;
if (!ClassDB::class_exists(class_name)) {
base_type.has_type = false;
break;
}
base_type.has_type = false;
break;
}

List<MethodInfo> methods;
Expand Down Expand Up @@ -2601,10 +2572,7 @@ Error GDScriptLanguage::complete_code(const String &p_code, const String &p_path

StringName class_name = native_type.native_type;
if (!ClassDB::class_exists(class_name)) {
class_name = String("_") + class_name;
if (!ClassDB::class_exists(class_name)) {
break;
}
break;
}

bool use_type_hint = EditorSettings::get_singleton()->get_setting("text_editor/completion/add_type_hints").operator bool();
Expand Down Expand Up @@ -2700,10 +2668,7 @@ Error GDScriptLanguage::complete_code(const String &p_code, const String &p_path

StringName class_name = base_type.native_type;
if (!ClassDB::class_exists(class_name)) {
class_name = String("_") + class_name;
if (!ClassDB::class_exists(class_name)) {
break;
}
break;
}

List<MethodInfo> signals;
Expand Down Expand Up @@ -2765,9 +2730,6 @@ Error GDScriptLanguage::complete_code(const String &p_code, const String &p_path
ClassDB::get_class_list(&native_classes);
for (List<StringName>::Element *E = native_classes.front(); E; E = E->next()) {
String class_name = E->get().operator String();
if (class_name.begins_with("_")) {
class_name = class_name.right(1);
}
if (Engine::get_singleton()->has_singleton(class_name)) {
continue;
}
Expand Down Expand Up @@ -3041,11 +3003,8 @@ static Error _lookup_symbol_from_base(const GDScriptParser::DataType &p_base, co
case GDScriptParser::DataType::NATIVE: {
StringName class_name = base_type.native_type;
if (!ClassDB::class_exists(class_name)) {
class_name = String("_") + class_name;
if (!ClassDB::class_exists(class_name)) {
base_type.has_type = false;
break;
}
base_type.has_type = false;
break;
}

if (ClassDB::has_method(class_name, p_symbol, true)) {
Expand Down Expand Up @@ -3098,11 +3057,7 @@ static Error _lookup_symbol_from_base(const GDScriptParser::DataType &p_base, co

StringName parent = ClassDB::get_parent_class(class_name);
if (parent != StringName()) {
if (String(parent).begins_with("_")) {
base_type.native_type = String(parent).right(1);
} else {
base_type.native_type = parent;
}
base_type.native_type = parent;
} else {
base_type.has_type = false;
}
Expand Down Expand Up @@ -3162,13 +3117,6 @@ Error GDScriptLanguage::lookup_code(const String &p_code, const String &p_symbol
r_result.type = ScriptLanguage::LookupResult::RESULT_CLASS;
r_result.class_name = p_symbol;
return OK;
} else {
String under_prefix = "_" + p_symbol;
if (ClassDB::class_exists(under_prefix)) {
r_result.type = ScriptLanguage::LookupResult::RESULT_CLASS;
r_result.class_name = p_symbol;
return OK;
}
}

for (int i = 0; i < Variant::VARIANT_MAX; i++) {
Expand Down Expand Up @@ -3331,10 +3279,6 @@ Error GDScriptLanguage::lookup_code(const String &p_code, const String &p_symbol
r_result.class_name = obj->get_class();
}

// proxy class remove the underscore.
if (r_result.class_name.begins_with("_")) {
r_result.class_name = r_result.class_name.right(1);
}
return OK;
}
} else {
Expand Down
6 changes: 1 addition & 5 deletions modules/gdscript/gdscript_function.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,7 @@ struct GDScriptDataType {
Object *obj = p_variant.operator Object *();
if (obj) {
if (!ClassDB::is_parent_class(obj->get_class_name(), native_type)) {
// Try with underscore prefix
StringName underscore_native_type = "_" + native_type;
if (!ClassDB::is_parent_class(obj->get_class_name(), underscore_native_type)) {
return false;
}
return false;
}
}
return true;
Expand Down
14 changes: 4 additions & 10 deletions modules/gdscript/gdscript_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3583,7 +3583,7 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
tokenizer->advance(2);

// Check if name is shadowing something else
if (ClassDB::class_exists(name) || ClassDB::class_exists("_" + name.operator String())) {
if (ClassDB::class_exists(name)) {
_set_error("Class '" + String(name) + "' shadows a native class.");
return;
}
Expand Down Expand Up @@ -5467,7 +5467,7 @@ bool GDScriptParser::_parse_type(DataType &r_type, bool p_can_be_void) {
} break;
case GDScriptTokenizer::TK_IDENTIFIER: {
r_type.native_type = tokenizer->get_token_identifier();
if (ClassDB::class_exists(r_type.native_type) || ClassDB::class_exists("_" + r_type.native_type.operator String())) {
if (ClassDB::class_exists(r_type.native_type)) {
r_type.kind = DataType::NATIVE;
} else {
r_type.kind = DataType::UNRESOLVED;
Expand Down Expand Up @@ -6690,9 +6690,6 @@ bool GDScriptParser::_get_function_signature(DataType &p_base_type, const String
#ifdef DEBUG_METHODS_ENABLED

// Only native remains
if (!ClassDB::class_exists(native)) {
native = "_" + native.operator String();
}
if (!ClassDB::class_exists(native)) {
if (!check_types) return false;
ERR_EXPLAIN("Parser bug: Class '" + String(native) + "' not found.");
Expand Down Expand Up @@ -7199,9 +7196,6 @@ bool GDScriptParser::_get_member_type(const DataType &p_base_type, const StringN
}

// Check ClassDB
if (!ClassDB::class_exists(native)) {
native = "_" + native.operator String();
}
if (!ClassDB::class_exists(native)) {
if (!check_types) return false;
ERR_EXPLAIN("Parser bug: Class '" + String(native) + "' not found.");
Expand Down Expand Up @@ -7320,12 +7314,12 @@ GDScriptParser::DataType GDScriptParser::_reduce_identifier_type(const DataType
if (!p_base_type) {
// Possibly this is a global, check before failing

if (ClassDB::class_exists(p_identifier) || ClassDB::class_exists("_" + p_identifier.operator String())) {
if (ClassDB::class_exists(p_identifier)) {
DataType result;
result.has_type = true;
result.is_constant = true;
result.is_meta_type = true;
if (Engine::get_singleton()->has_singleton(p_identifier) || Engine::get_singleton()->has_singleton("_" + p_identifier.operator String())) {
if (Engine::get_singleton()->has_singleton(p_identifier)) {
result.is_meta_type = false;
}
result.kind = DataType::NATIVE;
Expand Down
2 changes: 1 addition & 1 deletion modules/mono/editor/bindings_generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ class BindingsGenerator {

itype.name = p_cname;
itype.cname = p_cname;
itype.proxy_name = itype.name.begins_with("_") ? itype.name.substr(1, itype.name.length()) : itype.name;
itype.proxy_name = itype.name;
itype.api_type = p_api_type;
itype.is_object_type = true;
itype.class_doc = &EditorHelp::get_doc_data()->class_list[itype.proxy_name];
Expand Down

0 comments on commit 31905de

Please sign in to comment.