Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 278ab4b

Browse files
committed
Python: CG trace: Much improved toString for QL
1 parent a5838b6 commit 278ab4b

1 file changed

Lines changed: 21 additions & 7 deletions

File tree

python/tools/recorded-call-graph-metrics/ql/RecordedCalls.qll

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,19 @@ class XMLRecordedCall extends XMLElement {
3030
}
3131

3232
override string toString() {
33-
result =
34-
this.getName() + ": <..>/" +
35-
this.getXMLCall().get_filename_data().regexpCapture(".*/([^/]+)$", 1) + ":" +
36-
this.getXMLCall().get_linenum_data()
33+
exists(string path |
34+
path =
35+
any(File file | file.getAbsolutePath() = this.getXMLCall().get_filename_data())
36+
.getRelativePath()
37+
or
38+
not exists(File file |
39+
file.getAbsolutePath() = this.getXMLCall().get_filename_data() and
40+
exists(file.getRelativePath())
41+
) and
42+
path = this.getXMLCall().get_filename_data()
43+
|
44+
result = this.getName() + ": " + path + ":" + this.getXMLCall().get_linenum_data()
45+
)
3746
}
3847
}
3948

@@ -161,10 +170,15 @@ class IdentifiedRecordedCall extends XMLRecordedCall {
161170

162171
override string toString() {
163172
exists(string callee_str |
164-
exists(Function callee | callee = this.getPythonCallee() |
173+
exists(Function callee, string path | callee = this.getPythonCallee() |
174+
(
175+
path = callee.getLocation().getFile().getRelativePath()
176+
or
177+
not exists(callee.getLocation().getFile().getRelativePath()) and
178+
path = callee.getLocation().getFile().getAbsolutePath()
179+
) and
165180
callee_str =
166-
callee.toString() + " (<..>/" + callee.getLocation().getFile().getRelativePath() + ":" +
167-
callee.getLocation().getStartLine() + ")"
181+
callee.toString() + " (" + path + ":" + callee.getLocation().getStartLine() + ")"
168182
)
169183
or
170184
callee_str = this.getBuiltinCallee().toString()

0 commit comments

Comments
 (0)