Skip to content

Commit 08bf464

Browse files
authored
Merge pull request #4540 from criemen/printast-performance
C++: Improve PrintAST performance if only individual files are printed
2 parents a1b59e2 + 6b07268 commit 08bf464

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)