Skip to content

Commit b0b2fc8

Browse files
Merge pull request #855 from jbj/ir-getRealParent
C++: Simplify TranslatedElement.getRealParent
2 parents 8896d3b + 5b68538 commit b0b2fc8

File tree

1 file changed

+3
-24
lines changed

1 file changed

+3
-24
lines changed

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

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,36 +17,15 @@ Type getIntType() {
1717
result.(IntType).isImplicitlySigned()
1818
}
1919

20-
/**
21-
* If `expr` is a conversion, gets the expression being converted. Otherwise,
22-
* returns `expr`.
23-
*/
24-
private Expr getUnconvertedExpr(Expr expr) {
25-
if expr instanceof Conversion then (
26-
result = getUnconvertedExpr(expr.(Conversion).getExpr())
27-
) else (
28-
result = expr
29-
)
30-
}
31-
3220
/**
3321
* Gets the "real" parent of `expr`. This predicate treats conversions as if
3422
* they were explicit nodes in the expression tree, rather than as implicit
3523
* nodes as in the regular AST representation.
3624
*/
3725
private Element getRealParent(Expr expr) {
38-
if expr.hasConversion() then (
39-
// The expression has a conversion, so treat that as its parent
40-
result = expr.getConversion()
41-
)
42-
else (
43-
// Either the expression is a top-level conversion, or it's not a
44-
// conversion. The real parent is the parent of the original unconverted
45-
// expression.
46-
result = getUnconvertedExpr(expr).getParent() or
47-
// The parent of a DestructorDestruction is the destructor itself.
48-
result.(Destructor).getADestruction() = expr
49-
)
26+
result = expr.getParentWithConversions()
27+
or
28+
result.(Destructor).getADestruction() = expr
5029
}
5130

5231
/**

0 commit comments

Comments
 (0)