-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathprintAst.ql
33 lines (30 loc) · 915 Bytes
/
printAst.ql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/**
* @name Print AST
* @description Outputs a representation of a file's Abstract Syntax Tree. This
* query is used by the VS Code extension.
* @id swift/print-ast
* @kind graph
* @tags ide-contextual-queries/print-ast
*/
import swift
import codeql.swift.printast.PrintAst
import codeql.IDEContextual
import codeql.swift.generated.ParentChild
/**
* Gets the source file to generate an AST from.
*/
external string selectedSourceFile();
class PrintAstConfigurationOverride extends PrintAstConfiguration {
/**
* Holds if the location matches the selected file in the VS Code extension and
* the element is `e`.
*/
override predicate shouldPrint(Locatable e) {
super.shouldPrint(e) and
(
e.getFile() = getFileBySourceArchiveName(selectedSourceFile())
or
exists(Locatable parent | this.shouldPrint(parent) and parent = getImmediateParent(e))
)
}
}