Skip to content

Commit 6b07268

Browse files
committed
C++: Improve PrintAST performance.
This improves the performance of the printAst.ql query by excluding a lot of string concatenations that happen in files unrelated to the one the user is interested in printing. This is supposed to help the performance of the AST Viewer on bigger databases.
1 parent e89e99d commit 6b07268

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

cpp/ql/src/semmle/code/cpp/Print.qll

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,17 @@
11
import cpp
2+
private import PrintAST
3+
4+
/**
5+
* Print function declarations only if there is a `PrintASTConfiguration`
6+
* that requests that function, or no `PrintASTConfiguration` exists.
7+
*/
8+
private predicate shouldPrintDeclaration(Declaration decl) {
9+
not decl instanceof Function
10+
or
11+
not exists(PrintASTConfiguration c)
12+
or
13+
exists(PrintASTConfiguration config | config.shouldPrintFunction(decl))
14+
}
215

316
/**
417
* Gets a string containing the scope in which this declaration is declared.
@@ -48,6 +61,8 @@ private string getTemplateArgumentString(Declaration d, int i) {
4861
* A `Declaration` extended to add methods for generating strings useful only for dumps and debugging.
4962
*/
5063
abstract private class DumpDeclaration extends Declaration {
64+
DumpDeclaration() { shouldPrintDeclaration(this) }
65+
5166
/**
5267
* Gets a string that uniquely identifies this declaration, suitable for use when debugging queries. Only holds for
5368
* functions, user-defined types, global and namespace-scope variables, and member variables.

0 commit comments

Comments
 (0)