Class ParsedModule

java.lang.Object
org.ek9lang.compiler.ParsedModule
All Implemented Interfaces:
Serializable, Module

public class ParsedModule extends Object implements Module, Serializable
Once we have parsed a module (source file) we need to keep track of the results. Now there is the normal CompilationUnitContext which has the entry point into the compiled file. But there are also a set of scopes we create when we visit the context with the visitor. The scopes are critical to being able to check for multiple definitions of the same identity (and type) but also when it comes to resolving names. Importantly because we can define the same 'module name' in more than one source file and also because we can 'reference' other modules by name it means we have to be able to resolve names across multiple ParsedModules to find the scope they are in. It also means that if a single source code file is altered we need to remove the related ParsedModule (for that source file) but keep the many others we have - because these will not have changed. But the identities they reference may now have been removed (if we alter a source file). As there will be very many source files we should only parse them when we really have to - the reading and parsing is the most expensive part. But we may still have to re-run the definition and resolving phases for all ParsedModules. Importantly if we have a module that is parsed but is marked as being in error (i.e. duplicate definition or missing reference) we also need to re-run the redefinition on these modules as well (even though their source code might not have changed). But we might be able to get around unnecessary definition and resolving if we keep a reference to the compilation unit where we resolved the definition. Clearly when adding new compilation units we may have to complete a resolve again. All access to symbol tables of anything shared is via SharedThreadContext. So this will be created on a per source file basis and then can be parsed with a listener or a visitor. An instance of this parsedModule will be given to the visitor/listener then the compilationUnitContext can be set and the scope tree built up. So the listener/visitor during the first parse will need to keep a local variable of the current scope and deal with interacting with this object to put both the contexts and scopes into the ParseTreeProperty scopes object.
See Also:
  • Constructor Details

  • Method Details

    • getModuleScope

      public ModuleScope getModuleScope()
    • setModuleScope

      public void setModuleScope(ModuleScope moduleScope)
    • getEk9Types

      public Ek9Types getEk9Types()
      If cached ek9 types have been provided, they can be accessed here.
    • isExternallyImplemented

      public boolean isExternallyImplemented()
    • setExternallyImplemented

      public void setExternallyImplemented(boolean externallyImplemented)
    • isEk9Core

      public boolean isEk9Core()
      Specified by:
      isEk9Core in interface Module
    • acceptCompilationUnitContext

      public ModuleScope acceptCompilationUnitContext(EK9Parser.CompilationUnitContext compilationUnitContext)
      Once the source code has been parsed by one of the stages in the compiler, the CompilationUnitContext can be provided to this Parsed module. It will then have the second part of its initialisation complete. It will create a module scope and that can be used to add and define symbols.
    • isForThisCompilableSource

      public boolean isForThisCompilableSource(CompilableSource compilableSource)
    • recordDirective

      public void recordDirective(Directive directive)
      When processing EK9 source code the developer now has some ability to use '@directives'. These are aimed at code compilation, instrumentation and error checking. This means that for compiler development, we can reduce the number of Java unit tests and specific coding (to some extent), by adding in our expectations just before we write so erroneous code (to check the compiler). This means that the test and the deliberated defective code as co-located.
    • getDirectives

      public List<Directive> getDirectives(DirectiveType type, CompilationPhase phase)
      Provide access to any directives recorded of a specific type and compilation phase.
    • getDirectives

      public List<Directive> getDirectives(DirectiveType type)
      Provide access to any directives recorded.
    • recordScope

      public void recordScope(org.antlr.v4.runtime.tree.ParseTree node, IScope withScope)
      Record a particular node context during listen/visit of a context with a particular scope.
    • getRecordedScope

      public IScope getRecordedScope(org.antlr.v4.runtime.tree.ParseTree node)
      Locate and return a recorded scope against part of the parse tree, this may return null if nothing has been recorded.
    • recordSymbol

      public void recordSymbol(org.antlr.v4.runtime.tree.ParseTree node, ISymbol symbol)
      Record a particular node context with a particular symbol.
    • getRecordedSymbol

      public ISymbol getRecordedSymbol(org.antlr.v4.runtime.tree.ParseTree node)
      Locate and return a recorded symbol against part of the parse tree, this may return null if nothing has been recorded.
    • equals

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

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getModuleName

      public String getModuleName()
    • setModuleName

      public void setModuleName(String moduleName)
    • getSource

      public CompilableSource getSource()
      Specified by:
      getSource in interface Module
    • getScopeName

      public String getScopeName()
      Specified by:
      getScopeName in interface Module