diff options
author | Adrian Thurston <thurston@complang.org> | 2015-08-09 15:06:04 -0400 |
---|---|---|
committer | Adrian Thurston <thurston@complang.org> | 2015-08-09 15:06:04 -0400 |
commit | 93dccf445bb3079dfa60d654ea5e56fbcc3f1c54 (patch) | |
tree | c8297427852cb8eb7bfbc9e6172a6fdbfc0405f8 /src/lookup.cc | |
parent | e54d88ee00461f0dc2aead950a232a721ee4644d (diff) | |
download | colm-93dccf445bb3079dfa60d654ea5e56fbcc3f1c54.tar.gz |
allow globals to be declared in namespaces
Diffstat (limited to 'src/lookup.cc')
-rw-r--r-- | src/lookup.cc | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/src/lookup.cc b/src/lookup.cc index 5a57b66f..c5155bdb 100644 --- a/src/lookup.cc +++ b/src/lookup.cc @@ -59,7 +59,7 @@ ObjectField *ObjectDef::findFieldInScope( const NameScope *inScope, ObjectField *NameScope::findField( const String &name ) const { - return owner->findFieldInScope( this, name ); + return owningObj->findFieldInScope( this, name ); } ObjectMethod *NameScope::findMethod( const String &name ) const @@ -116,7 +116,7 @@ VarRefLookup LangVarRef::lookupQualification( Compiler *pd, NameScope *rootScope searchScope = searchObjDef->rootScope; } - return VarRefLookup( lastPtrInQual, firstConstPart, searchScope->owner, searchScope ); + return VarRefLookup( lastPtrInQual, firstConstPart, searchScope->owningObj, searchScope ); } bool LangVarRef::isLocalRef() const @@ -169,12 +169,17 @@ bool LangVarRef::isInbuiltObject() const VarRefLookup LangVarRef::lookupObj( Compiler *pd ) const { NameScope *rootScope; - if ( isLocalRef() ) + + if ( nspaceQual != 0 && nspaceQual->qualNames.length() > 0 ) { + Namespace *nspace = pd->rootNamespace->findNamespace( nspaceQual->qualNames[0] ); + rootScope = nspace->rootScope; + } + else if ( isLocalRef() ) rootScope = scope; else if ( isStructRef() ) rootScope = structDef->objectDef->rootScope; else - rootScope = pd->globalObjectDef->rootScope; + rootScope = nspace != 0 ? nspace->rootScope : pd->rootNamespace->rootScope; return lookupQualification( pd, rootScope ); } @@ -183,7 +188,7 @@ VarRefLookup LangVarRef::lookupMethodObj( Compiler *pd ) const { NameScope *rootScope; - if ( qual->length() == 0 && nspaceQual != 0 && nspaceQual->qualNames.length() > 0 ) { + if ( nspaceQual != 0 && nspaceQual->qualNames.length() > 0 ) { Namespace *nspace = pd->rootNamespace->findNamespace( nspaceQual->qualNames[0] ); rootScope = nspace->rootScope; } @@ -191,11 +196,8 @@ VarRefLookup LangVarRef::lookupMethodObj( Compiler *pd ) const rootScope = scope; else if ( isStructRef() ) rootScope = structDef->objectDef->rootScope; - else if ( qual->length() == 0 ) { - rootScope = nspace != 0 ? nspace->rootScope : pd->rootNamespace->rootScope; - } else - rootScope = pd->globalObjectDef->rootScope; + rootScope = nspace != 0 ? nspace->rootScope : pd->rootNamespace->rootScope; return lookupQualification( pd, rootScope ); } @@ -235,7 +237,6 @@ UniqueType *LangVarRef::lookup( Compiler *pd ) const return elUT; } - VarRefLookup LangVarRef::lookupMethod( Compiler *pd ) const { /* Lookup the object that the field is in. */ |