Dataflow/Go: Add getLocation to calls and callables for easier debugging.

This commit is contained in:
Anders Schack-Mulligen
2024-05-28 13:33:41 +02:00
parent 69fb2bb97c
commit 3b12f69dd9
2 changed files with 23 additions and 0 deletions

View File

@@ -311,6 +311,13 @@ class DataFlowCallable extends TDataFlowCallable {
.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
}
/** Gets the location of this callable. */
Location getLocation() {
result = getCallableLocation(this.asCallable()) or
result = this.asFileScope().getLocation() or
result = getCallableLocation(this.asSummarizedCallable())
}
/** Gets a best-effort total ordering. */
int totalorder() {
this =
@@ -322,6 +329,13 @@ class DataFlowCallable extends TDataFlowCallable {
}
}
private Location getCallableLocation(Callable c) {
exists(string filepath, int startline, int startcolumn, int endline, int endcolumn |
c.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) and
result.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
)
}
/** A function call relevant for data flow. */
class DataFlowCall extends Expr {
DataFlow::CallNode call;
@@ -344,6 +358,9 @@ class DataFlowCall extends Expr {
not exists(this.getEnclosingFunction()) and result.asFileScope() = this.getFile()
}
/** Gets the location of this call. */
Location getLocation() { result = super.getLocation() }
/** Gets a best-effort total ordering. */
int totalorder() {
this =