C++: Implement Function::hasErrors()

This commit is contained in:
Calum Grant
2024-10-01 11:00:44 +01:00
parent 60abea17e6
commit 4b5aa1497b
4 changed files with 17 additions and 2 deletions

View File

@@ -500,6 +500,14 @@ class Function extends Declaration, ControlFlowNode, AccessHolder, @function {
* Gets the nearest enclosing AccessHolder.
*/
override AccessHolder getEnclosingAccessHolder() { result = this.getDeclaringType() }
/**
* Holds if this function has extraction errors that create an `ErrorExpr`.
*/
predicate hasErrors() {
// Exclude allocator call arguments because they are are always extracted as `ErrorExpr`.
exists(ErrorExpr e | e.getEnclosingFunction() = this and not e.isFirstAllocatorCallArgument())
}
}
pragma[noinline]

View File

@@ -744,6 +744,13 @@ class ErrorExpr extends Expr, @errorexpr {
override string toString() { result = "<error expr>" }
override string getAPrimaryQlClass() { result = "ErrorExpr" }
/**
* Holds if this error expression is the first argument to a `new` allocation call.
*/
predicate isFirstAllocatorCallArgument() {
this = any(NewOrNewArrayExpr new).getAllocatorCall().getArgument(0)
}
}
/**