@@ -8,6 +8,8 @@ private import TranslatedDeclarationEntry
88private import TranslatedElement
99private import TranslatedFunction
1010private import TranslatedInitialization
11+ private import TranslatedFunction
12+ private import TranslatedStmt
1113import TranslatedCall
1214
1315/**
@@ -2727,3 +2729,53 @@ class TranslatedLambdaExpr extends TranslatedNonConstantExpr, InitializationCont
27272729 result = getTranslatedInitialization ( expr .getChild ( 0 ) .getFullyConverted ( ) )
27282730 }
27292731}
2732+
2733+ /**
2734+ * The IR translation of `StmtExpr` (the GNU statement expression extension to C/C++), such as
2735+ * ``` ({ doSomething(); a + b; })```
2736+ */
2737+ class TranslatedStmtExpr extends TranslatedNonConstantExpr {
2738+ override StmtExpr expr ;
2739+
2740+ override final Instruction getFirstInstruction ( ) {
2741+ result = getStmt ( ) .getFirstInstruction ( )
2742+ }
2743+
2744+ override final TranslatedElement getChild ( int id ) {
2745+ id = 0 and result = getStmt ( )
2746+ }
2747+
2748+ override Instruction getInstructionSuccessor ( InstructionTag tag , EdgeKind kind ) {
2749+ tag instanceof OnlyInstructionTag and
2750+ kind instanceof GotoEdge and
2751+ result = getParent ( ) .getChildSuccessor ( this )
2752+ }
2753+
2754+ override Instruction getChildSuccessor ( TranslatedElement child ) {
2755+ child = getStmt ( ) and
2756+ result = getInstruction ( OnlyInstructionTag ( ) )
2757+ }
2758+
2759+ override predicate hasInstruction ( Opcode opcode , InstructionTag tag , Type resultType ,
2760+ boolean isGLValue ) {
2761+ opcode instanceof Opcode:: CopyValue and
2762+ tag instanceof OnlyInstructionTag and
2763+ resultType = expr .getType ( ) and
2764+ isGLValue = false
2765+ }
2766+
2767+ override Instruction getResult ( ) {
2768+ result = getInstruction ( OnlyInstructionTag ( ) )
2769+ }
2770+
2771+ override Instruction getInstructionOperand ( InstructionTag tag ,
2772+ OperandTag operandTag ) {
2773+ tag instanceof OnlyInstructionTag and
2774+ operandTag instanceof UnaryOperandTag and
2775+ result = getTranslatedExpr ( expr .getResultExpr ( ) .getFullyConverted ( ) ) .getResult ( )
2776+ }
2777+
2778+ TranslatedStmt getStmt ( ) {
2779+ result = getTranslatedStmt ( expr .getStmt ( ) )
2780+ }
2781+ }
0 commit comments