Package com.strobel.expressions
Class LambdaCompiler
- java.lang.Object
-
- com.strobel.expressions.LambdaCompiler
-
final class LambdaCompiler extends java.lang.Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classLambdaCompiler.CompilationFlags
-
Field Summary
Fields Modifier and Type Field Description private BoundConstants_boundConstantsprivate FieldBuilder_closureFieldprivate ConstructorBuilder_constructorBuilderprivate FinallyInfo_finallyInfoprivate KeyedQueue<Type<?>,LocalBuilder>_freeLocalsprivate boolean_hasClosureArgumentprivate LabelScopeInfo_labelBlockprivate java.util.Map<LabelTarget,LabelInfo>_labelInfoprivate CompilerScope_scopeprivate AnalyzedTree_tree(package private) static Type<Closure>closureType(package private) CodeGeneratorgenerator(package private) LambdaExpression<?>lambda(package private) MethodBuildermethodBuilder(package private) static java.util.concurrent.atomic.AtomicIntegernextId(package private) TypeBuildertypeBuilder
-
Constructor Summary
Constructors Modifier Constructor Description (package private)LambdaCompiler(AnalyzedTree tree, LambdaExpression<?> lambda)(package private)LambdaCompiler(AnalyzedTree tree, LambdaExpression<?> lambda, MethodBuilder method, ConstructorBuilder constructor)privateLambdaCompiler(LambdaCompiler parent, LambdaExpression lambda)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidaddReturnLabel(LambdaExpression lambda)private static <T> Pair<AnalyzedTree,LambdaExpression<T>>analyzeLambda(LambdaExpression<T> lambda)(package private) booleancanEmitBoundConstants()private static booleancanOptimizeSwitchType(Type<?> valueType)private voidcheckTry()(package private) static <T> Delegate<T>compile(LambdaExpression<T> lambda, DebugInfoGenerator debugInfoGenerator)(package private) static <T> voidcompile(LambdaExpression<T> lambda, MethodBuilder methodBuilder, DebugInfoGenerator debugInfoGenerator)private <T> Delegate<T>createDelegate(java.lang.Class<T> generatedClass)private FieldBuildercreateStaticField(java.lang.String name, Type type)private voiddefineBlockLabels(Expression node)private LabelInfodefineLabel(LabelTarget node)private voidemit(BlockExpression node, int flags)private voidemitAndAlsoBinaryExpression(Expression expr, int flags)private voidemitArguments(MethodBase method, IArgumentProvider args)private voidemitArguments(MethodBase method, IArgumentProvider args, int skipParameters)private voidemitArithmeticBinaryOp(ExpressionType op, Type<?> operandType)private voidemitAssign(BinaryExpression node, int emitAs)private voidemitAssignBinaryExpression(Expression expr)private voidemitBinaryExpression(Expression expr)private voidemitBinaryExpression(Expression expr, int flags)private voidemitBinaryMethod(BinaryExpression b, int flags)private voidemitBinaryOperator(ExpressionType op, Type<?> leftType, Type<?> rightType, Type resultType)private voidemitBlockExpression(Expression expr, int flags)private voidemitBranchAnd(boolean branch, BinaryExpression node, Label label)private voidemitBranchBlock(boolean branch, BlockExpression node, Label label)private voidemitBranchLogical(boolean branch, BinaryExpression node, Label label)private voidemitBranchNot(boolean branch, UnaryExpression node, Label label)private voidemitBranchNullCheck(boolean branch, UnaryExpression node, Label label)private voidemitBranchOp(boolean branch, Label label)private voidemitBranchOr(boolean branch, BinaryExpression node, Label label)private voidemitBranchRelation(boolean branch, BinaryExpression node, Label label)private voidemitCatchStart(CatchBlock cb)(package private) voidemitClosureArgument()private voidemitClosureCreation(LambdaCompiler inner)private voidemitCoalesceBinaryExpression(Expression expr)private voidemitConditionalExpression(Expression expr, int flags)private voidemitConstant(java.lang.Object value, Type<?> type)(package private) voidemitConstantArray(java.lang.Object array)private voidemitConstantExpression(Expression expr)private voidemitConvert(UnaryExpression node, int flags)private voidemitConvertArithmeticResult(ExpressionType op, Type sourceType, Type resultType)private voidemitConvertUnaryExpression(Expression expr, int flags)(package private) booleanemitDebugSymbols()private voidemitDefaultValueExpression(Expression node)private voidemitDelegateConstruction(LambdaCompiler inner)private voidemitDelegateConstruction(LambdaExpression lambda)(package private) voidemitExpression(Expression node)private voidemitExpression(Expression node, int flags)private voidemitExpressionAndBranch(boolean branchValue, Expression node, Label label)private voidemitExpressionAsType(Expression node, Type type, int flags)private voidemitExpressionAsVoid(Expression node)private voidemitExpressionAsVoid(Expression node, int flags)private voidemitExpressionEnd(int flags)private intemitExpressionStart(Expression node)private voidemitExtensionExpression(Expression node)private voidemitGotoExpression(Expression expr, int flags)private voidemitIndexAssignment(BinaryExpression node, int flags)private voidemitInlinedInvoke(InvocationExpression invoke, int flags)private voidemitInvocationExpression(Expression expr, int flags)private voidemitLabelExpression(Expression expr, int flags)(package private) voidemitLambdaArgument(int index)private voidemitLambdaBody()private voidemitLambdaBody(CompilerScope parent, boolean inlined, int flags)private voidemitLambdaExpression(Expression expr)private voidemitLambdaReferenceCoalesce(BinaryExpression b)private voidemitLiftedBooleanAnd(Type leftType, Type rightType)private voidemitLiftedBooleanOr(Type leftType, Type rightType)private voidemitLiftedRelational(ExpressionType op, Type leftType, Type rightType, Type resultType)private voidemitLoopExpression(Expression expr)private voidemitMemberAssignment(BinaryExpression node, int flags)private voidemitMemberExpression(Expression expr)private voidemitMemberGet(MemberInfo member)private voidemitMethodCall(Expression target, MethodInfo method, IArgumentProvider methodCallExpr)private voidemitMethodCall(Expression target, MethodInfo method, IArgumentProvider expr, int flags)private voidemitMethodCall(Expression target, MethodInfo method, MethodCallExpression expr, int flags)private voidemitMethodCall(MethodInfo method, IArgumentProvider args, Type<?> objectType, int flags)private voidemitMethodCallExpression(Expression expr)private voidemitMethodCallExpression(Expression expr, int flags)private voidemitNewArrayExpression(Expression expr)private voidemitNewExpression(Expression expr)private voidemitObjectBinaryOp(ExpressionType op)private voidemitOrElseBinaryExpression(Expression expr, int flags)private voidemitParameterExpression(Expression expr)private voidemitPrimitiveAndAlso(BinaryExpression b)private Type<?>emitPrimitiveBinaryOp(ExpressionType op, Type leftType, Type rightType)private voidemitPrimitiveOrElse(BinaryExpression b)private voidemitReferenceCoalesceWithoutConversion(BinaryExpression b)private voidemitRelationalBranchOp(ExpressionType op, Type<?> operandType, boolean branch, Label label)private voidemitRuntimeVariablesExpression(Expression expr)private voidemitSaveExceptionOrPop(CatchBlock cb)private voidemitSetIndexCall(BinaryExpression index)private voidemitSwitchExpression(Expression expr, int flags)private voidemitThrow(UnaryExpression expr, int flags)private voidemitThrowUnaryExpression(Expression expr)private voidemitTryExpression(Expression expr)private voidemitTypeBinaryExpression(Expression expr)private voidemitUnary(UnaryExpression node, int flags)private voidemitUnaryExpression(Expression expr, int flags)private voidemitUnaryMethod(UnaryExpression node, int flags)private voidemitUnaryOperator(ExpressionType op, Type operandType, Type resultType)private voidemitUnboxingAndAlso(BinaryExpression b)private voidemitUnboxingBinaryArithmetic(ExpressionType op, Type leftType, Type rightType, Type resultType)private voidemitUnboxingBinaryOp(ExpressionType op, Type leftType, Type rightType, Type resultType)private voidemitUnboxingOrElse(BinaryExpression b)private voidemitUnboxUnaryExpression(Expression expr)private voidemitUnreachable(Expression node, int flags)private voidemitVariableAssignment(BinaryExpression node, int flags)private voidensureClosure()private voidensureConstructor()private LabelInfoensureLabel(LabelTarget node)private voidenterScope(java.lang.Object node)private voidenterTry(TryExpression tryExpression)private voidexitScope(java.lang.Object node)private voidexitTry(TryExpression tryExpression)(package private) voidfreeLocal(LocalBuilder local)private ExpressiongetEqualityOperand(Expression expression)(package private) intgetLambdaArgument(int index)(package private) LocalBuildergetLocal(Type<?> type)(package private) LocalBuildergetNamedLocal(Type type, ParameterExpression variable)(package private) ParameterExpressionListgetParameters()private TypeListgetParameterTypes(LambdaExpression<?> lambda)(package private) static java.lang.StringgetUniqueLambdaName(java.lang.String name, java.lang.Class<?> creationContext)(package private) static java.lang.StringgetUniqueMethodName()private static booleanhasVariables(java.lang.Object node)(package private) voidinitializeMethod()private static booleannotEmpty(Expression node)private voidpopLabelBlock(LabelScopeKind kind)private voidpushLabelBlock(LabelScopeKind type)private LabelInforeferenceLabel(LabelTarget node)private static booleansignificant(Expression node)private booleantryEmitLookupSwitch(SwitchExpression node, int flags)private booleantryEmitStringSwitch(SwitchExpression node, int flags)private booleantryPushLabelBlock(Expression node)private TypeunboxLeftBinaryOperand(Type leftType, Type rightType)private TypeunboxRightBinaryOperand(Type rightType)private static intupdateEmitAsTailCallFlag(int flags, int newValue)private static intupdateEmitAsTypeFlag(int flags, int newValue)private static intupdateEmitExpressionStartFlag(int flags, int newValue)
-
-
-
Field Detail
-
nextId
static final java.util.concurrent.atomic.AtomicInteger nextId
-
lambda
final LambdaExpression<?> lambda
-
typeBuilder
final TypeBuilder typeBuilder
-
methodBuilder
final MethodBuilder methodBuilder
-
generator
final CodeGenerator generator
-
_tree
private final AnalyzedTree _tree
-
_freeLocals
private final KeyedQueue<Type<?>,LocalBuilder> _freeLocals
-
_boundConstants
private final BoundConstants _boundConstants
-
_labelInfo
private final java.util.Map<LabelTarget,LabelInfo> _labelInfo
-
_constructorBuilder
private ConstructorBuilder _constructorBuilder
-
_hasClosureArgument
private boolean _hasClosureArgument
-
_closureField
private FieldBuilder _closureField
-
_scope
private CompilerScope _scope
-
_labelBlock
private LabelScopeInfo _labelBlock
-
_finallyInfo
private FinallyInfo _finallyInfo
-
-
Constructor Detail
-
LambdaCompiler
LambdaCompiler(AnalyzedTree tree, LambdaExpression<?> lambda)
-
LambdaCompiler
LambdaCompiler(AnalyzedTree tree, LambdaExpression<?> lambda, MethodBuilder method, ConstructorBuilder constructor)
-
LambdaCompiler
private LambdaCompiler(LambdaCompiler parent, LambdaExpression lambda)
-
-
Method Detail
-
getParameterTypes
private TypeList getParameterTypes(LambdaExpression<?> lambda)
-
getParameters
ParameterExpressionList getParameters()
-
canEmitBoundConstants
boolean canEmitBoundConstants()
-
emitDebugSymbols
boolean emitDebugSymbols()
-
emitClosureArgument
void emitClosureArgument()
-
emitLambdaArgument
void emitLambdaArgument(int index)
-
createStaticField
private FieldBuilder createStaticField(java.lang.String name, Type type)
-
initializeMethod
void initializeMethod()
-
addReturnLabel
private void addReturnLabel(LambdaExpression lambda)
-
notEmpty
private static boolean notEmpty(Expression node)
-
significant
private static boolean significant(Expression node)
-
compile
static <T> Delegate<T> compile(LambdaExpression<T> lambda, DebugInfoGenerator debugInfoGenerator)
-
createDelegate
private <T> Delegate<T> createDelegate(java.lang.Class<T> generatedClass)
-
compile
static <T> void compile(LambdaExpression<T> lambda, MethodBuilder methodBuilder, DebugInfoGenerator debugInfoGenerator)
-
analyzeLambda
private static <T> Pair<AnalyzedTree,LambdaExpression<T>> analyzeLambda(LambdaExpression<T> lambda)
-
getNamedLocal
LocalBuilder getNamedLocal(Type type, ParameterExpression variable)
-
getLambdaArgument
int getLambdaArgument(int index)
-
getLocal
LocalBuilder getLocal(Type<?> type)
-
freeLocal
void freeLocal(LocalBuilder local)
-
updateEmitAsTailCallFlag
private static int updateEmitAsTailCallFlag(int flags, int newValue)
-
updateEmitExpressionStartFlag
private static int updateEmitExpressionStartFlag(int flags, int newValue)
-
updateEmitAsTypeFlag
private static int updateEmitAsTypeFlag(int flags, int newValue)
-
emitExpression
void emitExpression(Expression node)
-
emitExpressionStart
private int emitExpressionStart(Expression node)
-
emitExpressionEnd
private void emitExpressionEnd(int flags)
-
emitExpression
private void emitExpression(Expression node, int flags)
-
emitExtensionExpression
private void emitExtensionExpression(Expression node)
-
emitExpressionAsVoid
private void emitExpressionAsVoid(Expression node)
-
emitExpressionAsVoid
private void emitExpressionAsVoid(Expression node, int flags)
-
emitExpressionAsType
private void emitExpressionAsType(Expression node, Type type, int flags)
-
emitAssignBinaryExpression
private void emitAssignBinaryExpression(Expression expr)
-
emitAssign
private void emitAssign(BinaryExpression node, int emitAs)
-
emitMemberAssignment
private void emitMemberAssignment(BinaryExpression node, int flags)
-
emitVariableAssignment
private void emitVariableAssignment(BinaryExpression node, int flags)
-
emitIndexAssignment
private void emitIndexAssignment(BinaryExpression node, int flags)
-
emitSetIndexCall
private void emitSetIndexCall(BinaryExpression index)
-
hasVariables
private static boolean hasVariables(java.lang.Object node)
-
enterTry
private void enterTry(TryExpression tryExpression)
-
exitTry
private void exitTry(TryExpression tryExpression)
-
enterScope
private void enterScope(java.lang.Object node)
-
exitScope
private void exitScope(java.lang.Object node)
-
emitBlockExpression
private void emitBlockExpression(Expression expr, int flags)
-
emit
private void emit(BlockExpression node, int flags)
-
emitAndAlsoBinaryExpression
private void emitAndAlsoBinaryExpression(Expression expr, int flags)
-
emitPrimitiveAndAlso
private void emitPrimitiveAndAlso(BinaryExpression b)
-
emitUnboxingAndAlso
private void emitUnboxingAndAlso(BinaryExpression b)
-
emitOrElseBinaryExpression
private void emitOrElseBinaryExpression(Expression expr, int flags)
-
emitPrimitiveOrElse
private void emitPrimitiveOrElse(BinaryExpression b)
-
emitUnboxingOrElse
private void emitUnboxingOrElse(BinaryExpression b)
-
emitCoalesceBinaryExpression
private void emitCoalesceBinaryExpression(Expression expr)
-
emitReferenceCoalesceWithoutConversion
private void emitReferenceCoalesceWithoutConversion(BinaryExpression b)
-
emitLambdaReferenceCoalesce
private void emitLambdaReferenceCoalesce(BinaryExpression b)
-
emitConditionalExpression
private void emitConditionalExpression(Expression expr, int flags)
-
emitBinaryExpression
private void emitBinaryExpression(Expression expr)
-
emitBinaryExpression
private void emitBinaryExpression(Expression expr, int flags)
-
getEqualityOperand
private Expression getEqualityOperand(Expression expression)
-
emitBinaryMethod
private void emitBinaryMethod(BinaryExpression b, int flags)
-
emitBinaryOperator
private void emitBinaryOperator(ExpressionType op, Type<?> leftType, Type<?> rightType, Type resultType)
-
emitConvertArithmeticResult
private void emitConvertArithmeticResult(ExpressionType op, Type sourceType, Type resultType)
-
emitPrimitiveBinaryOp
private Type<?> emitPrimitiveBinaryOp(ExpressionType op, Type leftType, Type rightType)
-
emitUnboxingBinaryOp
private void emitUnboxingBinaryOp(ExpressionType op, Type leftType, Type rightType, Type resultType)
-
emitUnboxingBinaryArithmetic
private void emitUnboxingBinaryArithmetic(ExpressionType op, Type leftType, Type rightType, Type resultType)
-
emitLiftedRelational
private void emitLiftedRelational(ExpressionType op, Type leftType, Type rightType, Type resultType)
-
emitObjectBinaryOp
private void emitObjectBinaryOp(ExpressionType op)
-
emitArithmeticBinaryOp
private void emitArithmeticBinaryOp(ExpressionType op, Type<?> operandType)
-
emitConstantExpression
private void emitConstantExpression(Expression expr)
-
emitConstant
private void emitConstant(java.lang.Object value, Type<?> type)
-
emitDefaultValueExpression
private void emitDefaultValueExpression(Expression node)
-
emitGotoExpression
private void emitGotoExpression(Expression expr, int flags)
-
emitUnreachable
private void emitUnreachable(Expression node, int flags)
-
emitExpressionAndBranch
private void emitExpressionAndBranch(boolean branchValue, Expression node, Label label)
-
emitBranchNot
private void emitBranchNot(boolean branch, UnaryExpression node, Label label)
-
emitBranchNullCheck
private void emitBranchNullCheck(boolean branch, UnaryExpression node, Label label)
-
emitBranchRelation
private void emitBranchRelation(boolean branch, BinaryExpression node, Label label)
-
emitRelationalBranchOp
private void emitRelationalBranchOp(ExpressionType op, Type<?> operandType, boolean branch, Label label)
-
emitBranchOp
private void emitBranchOp(boolean branch, Label label)
-
emitBranchLogical
private void emitBranchLogical(boolean branch, BinaryExpression node, Label label)
-
emitBranchAnd
private void emitBranchAnd(boolean branch, BinaryExpression node, Label label)
-
emitBranchOr
private void emitBranchOr(boolean branch, BinaryExpression node, Label label)
-
emitBranchBlock
private void emitBranchBlock(boolean branch, BlockExpression node, Label label)
-
emitInvocationExpression
private void emitInvocationExpression(Expression expr, int flags)
-
emitInlinedInvoke
private void emitInlinedInvoke(InvocationExpression invoke, int flags)
-
emitLabelExpression
private void emitLabelExpression(Expression expr, int flags)
-
pushLabelBlock
private void pushLabelBlock(LabelScopeKind type)
-
tryPushLabelBlock
private boolean tryPushLabelBlock(Expression node)
-
popLabelBlock
private void popLabelBlock(LabelScopeKind kind)
-
defineBlockLabels
private void defineBlockLabels(Expression node)
-
ensureLabel
private LabelInfo ensureLabel(LabelTarget node)
-
referenceLabel
private LabelInfo referenceLabel(LabelTarget node)
-
defineLabel
private LabelInfo defineLabel(LabelTarget node)
-
emitLambdaExpression
private void emitLambdaExpression(Expression expr)
-
emitDelegateConstruction
private void emitDelegateConstruction(LambdaExpression lambda)
-
getUniqueMethodName
static java.lang.String getUniqueMethodName()
-
getUniqueLambdaName
static java.lang.String getUniqueLambdaName(java.lang.String name, java.lang.Class<?> creationContext)
-
emitLambdaBody
private void emitLambdaBody()
-
emitLambdaBody
private void emitLambdaBody(CompilerScope parent, boolean inlined, int flags)
-
emitDelegateConstruction
private void emitDelegateConstruction(LambdaCompiler inner)
-
emitClosureCreation
private void emitClosureCreation(LambdaCompiler inner)
-
ensureConstructor
private void ensureConstructor()
-
ensureClosure
private void ensureClosure()
-
emitConstantArray
final void emitConstantArray(java.lang.Object array)
-
emitLoopExpression
private void emitLoopExpression(Expression expr)
-
emitMemberExpression
private void emitMemberExpression(Expression expr)
-
emitMemberGet
private void emitMemberGet(MemberInfo member)
-
emitMethodCallExpression
private void emitMethodCallExpression(Expression expr)
-
emitMethodCallExpression
private void emitMethodCallExpression(Expression expr, int flags)
-
emitMethodCall
private void emitMethodCall(Expression target, MethodInfo method, IArgumentProvider methodCallExpr)
-
emitMethodCall
private void emitMethodCall(Expression target, MethodInfo method, IArgumentProvider expr, int flags)
-
emitMethodCall
private void emitMethodCall(Expression target, MethodInfo method, MethodCallExpression expr, int flags)
-
emitMethodCall
private void emitMethodCall(MethodInfo method, IArgumentProvider args, Type<?> objectType, int flags)
-
emitArguments
private void emitArguments(MethodBase method, IArgumentProvider args)
-
emitArguments
private void emitArguments(MethodBase method, IArgumentProvider args, int skipParameters)
-
emitNewExpression
private void emitNewExpression(Expression expr)
-
emitNewArrayExpression
private void emitNewArrayExpression(Expression expr)
-
emitParameterExpression
private void emitParameterExpression(Expression expr)
-
emitRuntimeVariablesExpression
private void emitRuntimeVariablesExpression(Expression expr)
-
emitTypeBinaryExpression
private void emitTypeBinaryExpression(Expression expr)
-
emitUnaryExpression
private void emitUnaryExpression(Expression expr, int flags)
-
emitUnary
private void emitUnary(UnaryExpression node, int flags)
-
emitUnaryOperator
private void emitUnaryOperator(ExpressionType op, Type operandType, Type resultType)
-
emitUnaryMethod
private void emitUnaryMethod(UnaryExpression node, int flags)
-
emitConvertUnaryExpression
private void emitConvertUnaryExpression(Expression expr, int flags)
-
emitConvert
private void emitConvert(UnaryExpression node, int flags)
-
emitUnboxUnaryExpression
private void emitUnboxUnaryExpression(Expression expr)
-
emitThrowUnaryExpression
private void emitThrowUnaryExpression(Expression expr)
-
emitThrow
private void emitThrow(UnaryExpression expr, int flags)
-
emitTryExpression
private void emitTryExpression(Expression expr)
-
emitCatchStart
private void emitCatchStart(CatchBlock cb)
-
checkTry
private void checkTry()
-
emitSaveExceptionOrPop
private void emitSaveExceptionOrPop(CatchBlock cb)
-
emitSwitchExpression
private void emitSwitchExpression(Expression expr, int flags)
-
tryEmitStringSwitch
private boolean tryEmitStringSwitch(SwitchExpression node, int flags)
-
tryEmitLookupSwitch
private boolean tryEmitLookupSwitch(SwitchExpression node, int flags)
-
canOptimizeSwitchType
private static boolean canOptimizeSwitchType(Type<?> valueType)
-
-