Package com.tonic.analysis.source.lower
Class ASTLowerer
- java.lang.Object
-
- com.tonic.analysis.source.lower.ASTLowerer
-
public class ASTLowerer extends Object
Facade that lowers a source-level AST method body into SSA IR ready for bytecode emission.
-
-
Constructor Summary
Constructors Constructor Description ASTLowerer(ConstPool constPool, ClassPool classPool)Creates a lowerer bound to the given pools.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description List<SyntheticArrayConstructor>drainPendingArrayConstructors()Empties the array-constructor queue.List<SyntheticLambdaMethod>drainPendingLambdas()Empties the lambda queue.booleanhasPendingSynthetics()IRMethodlower(MethodDecl methodDecl, String ownerClass)Desugars and lowers a full method declaration to a new IRMethod.IRMethodlower(BlockStmt body, String methodName, String ownerClass, boolean isStatic, List<SourceType> parameters, SourceType returnType)Lowers an AST method body to a new IRMethod.static IRMethodlowerMethod(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.IRMethodlowerSyntheticArrayConstructor(SyntheticArrayConstructor constructor, String ownerClass)Lowers a synthetic array-constructor method ((I)[Treturningnew T[arg0]).IRMethodlowerSyntheticLambda(SyntheticLambdaMethod synthetic, String ownerClass)Lowers a synthetic lambda body, binding captures then lambda parameters as named locals.voidreplaceBody(BlockStmt body, IRMethod irMethod)Convenience method to lower and replace an IRMethod's body from AST.voidsetCurrentClassDecl(TypeDecl currentClassDecl)Sets the enclosing class declaration used to resolve member references during lowering.voidsetImports(List<ImportDecl> imports)Sets the imports used to resolve simple type names during lowering.
-
-
-
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 BlockStmtmethodName- the method nameownerClass- the owning class (internal name)isStatic- whether the method is staticparameters- list of parameter typesreturnType- 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 bodyownerClass- 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 orderownerClass- 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 capturesthis, which cannot be emitted here
-
lowerSyntheticArrayConstructor
public IRMethod lowerSyntheticArrayConstructor(SyntheticArrayConstructor constructor, String ownerClass)
Lowers a synthetic array-constructor method ((I)[Treturningnew T[arg0]).- Parameters:
constructor- the queued constructor, supplying the name and array typeownerClass- 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 bodyirMethod- 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 lowermethodName- name of the method being loweredownerClass- internal name of the declaring classisStatic- true when the method takes nothisslotparameters- declared parameter types, in orderreturnType- declared return typeconstPool- constant pool the lowered references are written intoclassPool- pool used to resolve referenced types- Returns:
- the lowered method
-
-