Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C++: Print handler parameters in PrintAST #17734

Merged
merged 1 commit into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions cpp/ql/lib/semmle/code/cpp/PrintAST.qll
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ private Declaration getAnEnclosingDeclaration(Locatable ast) {
or
result = ast.(Parameter).getFunction()
or
result = ast.(Parameter).getCatchBlock().getEnclosingFunction()
or
result = ast.(Expr).getEnclosingDeclaration()
or
result = ast.(Initializer).getDeclaration()
Expand Down Expand Up @@ -510,6 +512,22 @@ class DeclStmtNode extends StmtNode {
}
}

/**
* A node representing a `Handler`.
*/
class HandlerNode extends ChildStmtNode {
Handler handler;

HandlerNode() { handler = stmt }

override BaseAstNode getChildInternal(int childIndex) {
result = super.getChildInternal(childIndex)
or
childIndex = -1 and
result.getAst() = handler.getParameter()
}
}

/**
* A node representing a `Parameter`.
*/
Expand Down Expand Up @@ -754,6 +772,8 @@ private predicate namedStmtChildPredicates(Locatable s, Element e, string pred)
or
s.(ConstexprIfStmt).getElse() = e and pred = "getElse()"
or
s.(Handler).getParameter() = e and pred = "getParameter()"
or
s.(IfStmt).getInitialization() = e and pred = "getInitialization()"
or
s.(IfStmt).getCondition() = e and pred = "getCondition()"
Expand Down
2 changes: 2 additions & 0 deletions cpp/ql/test/examples/expressions/PrintAST.expected
Original file line number Diff line number Diff line change
Expand Up @@ -870,6 +870,8 @@ Throw.cpp:
# 8| Type = [BoolType] bool
# 8| ValueCategory = prvalue
# 12| getChild(1): [Handler] <handler>
# 12| getParameter(): [Parameter] e
# 12| Type = [PointerType] E *
# 12| getBlock(): [CatchBlock] { ... }
# 13| getStmt(0): [ExprStmt] ExprStmt
# 13| getExpr(): [ReThrowExpr] re-throw exception
Expand Down
14 changes: 14 additions & 0 deletions cpp/ql/test/library-tests/ir/ir/PrintAST.expected
Original file line number Diff line number Diff line change
Expand Up @@ -9055,6 +9055,8 @@ ir.cpp:
# 733| Value = [Literal] 7
# 733| ValueCategory = prvalue
# 735| getChild(1): [Handler] <handler>
# 735| getParameter(): [Parameter] s
# 735| Type = [PointerType] const char *
# 735| getBlock(): [CatchBlock] { ... }
# 736| getStmt(0): [ExprStmt] ExprStmt
# 736| getExpr(): [ThrowExpr] throw ...
Expand All @@ -9067,6 +9069,8 @@ ir.cpp:
# 736| Type = [PointerType] const char *
# 736| ValueCategory = prvalue(load)
# 738| getChild(2): [Handler] <handler>
# 738| getParameter(): [Parameter] e
# 738| Type = [LValueReferenceType] const String &
# 738| getBlock(): [CatchBlock] { ... }
# 740| getChild(3): [Handler] <handler>
# 740| getBlock(): [CatchAnyBlock] { ... }
Expand Down Expand Up @@ -12852,6 +12856,8 @@ ir.cpp:
# 1200| Value = [Literal] 7
# 1200| ValueCategory = prvalue
# 1202| getChild(1): [Handler] <handler>
# 1202| getParameter(): [Parameter] s
# 1202| Type = [PointerType] const char *
# 1202| getBlock(): [CatchBlock] { ... }
# 1203| getStmt(0): [ExprStmt] ExprStmt
# 1203| getExpr(): [ThrowExpr] throw ...
Expand All @@ -12864,6 +12870,8 @@ ir.cpp:
# 1203| Type = [PointerType] const char *
# 1203| ValueCategory = prvalue(load)
# 1205| getChild(2): [Handler] <handler>
# 1205| getParameter(): [Parameter] e
# 1205| Type = [LValueReferenceType] const String &
# 1205| getBlock(): [CatchBlock] { ... }
# 1207| getStmt(1): [ReturnStmt] return ...
# 1211| [TopLevelFunction] void VectorTypes(int)
Expand Down Expand Up @@ -20586,6 +20594,8 @@ ir.cpp:
# 2281| Type = [Struct] String
# 2281| ValueCategory = lvalue
# 2282| getChild(1): [Handler] <handler>
# 2282| getParameter(): [Parameter] s
# 2282| Type = [PointerType] const char *
# 2282| getBlock(): [CatchBlock] { ... }
# 2283| getStmt(0): [ExprStmt] ExprStmt
# 2283| getExpr(): [ThrowExpr] throw ...
Expand All @@ -20598,6 +20608,8 @@ ir.cpp:
# 2283| Type = [PointerType] const char *
# 2283| ValueCategory = prvalue(load)
# 2285| getChild(2): [Handler] <handler>
# 2285| getParameter(): [Parameter] e
# 2285| Type = [LValueReferenceType] const String &
# 2285| getBlock(): [CatchBlock] { ... }
# 2287| getChild(3): [Handler] <handler>
# 2287| getBlock(): [CatchAnyBlock] { ... }
Expand Down Expand Up @@ -22845,6 +22857,8 @@ ir.cpp:
# 2537| Value = [Literal] 42
# 2537| ValueCategory = prvalue
# 2539| getChild(1): [Handler] <handler>
# 2539| getParameter(): [Parameter] (unnamed parameter 0)
# 2539| Type = [PlainCharType] char
# 2539| getBlock(): [CatchBlock] { ... }
# 2541| getImplicitDestructorCall(0): [DestructorCall] call to ~ClassWithDestructor
# 2541| Type = [VoidType] void
Expand Down
Loading