Class ASTLowerer


  • public class ASTLowerer
    extends Object
    Facade that lowers a source-level AST method body into SSA IR ready for bytecode emission.
    • Constructor Detail

      • ASTLowerer

        public ASTLowerer​(ConstPool constPool,
                          ClassPool classPool)
        Creates a lowerer bound to the given pools.
        Parameters:
        constPool - the constant pool that receives emitted entries
        classPool - the class pool used for type resolution
    • Method Detail

      • setCurrentClassDecl

        public void setCurrentClassDecl​(TypeDecl currentClassDecl)
        Sets the enclosing class declaration used to resolve member references during lowering.
        Parameters:
        currentClassDecl - the class declaration being lowered
      • setImports

        public void setImports​(List<ImportDecl> imports)
        Sets the imports used to resolve simple type names during lowering.
        Parameters:
        imports - the compilation unit's import declarations
      • lower

        public IRMethod lower​(BlockStmt body,
                              String methodName,
                              String ownerClass,
                              boolean isStatic,
                              List<SourceType> parameters,
                              SourceType returnType)
        Lowers an AST method body to a new IRMethod.
        Parameters:
        body - the method body as BlockStmt
        methodName - the method name
        ownerClass - the owning class (internal name)
        isStatic - whether the method is static
        parameters - list of parameter types
        returnType - the return type
        Returns:
        the generated IRMethod
      • lower

        public IRMethod lower​(MethodDecl methodDecl,
                              String ownerClass)
        Desugars and lowers a full method declaration to a new IRMethod.
        Parameters:
        methodDecl - the method declaration; must have a body
        ownerClass - the owning class internal name
        Returns:
        the generated IRMethod
        Throws:
        LoweringException - if the method has no body
      • hasPendingSynthetics

        public boolean hasPendingSynthetics()
        Returns:
        true while a lambda or array-constructor synthetic is still queued
      • drainPendingLambdas

        public List<SyntheticLambdaMethod> drainPendingLambdas()
        Empties the lambda queue.
        Returns:
        the queued synthetic lambda methods
      • drainPendingArrayConstructors

        public List<SyntheticArrayConstructor> drainPendingArrayConstructors()
        Empties the array-constructor queue.
        Returns:
        the queued synthetic array-constructor methods
      • lowerSyntheticLambda

        public IRMethod lowerSyntheticLambda​(SyntheticLambdaMethod synthetic,
                                             String ownerClass)
        Lowers a synthetic lambda body, binding captures then lambda parameters as named locals.
        Parameters:
        synthetic - the queued lambda, whose descriptor fixes the parameter order
        ownerClass - internal name of the class the synthetic is emitted into
        Returns:
        the lowered method, in SSA form when the body branches or loops
        Throws:
        LoweringException - if the synthetic captures this, which cannot be emitted here
      • lowerSyntheticArrayConstructor

        public IRMethod lowerSyntheticArrayConstructor​(SyntheticArrayConstructor constructor,
                                                       String ownerClass)
        Lowers a synthetic array-constructor method ((I)[T returning new T[arg0]).
        Parameters:
        constructor - the queued constructor, supplying the name and array type
        ownerClass - internal name of the class the synthetic is emitted into
        Returns:
        the lowered method
      • replaceBody

        public void replaceBody​(BlockStmt body,
                                IRMethod irMethod)
        Convenience method to lower and replace an IRMethod's body from AST.
        Parameters:
        body - the new method body
        irMethod - the existing IRMethod
      • lowerMethod

        public static IRMethod lowerMethod​(BlockStmt body,
                                           String methodName,
                                           String ownerClass,
                                           boolean isStatic,
                                           List<SourceType> parameters,
                                           SourceType returnType,
                                           ConstPool constPool,
                                           ClassPool classPool)
        Lowers one method body without keeping the lowerer around.
        Parameters:
        body - the statements to lower
        methodName - name of the method being lowered
        ownerClass - internal name of the declaring class
        isStatic - true when the method takes no this slot
        parameters - declared parameter types, in order
        returnType - declared return type
        constPool - constant pool the lowered references are written into
        classPool - pool used to resolve referenced types
        Returns:
        the lowered method