Package org.ek9lang.compiler
Class ParsedModule
java.lang.Object
org.ek9lang.compiler.ParsedModule
- All Implemented Interfaces:
Serializable
,Module
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 Summary
ConstructorDescriptionParsedModule
(CompilableSource source, SharedThreadContext<CompilableProgram> compilableProgram) We may hold Nodes in here - but not sure yet. -
Method Summary
Modifier and TypeMethodDescriptionacceptCompilationUnitContext
(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.boolean
getDirectives
(DirectiveType type) Provide access to any directives recorded.getDirectives
(DirectiveType type, CompilationPhase phase) Provide access to any directives recorded of a specific type and compilation phase.If cached ek9 types have been provided, they can be accessed here.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.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.int
hashCode()
boolean
boolean
boolean
isForThisCompilableSource
(CompilableSource compilableSource) void
recordDirective
(Directive directive) When processing EK9 source code the developer now has some ability to use '@directives'.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.void
recordSymbol
(org.antlr.v4.runtime.tree.ParseTree node, ISymbol symbol) Record a particular node context with a particular symbol.void
setExternallyImplemented
(boolean externallyImplemented) void
setModuleName
(String moduleName) void
setModuleScope
(ModuleScope moduleScope) toString()
-
Constructor Details
-
Method Details
-
getModuleScope
-
setModuleScope
-
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() -
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
-
recordDirective
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
Provide access to any directives recorded of a specific type and compilation phase. -
getDirectives
Provide access to any directives recorded. -
recordScope
Record a particular node context during listen/visit of a context with a particular scope. -
getRecordedScope
Locate and return a recorded scope against part of the parse tree, this may return null if nothing has been recorded. -
recordSymbol
Record a particular node context with a particular symbol. -
getRecordedSymbol
Locate and return a recorded symbol against part of the parse tree, this may return null if nothing has been recorded. -
equals
-
hashCode
public int hashCode() -
toString
-
getModuleName
-
setModuleName
-
getSource
-
getScopeName
- Specified by:
getScopeName
in interfaceModule
-