You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-04 12:00:25 +00:00
GDScript: Allow constant expressions in annotations
This commit is contained in:
@@ -2448,7 +2448,6 @@ bool GDScriptLanguage::handles_global_class_type(const String &p_type) const {
|
||||
}
|
||||
|
||||
String GDScriptLanguage::get_global_class_name(const String &p_path, String *r_base_type, String *r_icon_path) const {
|
||||
Vector<uint8_t> sourcef;
|
||||
Error err;
|
||||
Ref<FileAccess> f = FileAccess::open(p_path, FileAccess::READ, &err);
|
||||
if (err) {
|
||||
@@ -2459,88 +2458,31 @@ String GDScriptLanguage::get_global_class_name(const String &p_path, String *r_b
|
||||
|
||||
GDScriptParser parser;
|
||||
err = parser.parse(source, p_path, false);
|
||||
|
||||
// TODO: Simplify this code by using the analyzer to get full inheritance.
|
||||
if (err == OK) {
|
||||
const GDScriptParser::ClassNode *c = parser.get_tree();
|
||||
if (r_icon_path) {
|
||||
if (c->icon_path.is_empty() || c->icon_path.is_absolute_path()) {
|
||||
*r_icon_path = c->icon_path;
|
||||
} else if (c->icon_path.is_relative_path()) {
|
||||
*r_icon_path = p_path.get_base_dir().path_join(c->icon_path).simplify_path();
|
||||
}
|
||||
}
|
||||
if (r_base_type) {
|
||||
const GDScriptParser::ClassNode *subclass = c;
|
||||
String path = p_path;
|
||||
GDScriptParser subparser;
|
||||
while (subclass) {
|
||||
if (subclass->extends_used) {
|
||||
if (!subclass->extends_path.is_empty()) {
|
||||
if (subclass->extends.size() == 0) {
|
||||
get_global_class_name(subclass->extends_path, r_base_type);
|
||||
subclass = nullptr;
|
||||
break;
|
||||
} else {
|
||||
Vector<StringName> extend_classes = subclass->extends;
|
||||
|
||||
Ref<FileAccess> subfile = FileAccess::open(subclass->extends_path, FileAccess::READ);
|
||||
if (subfile.is_null()) {
|
||||
break;
|
||||
}
|
||||
String subsource = subfile->get_as_utf8_string();
|
||||
|
||||
if (subsource.is_empty()) {
|
||||
break;
|
||||
}
|
||||
String subpath = subclass->extends_path;
|
||||
if (subpath.is_relative_path()) {
|
||||
subpath = path.get_base_dir().path_join(subpath).simplify_path();
|
||||
}
|
||||
|
||||
if (OK != subparser.parse(subsource, subpath, false)) {
|
||||
break;
|
||||
}
|
||||
path = subpath;
|
||||
subclass = subparser.get_tree();
|
||||
|
||||
while (extend_classes.size() > 0) {
|
||||
bool found = false;
|
||||
for (int i = 0; i < subclass->members.size(); i++) {
|
||||
if (subclass->members[i].type != GDScriptParser::ClassNode::Member::CLASS) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const GDScriptParser::ClassNode *inner_class = subclass->members[i].m_class;
|
||||
if (inner_class->identifier->name == extend_classes[0]) {
|
||||
extend_classes.remove_at(0);
|
||||
found = true;
|
||||
subclass = inner_class;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
subclass = nullptr;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (subclass->extends.size() == 1) {
|
||||
*r_base_type = subclass->extends[0];
|
||||
subclass = nullptr;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
*r_base_type = "RefCounted";
|
||||
subclass = nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
return c->identifier != nullptr ? String(c->identifier->name) : String();
|
||||
if (err) {
|
||||
return String();
|
||||
}
|
||||
|
||||
return String();
|
||||
GDScriptAnalyzer analyzer(&parser);
|
||||
err = analyzer.resolve_inheritance();
|
||||
if (err) {
|
||||
return String();
|
||||
}
|
||||
|
||||
const GDScriptParser::ClassNode *c = parser.get_tree();
|
||||
|
||||
if (r_base_type) {
|
||||
*r_base_type = c->get_datatype().native_type;
|
||||
}
|
||||
|
||||
if (r_icon_path) {
|
||||
if (c->icon_path.is_empty() || c->icon_path.is_absolute_path()) {
|
||||
*r_icon_path = c->icon_path.simplify_path();
|
||||
} else if (c->icon_path.is_relative_path()) {
|
||||
*r_icon_path = p_path.get_base_dir().path_join(c->icon_path).simplify_path();
|
||||
}
|
||||
}
|
||||
|
||||
return c->identifier != nullptr ? String(c->identifier->name) : String();
|
||||
}
|
||||
|
||||
GDScriptLanguage::GDScriptLanguage() {
|
||||
|
||||
Reference in New Issue
Block a user