Skip to content

Commit 782759d

Browse files
committed
Add the printAst.ql contextual query for C++
This query will be used by the VS Code extension for viewing ASTs of C/C++ files.
1 parent 0bbbfe5 commit 782759d

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

cpp/ql/src/printAst.ql

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* @name Print AST
3+
* @description Outputs a representation of a file's Abstract Syntax Tree. This
4+
* query is used by the VS Code extension.
5+
* @id cpp/print-ast
6+
* @kind graph
7+
* @tags ide-contextual-queries/print-ast
8+
*/
9+
10+
import cpp
11+
import semmle.code.cpp.PrintAST
12+
import definitions
13+
14+
/**
15+
* The source file to generate an AST from.
16+
*/
17+
external string selectedSourceFile();
18+
19+
class Cfg extends PrintASTConfiguration {
20+
/**
21+
* Holds if the AST for `func` should be printed.
22+
* Print All functions from the selected file.
23+
*/
24+
override predicate shouldPrintFunction(Function func) {
25+
func.getFile() = getEncodedFile(selectedSourceFile())
26+
}
27+
}

0 commit comments

Comments
 (0)