Class ModuleScope

java.lang.Object
org.ek9lang.compiler.symbols.SymbolTable
org.ek9lang.compiler.symbols.ModuleScope
All Implemented Interfaces:
Serializable, IScope

public class ModuleScope extends SymbolTable
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:
  • Constructor Details

  • Method Details

    • clone

      Create a clone of this ModuleScope.
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class SymbolTable
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class SymbolTable
    • defineReference

      public 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.
    • getOriginalReferenceLocation

      public Optional<IToken> getOriginalReferenceLocation(SymbolSearch search)
      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

      public 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. This is expensive in the sense that it does the check and define by owning the re-entrant lock on the compilable program.
    • resolve

      public Optional<ISymbol> resolve(SymbolSearch search)
      Description copied from class: SymbolTable
      Search and resolve from a symbol search.
      Specified by:
      resolve in interface IScope
      Overrides:
      resolve in class SymbolTable
    • resolveInThisModuleOnly

      public Optional<ISymbol> resolveInThisModuleOnly(SymbolSearch search)
      Looks to resolve search in either the references held or the symbols in all the scopes for this module.
    • resolveInThisScopeOnly

      public Optional<ISymbol> resolveInThisScopeOnly(SymbolSearch search)
      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 interface IScope
      Overrides:
      resolveInThisScopeOnly in class SymbolTable
    • resolveReferenceInThisScopeOnly

      public Optional<ISymbol> resolveReferenceInThisScopeOnly(SymbolSearch search)
      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

      public Optional<ISymbol> resolveWithEnclosingScope(SymbolSearch search)
      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 class SymbolTable