Class UnitCompiler
- java.lang.Object
-
- org.codehaus.janino.UnitCompiler
-
public class UnitCompiler extends java.lang.Object
This class actually implements the Java™ compiler. It is associated with exactly one compilation unit which it compiles.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static interface
UnitCompiler.Compilable
Helper interface for string conversion.static class
UnitCompiler.SimpleIField
Short-hand implementation ofIClass.IField
that implements a non-constant, non-static, package-accessible field.
-
Field Summary
Fields Modifier and Type Field Description private CodeContext
codeContext
private Java.CompilationUnit
compilationUnit
private int
compileErrorCount
private static boolean
DEBUG
private boolean
debugLines
private boolean
debugSource
private boolean
debugVars
private java.util.List<ClassFile>
generatedClassFiles
private IClassLoader
iClassLoader
static boolean
JUMP_IF_FALSE
Special value for theorientation
parameter of thecompileBoolean(Java.Rvalue, CodeContext.Offset, boolean)
methods, indicating that the code should be generated such that execution branches if the value on top of the operand stack is FALSE.static boolean
JUMP_IF_TRUE
Special value for theorientation
parameter of thecompileBoolean(Java.Rvalue, CodeContext.Offset, boolean)
methods, indicating that the code should be generated such that execution branches if the value on top of the operand stack is TRUE.static java.lang.Object
NOT_CONSTANT
Special return value for thegetConstantValue(Java.Rvalue)
method family indicating that the givenJava.Rvalue
does not evaluate to a constant value.private java.util.Map<java.lang.String,IClass>
onDemandImportableTypes
To be used only byimportTypeOnDemand(String, Location)
; cache for on-demand-imported types.private ErrorHandler
optionalCompileErrorHandler
private WarningHandler
optionalWarningHandler
private static java.util.Map<java.lang.String,byte[]>
PRIMITIVE_NARROWING_CONVERSIONS
private static java.util.Map<java.lang.String,byte[]>
PRIMITIVE_WIDENING_CONVERSIONS
private java.util.Map<java.lang.String,java.util.List<java.lang.Object>>
singleStaticImports
private java.util.Map<java.lang.String,java.lang.String[]>
singleTypeImports
To be used only bygetSingleTypeImport(String, Location)
;null
means "not yet initialized"private java.util.Collection<IClass>
staticImportsOnDemand
private static int
STRING_CONCAT_LIMIT
This constant determines the number of operands up to which theprivate java.util.Collection<java.lang.String[]>
typeImportsOnDemand
To be used only byimportTypeOnDemand(String, Location)
;null
means "not yet initialized.
-
Constructor Summary
Constructors Constructor Description UnitCompiler(Java.CompilationUnit compilationUnit, IClassLoader iClassLoader)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private short
addConstantFloatInfo(float value)
private short
addConstantIntegerInfo(int value)
private short
addConstantStringInfo(java.lang.String value)
private void
addFields(Java.FieldDeclaration fd, ClassFile cf)
CreatesClassFile.FieldInfo
s for all fields declared by the givenJava.FieldDeclaration
.private static java.lang.String[]
allButLast(java.lang.String[] sa)
private java.lang.Object
assignmentConversion(Java.Locatable locatable, java.lang.Object value, IClass targetType)
Implements "assignment conversion" (JLS7 5.2) on a constant value.private void
assignmentConversion(Java.Locatable locatable, IClass sourceType, IClass targetType, java.lang.Object optionalConstantValue)
Implements "assignment conversion" (JLS7 5.2).(package private) void
assignSyntheticParametersToSyntheticFields(Java.ConstructorDeclarator cd)
Copies the values of the synthetic parameters of this constructor ("this$..." and "val$...") to the synthetic fields of the object ("this$..." and "val$...").private IClass
binaryNumericPromotion(Java.Locatable locatable, IClass type1, CodeContext.Inserter convertInserter1, IClass type2)
Implements "binary numeric promotion" (5.6.2)private IClass
binaryNumericPromotion(Java.Locatable locatable, IClass type1, CodeContext.Inserter convertInserter1, IClass type2, CodeContext.Inserter convertInserter2)
Implements "binary numeric promotion" (5.6.2), which may perform unboxing conversion.private IClass
binaryNumericPromotionType(Java.Locatable locatable, IClass type1, IClass type2)
private void
boxingConversion(Java.Locatable locatable, IClass sourceType, IClass targetType)
private void
buildLocalVariableMap(Java.Block block, java.util.Map<java.lang.String,Java.LocalVariable> localVars)
private java.util.Map<java.lang.String,Java.LocalVariable>
buildLocalVariableMap(Java.BlockStatement blockStatement, java.util.Map<java.lang.String,Java.LocalVariable> localVars)
Computes and fills in the 'local variable map' for the givenblockStatement
.protected void
buildLocalVariableMap(Java.CatchClause catchClause, java.util.Map<java.lang.String,Java.LocalVariable> localVars)
Adds the givenlocalVars
to the 'local variable map' of the givencatchClause
.private static java.util.Map<java.lang.String,Java.LocalVariable>
buildLocalVariableMap(Java.ConstructorInvocation ci, java.util.Map<java.lang.String,Java.LocalVariable> localVars)
private void
buildLocalVariableMap(Java.DoStatement ds, java.util.Map<java.lang.String,Java.LocalVariable> localVars)
private void
buildLocalVariableMap(Java.ForEachStatement fes, java.util.Map<java.lang.String,Java.LocalVariable> localVars)
private void
buildLocalVariableMap(Java.ForStatement fs, java.util.Map<java.lang.String,Java.LocalVariable> localVars)
private void
buildLocalVariableMap(Java.FunctionDeclarator fd)
private void
buildLocalVariableMap(Java.IfStatement is, java.util.Map<java.lang.String,Java.LocalVariable> localVars)
private void
buildLocalVariableMap(Java.Initializer i, java.util.Map<java.lang.String,Java.LocalVariable> localVars)
private java.util.Map<java.lang.String,Java.LocalVariable>
buildLocalVariableMap(Java.LabeledStatement ls, java.util.Map<java.lang.String,Java.LocalVariable> localVars)
private java.util.Map<java.lang.String,Java.LocalVariable>
buildLocalVariableMap(Java.LocalVariableDeclarationStatement lvds, java.util.Map<java.lang.String,Java.LocalVariable> localVars)
private static java.util.Map<java.lang.String,Java.LocalVariable>
buildLocalVariableMap(Java.Statement s, java.util.Map<java.lang.String,Java.LocalVariable> localVars)
private void
buildLocalVariableMap(Java.SwitchStatement ss, java.util.Map<java.lang.String,Java.LocalVariable> localVars)
private void
buildLocalVariableMap(Java.SynchronizedStatement ss, java.util.Map<java.lang.String,Java.LocalVariable> localVars)
private void
buildLocalVariableMap(Java.TryStatement ts, java.util.Map<java.lang.String,Java.LocalVariable> localVars)
private void
buildLocalVariableMap(Java.WhileStatement ws, java.util.Map<java.lang.String,Java.LocalVariable> localVars)
private void
checkAccessible(IClass.IMember member, Java.BlockStatement contextBlockStatement)
Checks whether the givenIClass.IMember
is accessible in the given context, according to JLS7 6.6.1.BL1.B4.private void
checkAccessible(IClass iClassDeclaringMember, Access memberAccess, Java.BlockStatement contextBlockStatement)
Verifies that a member (class, interface, field or method) declared in a given class is accessible from a given block statement context, according to JLS7 6.6.1.4.private void
checkAccessible(IClass type, Java.BlockStatement contextBlockStatement)
Checks whether the givenIClass
is accessible in the given context, according to JLS7 6.6.1.2 and 6.6.1.4.private void
checkThrownException(Java.Locatable locatable, IClass type, Java.Scope scope)
private void
checkThrownExceptions(Java.Invocation in, IClass.IMethod iMethod)
private boolean
compile(Java.BlockStatement bs)
private void
compile(Java.FunctionDeclarator fd, ClassFile classFile)
private void
compile(Java.Rvalue rv)
SomeJava.Rvalue
s compile more efficiently when their value is not needed, e.g.private void
compile(Java.TypeDeclaration td)
private boolean
compile2(Java.AlternateConstructorInvocation aci)
private void
compile2(Java.AnonymousClassDeclaration acd)
private boolean
compile2(Java.AssertStatement as)
private void
compile2(Java.Assignment a)
private boolean
compile2(Java.Block b)
private boolean
compile2(Java.BreakStatement bs)
private void
compile2(Java.ClassDeclaration cd)
private boolean
compile2(Java.ContinueStatement cs)
private void
compile2(Java.Crement c)
private boolean
compile2(Java.DoStatement ds)
private boolean
compile2(Java.EmptyStatement es)
private boolean
compile2(Java.ExpressionStatement ee)
private boolean
compile2(Java.FieldDeclaration fd)
private boolean
compile2(Java.ForEachStatement fes)
private boolean
compile2(Java.ForStatement fs)
private boolean
compile2(Java.IfStatement is)
private boolean
compile2(Java.Initializer i)
private void
compile2(Java.InnerClassDeclaration icd)
private void
compile2(Java.InterfaceDeclaration id)
private boolean
compile2(Java.LabeledStatement ls)
private void
compile2(Java.LocalClassDeclaration lcd)
private boolean
compile2(Java.LocalClassDeclarationStatement lcds)
private boolean
compile2(Java.LocalVariableDeclarationStatement lvds)
private void
compile2(Java.MemberClassDeclaration mcd)
private void
compile2(Java.PackageMemberTypeDeclaration pmtd)
private void
compile2(Java.ParenthesizedExpression pe)
private boolean
compile2(Java.ReturnStatement rs)
private void
compile2(Java.Rvalue rv)
private boolean
compile2(Java.SuperConstructorInvocation sci)
private boolean
compile2(Java.SwitchStatement ss)
private boolean
compile2(Java.SynchronizedStatement ss)
private boolean
compile2(Java.ThrowStatement ts)
private boolean
compile2(Java.TryStatement ts)
private boolean
compile2(Java.WhileStatement ws)
private IClass
compileArithmeticBinaryOperation(Java.Locatable locatable, IClass lhsType, java.lang.String operator, Java.Rvalue rhs)
The LHS operand of typelhsType
is expected on the stack.private IClass
compileArithmeticOperation(Java.Locatable locatable, IClass type, java.util.Iterator<Java.Rvalue> operands, java.lang.String operator)
Execute an arithmetic operation on a sequence ofoperands
.private void
compileBoolean(Java.Rvalue rv, CodeContext.Offset dst, boolean orientation)
SomeJava.Rvalue
s compile more efficiently when their value is the condition for a branch.private void
compileBoolean2(Java.BinaryOperation bo, CodeContext.Offset dst, boolean orientation)
private void
compileBoolean2(Java.ParenthesizedExpression pe, CodeContext.Offset dst, boolean orientation)
private void
compileBoolean2(Java.Rvalue rv, CodeContext.Offset dst, boolean orientation)
private void
compileBoolean2(Java.UnaryOperation ue, CodeContext.Offset dst, boolean orientation)
private void
compileBridgeMethod(ClassFile cf, IClass.IMethod base, IClass.IMethod override)
Compiles a bridge method which will add a method of the signature of base that delegates to override.private int
compileContext(Java.Rvalue rv)
Generates code that determines the context of theJava.Rvalue
and puts it on the operand stack.private int
compileContext2(Java.AmbiguousName an)
private int
compileContext2(Java.ArrayAccessExpression aae)
private int
compileContext2(Java.ArrayLength al)
private int
compileContext2(Java.FieldAccess fa)
private int
compileContext2(Java.FieldAccessExpression fae)
private int
compileContext2(Java.ParenthesizedExpression pe)
private int
compileContext2(Java.Rvalue rv)
private int
compileContext2(Java.SuperclassFieldAccessExpression scfae)
private void
compileDeclaredMemberTypes(Java.TypeDeclaration decl, ClassFile cf)
Compile all of the types for this declarationprivate void
compileDeclaredMethods(Java.AbstractTypeDeclaration typeDeclaration, ClassFile cf)
Compile all of the methods for this declarationprivate void
compileDeclaredMethods(Java.TypeDeclaration typeDeclaration, ClassFile cf, int startPos)
Compile methods for this declaration starting atstartPos
.private void
compileError(java.lang.String message)
Equivalent withcompileError(String, Location)
with anull
location argument.private void
compileError(java.lang.String message, Location optionalLocation)
Issue a compile error with the given message.private static CompileException
compileException(Java.Locatable locatable, java.lang.String message)
private IClass
compileGet(Java.Rvalue rv)
Generates code that determines the value of theJava.Rvalue
and puts it on the operand stack.private IClass
compileGet2(Java.AmbiguousName an)
private IClass
compileGet2(Java.ArrayAccessExpression aae)
private IClass
compileGet2(Java.ArrayLength al)
private IClass
compileGet2(Java.Assignment a)
private IClass
compileGet2(Java.BinaryOperation bo)
private IClass
compileGet2(Java.BooleanRvalue brv)
private IClass
compileGet2(Java.Cast c)
private IClass
compileGet2(Java.ClassLiteral cl)
private IClass
compileGet2(Java.ConditionalExpression ce)
private IClass
compileGet2(Java.Crement c)
private IClass
compileGet2(Java.FieldAccess fa)
private IClass
compileGet2(Java.FieldAccessExpression fae)
private IClass
compileGet2(Java.Instanceof io)
private IClass
compileGet2(Java.Literal l)
private IClass
compileGet2(Java.LocalVariableAccess lva)
private IClass
compileGet2(Java.MethodInvocation mi)
private IClass
compileGet2(Java.NewAnonymousClassInstance naci)
private IClass
compileGet2(Java.NewArray na)
private IClass
compileGet2(Java.NewClassInstance nci)
private IClass
compileGet2(Java.NewInitializedArray nia)
private IClass
compileGet2(Java.ParameterAccess pa)
private IClass
compileGet2(Java.ParenthesizedExpression pe)
private IClass
compileGet2(Java.QualifiedThisReference qtr)
private IClass
compileGet2(Java.SimpleConstant sl)
private IClass
compileGet2(Java.SuperclassFieldAccessExpression scfae)
private IClass
compileGet2(Java.SuperclassMethodInvocation scmi)
private IClass
compileGet2(Java.ThisReference tr)
private IClass
compileGet2(Java.UnaryOperation uo)
private void
compileGetValue(Java.ArrayInitializer ai, IClass arrayType)
private IClass
compileGetValue(Java.Rvalue rv)
Convenience function that callscompileContext(Rvalue)
andcompileGet(Rvalue)
.private void
compileLocalVariableCrement(Java.Crement c, Java.LocalVariable lv)
private void
compileSet(Java.Lvalue lv)
Generates code that stores a value in theJava.Lvalue
.private void
compileSet2(Java.AmbiguousName an)
private void
compileSet2(Java.ArrayAccessExpression aae)
private void
compileSet2(Java.FieldAccess fa)
private void
compileSet2(Java.FieldAccessExpression fae)
private void
compileSet2(Java.LocalVariableAccess lva)
private void
compileSet2(Java.ParenthesizedExpression pe)
private void
compileSet2(Java.SuperclassFieldAccessExpression scfae)
private boolean
compileStatements(java.util.List<? extends Java.BlockStatement> statements)
private IClass
compileStringConcatenation(Java.Locatable locatable, IClass type, Java.Rvalue operand, java.util.Iterator<Java.Rvalue> operands)
private boolean
compileUnconditionalLoop(Java.ContinuableStatement cs, Java.BlockStatement body, Java.Rvalue[] optionalUpdate)
private boolean
compileUnconditionalLoopWithUpdate(Java.ContinuableStatement cs, Java.BlockStatement body, Java.Rvalue[] update)
ClassFile[]
compileUnit(boolean debugSource, boolean debugLines, boolean debugVars)
Generates an array ofClassFile
objects which represent the classes and interfaces declared in the compilation unit.private static java.lang.String[]
concat(java.lang.String[] sa, java.lang.String s)
private IClass
convertToPrimitiveNumericType(Java.Locatable locatable, IClass type)
If the given type is a primitive type, return that type.private void
crement(Java.Locatable locatable, Java.LocalVariable lv, java.lang.String operator)
private void
declareClassDollarMethod(Java.ClassLiteral cl)
private void
determineValue(Java.FieldAccessExpression fae)
private void
determineValue(Java.SuperclassFieldAccessExpression scfae)
"super.fld", "Type.super.fld"private void
dup(Java.Locatable locatable, int n)
private void
dupx(Java.Locatable locatable, IClass type, int x)
private boolean
fakeCompile(Java.BlockStatement bs)
Called to check whether the givenJava.Rvalue
compiles or not.private void
fakeCompile(Java.Rvalue rv)
Called to check whether the givenJava.Rvalue
compiles or not.private IClass.IMethod
fakeIMethod(IClass targetType, java.lang.String name, Java.Rvalue[] arguments)
private static void
fillConversionMap(java.lang.Object[] array, java.util.Map<java.lang.String,byte[]> map)
IClass
findClass(java.lang.String className)
Find one class or interface declared in this compilation unit by name.private IClass.IField
findIField(IClass iClass, java.lang.String name, Location location)
Finds a named field in the givenIClass
.private IClass.IMethod
findIMethod(IClass targetType, Java.Invocation invocation)
Find aIClass.IMethod
in the giventargetType
, its superclasses or superinterfaces with the givenname
and for the givenarguments
.IClass.IMethod
findIMethod(Java.MethodInvocation mi)
Find named methods of "targetType", examine the argument types and choose the most specific method.IClass.IMethod
findIMethod(Java.SuperclassMethodInvocation superclassMethodInvocation)
private static Java.LocalClassDeclaration
findLocalClassDeclaration(Java.Scope s, java.lang.String name)
Finds a local class declared in any block enclosing the given block statement.private IClass
findMemberType(IClass iClass, java.lang.String name, Location location)
Finds a named type in the givenIClass
.IClass.IInvocable
findMostSpecificIInvocable(Java.Locatable locatable, IClass.IInvocable[] iInvocables, IClass[] argumentTypes, boolean boxingPermitted, Java.Scope contextScope)
Determine the applicable invocables and choose the most specific invocable.private IClass.IInvocable
findMostSpecificIInvocable(Java.Locatable locatable, IClass.IInvocable[] iInvocables, Java.Rvalue[] arguments, Java.Scope contextScope)
Determine the arguments' types, determine the applicable invocables and choose the most specific invocable and adjust arguments as needed (for varargs case).private IClass
findTypeByFullyQualifiedName(Location location, java.lang.String[] identifiers)
Attempts to load anIClass
by fully-qualified name throughiClassLoader
.private IClass
findTypeByName(Location location, java.lang.String className)
Find the namedIClass
in this compilation unit, or through theiClassLoader
.private boolean
generatesCode(Java.BlockStatement bs)
Checks whether invocation ofcompile(BlockStatement)
would generate more than zero code bytes.private boolean
generatesCode2(java.util.List<Java.BlockStatement> l)
private boolean
generatesCode2(Java.AssertStatement as)
private boolean
generatesCode2(Java.Block b)
private boolean
generatesCode2(Java.BlockStatement bs)
private boolean
generatesCode2(Java.EmptyStatement es)
private boolean
generatesCode2(Java.FieldDeclaration fd)
private boolean
generatesCode2(Java.Initializer i)
private boolean
generatesCode2(Java.LocalClassDeclarationStatement lcds)
Java.CompilationUnit
getCompilationUnit()
java.lang.Object
getConstantValue(Java.Rvalue rv)
Attempts to evaluate as a constant expression.private java.lang.Object
getConstantValue2(Java.AmbiguousName an)
private java.lang.Object
getConstantValue2(Java.BinaryOperation bo)
private java.lang.Object
getConstantValue2(Java.BooleanLiteral bl)
private java.lang.Object
getConstantValue2(Java.Cast c)
private java.lang.Object
getConstantValue2(Java.CharacterLiteral cl)
private java.lang.Object
getConstantValue2(Java.ConditionalExpression ce)
private java.lang.Object
getConstantValue2(Java.FieldAccess fa)
private java.lang.Object
getConstantValue2(Java.FloatingPointLiteral fpl)
private java.lang.Object
getConstantValue2(Java.IntegerLiteral il)
private java.lang.Object
getConstantValue2(Java.NullLiteral nl)
private java.lang.Object
getConstantValue2(Java.ParenthesizedExpression pe)
private java.lang.Object
getConstantValue2(Java.Rvalue rv)
private java.lang.Object
getConstantValue2(Java.SimpleConstant sl)
private java.lang.Object
getConstantValue2(Java.StringLiteral sl)
private java.lang.Object
getConstantValue2(Java.UnaryOperation uo)
private Java.ClassDeclaration
getDeclaringClass(Java.QualifiedThisReference qtr)
private Java.TypeBodyDeclaration
getDeclaringTypeBodyDeclaration(Java.QualifiedThisReference qtr)
private void
getfield(Java.Locatable locatable, IClass.IField iField)
private IClass
getIClass(Java.ThisReference tr)
private IClass.IField[]
getIFields(Java.FieldDeclaration fieldDeclaration)
void
getIMethods(IClass type, java.lang.String methodName, java.util.List<IClass.IMethod> v)
Add all methods with the givenmethodName
that are declared by thetype
, its superclasses and all their superinterfaces to the result listv
.Java.LocalVariable
getLocalVariable(Java.FunctionDeclarator.FormalParameter parameter)
Java.LocalVariable
getLocalVariable(Java.FunctionDeclarator.FormalParameter parameter, boolean isVariableArityParameter)
Java.LocalVariable
getLocalVariable(Java.LocalVariableDeclarationStatement lvds, Java.VariableDeclarator vd)
private java.lang.Object
getNegatedConstantValue(Java.Rvalue rv)
Attempts to evaluate the negated value of a constantJava.Rvalue
.private java.lang.Object
getNegatedConstantValue2(Java.IntegerLiteral il)
private java.lang.Object
getNegatedConstantValue2(Java.ParenthesizedExpression pe)
private java.lang.Object
getNegatedConstantValue2(Java.Rvalue rv)
private java.lang.Object
getNegatedConstantValue2(Java.UnaryOperation uo)
(package private) Java.ArrayInitializerOrRvalue
getNonConstantFinalInitializer(Java.FieldDeclaration fd, Java.VariableDeclarator vd)
Determine the non-constant-final initializer of the givenJava.VariableDeclarator
.(package private) static Java.TypeDeclaration
getOuterClass(Java.TypeDeclaration typeDeclaration)
private static java.util.List<Java.TypeDeclaration>
getOuterClasses(Java.TypeDeclaration inner)
Return a list consisting of the giveninner
class and all its outer classes.private IClass
getReferenceType(Location location, java.lang.String simpleTypeName, Java.Scope scope)
JLS7 6.5.5.1 Simple type name (single identifier)private IClass
getReferenceType(Location location, Java.Scope scope, java.lang.String[] identifiers, int n)
private IClass
getReturnType(Java.FunctionDeclarator fd)
java.lang.String[]
getSingleTypeImport(java.lang.String name, Location location)
Check if the given simple name was imported through a single type import.private IClass
getTargetIClass(Java.QualifiedThisReference qtr)
private IClass
getType(Java.Atom a)
private IClass
getType2(Java.AmbiguousName an)
private IClass
getType2(Java.ArrayAccessExpression aae)
private IClass
getType2(Java.ArrayLength al)
private IClass
getType2(Java.ArrayType at)
private IClass
getType2(Java.Assignment a)
private IClass
getType2(Java.BasicType bt)
private IClass
getType2(Java.BinaryOperation bo)
private IClass
getType2(Java.BooleanLiteral bl)
private IClass
getType2(Java.Cast c)
private IClass
getType2(Java.CharacterLiteral cl)
private IClass
getType2(Java.ClassLiteral cl)
private IClass
getType2(Java.ConditionalExpression ce)
private IClass
getType2(Java.Crement c)
private IClass
getType2(Java.FieldAccess fa)
private IClass
getType2(Java.FieldAccessExpression fae)
private IClass
getType2(Java.FloatingPointLiteral fpl)
private IClass
getType2(Java.Instanceof io)
private IClass
getType2(Java.IntegerLiteral il)
private IClass
getType2(Java.LocalVariableAccess lva)
private IClass
getType2(Java.MethodInvocation mi)
private IClass
getType2(Java.NewAnonymousClassInstance naci)
private IClass
getType2(Java.NewArray na)
private IClass
getType2(Java.NewClassInstance nci)
private IClass
getType2(Java.NewInitializedArray nia)
private IClass
getType2(Java.NullLiteral nl)
private IClass
getType2(Java.Package p)
private IClass
getType2(Java.ParameterAccess pa)
private IClass
getType2(Java.ParenthesizedExpression pe)
private IClass
getType2(Java.QualifiedThisReference qtr)
private IClass
getType2(Java.ReferenceType rt)
private IClass
getType2(Java.RvalueMemberType rvmt)
private IClass
getType2(Java.SimpleConstant sl)
private IClass
getType2(Java.SimpleType st)
private IClass
getType2(Java.StringLiteral sl)
private IClass
getType2(Java.SuperclassFieldAccessExpression scfae)
private IClass
getType2(Java.SuperclassMethodInvocation scmi)
private IClass
getType2(Java.ThisReference tr)
private IClass
getType2(Java.UnaryOperation uo)
private IClass
getUnboxedType(IClass type)
private CodeContext.Offset
getWhereToBreak(Java.BreakableStatement bs)
private boolean
hasAnnotation(Java.FunctionDeclarator fd, IClass methodAnnotation)
private static int
hex2Int(Java.Locatable locatable, java.lang.String value)
private static long
hex2Long(Java.Locatable locatable, java.lang.String value)
private static int
ilfd(IClass t)
private static int
ilfd(IClass t, int opcodeInt, int opcodeLong, int opcodeFloat, int opcodeDouble)
private static int
ilfda(IClass t)
private static int
ilfdabcs(IClass t)
private void
import2(Java.CompilationUnit.SingleStaticImportDeclaration ssid)
private void
import2(Java.CompilationUnit.StaticImportOnDemandDeclaration siodd)
private IClass
importSingleType(java.lang.String simpleTypeName, Location location)
If the given name was declared in a simple type import, load that class.IClass
importTypeOnDemand(java.lang.String simpleTypeName, Location location)
6.5.2.BL1.B1.B5, 6.5.2.BL1.B1.B6 Type-import-on-demand.
6.5.5.1.6 Type-import-on-demand declaration.(package private) void
initializeInstanceVariablesAndInvokeInstanceInitializers(Java.ConstructorDeclarator cd)
Compiles the instance variable initializers and the instance initializers in their lexical order.private java.lang.String
internalCheckAccessible(IClass iClassDeclaringMember, Access memberAccess, Java.Scope contextScope)
private java.lang.String
internalCheckAccessible(IClass type, Java.Scope contextScope)
private void
invoke(Java.Locatable locatable, IClass.IConstructor iConstructor)
private void
invoke(Java.Locatable locatable, IClass.IMethod iMethod)
private void
invokeConstructor(Java.Locatable locatable, Java.Scope scope, Java.Rvalue optionalEnclosingInstance, IClass targetClass, Java.Rvalue[] arguments)
Expects the object to initialize on the stack.private boolean
isAccessible(IClass.IMember member, Java.Scope contextScope)
Determines whether the givenIClass.IMember
is accessible in the given context, according to JLS7 6.6.1.BL1.B4.private boolean
isAccessible(IClass iClassDeclaringMember, Access memberAccess, Java.Scope contextScope)
Determines whether a member (class, interface, field or method) declared in a given class is accessible from a given block statement context, according to JLS7 6.6.1.4.private boolean
isAccessible(IClass type, Java.Scope contextScope)
Determines whether the givenIClass
is accessible in the given context, according to JLS7 6.6.1.2 and 6.6.1.4.private IClass
isBoxingConvertible(IClass sourceType)
private boolean
isCastReferenceConvertible(IClass sourceType, IClass targetType)
JLS7 5.5private boolean
isConvertibleToPrimitiveNumeric(IClass sourceType)
private boolean
isIdentityConvertible(IClass sourceType, IClass targetType)
Checks whether "identity conversion" (5.1.1) is possible.(package private) Java.LocalVariable
isIntLv(Java.Crement c)
Checks whether the operand is an integer-like local variable.private boolean
isMethodInvocationConvertible(IClass sourceType, IClass targetType, boolean boxingPermitted)
Checks if "method invocation conversion" (5.3) is possible.private boolean
isNarrowingPrimitiveConvertible(IClass sourceType, IClass targetType)
Checks whether "narrowing primitive conversion" (JLS7 5.1.3) is possible.private boolean
isNarrowingReferenceConvertible(IClass sourceType, IClass targetType)
Check whether "narrowing reference conversion" (JLS7 5.1.5) is possible.private boolean
isType(Java.Atom a)
private boolean
isType2(Java.AmbiguousName an)
private boolean
isType2(Java.Atom a)
private IClass
isUnboxingConvertible(IClass sourceType)
private boolean
isWideningPrimitiveConvertible(IClass sourceType, IClass targetType)
private boolean
isWideningReferenceConvertible(IClass sourceType, IClass targetType)
Checks if "widening reference conversion" (5.1.4) is possible.private static java.lang.String
last(java.lang.String[] sa)
private void
leave(Java.BlockStatement bs, IClass optionalStackValueType)
Clean up the statement context.private void
leave2(Java.BlockStatement bs, IClass optionalStackValueType)
private void
leave2(Java.SynchronizedStatement ss, IClass optionalStackValueType)
private void
leave2(Java.TryStatement ts, IClass optionalStackValueType)
private void
leaveStatements(Java.Scope from, Java.Scope to, IClass optionalStackValueType)
Statements that jump out of blocks ("return", "break", "continue") must call this method to make sure that the "finally" clauses of all "try...catch" statements are executed.private void
load(Java.Locatable locatable, IClass type, int index)
private IClass
load(Java.Locatable locatable, Java.LocalVariable localVariable)
private static void
makeLocalVariableNames(CodeContext cc, ClassFile.MethodInfo mi)
Makes the variable name and class name Constant Pool names used by local variables.private static java.lang.String[]
makeUtf8Able(java.lang.String s)
Only strings that can be UTF8-encoded into 65535 bytes can be stored as a constant string info.private void
maybeCreateInitMethod(Java.AbstractTypeDeclaration decl, ClassFile cf, java.util.List<Java.BlockStatement> statements)
Create class initialization method iff there is any initialization code.private static Access
modifiers2Access(short modifiers)
private IClass
newArray(Java.Locatable locatable, int dimExprCount, int dims, IClass componentType)
ExpectsdimExprCount
values of typeint
on the operand stack.private void
numericPromotion(Java.Locatable locatable, IClass sourceType, IClass targetType)
private static int
oct2Int(Java.Locatable locatable, java.lang.String value)
private static long
oct2Long(Java.Locatable locatable, java.lang.String value)
private boolean
overridesMethod(IClass.IMethod method, IClass type)
private boolean
overridesMethodFromSupertype(IClass.IMethod m, IClass type)
private void
pop(Java.Locatable locatable, IClass type)
private IClass
pushConstant(Java.Locatable locatable, java.lang.Object value)
private void
putfield(Java.Locatable locatable, IClass.IField iField)
private Java.Atom
reclassify(Java.AmbiguousName an)
private Java.Atom
reclassifyName(Location location, Java.Scope scope, java.lang.String identifier)
JLS7 6.5.2.1private Java.Atom
reclassifyName(Location location, Java.Scope scope, java.lang.String[] identifiers, int n)
Reclassifies the ambiguous name consisting of the firstn
of theidentifiers
(JLS7 6.5.2.2).private void
referenceThis(Java.Locatable locatable)
private void
referenceThis(Java.Locatable locatable, Java.ClassDeclaration declaringClass, Java.TypeBodyDeclaration declaringTypeBodyDeclaration, IClass targetIClass)
private CodeContext
replaceCodeContext(CodeContext newCodeContext)
private IClass
resolve(Java.TypeDeclaration td)
private void
reverseUnaryNumericPromotion(Java.Locatable locatable, IClass sourceType, IClass targetType)
void
setCompileErrorHandler(ErrorHandler optionalCompileErrorHandler)
By default,CompileException
s are thrown on compile errors, but an application my install its own (thread-local)ErrorHandler
.void
setWarningHandler(WarningHandler optionalWarningHandler)
By default, warnings are discarded, but an application my install a customWarningHandler
.private void
store(Java.Locatable locatable, IClass lvType, short lvIndex)
private void
store(Java.Locatable locatable, Java.LocalVariable localVariable)
Assign top stack top value to the given local variable.private void
stringConversion(Java.Locatable locatable, IClass sourceType)
Converts object of type "sourceType" to type "String" (JLS7 15.18.1.1).(package private) IClass.IConstructor
toIConstructor(Java.ConstructorDeclarator constructorDeclarator)
private IClass.IInvocable
toIInvocable(Java.FunctionDeclarator fd)
IClass.IMethod
toIMethod(Java.MethodDeclarator methodDeclarator)
private Java.Lvalue
toLvalueOrCompileException(Java.Atom a)
private Java.Rvalue
toRvalueOrCompileException(Java.Atom a)
private Java.Type
toTypeOrCompileException(Java.Atom a)
private boolean
tryAssignmentConversion(Java.Locatable locatable, IClass sourceType, IClass targetType, java.lang.Object optionalConstantValue)
private boolean
tryBoxingConversion(Java.Locatable locatable, IClass sourceType, IClass targetType)
private boolean
tryConstantAssignmentConversion(Java.Locatable locatable, java.lang.Object constantValue, IClass targetType)
Check if "constant assignment conversion" (JLS7 5.2, paragraph 1) is possible.private boolean
tryIdentityConversion(IClass sourceType, IClass targetType)
Implements "identity conversion" (5.1.1).private boolean
tryNarrowingPrimitiveConversion(Java.Locatable locatable, IClass sourceType, IClass targetType)
Implements "narrowing primitive conversion" (JLS7 5.1.3).private boolean
tryNarrowingReferenceConversion(Java.Locatable locatable, IClass sourceType, IClass targetType)
Implements "narrowing reference conversion" (5.1.5).private boolean
tryUnboxingConversion(Java.Locatable locatable, IClass sourceType, IClass targetType, CodeContext.Inserter optionalInserter)
private boolean
tryWideningPrimitiveConversion(Java.Locatable locatable, IClass sourceType, IClass targetType)
Implements "widening primitive conversion" (5.1.2).private boolean
tryWideningReferenceConversion(IClass sourceType, IClass targetType)
Performs "widening reference conversion" (5.1.4) if possible.private IClass
unaryNumericPromotion(Java.Locatable locatable, IClass type)
Implements "unary numeric promotion" (JLS7 5.6.1).private IClass
unaryNumericPromotionType(Java.Locatable locatable, IClass type)
private void
unboxingConversion(Java.Locatable locatable, IClass sourceType, IClass targetType)
private void
unboxingConversion(Java.Locatable locatable, IClass sourceType, IClass targetType, CodeContext.Inserter optionalInserter)
private static java.lang.String
unescape(java.lang.String s)
private void
warning(java.lang.String handle, java.lang.String message, Location optionalLocation)
Issues a warning with the given message an location an returns.private void
writeBranch(Java.Locatable locatable, int opcode, CodeContext.Offset dst)
private void
writeByte(int v)
private void
writeConstantClassInfo(java.lang.String descriptor)
private void
writeConstantDoubleInfo(double value)
private void
writeConstantFieldrefInfo(java.lang.String classFd, java.lang.String fieldName, java.lang.String fieldFd)
private void
writeConstantInterfaceMethodrefInfo(java.lang.String classFd, java.lang.String methodName, java.lang.String methodMd)
private void
writeConstantLongInfo(long value)
private void
writeConstantMethodrefInfo(java.lang.String classFd, java.lang.String methodName, java.lang.String methodMd)
private void
writeInt(int v)
private void
writeLdc(Java.Locatable locatable, short index)
private void
writeOffset(CodeContext.Offset src, CodeContext.Offset dst)
private void
writeOpcode(Java.Locatable locatable, int opcode)
private void
writeOpcodes(Java.Locatable locatable, byte[] opcodes)
private void
writeShort(int v)
-
-
-
Field Detail
-
DEBUG
private static final boolean DEBUG
- See Also:
- Constant Field Values
-
STRING_CONCAT_LIMIT
private static final int STRING_CONCAT_LIMIT
This constant determines the number of operands up to which thea.concat(b).concat(c)
strategy is used to implement string concatenation. For more operands, thenew StringBuilder(a).append(b).append(c).append(d).toString()
strategy is chosen.A very good article from Tom Gibara analyzes the impact of this decision and recommends a value of three.
- See Also:
- Constant Field Values
-
JUMP_IF_TRUE
public static final boolean JUMP_IF_TRUE
Special value for theorientation
parameter of thecompileBoolean(Java.Rvalue, CodeContext.Offset, boolean)
methods, indicating that the code should be generated such that execution branches if the value on top of the operand stack is TRUE.- See Also:
- Constant Field Values
-
JUMP_IF_FALSE
public static final boolean JUMP_IF_FALSE
Special value for theorientation
parameter of thecompileBoolean(Java.Rvalue, CodeContext.Offset, boolean)
methods, indicating that the code should be generated such that execution branches if the value on top of the operand stack is FALSE.- See Also:
- Constant Field Values
-
NOT_CONSTANT
public static final java.lang.Object NOT_CONSTANT
Special return value for thegetConstantValue(Java.Rvalue)
method family indicating that the givenJava.Rvalue
does not evaluate to a constant value.
-
singleTypeImports
private java.util.Map<java.lang.String,java.lang.String[]> singleTypeImports
To be used only bygetSingleTypeImport(String, Location)
;null
means "not yet initialized"
-
typeImportsOnDemand
private java.util.Collection<java.lang.String[]> typeImportsOnDemand
To be used only byimportTypeOnDemand(String, Location)
;null
means "not yet initialized.
-
onDemandImportableTypes
private final java.util.Map<java.lang.String,IClass> onDemandImportableTypes
To be used only byimportTypeOnDemand(String, Location)
; cache for on-demand-imported types.
-
PRIMITIVE_WIDENING_CONVERSIONS
private static final java.util.Map<java.lang.String,byte[]> PRIMITIVE_WIDENING_CONVERSIONS
-
PRIMITIVE_NARROWING_CONVERSIONS
private static final java.util.Map<java.lang.String,byte[]> PRIMITIVE_NARROWING_CONVERSIONS
-
codeContext
private CodeContext codeContext
-
optionalCompileErrorHandler
private ErrorHandler optionalCompileErrorHandler
-
compileErrorCount
private int compileErrorCount
-
optionalWarningHandler
private WarningHandler optionalWarningHandler
-
compilationUnit
private final Java.CompilationUnit compilationUnit
-
iClassLoader
private final IClassLoader iClassLoader
-
generatedClassFiles
private java.util.List<ClassFile> generatedClassFiles
-
debugSource
private boolean debugSource
-
debugLines
private boolean debugLines
-
debugVars
private boolean debugVars
-
singleStaticImports
private final java.util.Map<java.lang.String,java.util.List<java.lang.Object>> singleStaticImports
-
staticImportsOnDemand
private final java.util.Collection<IClass> staticImportsOnDemand
-
-
Constructor Detail
-
UnitCompiler
public UnitCompiler(Java.CompilationUnit compilationUnit, IClassLoader iClassLoader)
-
-
Method Detail
-
getCompilationUnit
public Java.CompilationUnit getCompilationUnit()
- Returns:
- The
Java.CompilationUnit
that thisUnitCompiler
compiles
-
import2
private void import2(Java.CompilationUnit.SingleStaticImportDeclaration ssid) throws CompileException
- Throws:
CompileException
-
import2
private void import2(Java.CompilationUnit.StaticImportOnDemandDeclaration siodd) throws CompileException
- Throws:
CompileException
-
compileUnit
public ClassFile[] compileUnit(boolean debugSource, boolean debugLines, boolean debugVars) throws CompileException
Generates an array ofClassFile
objects which represent the classes and interfaces declared in the compilation unit.- Throws:
CompileException
-
compile
private void compile(Java.TypeDeclaration td) throws CompileException
- Throws:
CompileException
-
compile2
private void compile2(Java.PackageMemberTypeDeclaration pmtd) throws CompileException
- Throws:
CompileException
-
compile2
private void compile2(Java.ClassDeclaration cd) throws CompileException
- Throws:
CompileException
-
addFields
private void addFields(Java.FieldDeclaration fd, ClassFile cf) throws CompileException
CreatesClassFile.FieldInfo
s for all fields declared by the givenJava.FieldDeclaration
.- Throws:
CompileException
-
compile2
private void compile2(Java.AnonymousClassDeclaration acd) throws CompileException
- Throws:
CompileException
-
compile2
private void compile2(Java.LocalClassDeclaration lcd) throws CompileException
- Throws:
CompileException
-
compile2
private void compile2(Java.InnerClassDeclaration icd) throws CompileException
- Throws:
CompileException
-
compile2
private void compile2(Java.MemberClassDeclaration mcd) throws CompileException
- Throws:
CompileException
-
compile2
private void compile2(Java.InterfaceDeclaration id) throws CompileException
- Throws:
CompileException
-
maybeCreateInitMethod
private void maybeCreateInitMethod(Java.AbstractTypeDeclaration decl, ClassFile cf, java.util.List<Java.BlockStatement> statements) throws CompileException
Create class initialization method iff there is any initialization code.- Parameters:
decl
- The type declarationcf
- The class file into which to put the methodb
- The block for the method (possibly empty)- Throws:
CompileException
-
compileDeclaredMemberTypes
private void compileDeclaredMemberTypes(Java.TypeDeclaration decl, ClassFile cf) throws CompileException
Compile all of the types for this declarationNB: as a side effect this will fill in the synthetic field map
- Throws:
CompileException
-
compileDeclaredMethods
private void compileDeclaredMethods(Java.AbstractTypeDeclaration typeDeclaration, ClassFile cf) throws CompileException
Compile all of the methods for this declarationNB: as a side effect this will fill in the synthetic field map
- Throws:
CompileException
-
compileDeclaredMethods
private void compileDeclaredMethods(Java.TypeDeclaration typeDeclaration, ClassFile cf, int startPos) throws CompileException
Compile methods for this declaration starting atstartPos
.- Parameters:
startPos
- Starting parameter to fill in- Throws:
CompileException
-
hasAnnotation
private boolean hasAnnotation(Java.FunctionDeclarator fd, IClass methodAnnotation) throws CompileException
- Throws:
CompileException
-
overridesMethodFromSupertype
private boolean overridesMethodFromSupertype(IClass.IMethod m, IClass type) throws CompileException
- Throws:
CompileException
-
overridesMethod
private boolean overridesMethod(IClass.IMethod method, IClass type) throws CompileException
- Returns:
- Whether
method
overrides a method oftype
or any of its supertypes - Throws:
CompileException
-
compileBridgeMethod
private void compileBridgeMethod(ClassFile cf, IClass.IMethod base, IClass.IMethod override) throws CompileException
Compiles a bridge method which will add a method of the signature of base that delegates to override.- Throws:
CompileException
-
compile
private boolean compile(Java.BlockStatement bs) throws CompileException
- Returns:
- Whether this statement can complete normally (JLS7 14.1)
- Throws:
CompileException
-
fakeCompile
private boolean fakeCompile(Java.BlockStatement bs) throws CompileException
Called to check whether the givenJava.Rvalue
compiles or not.- Returns:
- Whether the block statement can complete normally
- Throws:
CompileException
-
compile2
private boolean compile2(Java.Initializer i) throws CompileException
- Throws:
CompileException
-
compile2
private boolean compile2(Java.Block b) throws CompileException
- Throws:
CompileException
-
compileStatements
private boolean compileStatements(java.util.List<? extends Java.BlockStatement> statements) throws CompileException
- Throws:
CompileException
-
compile2
private boolean compile2(Java.DoStatement ds) throws CompileException
- Throws:
CompileException
-
compile2
private boolean compile2(Java.ForStatement fs) throws CompileException
- Throws:
CompileException
-
compile2
private boolean compile2(Java.ForEachStatement fes) throws CompileException
- Throws:
CompileException
-
compile2
private boolean compile2(Java.WhileStatement ws) throws CompileException
- Throws:
CompileException
-
compileUnconditionalLoop
private boolean compileUnconditionalLoop(Java.ContinuableStatement cs, Java.BlockStatement body, Java.Rvalue[] optionalUpdate) throws CompileException
- Throws:
CompileException
-
compileUnconditionalLoopWithUpdate
private boolean compileUnconditionalLoopWithUpdate(Java.ContinuableStatement cs, Java.BlockStatement body, Java.Rvalue[] update) throws CompileException
- Throws:
CompileException
-
compile2
private boolean compile2(Java.LabeledStatement ls) throws CompileException
- Throws:
CompileException
-
compile2
private boolean compile2(Java.SwitchStatement ss) throws CompileException
- Throws:
CompileException
-
compile2
private boolean compile2(Java.BreakStatement bs) throws CompileException
- Throws:
CompileException
-
compile2
private boolean compile2(Java.ContinueStatement cs) throws CompileException
- Throws:
CompileException
-
compile2
private boolean compile2(Java.AssertStatement as) throws CompileException
- Throws:
CompileException
-
compile2
private boolean compile2(Java.EmptyStatement es)
-
compile2
private boolean compile2(Java.ExpressionStatement ee) throws CompileException
- Throws:
CompileException
-
compile2
private boolean compile2(Java.FieldDeclaration fd) throws CompileException
- Throws:
CompileException
-
compile2
private boolean compile2(Java.IfStatement is) throws CompileException
- Throws:
CompileException
-
compile2
private boolean compile2(Java.LocalClassDeclarationStatement lcds) throws CompileException
- Throws:
CompileException
-
findLocalClassDeclaration
private static Java.LocalClassDeclaration findLocalClassDeclaration(Java.Scope s, java.lang.String name)
Finds a local class declared in any block enclosing the given block statement.
-
compile2
private boolean compile2(Java.LocalVariableDeclarationStatement lvds) throws CompileException
- Throws:
CompileException
-
getLocalVariable
public Java.LocalVariable getLocalVariable(Java.LocalVariableDeclarationStatement lvds, Java.VariableDeclarator vd) throws CompileException
- Returns:
- The
Java.LocalVariable
corresponding with the local variable declaration/declarator - Throws:
CompileException
-
compile2
private boolean compile2(Java.ReturnStatement rs) throws CompileException
- Throws:
CompileException
-
compile2
private boolean compile2(Java.SynchronizedStatement ss) throws CompileException
- Throws:
CompileException
-
compile2
private boolean compile2(Java.ThrowStatement ts) throws CompileException
- Throws:
CompileException
-
compile2
private boolean compile2(Java.TryStatement ts) throws CompileException
- Throws:
CompileException
-
compile
private void compile(Java.FunctionDeclarator fd, ClassFile classFile) throws CompileException
- Throws:
CompileException
-
makeLocalVariableNames
private static void makeLocalVariableNames(CodeContext cc, ClassFile.MethodInfo mi)
Makes the variable name and class name Constant Pool names used by local variables.
-
buildLocalVariableMap
private void buildLocalVariableMap(Java.FunctionDeclarator fd) throws CompileException
- Throws:
CompileException
-
buildLocalVariableMap
private java.util.Map<java.lang.String,Java.LocalVariable> buildLocalVariableMap(Java.BlockStatement blockStatement, java.util.Map<java.lang.String,Java.LocalVariable> localVars) throws CompileException
Computes and fills in the 'local variable map' for the givenblockStatement
.- Throws:
CompileException
-
buildLocalVariableMap
private static java.util.Map<java.lang.String,Java.LocalVariable> buildLocalVariableMap(Java.Statement s, java.util.Map<java.lang.String,Java.LocalVariable> localVars)
-
buildLocalVariableMap
private static java.util.Map<java.lang.String,Java.LocalVariable> buildLocalVariableMap(Java.ConstructorInvocation ci, java.util.Map<java.lang.String,Java.LocalVariable> localVars)
-
buildLocalVariableMap
private void buildLocalVariableMap(Java.Block block, java.util.Map<java.lang.String,Java.LocalVariable> localVars) throws CompileException
- Throws:
CompileException
-
buildLocalVariableMap
private void buildLocalVariableMap(Java.DoStatement ds, java.util.Map<java.lang.String,Java.LocalVariable> localVars) throws CompileException
- Throws:
CompileException
-
buildLocalVariableMap
private void buildLocalVariableMap(Java.ForStatement fs, java.util.Map<java.lang.String,Java.LocalVariable> localVars) throws CompileException
- Throws:
CompileException
-
buildLocalVariableMap
private void buildLocalVariableMap(Java.ForEachStatement fes, java.util.Map<java.lang.String,Java.LocalVariable> localVars) throws CompileException
- Throws:
CompileException
-
buildLocalVariableMap
private void buildLocalVariableMap(Java.IfStatement is, java.util.Map<java.lang.String,Java.LocalVariable> localVars) throws CompileException
- Throws:
CompileException
-
buildLocalVariableMap
private void buildLocalVariableMap(Java.Initializer i, java.util.Map<java.lang.String,Java.LocalVariable> localVars) throws CompileException
- Throws:
CompileException
-
buildLocalVariableMap
private void buildLocalVariableMap(Java.SwitchStatement ss, java.util.Map<java.lang.String,Java.LocalVariable> localVars) throws CompileException
- Throws:
CompileException
-
buildLocalVariableMap
private void buildLocalVariableMap(Java.SynchronizedStatement ss, java.util.Map<java.lang.String,Java.LocalVariable> localVars) throws CompileException
- Throws:
CompileException
-
buildLocalVariableMap
private void buildLocalVariableMap(Java.TryStatement ts, java.util.Map<java.lang.String,Java.LocalVariable> localVars) throws CompileException
- Throws:
CompileException
-
buildLocalVariableMap
private void buildLocalVariableMap(Java.WhileStatement ws, java.util.Map<java.lang.String,Java.LocalVariable> localVars) throws CompileException
- Throws:
CompileException
-
buildLocalVariableMap
private java.util.Map<java.lang.String,Java.LocalVariable> buildLocalVariableMap(Java.LabeledStatement ls, java.util.Map<java.lang.String,Java.LocalVariable> localVars) throws CompileException
- Throws:
CompileException
-
buildLocalVariableMap
private java.util.Map<java.lang.String,Java.LocalVariable> buildLocalVariableMap(Java.LocalVariableDeclarationStatement lvds, java.util.Map<java.lang.String,Java.LocalVariable> localVars) throws CompileException
- Throws:
CompileException
-
buildLocalVariableMap
protected void buildLocalVariableMap(Java.CatchClause catchClause, java.util.Map<java.lang.String,Java.LocalVariable> localVars) throws CompileException
Adds the givenlocalVars
to the 'local variable map' of the givencatchClause
.- Throws:
CompileException
-
getLocalVariable
public Java.LocalVariable getLocalVariable(Java.FunctionDeclarator.FormalParameter parameter) throws CompileException
- Returns:
- The
Java.LocalVariable
corresponding with theparameter
- Throws:
CompileException
-
getLocalVariable
public Java.LocalVariable getLocalVariable(Java.FunctionDeclarator.FormalParameter parameter, boolean isVariableArityParameter) throws CompileException
- Parameters:
isVariableArityParameter
- Whether theparameter
is the last parameter of a 'variable arity' (a.k.a. 'varargs') method declaration- Returns:
- The
Java.LocalVariable
corresponding with theparameter
- Throws:
CompileException
-
fakeCompile
private void fakeCompile(Java.Rvalue rv) throws CompileException
Called to check whether the givenJava.Rvalue
compiles or not.- Throws:
CompileException
-
compile
private void compile(Java.Rvalue rv) throws CompileException
SomeJava.Rvalue
s compile more efficiently when their value is not needed, e.g. "i++".- Throws:
CompileException
-
compile2
private void compile2(Java.Rvalue rv) throws CompileException
- Throws:
CompileException
-
compile2
private void compile2(Java.Assignment a) throws CompileException
- Throws:
CompileException
-
compile2
private void compile2(Java.Crement c) throws CompileException
- Throws:
CompileException
-
compile2
private void compile2(Java.ParenthesizedExpression pe) throws CompileException
- Throws:
CompileException
-
compile2
private boolean compile2(Java.AlternateConstructorInvocation aci) throws CompileException
- Throws:
CompileException
-
compile2
private boolean compile2(Java.SuperConstructorInvocation sci) throws CompileException
- Throws:
CompileException
-
compileBoolean
private void compileBoolean(Java.Rvalue rv, CodeContext.Offset dst, boolean orientation) throws CompileException
SomeJava.Rvalue
s compile more efficiently when their value is the condition for a branch.Notice that if "this" is a constant, then either
dst
is never branched to, or it is unconditionally branched to. "Unexamined code" errors may result during bytecode validation.- Parameters:
dst
- Where to jumporientation
-JUMP_IF_TRUE
orJUMP_IF_FALSE
- Throws:
CompileException
-
compileBoolean2
private void compileBoolean2(Java.Rvalue rv, CodeContext.Offset dst, boolean orientation) throws CompileException
- Parameters:
dst
- Where to jumporientation
-JUMP_IF_TRUE
orJUMP_IF_FALSE
- Throws:
CompileException
-
compileBoolean2
private void compileBoolean2(Java.UnaryOperation ue, CodeContext.Offset dst, boolean orientation) throws CompileException
- Parameters:
dst
- Where to jumporientation
-JUMP_IF_TRUE
orJUMP_IF_FALSE
- Throws:
CompileException
-
compileBoolean2
private void compileBoolean2(Java.BinaryOperation bo, CodeContext.Offset dst, boolean orientation) throws CompileException
- Parameters:
dst
- Where to jumporientation
-JUMP_IF_TRUE
orJUMP_IF_FALSE
- Throws:
CompileException
-
compileBoolean2
private void compileBoolean2(Java.ParenthesizedExpression pe, CodeContext.Offset dst, boolean orientation) throws CompileException
- Parameters:
dst
- Where to jumporientation
-JUMP_IF_TRUE
orJUMP_IF_FALSE
- Throws:
CompileException
-
compileContext
private int compileContext(Java.Rvalue rv) throws CompileException
Generates code that determines the context of theJava.Rvalue
and puts it on the operand stack. Most expressions do not have a "context", but some do. E.g. for "x[y]", the context is "x, y". The bottom line is that for statements like "x[y] += 3" the context is only evaluated once.- Returns:
- The size of the context on the operand stack
- Throws:
CompileException
-
compileContext2
private int compileContext2(Java.Rvalue rv)
-
compileContext2
private int compileContext2(Java.AmbiguousName an) throws CompileException
- Throws:
CompileException
-
compileContext2
private int compileContext2(Java.FieldAccess fa) throws CompileException
- Throws:
CompileException
-
compileContext2
private int compileContext2(Java.ArrayLength al) throws CompileException
- Throws:
CompileException
-
compileContext2
private int compileContext2(Java.ArrayAccessExpression aae) throws CompileException
- Throws:
CompileException
-
compileContext2
private int compileContext2(Java.FieldAccessExpression fae) throws CompileException
- Throws:
CompileException
-
compileContext2
private int compileContext2(Java.SuperclassFieldAccessExpression scfae) throws CompileException
- Throws:
CompileException
-
compileContext2
private int compileContext2(Java.ParenthesizedExpression pe) throws CompileException
- Throws:
CompileException
-
compileGet
private IClass compileGet(Java.Rvalue rv) throws CompileException
Generates code that determines the value of theJava.Rvalue
and puts it on the operand stack. This method relies on that the "context" of theJava.Rvalue
is on top of the operand stack (seecompileContext(Rvalue)
).- Returns:
- The type of the
Java.Rvalue
- Throws:
CompileException
-
compileGet2
private IClass compileGet2(Java.BooleanRvalue brv) throws CompileException
- Throws:
CompileException
-
compileGet2
private IClass compileGet2(Java.AmbiguousName an) throws CompileException
- Throws:
CompileException
-
compileGet2
private IClass compileGet2(Java.LocalVariableAccess lva)
-
compileGet2
private IClass compileGet2(Java.FieldAccess fa) throws CompileException
- Throws:
CompileException
-
compileGet2
private IClass compileGet2(Java.ArrayLength al)
-
compileGet2
private IClass compileGet2(Java.ThisReference tr) throws CompileException
- Throws:
CompileException
-
compileGet2
private IClass compileGet2(Java.QualifiedThisReference qtr) throws CompileException
- Throws:
CompileException
-
compileGet2
private IClass compileGet2(Java.ClassLiteral cl) throws CompileException
- Throws:
CompileException
-
compileGet2
private IClass compileGet2(Java.Assignment a) throws CompileException
- Throws:
CompileException
-
compileGet2
private IClass compileGet2(Java.ConditionalExpression ce) throws CompileException
- Throws:
CompileException
-
compileGet2
private IClass compileGet2(Java.Crement c) throws CompileException
- Throws:
CompileException
-
compileLocalVariableCrement
private void compileLocalVariableCrement(Java.Crement c, Java.LocalVariable lv)
-
crement
private void crement(Java.Locatable locatable, Java.LocalVariable lv, java.lang.String operator)
-
compileGet2
private IClass compileGet2(Java.ArrayAccessExpression aae) throws CompileException
- Throws:
CompileException
-
compileGet2
private IClass compileGet2(Java.FieldAccessExpression fae) throws CompileException
- Throws:
CompileException
-
compileGet2
private IClass compileGet2(Java.SuperclassFieldAccessExpression scfae) throws CompileException
- Throws:
CompileException
-
compileGet2
private IClass compileGet2(Java.UnaryOperation uo) throws CompileException
- Throws:
CompileException
-
compileGet2
private IClass compileGet2(Java.Instanceof io) throws CompileException
- Throws:
CompileException
-
compileGet2
private IClass compileGet2(Java.BinaryOperation bo) throws CompileException
- Throws:
CompileException
-
compileGet2
private IClass compileGet2(Java.Cast c) throws CompileException
- Throws:
CompileException
-
compileGet2
private IClass compileGet2(Java.ParenthesizedExpression pe) throws CompileException
- Throws:
CompileException
-
compileGet2
private IClass compileGet2(Java.MethodInvocation mi) throws CompileException
- Throws:
CompileException
-
compileGet2
private IClass compileGet2(Java.SuperclassMethodInvocation scmi) throws CompileException
- Throws:
CompileException
-
compileGet2
private IClass compileGet2(Java.NewClassInstance nci) throws CompileException
- Throws:
CompileException
-
compileGet2
private IClass compileGet2(Java.NewAnonymousClassInstance naci) throws CompileException
- Throws:
CompileException
-
compileGet2
private IClass compileGet2(Java.ParameterAccess pa) throws CompileException
- Throws:
CompileException
-
compileGet2
private IClass compileGet2(Java.NewArray na) throws CompileException
- Throws:
CompileException
-
compileGet2
private IClass compileGet2(Java.NewInitializedArray nia) throws CompileException
- Throws:
CompileException
-
compileGetValue
private void compileGetValue(Java.ArrayInitializer ai, IClass arrayType) throws CompileException
- Throws:
CompileException
-
compileGet2
private IClass compileGet2(Java.Literal l) throws CompileException
- Throws:
CompileException
-
compileGet2
private IClass compileGet2(Java.SimpleConstant sl) throws CompileException
- Throws:
CompileException
-
compileGetValue
private IClass compileGetValue(Java.Rvalue rv) throws CompileException
Convenience function that callscompileContext(Rvalue)
andcompileGet(Rvalue)
.- Returns:
- The type of the Rvalue
- Throws:
CompileException
-
getConstantValue
public final java.lang.Object getConstantValue(Java.Rvalue rv) throws CompileException
Attempts to evaluate as a constant expression.- Returns:
NOT_CONSTANT
iff the rvalue is not a constant value- Throws:
CompileException
-
getConstantValue2
private java.lang.Object getConstantValue2(Java.Rvalue rv)
-
getConstantValue2
private java.lang.Object getConstantValue2(Java.AmbiguousName an) throws CompileException
- Throws:
CompileException
-
getConstantValue2
private java.lang.Object getConstantValue2(Java.FieldAccess fa) throws CompileException
- Throws:
CompileException
-
getConstantValue2
private java.lang.Object getConstantValue2(Java.UnaryOperation uo) throws CompileException
- Throws:
CompileException
-
getConstantValue2
private java.lang.Object getConstantValue2(Java.ConditionalExpression ce) throws CompileException
- Throws:
CompileException
-
getConstantValue2
private java.lang.Object getConstantValue2(Java.BinaryOperation bo) throws CompileException
- Throws:
CompileException
-
getConstantValue2
private java.lang.Object getConstantValue2(Java.Cast c) throws CompileException
- Throws:
CompileException
-
getConstantValue2
private java.lang.Object getConstantValue2(Java.ParenthesizedExpression pe) throws CompileException
- Throws:
CompileException
-
getConstantValue2
private java.lang.Object getConstantValue2(Java.IntegerLiteral il) throws CompileException
- Throws:
CompileException
-
getConstantValue2
private java.lang.Object getConstantValue2(Java.FloatingPointLiteral fpl) throws CompileException
- Throws:
CompileException
-
getConstantValue2
private java.lang.Object getConstantValue2(Java.BooleanLiteral bl)
-
getConstantValue2
private java.lang.Object getConstantValue2(Java.CharacterLiteral cl)
-
getConstantValue2
private java.lang.Object getConstantValue2(Java.StringLiteral sl)
-
getConstantValue2
private java.lang.Object getConstantValue2(Java.NullLiteral nl)
-
getConstantValue2
private java.lang.Object getConstantValue2(Java.SimpleConstant sl)
-
getNegatedConstantValue
private java.lang.Object getNegatedConstantValue(Java.Rvalue rv) throws CompileException
Attempts to evaluate the negated value of a constantJava.Rvalue
. This is particularly relevant for the smallest value of an integer or long literal.- Returns:
NOT_CONSTANT
iff value is not constant; otherwise aString
,Byte
,Short
,Integer
,Boolean
,Character
,Float
,Long
,Double
ornull
- Throws:
CompileException
-
getNegatedConstantValue2
private java.lang.Object getNegatedConstantValue2(Java.Rvalue rv) throws CompileException
- Throws:
CompileException
-
getNegatedConstantValue2
private java.lang.Object getNegatedConstantValue2(Java.UnaryOperation uo) throws CompileException
- Throws:
CompileException
-
getNegatedConstantValue2
private java.lang.Object getNegatedConstantValue2(Java.ParenthesizedExpression pe) throws CompileException
- Throws:
CompileException
-
getNegatedConstantValue2
private java.lang.Object getNegatedConstantValue2(Java.IntegerLiteral il) throws CompileException
- Throws:
CompileException
-
generatesCode
private boolean generatesCode(Java.BlockStatement bs) throws CompileException
Checks whether invocation ofcompile(BlockStatement)
would generate more than zero code bytes.- Throws:
CompileException
-
generatesCode2
private boolean generatesCode2(Java.BlockStatement bs)
-
generatesCode2
private boolean generatesCode2(Java.AssertStatement as)
-
generatesCode2
private boolean generatesCode2(Java.EmptyStatement es)
-
generatesCode2
private boolean generatesCode2(Java.LocalClassDeclarationStatement lcds)
-
generatesCode2
private boolean generatesCode2(Java.Initializer i) throws CompileException
- Throws:
CompileException
-
generatesCode2
private boolean generatesCode2(java.util.List<Java.BlockStatement> l) throws CompileException
- Throws:
CompileException
-
generatesCode2
private boolean generatesCode2(Java.Block b) throws CompileException
- Throws:
CompileException
-
generatesCode2
private boolean generatesCode2(Java.FieldDeclaration fd) throws CompileException
- Throws:
CompileException
-
leave
private void leave(Java.BlockStatement bs, IClass optionalStackValueType)
Clean up the statement context. This is currently relevant for "try ... catch ... finally" statements (execute "finally" clause) and "synchronized" statements (monitorexit).Statements like "return", "break", "continue" must call this method for all the statements they terminate.
Notice: If
optionalStackValueType
isnull
, then the operand stack is empty; otherwise exactly one operand with that type is on the stack. This information is vital to implementations ofleave(BlockStatement, IClass)
that require a specific operand stack state (e.g. an empty operand stack for JSR).
-
leave2
private void leave2(Java.BlockStatement bs, IClass optionalStackValueType)
-
leave2
private void leave2(Java.SynchronizedStatement ss, IClass optionalStackValueType)
-
leave2
private void leave2(Java.TryStatement ts, IClass optionalStackValueType)
-
compileSet
private void compileSet(Java.Lvalue lv) throws CompileException
Generates code that stores a value in theJava.Lvalue
. Expects theJava.Lvalue
's context (seecompileContext(org.codehaus.janino.Java.Rvalue)
) and a value of theJava.Lvalue
's type on the operand stack.- Throws:
CompileException
-
compileSet2
private void compileSet2(Java.AmbiguousName an) throws CompileException
- Throws:
CompileException
-
compileSet2
private void compileSet2(Java.LocalVariableAccess lva)
-
compileSet2
private void compileSet2(Java.FieldAccess fa) throws CompileException
- Throws:
CompileException
-
compileSet2
private void compileSet2(Java.ArrayAccessExpression aae) throws CompileException
- Throws:
CompileException
-
compileSet2
private void compileSet2(Java.FieldAccessExpression fae) throws CompileException
- Throws:
CompileException
-
compileSet2
private void compileSet2(Java.SuperclassFieldAccessExpression scfae) throws CompileException
- Throws:
CompileException
-
compileSet2
private void compileSet2(Java.ParenthesizedExpression pe) throws CompileException
- Throws:
CompileException
-
getType
private IClass getType(Java.Atom a) throws CompileException
- Throws:
CompileException
-
getType2
private IClass getType2(Java.SimpleType st)
-
getType2
private IClass getType2(Java.BasicType bt)
-
getType2
private IClass getType2(Java.ReferenceType rt) throws CompileException
- Throws:
CompileException
-
getReferenceType
private IClass getReferenceType(Location location, Java.Scope scope, java.lang.String[] identifiers, int n) throws CompileException
- Returns:
- The resolved
IClass
, ornull
- Throws:
CompileException
-
getReferenceType
private IClass getReferenceType(Location location, java.lang.String simpleTypeName, Java.Scope scope) throws CompileException
JLS7 6.5.5.1 Simple type name (single identifier)- Returns:
- The resolved
IClass
, ornull
- Throws:
CompileException
-
getType2
private IClass getType2(Java.RvalueMemberType rvmt) throws CompileException
- Throws:
CompileException
-
getType2
private IClass getType2(Java.ArrayType at) throws CompileException
- Throws:
CompileException
-
getType2
private IClass getType2(Java.AmbiguousName an) throws CompileException
- Throws:
CompileException
-
getType2
private IClass getType2(Java.Package p) throws CompileException
- Throws:
CompileException
-
getType2
private IClass getType2(Java.LocalVariableAccess lva)
-
getType2
private IClass getType2(Java.FieldAccess fa) throws CompileException
- Throws:
CompileException
-
getType2
private IClass getType2(Java.ArrayLength al)
-
getType2
private IClass getType2(Java.ThisReference tr) throws CompileException
- Throws:
CompileException
-
getType2
private IClass getType2(Java.QualifiedThisReference qtr) throws CompileException
- Throws:
CompileException
-
getType2
private IClass getType2(Java.ClassLiteral cl)
-
getType2
private IClass getType2(Java.Assignment a) throws CompileException
- Throws:
CompileException
-
getType2
private IClass getType2(Java.ConditionalExpression ce) throws CompileException
- Throws:
CompileException
-
getType2
private IClass getType2(Java.Crement c) throws CompileException
- Throws:
CompileException
-
getType2
private IClass getType2(Java.ArrayAccessExpression aae) throws CompileException
- Throws:
CompileException
-
getType2
private IClass getType2(Java.FieldAccessExpression fae) throws CompileException
- Throws:
CompileException
-
getType2
private IClass getType2(Java.SuperclassFieldAccessExpression scfae) throws CompileException
- Throws:
CompileException
-
getType2
private IClass getType2(Java.UnaryOperation uo) throws CompileException
- Throws:
CompileException
-
getType2
private IClass getType2(Java.Instanceof io)
-
getType2
private IClass getType2(Java.BinaryOperation bo) throws CompileException
- Throws:
CompileException
-
getUnboxedType
private IClass getUnboxedType(IClass type)
- Returns:
- Iff
type
is a primitive wrapper type, the unwrappedtype
, otherwisetype
-
getType2
private IClass getType2(Java.Cast c) throws CompileException
- Throws:
CompileException
-
getType2
private IClass getType2(Java.ParenthesizedExpression pe) throws CompileException
- Throws:
CompileException
-
getType2
private IClass getType2(Java.MethodInvocation mi) throws CompileException
- Throws:
CompileException
-
getType2
private IClass getType2(Java.SuperclassMethodInvocation scmi) throws CompileException
- Throws:
CompileException
-
getType2
private IClass getType2(Java.NewClassInstance nci) throws CompileException
- Throws:
CompileException
-
getType2
private IClass getType2(Java.NewAnonymousClassInstance naci)
-
getType2
private IClass getType2(Java.ParameterAccess pa) throws CompileException
- Throws:
CompileException
-
getType2
private IClass getType2(Java.NewArray na) throws CompileException
- Throws:
CompileException
-
getType2
private IClass getType2(Java.NewInitializedArray nia) throws CompileException
- Throws:
CompileException
-
getType2
private IClass getType2(Java.IntegerLiteral il)
-
getType2
private IClass getType2(Java.FloatingPointLiteral fpl)
-
getType2
private IClass getType2(Java.BooleanLiteral bl)
-
getType2
private IClass getType2(Java.CharacterLiteral cl)
-
getType2
private IClass getType2(Java.StringLiteral sl)
-
getType2
private IClass getType2(Java.NullLiteral nl)
-
getType2
private IClass getType2(Java.SimpleConstant sl)
-
isType
private boolean isType(Java.Atom a) throws CompileException
- Throws:
CompileException
-
isType2
private boolean isType2(Java.Atom a)
-
isType2
private boolean isType2(Java.AmbiguousName an) throws CompileException
- Throws:
CompileException
-
isAccessible
private boolean isAccessible(IClass.IMember member, Java.Scope contextScope) throws CompileException
Determines whether the givenIClass.IMember
is accessible in the given context, according to JLS7 6.6.1.BL1.B4. Issues acompileError(String)
if not.- Throws:
CompileException
-
checkAccessible
private void checkAccessible(IClass.IMember member, Java.BlockStatement contextBlockStatement) throws CompileException
Checks whether the givenIClass.IMember
is accessible in the given context, according to JLS7 6.6.1.BL1.B4. Issues acompileError(String)
if not.- Throws:
CompileException
-
isAccessible
private boolean isAccessible(IClass iClassDeclaringMember, Access memberAccess, Java.Scope contextScope) throws CompileException
Determines whether a member (class, interface, field or method) declared in a given class is accessible from a given block statement context, according to JLS7 6.6.1.4.- Throws:
CompileException
-
checkAccessible
private void checkAccessible(IClass iClassDeclaringMember, Access memberAccess, Java.BlockStatement contextBlockStatement) throws CompileException
Verifies that a member (class, interface, field or method) declared in a given class is accessible from a given block statement context, according to JLS7 6.6.1.4. Issue acompileError(String)
if not.- Throws:
CompileException
-
internalCheckAccessible
private java.lang.String internalCheckAccessible(IClass iClassDeclaringMember, Access memberAccess, Java.Scope contextScope) throws CompileException
- Returns:
- a descriptive text iff a member declared in that
IClass
with thatAccess
is inaccessible - Throws:
CompileException
-
isAccessible
private boolean isAccessible(IClass type, Java.Scope contextScope) throws CompileException
Determines whether the givenIClass
is accessible in the given context, according to JLS7 6.6.1.2 and 6.6.1.4.- Throws:
CompileException
-
checkAccessible
private void checkAccessible(IClass type, Java.BlockStatement contextBlockStatement) throws CompileException
Checks whether the givenIClass
is accessible in the given context, according to JLS7 6.6.1.2 and 6.6.1.4. Issues acompileError(String)
if not.- Throws:
CompileException
-
internalCheckAccessible
private java.lang.String internalCheckAccessible(IClass type, Java.Scope contextScope) throws CompileException
- Throws:
CompileException
-
toTypeOrCompileException
private Java.Type toTypeOrCompileException(Java.Atom a) throws CompileException
- Throws:
CompileException
-
toRvalueOrCompileException
private Java.Rvalue toRvalueOrCompileException(Java.Atom a) throws CompileException
- Throws:
CompileException
-
toLvalueOrCompileException
private Java.Lvalue toLvalueOrCompileException(Java.Atom a) throws CompileException
- Throws:
CompileException
-
assignSyntheticParametersToSyntheticFields
void assignSyntheticParametersToSyntheticFields(Java.ConstructorDeclarator cd) throws CompileException
Copies the values of the synthetic parameters of this constructor ("this$..." and "val$...") to the synthetic fields of the object ("this$..." and "val$...").- Throws:
CompileException
-
initializeInstanceVariablesAndInvokeInstanceInitializers
void initializeInstanceVariablesAndInvokeInstanceInitializers(Java.ConstructorDeclarator cd) throws CompileException
Compiles the instance variable initializers and the instance initializers in their lexical order.- Throws:
CompileException
-
leaveStatements
private void leaveStatements(Java.Scope from, Java.Scope to, IClass optionalStackValueType)
Statements that jump out of blocks ("return", "break", "continue") must call this method to make sure that the "finally" clauses of all "try...catch" statements are executed.
-
compileArithmeticBinaryOperation
private IClass compileArithmeticBinaryOperation(Java.Locatable locatable, IClass lhsType, java.lang.String operator, Java.Rvalue rhs) throws CompileException
The LHS operand of typelhsType
is expected on the stack.The following operators are supported:
| ^ & * / % + - << >> >>>
- Throws:
CompileException
-
compileArithmeticOperation
private IClass compileArithmeticOperation(Java.Locatable locatable, IClass type, java.util.Iterator<Java.Rvalue> operands, java.lang.String operator) throws CompileException
Execute an arithmetic operation on a sequence ofoperands
. Iftype
is non-null, the first operand with that type is already on the stack.The following operators are supported:
| ^ & * / % + - << >> >>>
- Throws:
CompileException
-
compileStringConcatenation
private IClass compileStringConcatenation(Java.Locatable locatable, IClass type, Java.Rvalue operand, java.util.Iterator<Java.Rvalue> operands) throws CompileException
- Parameters:
type
- If non-null, the first operand with that type is already on the stackoperand
- The next operandoperands
- All following operands (Iterator
overJava.Rvalue
s)- Throws:
CompileException
-
stringConversion
private void stringConversion(Java.Locatable locatable, IClass sourceType) throws CompileException
Converts object of type "sourceType" to type "String" (JLS7 15.18.1.1).- Throws:
CompileException
-
invokeConstructor
private void invokeConstructor(Java.Locatable locatable, Java.Scope scope, Java.Rvalue optionalEnclosingInstance, IClass targetClass, Java.Rvalue[] arguments) throws CompileException
Expects the object to initialize on the stack.Notice: This method is used both for explicit constructor invocation (first statement of a constructor body) and implicit constructor invocation (right after NEW).
- Parameters:
optionalEnclosingInstance
- Used if the target class is an inner class- Throws:
CompileException
-
getIFields
private IClass.IField[] getIFields(Java.FieldDeclaration fieldDeclaration)
- Returns:
- The
IClass.IField
s that are declared by thefieldDeclaration
-
getNonConstantFinalInitializer
Java.ArrayInitializerOrRvalue getNonConstantFinalInitializer(Java.FieldDeclaration fd, Java.VariableDeclarator vd) throws CompileException
Determine the non-constant-final initializer of the givenJava.VariableDeclarator
.- Returns:
null
if the variable is declared without an initializer or if the initializer is constant-final- Throws:
CompileException
-
reclassify
private Java.Atom reclassify(Java.AmbiguousName an) throws CompileException
- Throws:
CompileException
-
reclassifyName
private Java.Atom reclassifyName(Location location, Java.Scope scope, java.lang.String[] identifiers, int n) throws CompileException
Reclassifies the ambiguous name consisting of the firstn
of theidentifiers
(JLS7 6.5.2.2).- Throws:
CompileException
-
findTypeByName
private IClass findTypeByName(Location location, java.lang.String className) throws CompileException
Find the namedIClass
in this compilation unit, or through theiClassLoader
.- Parameters:
className
- Fully qualified class name, e.g. "pkg1.pkg2.Outer$Inner".- Returns:
null
iff anIClass
with that name could not be loaded- Throws:
CompileException
- An exception was raised while loading theIClass
-
reclassifyName
private Java.Atom reclassifyName(Location location, Java.Scope scope, java.lang.String identifier) throws CompileException
JLS7 6.5.2.1- Throws:
CompileException
-
determineValue
private void determineValue(Java.FieldAccessExpression fae) throws CompileException
- Throws:
CompileException
-
determineValue
private void determineValue(Java.SuperclassFieldAccessExpression scfae) throws CompileException
"super.fld", "Type.super.fld"- Throws:
CompileException
-
findIMethod
public IClass.IMethod findIMethod(Java.MethodInvocation mi) throws CompileException
Find named methods of "targetType", examine the argument types and choose the most specific method. Check that only the allowed exceptions are thrown.Notice that the returned
IClass.IMethod
may be declared in an enclosing type.- Returns:
- The selected
IClass.IMethod
ornull
- Throws:
CompileException
-
findIMethod
private IClass.IMethod findIMethod(IClass targetType, Java.Invocation invocation) throws CompileException
Find aIClass.IMethod
in the giventargetType
, its superclasses or superinterfaces with the givenname
and for the givenarguments
. If more than one such method exists, choose the most specific one (JLS7 15.11.2).- Returns:
null
if no appropriate method could be found- Throws:
CompileException
-
fakeIMethod
private IClass.IMethod fakeIMethod(IClass targetType, java.lang.String name, Java.Rvalue[] arguments) throws CompileException
- Throws:
CompileException
-
getIMethods
public void getIMethods(IClass type, java.lang.String methodName, java.util.List<IClass.IMethod> v) throws CompileException
Add all methods with the givenmethodName
that are declared by thetype
, its superclasses and all their superinterfaces to the result listv
.- Throws:
CompileException
-
findIMethod
public IClass.IMethod findIMethod(Java.SuperclassMethodInvocation superclassMethodInvocation) throws CompileException
- Returns:
- The
IClass.IMethod
that implements thesuperclassMethodInvocation
- Throws:
CompileException
-
findMostSpecificIInvocable
private IClass.IInvocable findMostSpecificIInvocable(Java.Locatable locatable, IClass.IInvocable[] iInvocables, Java.Rvalue[] arguments, Java.Scope contextScope) throws CompileException
Determine the arguments' types, determine the applicable invocables and choose the most specific invocable and adjust arguments as needed (for varargs case).- Parameters:
iInvocables
- Length must be greater than zero- Returns:
- The selected
IClass.IInvocable
- Throws:
CompileException
-
findMostSpecificIInvocable
public IClass.IInvocable findMostSpecificIInvocable(Java.Locatable locatable, IClass.IInvocable[] iInvocables, IClass[] argumentTypes, boolean boxingPermitted, Java.Scope contextScope) throws CompileException
Determine the applicable invocables and choose the most specific invocable.- Returns:
- The maximally specific
IClass.IInvocable
ornull
if noIClass.IInvocable
is applicable - Throws:
CompileException
-
isMethodInvocationConvertible
private boolean isMethodInvocationConvertible(IClass sourceType, IClass targetType, boolean boxingPermitted) throws CompileException
Checks if "method invocation conversion" (5.3) is possible.- Throws:
CompileException
-
checkThrownExceptions
private void checkThrownExceptions(Java.Invocation in, IClass.IMethod iMethod) throws CompileException
- Throws:
CompileException
- if theJava.Invocation
throws exceptions that are disallowed in the given scope
-
checkThrownException
private void checkThrownException(Java.Locatable locatable, IClass type, Java.Scope scope) throws CompileException
- Throws:
CompileException
- The exception with the giventype
must not be thrown in the givenscope
-
getTargetIClass
private IClass getTargetIClass(Java.QualifiedThisReference qtr) throws CompileException
- Throws:
CompileException
-
isIntLv
Java.LocalVariable isIntLv(Java.Crement c) throws CompileException
Checks whether the operand is an integer-like local variable.- Throws:
CompileException
-
resolve
private IClass resolve(Java.TypeDeclaration td)
-
referenceThis
private void referenceThis(Java.Locatable locatable, Java.ClassDeclaration declaringClass, Java.TypeBodyDeclaration declaringTypeBodyDeclaration, IClass targetIClass) throws CompileException
- Throws:
CompileException
-
getOuterClasses
private static java.util.List<Java.TypeDeclaration> getOuterClasses(Java.TypeDeclaration inner)
Return a list consisting of the giveninner
class and all its outer classes.- Returns:
List
ofJava.TypeDeclaration
-
getOuterClass
static Java.TypeDeclaration getOuterClass(Java.TypeDeclaration typeDeclaration)
- Returns:
- The
Java.TypeDeclaration
that immediately encloses thetypeDeclaration
, ornull
-
getIClass
private IClass getIClass(Java.ThisReference tr) throws CompileException
- Throws:
CompileException
-
getReturnType
private IClass getReturnType(Java.FunctionDeclarator fd) throws CompileException
- Throws:
CompileException
-
toIConstructor
IClass.IConstructor toIConstructor(Java.ConstructorDeclarator constructorDeclarator)
- Returns:
- the
IClass.IConstructor
that implements theconstructorDeclarator
-
toIMethod
public IClass.IMethod toIMethod(Java.MethodDeclarator methodDeclarator)
- Returns:
- The
IClass.IMethod
that implements themethodDeclarator
-
toIInvocable
private IClass.IInvocable toIInvocable(Java.FunctionDeclarator fd)
-
importSingleType
private IClass importSingleType(java.lang.String simpleTypeName, Location location) throws CompileException
If the given name was declared in a simple type import, load that class.- Throws:
CompileException
-
getSingleTypeImport
public java.lang.String[] getSingleTypeImport(java.lang.String name, Location location) throws CompileException
Check if the given simple name was imported through a single type import.- Parameters:
name
- The simple type name, e.g.Inner
- Returns:
- The fully qualified name, e.g.
{ "pkg", "Outer", "Inner" }
, ornull
- Throws:
CompileException
-
importTypeOnDemand
public IClass importTypeOnDemand(java.lang.String simpleTypeName, Location location) throws CompileException
6.5.2.BL1.B1.B5, 6.5.2.BL1.B1.B6 Type-import-on-demand.
6.5.5.1.6 Type-import-on-demand declaration.- Returns:
null
if the givensimpleTypeName
cannot be resolved through any of the import-on-demand directives- Throws:
CompileException
-
declareClassDollarMethod
private void declareClassDollarMethod(Java.ClassLiteral cl)
-
pushConstant
private IClass pushConstant(Java.Locatable locatable, java.lang.Object value) throws CompileException
- Parameters:
value
- ACharacter
,Byte
,Short
,Integer
,Long
,Float
,Double
,String
,Boolean
ornull
- Throws:
CompileException
-
hex2Int
private static int hex2Int(Java.Locatable locatable, java.lang.String value) throws CompileException
- Throws:
CompileException
-
oct2Int
private static int oct2Int(Java.Locatable locatable, java.lang.String value) throws CompileException
- Throws:
CompileException
-
hex2Long
private static long hex2Long(Java.Locatable locatable, java.lang.String value) throws CompileException
- Throws:
CompileException
-
oct2Long
private static long oct2Long(Java.Locatable locatable, java.lang.String value) throws CompileException
- Throws:
CompileException
-
makeUtf8Able
private static java.lang.String[] makeUtf8Able(java.lang.String s)
Only strings that can be UTF8-encoded into 65535 bytes can be stored as a constant string info.- Parameters:
s
- The string to split into suitable chunks- Returns:
- The chunks that can be UTF8-encoded into 65535 bytes
-
writeLdc
private void writeLdc(Java.Locatable locatable, short index)
-
assignmentConversion
private void assignmentConversion(Java.Locatable locatable, IClass sourceType, IClass targetType, java.lang.Object optionalConstantValue) throws CompileException
Implements "assignment conversion" (JLS7 5.2).- Throws:
CompileException
-
tryAssignmentConversion
private boolean tryAssignmentConversion(Java.Locatable locatable, IClass sourceType, IClass targetType, java.lang.Object optionalConstantValue) throws CompileException
- Throws:
CompileException
-
assignmentConversion
private java.lang.Object assignmentConversion(Java.Locatable locatable, java.lang.Object value, IClass targetType) throws CompileException
Implements "assignment conversion" (JLS7 5.2) on a constant value.- Throws:
CompileException
-
unaryNumericPromotion
private IClass unaryNumericPromotion(Java.Locatable locatable, IClass type) throws CompileException
Implements "unary numeric promotion" (JLS7 5.6.1).- Returns:
- The promoted type
- Throws:
CompileException
-
reverseUnaryNumericPromotion
private void reverseUnaryNumericPromotion(Java.Locatable locatable, IClass sourceType, IClass targetType) throws CompileException
- Throws:
CompileException
-
convertToPrimitiveNumericType
private IClass convertToPrimitiveNumericType(Java.Locatable locatable, IClass type) throws CompileException
If the given type is a primitive type, return that type. If the given type is a primitive wrapper class, unbox the operand on top of the operand stack and return the primitive type. Otherwise, issue a compile error.- Throws:
CompileException
-
numericPromotion
private void numericPromotion(Java.Locatable locatable, IClass sourceType, IClass targetType)
-
unaryNumericPromotionType
private IClass unaryNumericPromotionType(Java.Locatable locatable, IClass type) throws CompileException
- Throws:
CompileException
-
binaryNumericPromotion
private IClass binaryNumericPromotion(Java.Locatable locatable, IClass type1, CodeContext.Inserter convertInserter1, IClass type2) throws CompileException
Implements "binary numeric promotion" (5.6.2)- Returns:
- The promoted type.
- Throws:
CompileException
-
binaryNumericPromotion
private IClass binaryNumericPromotion(Java.Locatable locatable, IClass type1, CodeContext.Inserter convertInserter1, IClass type2, CodeContext.Inserter convertInserter2) throws CompileException
Implements "binary numeric promotion" (5.6.2), which may perform unboxing conversion.- Returns:
- The promoted type.
- Throws:
CompileException
-
binaryNumericPromotionType
private IClass binaryNumericPromotionType(Java.Locatable locatable, IClass type1, IClass type2) throws CompileException
- Throws:
CompileException
-
isIdentityConvertible
private boolean isIdentityConvertible(IClass sourceType, IClass targetType)
Checks whether "identity conversion" (5.1.1) is possible.- Returns:
- Whether the conversion is possible
-
tryIdentityConversion
private boolean tryIdentityConversion(IClass sourceType, IClass targetType)
Implements "identity conversion" (5.1.1).- Returns:
- Whether the conversion was possible
-
isWideningPrimitiveConvertible
private boolean isWideningPrimitiveConvertible(IClass sourceType, IClass targetType)
-
tryWideningPrimitiveConversion
private boolean tryWideningPrimitiveConversion(Java.Locatable locatable, IClass sourceType, IClass targetType)
Implements "widening primitive conversion" (5.1.2).- Returns:
- Whether the conversion succeeded
-
fillConversionMap
private static void fillConversionMap(java.lang.Object[] array, java.util.Map<java.lang.String,byte[]> map)
-
isWideningReferenceConvertible
private boolean isWideningReferenceConvertible(IClass sourceType, IClass targetType) throws CompileException
Checks if "widening reference conversion" (5.1.4) is possible.- Returns:
- Whether the conversion is possible
- Throws:
CompileException
-
tryWideningReferenceConversion
private boolean tryWideningReferenceConversion(IClass sourceType, IClass targetType) throws CompileException
Performs "widening reference conversion" (5.1.4) if possible.- Returns:
- Whether the conversion was possible
- Throws:
CompileException
-
isNarrowingPrimitiveConvertible
private boolean isNarrowingPrimitiveConvertible(IClass sourceType, IClass targetType)
Checks whether "narrowing primitive conversion" (JLS7 5.1.3) is possible.
-
tryNarrowingPrimitiveConversion
private boolean tryNarrowingPrimitiveConversion(Java.Locatable locatable, IClass sourceType, IClass targetType)
Implements "narrowing primitive conversion" (JLS7 5.1.3).- Returns:
- Whether the conversion succeeded
-
tryConstantAssignmentConversion
private boolean tryConstantAssignmentConversion(Java.Locatable locatable, java.lang.Object constantValue, IClass targetType) throws CompileException
Check if "constant assignment conversion" (JLS7 5.2, paragraph 1) is possible.- Parameters:
constantValue
- The constant value that is to be convertedtargetType
- The type to convert to- Throws:
CompileException
-
isNarrowingReferenceConvertible
private boolean isNarrowingReferenceConvertible(IClass sourceType, IClass targetType) throws CompileException
Check whether "narrowing reference conversion" (JLS7 5.1.5) is possible.- Throws:
CompileException
-
tryNarrowingReferenceConversion
private boolean tryNarrowingReferenceConversion(Java.Locatable locatable, IClass sourceType, IClass targetType) throws CompileException
Implements "narrowing reference conversion" (5.1.5).- Returns:
- Whether the conversion succeeded
- Throws:
CompileException
-
isCastReferenceConvertible
private boolean isCastReferenceConvertible(IClass sourceType, IClass targetType) throws CompileException
JLS7 5.5- Throws:
CompileException
-
isBoxingConvertible
private IClass isBoxingConvertible(IClass sourceType)
- Returns:
- The boxed type or
null
-
tryBoxingConversion
private boolean tryBoxingConversion(Java.Locatable locatable, IClass sourceType, IClass targetType) throws CompileException
- Throws:
CompileException
-
boxingConversion
private void boxingConversion(Java.Locatable locatable, IClass sourceType, IClass targetType) throws CompileException
- Parameters:
sourceType
- a primitive type (except VOID)targetType
- the corresponding wrapper type- Throws:
CompileException
-
isUnboxingConvertible
private IClass isUnboxingConvertible(IClass sourceType)
- Returns:
- Iff
sourceType
is a primitive wrapper type, the unboxed type, otherwisenull
-
isConvertibleToPrimitiveNumeric
private boolean isConvertibleToPrimitiveNumeric(IClass sourceType)
- Returns:
- Whether the
sourceType
is a primitive numeric type, or a wrapper type of a primitive numeric type
-
tryUnboxingConversion
private boolean tryUnboxingConversion(Java.Locatable locatable, IClass sourceType, IClass targetType, CodeContext.Inserter optionalInserter)
-
unboxingConversion
private void unboxingConversion(Java.Locatable locatable, IClass sourceType, IClass targetType, CodeContext.Inserter optionalInserter)
- Parameters:
targetType
- a primitive type (except VOID)sourceType
- the corresponding wrapper type
-
unboxingConversion
private void unboxingConversion(Java.Locatable locatable, IClass sourceType, IClass targetType)
- Parameters:
targetType
- a primitive type (except VOID)sourceType
- the corresponding wrapper type
-
findTypeByFullyQualifiedName
private IClass findTypeByFullyQualifiedName(Location location, java.lang.String[] identifiers) throws CompileException
Attempts to load anIClass
by fully-qualified name throughiClassLoader
.- Parameters:
location
- TODOidentifiers
- The fully qualified type name, e.g. '{ "pkg", "Outer", "Inner" }
'- Returns:
null
if a class with the given name could not be loaded- Throws:
CompileException
- The type exists, but a problem occurred when it was loaded
-
load
private IClass load(Java.Locatable locatable, Java.LocalVariable localVariable)
-
load
private void load(Java.Locatable locatable, IClass type, int index)
-
store
private void store(Java.Locatable locatable, Java.LocalVariable localVariable)
Assign top stack top value to the given local variable.
-
store
private void store(Java.Locatable locatable, IClass lvType, short lvIndex)
-
getfield
private void getfield(Java.Locatable locatable, IClass.IField iField) throws CompileException
- Throws:
CompileException
-
putfield
private void putfield(Java.Locatable locatable, IClass.IField iField) throws CompileException
- Throws:
CompileException
-
dup
private void dup(Java.Locatable locatable, int n)
-
dupx
private void dupx(Java.Locatable locatable, IClass type, int x)
-
pop
private void pop(Java.Locatable locatable, IClass type)
-
ilfd
private static int ilfd(IClass t)
-
ilfd
private static int ilfd(IClass t, int opcodeInt, int opcodeLong, int opcodeFloat, int opcodeDouble)
-
ilfda
private static int ilfda(IClass t)
-
ilfdabcs
private static int ilfdabcs(IClass t)
-
invoke
private void invoke(Java.Locatable locatable, IClass.IMethod iMethod) throws CompileException
- Throws:
CompileException
-
invoke
private void invoke(Java.Locatable locatable, IClass.IConstructor iConstructor) throws CompileException
- Throws:
CompileException
-
findIField
private IClass.IField findIField(IClass iClass, java.lang.String name, Location location) throws CompileException
Finds a named field in the givenIClass
. Honors superclasses and interfaces. See JLS7 8.3.- Returns:
null
if no field is found- Throws:
CompileException
-
findMemberType
private IClass findMemberType(IClass iClass, java.lang.String name, Location location) throws CompileException
Finds a named type in the givenIClass
. Honors superclasses, interfaces and enclosing type declarations.- Returns:
null
if no type with the given name is found- Throws:
CompileException
-
findClass
public IClass findClass(java.lang.String className)
Find one class or interface declared in this compilation unit by name.- Parameters:
className
- Fully qualified class name, e.g. "pkg1.pkg2.Outer$Inner".- Returns:
null
if a class or an interface with that name is not declared in this compilation unit
-
compileError
private void compileError(java.lang.String message) throws CompileException
Equivalent withcompileError(String, Location)
with anull
location argument.- Throws:
CompileException
-
compileError
private void compileError(java.lang.String message, Location optionalLocation) throws CompileException
Issue a compile error with the given message. This is done through theErrorHandler
that was installed throughsetCompileErrorHandler(ErrorHandler)
. Such a handler typically throws aCompileException
, but it may as well decide to return normally. Consequently, the calling code must be prepared thatcompileError(String, Location)
returns normally, and must attempt to continue compiling.- Parameters:
message
- The message to reportoptionalLocation
- The location to report- Throws:
CompileException
-
warning
private void warning(java.lang.String handle, java.lang.String message, Location optionalLocation) throws CompileException
Issues a warning with the given message an location an returns. This is done through aWarningHandler
that was installed throughsetWarningHandler(WarningHandler)
.The
handle
argument qualifies the warning and is typically used by theWarningHandler
to suppress individual warnings.- Throws:
CompileException
-
setCompileErrorHandler
public void setCompileErrorHandler(ErrorHandler optionalCompileErrorHandler)
By default,CompileException
s are thrown on compile errors, but an application my install its own (thread-local)ErrorHandler
.Be aware that a single problem during compilation often causes a bunch of compile errors, so a good
ErrorHandler
counts errors and throws aCompileException
when a limit is reached.If the given
ErrorHandler
does not throwCompileException
s, thencompileUnit(boolean, boolean, boolean)
will throw one when the compilation of the unit is finished, and errors had occurred. In other words: TheErrorHandler
may throw aCompileException
or not, butcompileUnit(boolean, boolean, boolean)
will definitely throw aCompileException
if one or more compile errors have occurred.- Parameters:
optionalCompileErrorHandler
-null
to restore the default behavior (throwing aCompileException
-
setWarningHandler
public void setWarningHandler(WarningHandler optionalWarningHandler)
By default, warnings are discarded, but an application my install a customWarningHandler
.- Parameters:
optionalWarningHandler
-null
to indicate that no warnings be issued
-
replaceCodeContext
private CodeContext replaceCodeContext(CodeContext newCodeContext)
-
writeByte
private void writeByte(int v)
-
writeShort
private void writeShort(int v)
-
writeInt
private void writeInt(int v)
-
writeOpcode
private void writeOpcode(Java.Locatable locatable, int opcode)
-
writeOpcodes
private void writeOpcodes(Java.Locatable locatable, byte[] opcodes)
-
writeBranch
private void writeBranch(Java.Locatable locatable, int opcode, CodeContext.Offset dst)
-
writeOffset
private void writeOffset(CodeContext.Offset src, CodeContext.Offset dst)
-
writeConstantClassInfo
private void writeConstantClassInfo(java.lang.String descriptor)
-
writeConstantFieldrefInfo
private void writeConstantFieldrefInfo(java.lang.String classFd, java.lang.String fieldName, java.lang.String fieldFd)
-
writeConstantMethodrefInfo
private void writeConstantMethodrefInfo(java.lang.String classFd, java.lang.String methodName, java.lang.String methodMd)
-
writeConstantInterfaceMethodrefInfo
private void writeConstantInterfaceMethodrefInfo(java.lang.String classFd, java.lang.String methodName, java.lang.String methodMd)
-
addConstantStringInfo
private short addConstantStringInfo(java.lang.String value)
-
addConstantIntegerInfo
private short addConstantIntegerInfo(int value)
-
addConstantFloatInfo
private short addConstantFloatInfo(float value)
-
writeConstantLongInfo
private void writeConstantLongInfo(long value)
-
writeConstantDoubleInfo
private void writeConstantDoubleInfo(double value)
-
getWhereToBreak
private CodeContext.Offset getWhereToBreak(Java.BreakableStatement bs)
-
getDeclaringTypeBodyDeclaration
private Java.TypeBodyDeclaration getDeclaringTypeBodyDeclaration(Java.QualifiedThisReference qtr) throws CompileException
- Throws:
CompileException
-
getDeclaringClass
private Java.ClassDeclaration getDeclaringClass(Java.QualifiedThisReference qtr) throws CompileException
- Throws:
CompileException
-
referenceThis
private void referenceThis(Java.Locatable locatable)
-
newArray
private IClass newArray(Java.Locatable locatable, int dimExprCount, int dims, IClass componentType)
ExpectsdimExprCount
values of typeint
on the operand stack. Creates an array ofdimExprCount + dims
dimensions ofcomponentType
.- Returns:
- The type of the created array
-
modifiers2Access
private static Access modifiers2Access(short modifiers)
-
last
private static java.lang.String last(java.lang.String[] sa)
-
allButLast
private static java.lang.String[] allButLast(java.lang.String[] sa)
-
concat
private static java.lang.String[] concat(java.lang.String[] sa, java.lang.String s)
-
compileException
private static CompileException compileException(Java.Locatable locatable, java.lang.String message)
-
unescape
private static java.lang.String unescape(java.lang.String s)
-
-