1
0
mirror of https://github.com/godotengine/godot synced 2024-07-08 17:45:48 +00:00

Fixes to constants in scope

This commit is contained in:
Juan Linietsky 2014-05-02 12:40:34 -03:00
parent 6572d51288
commit f1d3b30a45
2 changed files with 47 additions and 32 deletions

View File

@ -185,51 +185,59 @@ int GDCompiler::_parse_expression(CodeGen& codegen,const GDParser::Node *p_expre
//TRY CLASS CONSTANTS //TRY CLASS CONSTANTS
GDScript *scr = codegen.script; GDScript *owner = codegen.script;
GDNativeClass *nc=NULL; while (owner) {
while(scr) {
if (scr->constants.has(identifier)) { GDScript *scr = owner;
GDNativeClass *nc=NULL;
while(scr) {
//int idx=scr->constants[identifier]; if (scr->constants.has(identifier)) {
int idx = codegen.get_name_map_pos(identifier);
return idx|(GDFunction::ADDR_TYPE_CLASS_CONSTANT<<GDFunction::ADDR_BITS); //argument (stack root) //int idx=scr->constants[identifier];
int idx = codegen.get_name_map_pos(identifier);
return idx|(GDFunction::ADDR_TYPE_CLASS_CONSTANT<<GDFunction::ADDR_BITS); //argument (stack root)
}
if (scr->native.is_valid())
nc=scr->native.ptr();
scr=scr->_base;
} }
if (scr->native.is_valid())
nc=scr->native.ptr();
scr=scr->_base;
}
// CLASS C++ Integer Constant // CLASS C++ Integer Constant
if (nc) { if (nc) {
bool success=false; bool success=false;
int constant = ObjectTypeDB::get_integer_constant(nc->get_name(),identifier,&success); int constant = ObjectTypeDB::get_integer_constant(nc->get_name(),identifier,&success);
if (success) { if (success) {
Variant key=constant; Variant key=constant;
int idx; int idx;
if (!codegen.constant_map.has(key)) { if (!codegen.constant_map.has(key)) {
idx=codegen.constant_map.size(); idx=codegen.constant_map.size();
codegen.constant_map[key]=idx; codegen.constant_map[key]=idx;
} else { } else {
idx=codegen.constant_map[key]; idx=codegen.constant_map[key];
}
return idx|(GDFunction::ADDR_TYPE_LOCAL_CONSTANT<<GDFunction::ADDR_BITS); //make it a local constant (faster access)
} }
return idx|(GDFunction::ADDR_TYPE_LOCAL_CONSTANT<<GDFunction::ADDR_BITS); //make it a local constant (faster access)
} }
owner=owner->_owner;
} }
if (codegen.script->subclasses.has(identifier)) { /*
handled in constants now
if (codegen.script->subclasses.has(identifier)) {
//same with a subclass, make it a local constant. //same with a subclass, make it a local constant.
int idx = codegen.get_constant_pos(codegen.script->subclasses[identifier]); int idx = codegen.get_constant_pos(codegen.script->subclasses[identifier]);
return idx|(GDFunction::ADDR_TYPE_LOCAL_CONSTANT<<GDFunction::ADDR_BITS); //make it a local constant (faster access) return idx|(GDFunction::ADDR_TYPE_LOCAL_CONSTANT<<GDFunction::ADDR_BITS); //make it a local constant (faster access)
} }*/
if (GDScriptLanguage::get_singleton()->get_global_map().has(identifier)) { if (GDScriptLanguage::get_singleton()->get_global_map().has(identifier)) {
@ -1457,6 +1465,8 @@ Error GDCompiler::_parse_class(GDScript *p_script,GDScript *p_owner,const GDPars
Error err = _parse_class(subclass.ptr(),p_script,p_class->subclasses[i]); Error err = _parse_class(subclass.ptr(),p_script,p_class->subclasses[i]);
if (err) if (err)
return err; return err;
p_script->constants.insert(name,subclass); //once parsed, goes to the list of constants
p_script->subclasses.insert(name,subclass); p_script->subclasses.insert(name,subclass);
} }

View File

@ -76,16 +76,21 @@ Variant *GDFunction::_get_variant(int p_address,GDInstance *p_instance,GDScript
case ADDR_TYPE_CLASS_CONSTANT: { case ADDR_TYPE_CLASS_CONSTANT: {
//todo change to index! //todo change to index!
GDScript *s=p_script; GDScript *o=p_script;
ERR_FAIL_INDEX_V(address,_global_names_count,NULL); ERR_FAIL_INDEX_V(address,_global_names_count,NULL);
const StringName *sn = &_global_names_ptr[address]; const StringName *sn = &_global_names_ptr[address];
while(s) { while(o) {
Map<StringName,Variant>::Element *E=s->constants.find(*sn); GDScript *s=o;
if (E) { while(s) {
return &E->get();
Map<StringName,Variant>::Element *E=s->constants.find(*sn);
if (E) {
return &E->get();
}
s=s->_base;
} }
s=s->_base; o=o->_owner;
} }