Allow to extends constant variable
This commit is contained in:
parent
24fe3bd605
commit
fb801d4964
2 changed files with 51 additions and 9 deletions
|
@ -1686,21 +1686,44 @@ Error GDScriptCompiler::_parse_class(GDScript *p_script, GDScript *p_owner, cons
|
|||
base_class = p->subclasses[base];
|
||||
break;
|
||||
}
|
||||
|
||||
if (p->constants.has(base)) {
|
||||
|
||||
base_class = p->constants[base];
|
||||
if (base_class.is_null()) {
|
||||
_set_error("Constant is not a class: " + base, p_class);
|
||||
return ERR_SCRIPT_FAILED;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
p = p->_owner;
|
||||
}
|
||||
|
||||
if (base_class.is_valid()) {
|
||||
|
||||
String ident = base;
|
||||
|
||||
for (int i = 1; i < p_class->extends_class.size(); i++) {
|
||||
|
||||
String subclass = p_class->extends_class[i];
|
||||
|
||||
ident += ("." + subclass);
|
||||
|
||||
if (base_class->subclasses.has(subclass)) {
|
||||
|
||||
base_class = base_class->subclasses[subclass];
|
||||
} else if (base_class->constants.has(subclass)) {
|
||||
|
||||
Ref<GDScript> new_base_class = base_class->constants[subclass];
|
||||
if (new_base_class.is_null()) {
|
||||
_set_error("Constant is not a class: " + ident, p_class);
|
||||
return ERR_SCRIPT_FAILED;
|
||||
}
|
||||
base_class = new_base_class;
|
||||
} else {
|
||||
|
||||
_set_error("Could not find subclass: " + subclass, p_class);
|
||||
_set_error("Could not find subclass: " + ident, p_class);
|
||||
return ERR_FILE_NOT_FOUND;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2971,18 +2971,37 @@ void GDScriptParser::_parse_extends(ClassNode *p_class) {
|
|||
}
|
||||
|
||||
while (true) {
|
||||
if (tokenizer->get_token() != GDScriptTokenizer::TK_IDENTIFIER) {
|
||||
|
||||
_set_error("Invalid 'extends' syntax, expected string constant (path) and/or identifier (parent class).");
|
||||
return;
|
||||
switch (tokenizer->get_token()) {
|
||||
|
||||
case GDScriptTokenizer::TK_IDENTIFIER: {
|
||||
|
||||
StringName identifier = tokenizer->get_token_identifier();
|
||||
p_class->extends_class.push_back(identifier);
|
||||
}
|
||||
break;
|
||||
|
||||
case GDScriptTokenizer::TK_PERIOD:
|
||||
break;
|
||||
|
||||
default: {
|
||||
|
||||
_set_error("Invalid 'extends' syntax, expected string constant (path) and/or identifier (parent class).");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
StringName identifier = tokenizer->get_token_identifier();
|
||||
p_class->extends_class.push_back(identifier);
|
||||
|
||||
tokenizer->advance(1);
|
||||
if (tokenizer->get_token() != GDScriptTokenizer::TK_PERIOD)
|
||||
return;
|
||||
|
||||
switch (tokenizer->get_token()) {
|
||||
|
||||
case GDScriptTokenizer::TK_IDENTIFIER:
|
||||
case GDScriptTokenizer::TK_PERIOD:
|
||||
continue;
|
||||
|
||||
default:
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue