Package org.ek9lang.compiler.symbols
Class ModuleScope
java.lang.Object
org.ek9lang.compiler.symbols.SymbolTable
org.ek9lang.compiler.symbols.ModuleScope
- All Implemented Interfaces:
Serializable
,IScope
This is a very special scope, because the same 'module name' can be defined in
multiple files. So when looking to resolve variables we need to look up the
scope tree back to the global (program) scope - but when we get here to this module
scope we need to look across all the other modules scopes (with the same module name)
to check in those as well.
So 'resolve' -> 'resolveInThisModuleOnly' or 'resolveWithEnclosingScope'
Then 'resolveInThisModuleOnly' -> scopes * 'resolveInThisScopeOnly' for all in scope in module
Also 'resolveInThisModuleOnly' -> scopes * 'resolveReferenceInThisScopeOnly' for all scopes in module
Finally 'resolveWithEnclosingScope' -> delegates to 'program' 'resolveByFullyQualifiedSearch'
And 'resolveWithEnclosingScope' -> delegates to 'program' 'resolveFromImplicitScopes' (org.ek9.lang etc.).
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.ek9lang.compiler.symbols.IScope
IScope.ScopeType
-
Constructor Summary
ConstructorDescriptionModuleScope
(String scopeName, SharedThreadContext<CompilableProgram> program) Create a new ModuleScope with a specific name and reference to the compilable program it is part of. -
Method Summary
Modifier and TypeMethodDescriptionclone
(SharedThreadContext<CompilableProgram> newContext) Create a clone of this ModuleScope.boolean
defineOrError
(ISymbol symbol, SymbolChecker symbolChecker) Defines a new symbol and returns true if all when OK But if there were errors created then false is returned.void
defineReference
(IToken token, ISymbol symbol) Add a reference to another construct in another module, so it can be used in shorthand form in this module.boolean
Returns the original location a reference was made (if present).int
hashCode()
resolve
(SymbolSearch search) Search and resolve from a symbol search.resolveInThisModuleOnly
(SymbolSearch search) Looks to resolve search in either the references held or the symbols in all the scopes for this module.resolveInThisScopeOnly
(SymbolSearch search) Just does a search in this particular module scope.resolveOrDefine
(PossibleGenericSymbol parameterisedSymbol, ErrorListener errorListener) Used when resolving or needing to define a parameterised type, like 'List of String' for example.Does a check if there is a references of that symbol already held in this module scope.This class is the root and so there is no enclosing scope.Methods inherited from class org.ek9lang.compiler.symbols.SymbolTable
clone, cloneIntoSymbolTable, define, findNearestDynamicBlockScopeInEnclosingScopes, findNearestNonBlockScopeInEnclosingScopes, getAllSymbolsMatchingName, getEnclosingScope, getEncounteredExceptionToken, getFriendlyScopeName, getScopeName, getScopeType, getSymbolsForThisScope, getSymbolsForThisScopeOfCategory, isMarkedPure, isScopeAMatchForEnclosingScope, isTerminatedNormally, resolveMatchingMethods, resolveMatchingMethodsInEnclosingScope, resolveMatchingMethodsInThisScopeOnly, resolveMember, searchIsNotInThisScope, setEncounteredExceptionToken, setMarkedPure, toString
-
Constructor Details
-
Method Details
-
equals
- Overrides:
equals
in classSymbolTable
-
hashCode
public int hashCode()- Overrides:
hashCode
in classSymbolTable
-
defineReference
Add a reference to another construct in another module, so it can be used in shorthand form in this module. -
getOriginalReferenceLocation
Returns the original location a reference was made (if present). -
resolveOrDefine
public Optional<ISymbol> resolveOrDefine(PossibleGenericSymbol parameterisedSymbol, ErrorListener errorListener) Used when resolving or needing to define a parameterised type, like 'List of String' for example. Now while this moduleScope maybe for the code being parsed and processed, the reference to a generic type like org.ek9.lang::List means that the resulting new type: 'org.ek9.lang::List of org.ek9.lang::String' or 'org.ek9.lang::List of my.mod.area::Widget' will be stored in the module space of the Generic Type. So do not assume this new type will reside in this module scope, it most probably won't. -
defineOrError
Defines a new symbol and returns true if all when OK But if there were errors created then false is returned. This is expensive in the sense that it does the check and define by owning the re-entrant lock on the compilable program. -
resolve
Description copied from class:SymbolTable
Search and resolve from a symbol search.- Specified by:
resolve
in interfaceIScope
- Overrides:
resolve
in classSymbolTable
-
resolveInThisModuleOnly
Looks to resolve search in either the references held or the symbols in all the scopes for this module. -
resolveInThisScopeOnly
Just does a search in this particular module scope. Which means as there can be multiple module scopes in the name module, this is only a partial search.- Specified by:
resolveInThisScopeOnly
in interfaceIScope
- Overrides:
resolveInThisScopeOnly
in classSymbolTable
-
resolveReferenceInThisScopeOnly
Does a check if there is a references of that symbol already held in this module scope. But remember there can be multiple of these per named module. -
resolveWithEnclosingScope
Description copied from class:SymbolTable
This class is the root and so there is no enclosing scope. subclasses will override to provide the scope that encloses them- Overrides:
resolveWithEnclosingScope
in classSymbolTable