Package iota
Class ICompilationUnit
java.lang.Object
iota.IAST
iota.ICompilationUnit
The abstract syntax tree (AST) node representing a compilation unit, and so the root of the AST.
The AST is produced by the Parser. Once the AST has been built, three successive methods are invoked:
- Method preAnalyze() is invoked for making a first pass at type analysis, recursively reaching down to the method headers. preAnalyze() creates a partial class file (in memory) with this information.
- Method analyze() is invoked for type-checking method bodies and determining the types of all expressions. A certain amount of tree surgery is also done here. And stack frame offsets are computed for method parameters and local variables.
- Method codegen() is invoked for generating intermediate, in-memory JVM bytecode for the compilation unit. It calls methods on the CLEmitter object output this purpose. Of course, codegen(), starting at the root of the AST, makes recursive calls down the tree, to the codegen() method at each node, for generating the appropriate instructions.
-
Field Summary
FieldsModifier and TypeFieldDescriptionModifiers of the class (ie, type) induced by this compilation unit.Fields inherited from class iota.IAST
compilationUnit, line
-
Constructor Summary
ConstructorsConstructorDescriptionICompilationUnit
(String fileName, int line, ArrayList<IMethodDeclaration> methodDeclarations) Constructs an AST node for a compilation unit. -
Method Summary
Modifier and TypeMethodDescriptionPerforms second phase of semantic analysis on this AST and returns the (possibly modified) AST.void
Performs code generation for this AST.boolean
Returns true if a semantic error has occurred up to now, and false otherwise.void
Records the fact that the entry point method (void main()) exists.void
preAnalyze
(Context context, CLEmitter partial) Performs first phase of semantic analysis on this AST.void
reportSemanticError
(int line, String message, Object... arguments) Reports a semantic error.thisType()
Returns the type induced by this compilation unit.void
toJSON
(JSONElement json) Stores information about this AST in JSON format.
-
Field Details
-
mods
Modifiers of the class (ie, type) induced by this compilation unit.
-
-
Constructor Details
-
ICompilationUnit
public ICompilationUnit(String fileName, int line, ArrayList<IMethodDeclaration> methodDeclarations) Constructs an AST node for a compilation unit.- Parameters:
fileName
- the name of the source file.line
- line in which the compilation unit occurs in the source file.methodDeclarations
- method declarations.
-
-
Method Details
-
hasEntryPoint
public void hasEntryPoint()Records the fact that the entry point method (void main()) exists. -
thisType
Returns the type induced by this compilation unit.- Returns:
- the type induced by this compilation unit.
-
errorHasOccurred
public boolean errorHasOccurred()Returns true if a semantic error has occurred up to now, and false otherwise.- Returns:
- true if a semantic error has occurred up to now, and false otherwise..
-
reportSemanticError
Reports a semantic error.- Parameters:
line
- line in which the error occurred in the source file.message
- message identifying the error.arguments
- related values.
-
preAnalyze
Performs first phase of semantic analysis on this AST.- Overrides:
preAnalyze
in classIAST
- Parameters:
context
- the environment (scope) in which code is pre-analyzed.partial
- the code emitter.
-
analyze
Performs second phase of semantic analysis on this AST and returns the (possibly modified) AST. -
codegen
Performs code generation for this AST. -
toJSON
Stores information about this AST in JSON format.
-