Skip to content

Commit 893b413

Browse files
committed
C++: Add 'expectsBooleanChild' predicate which we will need later.
1 parent 3bc1d47 commit 893b413

File tree

4 files changed

+21
-0
lines changed

4 files changed

+21
-0
lines changed

cpp/ql/lib/semmle/code/cpp/ir/implementation/raw/internal/TranslatedElement.qll

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -978,6 +978,12 @@ abstract class TranslatedElement extends TTranslatedElement {
978978
*/
979979
predicate hasAnImplicitDestructorCall() { none() }
980980

981+
/**
982+
* Holds if `child` is a child element of this `TranslatedElement` and
983+
* `child` is expected to return a Boolean result.
984+
*/
985+
predicate expectsBooleanChild(TranslatedExpr child) { none() }
986+
981987
/**
982988
* Gets the child index of the first destructor call that should be executed after this `TranslatedElement`
983989
*/

cpp/ql/lib/semmle/code/cpp/ir/implementation/raw/internal/TranslatedExpr.qll

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ abstract class TranslatedExpr extends TranslatedElement {
7272
*/
7373
Type getExprType() { result = expr.getType() }
7474

75+
final override predicate expectsBooleanChild(TranslatedExpr child) {
76+
child = this.getAChild() and
77+
child.getExprType() instanceof BoolType
78+
}
79+
7580
/**
7681
* Holds if the result of this `TranslatedExpr` is a glvalue.
7782
*/

cpp/ql/lib/semmle/code/cpp/ir/implementation/raw/internal/TranslatedInitialization.qll

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,11 @@ abstract class TranslatedInitialization extends TranslatedElement, TTranslatedIn
143143

144144
TranslatedInitialization() { this = TTranslatedInitialization(expr) }
145145

146+
final override predicate expectsBooleanChild(TranslatedExpr child) {
147+
child = this.getAChild() and
148+
child.getExprType() instanceof BoolType
149+
}
150+
146151
final override string toString() { result = "init: " + expr.toString() }
147152

148153
final override Declaration getFunction() {

cpp/ql/lib/semmle/code/cpp/ir/implementation/raw/internal/TranslatedStmt.qll

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,11 @@ abstract class TranslatedStmt extends TranslatedElement, TTranslatedStmt {
320320
final override Locatable getAst() { result = stmt }
321321

322322
final override Function getFunction() { result = stmt.getEnclosingFunction() }
323+
324+
final override predicate expectsBooleanChild(TranslatedExpr child) {
325+
child = this.getAChild() and
326+
child.getExprType() instanceof BoolType
327+
}
323328
}
324329

325330
class TranslatedEmptyStmt extends TranslatedStmt {

0 commit comments

Comments
 (0)