C++: Simplify TranslatedElement.getRealParent

Now that we have `Expr.getParentWithConversions`, we can implement
`TranslatedElement.getRealParent` simpler. This implementation also
avoids recursion.
This commit is contained in:
Jonas Jensen
2019-01-18 11:46:47 +01:00
parent fc5b9dd55e
commit 5b685383c8

View File

@@ -17,36 +17,15 @@ Type getIntType() {
result.(IntType).isImplicitlySigned()
}
/**
* If `expr` is a conversion, gets the expression being converted. Otherwise,
* returns `expr`.
*/
private Expr getUnconvertedExpr(Expr expr) {
if expr instanceof Conversion then (
result = getUnconvertedExpr(expr.(Conversion).getExpr())
) else (
result = expr
)
}
/**
* Gets the "real" parent of `expr`. This predicate treats conversions as if
* they were explicit nodes in the expression tree, rather than as implicit
* nodes as in the regular AST representation.
*/
private Element getRealParent(Expr expr) {
if expr.hasConversion() then (
// The expression has a conversion, so treat that as its parent
result = expr.getConversion()
)
else (
// Either the expression is a top-level conversion, or it's not a
// conversion. The real parent is the parent of the original unconverted
// expression.
result = getUnconvertedExpr(expr).getParent() or
// The parent of a DestructorDestruction is the destructor itself.
result.(Destructor).getADestruction() = expr
)
result = expr.getParentWithConversions()
or
result.(Destructor).getADestruction() = expr
}
/**