Skip to content

Commit 9718e00

Browse files
committed
C++: Add a few helper predicates.
1 parent 2ee82d0 commit 9718e00

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

cpp/ql/lib/semmle/code/cpp/Element.qll

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,11 @@ class Element extends ElementBase {
192192
*/
193193
predicate isAffectedByMacro() { affectedByMacro(this) }
194194

195+
/** Holds if this element is affected by the expansion of `mi`. */
196+
predicate isAffectedByMacro(MacroInvocation mi) {
197+
affectedbymacroexpansion(underlyingElement(this), unresolveElement(mi))
198+
}
199+
195200
private Element getEnclosingElementPref() {
196201
enclosingfunction(underlyingElement(this), unresolveElement(result)) or
197202
result.(Function) = stmtEnclosingElement(this) or

cpp/ql/lib/semmle/code/cpp/exprs/Expr.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class Expr extends StmtParent, @expr {
2323
predicate hasChild(Expr e, int n) { e = this.getChild(n) }
2424

2525
/** Gets the enclosing function of this expression, if any. */
26-
Function getEnclosingFunction() { result = exprEnclosingElement(this) }
26+
override Function getEnclosingFunction() { result = exprEnclosingElement(this) }
2727

2828
/** Gets the nearest enclosing set of curly braces around this expression in the source, if any. */
2929
BlockStmt getEnclosingBlock() { result = this.getEnclosingStmt().getEnclosingBlock() }

cpp/ql/lib/semmle/code/cpp/stmts/Stmt.qll

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class Stmt extends StmtParent, @stmt {
2020
predicate hasChild(Element e, int n) { this.getChild(n) = e }
2121

2222
/** Gets the enclosing function of this statement, if any. */
23-
Function getEnclosingFunction() { result = stmtEnclosingElement(this) }
23+
override Function getEnclosingFunction() { result = stmtEnclosingElement(this) }
2424

2525
/**
2626
* Gets the nearest enclosing block of this statement in the source, if any.
@@ -159,7 +159,10 @@ private class TStmtParent = @stmt or @expr;
159159
*
160160
* This is normally a statement, but may be a `StmtExpr`.
161161
*/
162-
class StmtParent extends ControlFlowNode, TStmtParent { }
162+
class StmtParent extends ControlFlowNode, TStmtParent {
163+
/** Gets the enclosing function of this element, if any. */
164+
Function getEnclosingFunction() { none() }
165+
}
163166

164167
/**
165168
* A C/C++ 'expression' statement.

0 commit comments

Comments
 (0)