diff options
author | Adrian Thurston <thurston@complang.org> | 2013-12-31 11:43:20 -0500 |
---|---|---|
committer | Adrian Thurston <thurston@complang.org> | 2013-12-31 11:43:20 -0500 |
commit | 415c21f86d1d0b7ff49932b4b61251870e7400fb (patch) | |
tree | b2bb76e45525bf496084e78be1ae1d3e8d2133a1 /src/lookup.cc | |
parent | fc1d502d70df74114c8edff5c7ce808895f156f9 (diff) | |
download | colm-415c21f86d1d0b7ff49932b4b61251870e7400fb.tar.gz |
pass the current scope to VarRef cons
This will lets us eliminate the scope walk needed for successful VarRef lookup.
Diffstat (limited to 'src/lookup.cc')
-rw-r--r-- | src/lookup.cc | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/lookup.cc b/src/lookup.cc index a2815acb..2c6dd9ea 100644 --- a/src/lookup.cc +++ b/src/lookup.cc @@ -29,6 +29,26 @@ using std::cout; using std::cerr; using std::endl; +/* Recurisve find through a single object def's scope. */ +ObjectField *ObjectDef::findFieldInScope( const String &name, ObjNameScope *inScope ) +{ + ObjFieldMapEl *objDefMapEl = inScope->objFieldMap->find( name ); + if ( objDefMapEl != 0 ) + return objDefMapEl->value; + if ( inScope->parentScope != 0 ) + return findFieldInScope( name, inScope->parentScope ); + return 0; +} + +ObjectField *ObjectDef::findField( const String &name ) +{ + //cout << "looking for " << name << endl; + ObjectField *objField = findFieldInScope( name, scope ); + if ( objField != 0 ) + return objField; + return 0; +} + UniqueType *LangVarRef::lookup( Compiler *pd ) const { /* Lookup the loadObj. */ |