Skip to content

Commit 310975b

Browse files
authored
Merge pull request #4581 from criemen/printast-stmtpexpr
C++: Add support for StmtExpr to Print AST.
2 parents d3631d8 + e7d9953 commit 310975b

File tree

5 files changed

+71
-3
lines changed

5 files changed

+71
-3
lines changed

cpp/ql/src/semmle/code/cpp/PrintAST.qll

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,18 @@ class CastNode extends ConversionNode {
341341
}
342342
}
343343

344+
/**
345+
* A node representing a `StmtExpr`.
346+
*/
347+
class StmtExprNode extends ExprNode {
348+
override StmtExpr expr;
349+
350+
override ASTNode getChildInternal(int childIndex) {
351+
childIndex = 0 and
352+
result.getAST() = expr.getStmt()
353+
}
354+
}
355+
344356
/**
345357
* A node representing a `DeclarationEntry`.
346358
*/

cpp/ql/test/examples/expressions/PrintAST.expected

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,19 @@ StatementExpr.c:
724724
# 2| getExpr(): [StmtExpr] (statement expression)
725725
# 2| Type = [IntType] int
726726
# 2| ValueCategory = prvalue
727+
# 2| getStmt(): [BlockStmt] { ... }
728+
# 2| getStmt(0): [DeclStmt] declaration
729+
# 2| getDeclarationEntry(0): [VariableDeclarationEntry] definition of i
730+
# 2| Type = [IntType] int
731+
# 2| getVariable().getInitializer(): [Initializer] initializer for i
732+
# 2| getExpr(): [Literal] 5
733+
# 2| Type = [IntType] int
734+
# 2| Value = [Literal] 5
735+
# 2| ValueCategory = prvalue
736+
# 2| getStmt(1): [ExprStmt] ExprStmt
737+
# 2| getExpr(): [VariableAccess] i
738+
# 2| Type = [IntType] int
739+
# 2| ValueCategory = prvalue(load)
727740
# 3| getStmt(1): [ReturnStmt] return ...
728741
StaticMemberAccess.cpp:
729742
# 1| [CopyAssignmentOperator] X& X::operator=(X const&)

cpp/ql/test/library-tests/ir/ir/PrintAST.expected

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8260,7 +8260,7 @@ ir.cpp:
82608260
# 997| Type = [FloatType] float
82618261
# 997| Value = [CStyleCast] 1.0
82628262
# 997| ValueCategory = prvalue
8263-
# 1000| [TopLevelFunction] int ExprStmt(int, int, int)
8263+
# 1000| [TopLevelFunction] int StmtExpr(int, int, int)
82648264
# 1000| <params>:
82658265
# 1000| getParameter(0): [Parameter] b
82668266
# 1000| Type = [IntType] int
@@ -8276,10 +8276,53 @@ ir.cpp:
82768276
# 1001| getExpr(): [StmtExpr] (statement expression)
82778277
# 1001| Type = [IntType] int
82788278
# 1001| ValueCategory = prvalue
8279+
# 1001| getStmt(): [BlockStmt] { ... }
8280+
# 1002| getStmt(0): [DeclStmt] declaration
8281+
# 1002| getDeclarationEntry(0): [VariableDeclarationEntry] definition of w
8282+
# 1002| Type = [IntType] int
8283+
# 1003| getStmt(1): [IfStmt] if (...) ...
8284+
# 1003| getCondition(): [VariableAccess] b
8285+
# 1003| Type = [IntType] int
8286+
# 1003| ValueCategory = prvalue(load)
8287+
# 1003| getThen(): [BlockStmt] { ... }
8288+
# 1004| getStmt(0): [ExprStmt] ExprStmt
8289+
# 1004| getExpr(): [AssignExpr] ... = ...
8290+
# 1004| Type = [IntType] int
8291+
# 1004| ValueCategory = lvalue
8292+
# 1004| getLValue(): [VariableAccess] w
8293+
# 1004| Type = [IntType] int
8294+
# 1004| ValueCategory = lvalue
8295+
# 1004| getRValue(): [VariableAccess] y
8296+
# 1004| Type = [IntType] int
8297+
# 1004| ValueCategory = prvalue(load)
8298+
# 1005| getElse(): [BlockStmt] { ... }
8299+
# 1006| getStmt(0): [ExprStmt] ExprStmt
8300+
# 1006| getExpr(): [AssignExpr] ... = ...
8301+
# 1006| Type = [IntType] int
8302+
# 1006| ValueCategory = lvalue
8303+
# 1006| getLValue(): [VariableAccess] w
8304+
# 1006| Type = [IntType] int
8305+
# 1006| ValueCategory = lvalue
8306+
# 1006| getRValue(): [VariableAccess] z
8307+
# 1006| Type = [IntType] int
8308+
# 1006| ValueCategory = prvalue(load)
8309+
# 1003| getCondition().getFullyConverted(): [CStyleCast] (bool)...
8310+
# 1003| Conversion = [BoolConversion] conversion to bool
8311+
# 1003| Type = [BoolType] bool
8312+
# 1003| ValueCategory = prvalue
8313+
# 1008| getStmt(2): [ExprStmt] ExprStmt
8314+
# 1008| getExpr(): [VariableAccess] w
8315+
# 1008| Type = [IntType] int
8316+
# 1008| ValueCategory = prvalue(load)
82798317
# 1011| getStmt(1): [ReturnStmt] return ...
82808318
# 1011| getExpr(): [StmtExpr] (statement expression)
82818319
# 1011| Type = [IntType] int
82828320
# 1011| ValueCategory = prvalue
8321+
# 1011| getStmt(): [BlockStmt] { ... }
8322+
# 1011| getStmt(0): [ExprStmt] ExprStmt
8323+
# 1011| getExpr(): [VariableAccess] x
8324+
# 1011| Type = [IntType] int
8325+
# 1011| ValueCategory = prvalue(load)
82838326
# 1015| [TopLevelFunction] void OperatorDelete()
82848327
# 1015| <params>:
82858328
# 1015| getEntryPoint(): [BlockStmt] { ... }

cpp/ql/test/library-tests/ir/ir/ir.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -997,7 +997,7 @@ int PointerDecay(int a[], int fn(float)) {
997997
return a[0] + fn(1.0);
998998
}
999999

1000-
int ExprStmt(int b, int y, int z) {
1000+
int StmtExpr(int b, int y, int z) {
10011001
int x = ({
10021002
int w;
10031003
if (b) {

cpp/ql/test/library-tests/ir/ir/raw_ir.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5532,7 +5532,7 @@ ir.cpp:
55325532
# 996| v996_13(void) = AliasedUse : ~m?
55335533
# 996| v996_14(void) = ExitFunction :
55345534

5535-
# 1000| int ExprStmt(int, int, int)
5535+
# 1000| int StmtExpr(int, int, int)
55365536
# 1000| Block 0
55375537
# 1000| v1000_1(void) = EnterFunction :
55385538
# 1000| mu1000_2(unknown) = AliasedDefinition :

0 commit comments

Comments
 (0)