@@ -2608,3 +2608,122 @@ class TranslatedConditionDeclExpr extends TranslatedNonConstantExpr {
26082608 result = getTranslatedExpr ( expr .getVariableAccess ( ) .getFullyConverted ( ) )
26092609 }
26102610}
2611+
2612+ /**
2613+ * The IR translation of a lambda expression. This initializes a temporary variable whose type is that of the lambda,
2614+ * using the initializer list that represents the captures of the lambda.
2615+ */
2616+ class TranslatedLambdaExpr extends TranslatedNonConstantExpr , InitializationContext {
2617+ override LambdaExpression expr ;
2618+
2619+ override final Instruction getFirstInstruction ( ) {
2620+ result = getInstruction ( InitializerVariableAddressTag ( ) )
2621+ }
2622+
2623+ override final TranslatedElement getChild ( int id ) {
2624+ id = 0 and result = getInitialization ( )
2625+ }
2626+
2627+ override Instruction getResult ( ) {
2628+ result = getInstruction ( LoadTag ( ) )
2629+ }
2630+
2631+ override Instruction getInstructionSuccessor ( InstructionTag tag , EdgeKind kind ) {
2632+ (
2633+ tag = InitializerVariableAddressTag ( ) and
2634+ kind instanceof GotoEdge and
2635+ result = getInstruction ( InitializerStoreTag ( ) )
2636+ ) or
2637+ (
2638+ tag = InitializerStoreTag ( ) and
2639+ kind instanceof GotoEdge and
2640+ (
2641+ result = getInitialization ( ) .getFirstInstruction ( ) or
2642+ not hasInitializer ( ) and result = getInstruction ( LoadTag ( ) )
2643+ )
2644+ ) or
2645+ (
2646+ tag = LoadTag ( ) and
2647+ kind instanceof GotoEdge and
2648+ result = getParent ( ) .getChildSuccessor ( this )
2649+ )
2650+ }
2651+
2652+ override Instruction getChildSuccessor ( TranslatedElement child ) {
2653+ child = getInitialization ( ) and
2654+ result = getInstruction ( LoadTag ( ) )
2655+ }
2656+
2657+ override predicate hasInstruction ( Opcode opcode , InstructionTag tag , Type resultType ,
2658+ boolean isGLValue ) {
2659+ (
2660+ tag = InitializerVariableAddressTag ( ) and
2661+ opcode instanceof Opcode:: VariableAddress and
2662+ resultType = getResultType ( ) and
2663+ isGLValue = true
2664+ ) or
2665+ (
2666+ tag = InitializerStoreTag ( ) and
2667+ opcode instanceof Opcode:: Uninitialized and
2668+ resultType = getResultType ( ) and
2669+ isGLValue = false
2670+ ) or
2671+ (
2672+ tag = LoadTag ( ) and
2673+ opcode instanceof Opcode:: Load and
2674+ resultType = getResultType ( ) and
2675+ isGLValue = false
2676+ )
2677+ }
2678+
2679+ override Instruction getInstructionOperand ( InstructionTag tag ,
2680+ OperandTag operandTag ) {
2681+ (
2682+ tag = InitializerStoreTag ( ) and
2683+ operandTag instanceof AddressOperandTag and
2684+ result = getInstruction ( InitializerVariableAddressTag ( ) )
2685+ ) or
2686+ (
2687+ tag = LoadTag ( ) and
2688+ (
2689+ (
2690+ operandTag instanceof AddressOperandTag and
2691+ result = getInstruction ( InitializerVariableAddressTag ( ) )
2692+ ) or
2693+ (
2694+ operandTag instanceof LoadOperandTag and
2695+ result = getEnclosingFunction ( ) .getUnmodeledDefinitionInstruction ( )
2696+ )
2697+ )
2698+ )
2699+ }
2700+
2701+ override IRVariable getInstructionVariable ( InstructionTag tag ) {
2702+ (
2703+ tag = InitializerVariableAddressTag ( ) or
2704+ tag = InitializerStoreTag ( )
2705+ ) and
2706+ result = getTempVariable ( LambdaTempVar ( ) )
2707+ }
2708+
2709+ override predicate hasTempVariable ( TempVariableTag tag , Type type ) {
2710+ tag = LambdaTempVar ( ) and
2711+ type = getResultType ( )
2712+ }
2713+
2714+ override final Instruction getTargetAddress ( ) {
2715+ result = getInstruction ( InitializerVariableAddressTag ( ) )
2716+ }
2717+
2718+ override final Type getTargetType ( ) {
2719+ result = getResultType ( )
2720+ }
2721+
2722+ private predicate hasInitializer ( ) {
2723+ exists ( getInitialization ( ) )
2724+ }
2725+
2726+ private TranslatedInitialization getInitialization ( ) {
2727+ result = getTranslatedInitialization ( expr .getChild ( 0 ) .getFullyConverted ( ) )
2728+ }
2729+ }
0 commit comments