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 class
LambdaCompiler.CompilationFlags
-
Field Summary
Fields Modifier and Type Field Description private BoundConstants
_boundConstants
private FieldBuilder
_closureField
private ConstructorBuilder
_constructorBuilder
private FinallyInfo
_finallyInfo
private KeyedQueue<Type<?>,LocalBuilder>
_freeLocals
private boolean
_hasClosureArgument
private LabelScopeInfo
_labelBlock
private java.util.Map<LabelTarget,LabelInfo>
_labelInfo
private CompilerScope
_scope
private AnalyzedTree
_tree
(package private) static Type<Closure>
closureType
(package private) CodeGenerator
generator
(package private) LambdaExpression<?>
lambda
(package private) MethodBuilder
methodBuilder
(package private) static java.util.concurrent.atomic.AtomicInteger
nextId
(package private) TypeBuilder
typeBuilder
-
Constructor Summary
Constructors Modifier Constructor Description (package private)
LambdaCompiler(AnalyzedTree tree, LambdaExpression<?> lambda)
(package private)
LambdaCompiler(AnalyzedTree tree, LambdaExpression<?> lambda, MethodBuilder method, ConstructorBuilder constructor)
private
LambdaCompiler(LambdaCompiler parent, LambdaExpression lambda)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
addReturnLabel(LambdaExpression lambda)
private static <T> Pair<AnalyzedTree,LambdaExpression<T>>
analyzeLambda(LambdaExpression<T> lambda)
(package private) boolean
canEmitBoundConstants()
private static boolean
canOptimizeSwitchType(Type<?> valueType)
private void
checkTry()
(package private) static <T> Delegate<T>
compile(LambdaExpression<T> lambda, DebugInfoGenerator debugInfoGenerator)
(package private) static <T> void
compile(LambdaExpression<T> lambda, MethodBuilder methodBuilder, DebugInfoGenerator debugInfoGenerator)
private <T> Delegate<T>
createDelegate(java.lang.Class<T> generatedClass)
private FieldBuilder
createStaticField(java.lang.String name, Type type)
private void
defineBlockLabels(Expression node)
private LabelInfo
defineLabel(LabelTarget node)
private void
emit(BlockExpression node, int flags)
private void
emitAndAlsoBinaryExpression(Expression expr, int flags)
private void
emitArguments(MethodBase method, IArgumentProvider args)
private void
emitArguments(MethodBase method, IArgumentProvider args, int skipParameters)
private void
emitArithmeticBinaryOp(ExpressionType op, Type<?> operandType)
private void
emitAssign(BinaryExpression node, int emitAs)
private void
emitAssignBinaryExpression(Expression expr)
private void
emitBinaryExpression(Expression expr)
private void
emitBinaryExpression(Expression expr, int flags)
private void
emitBinaryMethod(BinaryExpression b, int flags)
private void
emitBinaryOperator(ExpressionType op, Type<?> leftType, Type<?> rightType, Type resultType)
private void
emitBlockExpression(Expression expr, int flags)
private void
emitBranchAnd(boolean branch, BinaryExpression node, Label label)
private void
emitBranchBlock(boolean branch, BlockExpression node, Label label)
private void
emitBranchLogical(boolean branch, BinaryExpression node, Label label)
private void
emitBranchNot(boolean branch, UnaryExpression node, Label label)
private void
emitBranchNullCheck(boolean branch, UnaryExpression node, Label label)
private void
emitBranchOp(boolean branch, Label label)
private void
emitBranchOr(boolean branch, BinaryExpression node, Label label)
private void
emitBranchRelation(boolean branch, BinaryExpression node, Label label)
private void
emitCatchStart(CatchBlock cb)
(package private) void
emitClosureArgument()
private void
emitClosureCreation(LambdaCompiler inner)
private void
emitCoalesceBinaryExpression(Expression expr)
private void
emitConditionalExpression(Expression expr, int flags)
private void
emitConstant(java.lang.Object value, Type<?> type)
(package private) void
emitConstantArray(java.lang.Object array)
private void
emitConstantExpression(Expression expr)
private void
emitConvert(UnaryExpression node, int flags)
private void
emitConvertArithmeticResult(ExpressionType op, Type sourceType, Type resultType)
private void
emitConvertUnaryExpression(Expression expr, int flags)
(package private) boolean
emitDebugSymbols()
private void
emitDefaultValueExpression(Expression node)
private void
emitDelegateConstruction(LambdaCompiler inner)
private void
emitDelegateConstruction(LambdaExpression lambda)
(package private) void
emitExpression(Expression node)
private void
emitExpression(Expression node, int flags)
private void
emitExpressionAndBranch(boolean branchValue, Expression node, Label label)
private void
emitExpressionAsType(Expression node, Type type, int flags)
private void
emitExpressionAsVoid(Expression node)
private void
emitExpressionAsVoid(Expression node, int flags)
private void
emitExpressionEnd(int flags)
private int
emitExpressionStart(Expression node)
private void
emitExtensionExpression(Expression node)
private void
emitGotoExpression(Expression expr, int flags)
private void
emitIndexAssignment(BinaryExpression node, int flags)
private void
emitInlinedInvoke(InvocationExpression invoke, int flags)
private void
emitInvocationExpression(Expression expr, int flags)
private void
emitLabelExpression(Expression expr, int flags)
(package private) void
emitLambdaArgument(int index)
private void
emitLambdaBody()
private void
emitLambdaBody(CompilerScope parent, boolean inlined, int flags)
private void
emitLambdaExpression(Expression expr)
private void
emitLambdaReferenceCoalesce(BinaryExpression b)
private void
emitLiftedBooleanAnd(Type leftType, Type rightType)
private void
emitLiftedBooleanOr(Type leftType, Type rightType)
private void
emitLiftedRelational(ExpressionType op, Type leftType, Type rightType, Type resultType)
private void
emitLoopExpression(Expression expr)
private void
emitMemberAssignment(BinaryExpression node, int flags)
private void
emitMemberExpression(Expression expr)
private void
emitMemberGet(MemberInfo member)
private void
emitMethodCall(Expression target, MethodInfo method, IArgumentProvider methodCallExpr)
private void
emitMethodCall(Expression target, MethodInfo method, IArgumentProvider expr, int flags)
private void
emitMethodCall(Expression target, MethodInfo method, MethodCallExpression expr, int flags)
private void
emitMethodCall(MethodInfo method, IArgumentProvider args, Type<?> objectType, int flags)
private void
emitMethodCallExpression(Expression expr)
private void
emitMethodCallExpression(Expression expr, int flags)
private void
emitNewArrayExpression(Expression expr)
private void
emitNewExpression(Expression expr)
private void
emitObjectBinaryOp(ExpressionType op)
private void
emitOrElseBinaryExpression(Expression expr, int flags)
private void
emitParameterExpression(Expression expr)
private void
emitPrimitiveAndAlso(BinaryExpression b)
private Type<?>
emitPrimitiveBinaryOp(ExpressionType op, Type leftType, Type rightType)
private void
emitPrimitiveOrElse(BinaryExpression b)
private void
emitReferenceCoalesceWithoutConversion(BinaryExpression b)
private void
emitRelationalBranchOp(ExpressionType op, Type<?> operandType, boolean branch, Label label)
private void
emitRuntimeVariablesExpression(Expression expr)
private void
emitSaveExceptionOrPop(CatchBlock cb)
private void
emitSetIndexCall(BinaryExpression index)
private void
emitSwitchExpression(Expression expr, int flags)
private void
emitThrow(UnaryExpression expr, int flags)
private void
emitThrowUnaryExpression(Expression expr)
private void
emitTryExpression(Expression expr)
private void
emitTypeBinaryExpression(Expression expr)
private void
emitUnary(UnaryExpression node, int flags)
private void
emitUnaryExpression(Expression expr, int flags)
private void
emitUnaryMethod(UnaryExpression node, int flags)
private void
emitUnaryOperator(ExpressionType op, Type operandType, Type resultType)
private void
emitUnboxingAndAlso(BinaryExpression b)
private void
emitUnboxingBinaryArithmetic(ExpressionType op, Type leftType, Type rightType, Type resultType)
private void
emitUnboxingBinaryOp(ExpressionType op, Type leftType, Type rightType, Type resultType)
private void
emitUnboxingOrElse(BinaryExpression b)
private void
emitUnboxUnaryExpression(Expression expr)
private void
emitUnreachable(Expression node, int flags)
private void
emitVariableAssignment(BinaryExpression node, int flags)
private void
ensureClosure()
private void
ensureConstructor()
private LabelInfo
ensureLabel(LabelTarget node)
private void
enterScope(java.lang.Object node)
private void
enterTry(TryExpression tryExpression)
private void
exitScope(java.lang.Object node)
private void
exitTry(TryExpression tryExpression)
(package private) void
freeLocal(LocalBuilder local)
private Expression
getEqualityOperand(Expression expression)
(package private) int
getLambdaArgument(int index)
(package private) LocalBuilder
getLocal(Type<?> type)
(package private) LocalBuilder
getNamedLocal(Type type, ParameterExpression variable)
(package private) ParameterExpressionList
getParameters()
private TypeList
getParameterTypes(LambdaExpression<?> lambda)
(package private) static java.lang.String
getUniqueLambdaName(java.lang.String name, java.lang.Class<?> creationContext)
(package private) static java.lang.String
getUniqueMethodName()
private static boolean
hasVariables(java.lang.Object node)
(package private) void
initializeMethod()
private static boolean
notEmpty(Expression node)
private void
popLabelBlock(LabelScopeKind kind)
private void
pushLabelBlock(LabelScopeKind type)
private LabelInfo
referenceLabel(LabelTarget node)
private static boolean
significant(Expression node)
private boolean
tryEmitLookupSwitch(SwitchExpression node, int flags)
private boolean
tryEmitStringSwitch(SwitchExpression node, int flags)
private boolean
tryPushLabelBlock(Expression node)
private Type
unboxLeftBinaryOperand(Type leftType, Type rightType)
private Type
unboxRightBinaryOperand(Type rightType)
private static int
updateEmitAsTailCallFlag(int flags, int newValue)
private static int
updateEmitAsTypeFlag(int flags, int newValue)
private static int
updateEmitExpressionStartFlag(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)
-
-