Package iota

Class ICompilationUnit

java.lang.Object
iota.IAST
iota.ICompilationUnit

class ICompilationUnit extends IAST
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:

  1. 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.
  2. 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.
  3. 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 Details

    • mods

      protected ArrayList<String> 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

      public Type 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

      public void reportSemanticError(int line, String message, Object... arguments)
      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

      public void preAnalyze(Context context, CLEmitter partial)
      Performs first phase of semantic analysis on this AST.
      Overrides:
      preAnalyze in class IAST
      Parameters:
      context - the environment (scope) in which code is pre-analyzed.
      partial - the code emitter.
    • analyze

      public IAST analyze(Context context)
      Performs second phase of semantic analysis on this AST and returns the (possibly modified) AST.
      Specified by:
      analyze in class IAST
      Parameters:
      context - the environment (scope) in which code is analyzed.
      Returns:
      the (possibly modified) AST.
    • codegen

      public void codegen(CLEmitter output)
      Performs code generation for this AST.
      Specified by:
      codegen in class IAST
      Parameters:
      output - the code emitter.
    • toJSON

      public void toJSON(JSONElement json)
      Stores information about this AST in JSON format.
      Overrides:
      toJSON in class IAST
      Parameters:
      json - the JSON emitter.