Skip to content

Commit 3de650e

Browse files
committed
Swift: make toBeTested and shouldPrint propagate to children
1 parent fc98fd3 commit 3de650e

File tree

3 files changed

+795
-27
lines changed

3 files changed

+795
-27
lines changed

swift/ql/src/queries/ide-contextual-queries/printAst.ql

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import swift
1111
import codeql.swift.printast.PrintAst
1212
import IDEContextual
13+
import codeql.swift.generated.ParentChild
1314

1415
/**
1516
* Gets the source file to generate an AST from.
@@ -23,6 +24,10 @@ class PrintAstConfigurationOverride extends PrintAstConfiguration {
2324
*/
2425
override predicate shouldPrint(Locatable e) {
2526
super.shouldPrint(e) and
26-
e.getFile() = getFileBySourceArchiveName(selectedSourceFile())
27+
(
28+
e.getFile() = getFileBySourceArchiveName(selectedSourceFile())
29+
or
30+
exists(Locatable parent | this.shouldPrint(parent) and parent = getImmediateParent(e))
31+
)
2732
}
2833
}

swift/ql/test/TestUtils.qll

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
private import codeql.swift.elements
2+
private import codeql.swift.generated.ParentChild
23

34
cached
45
predicate toBeTested(Element e) {
56
e instanceof File
67
or
7-
e instanceof AppliedPropertyWrapperExpr
8-
or
98
exists(ModuleDecl m |
109
m = e and
1110
not m.isBuiltinModule() and
@@ -32,6 +31,8 @@ predicate toBeTested(Element e) {
3231
e.(UnspecifiedElement).getParent() = tested
3332
or
3433
e.(OpaqueTypeDecl).getNamingDeclaration() = tested
34+
or
35+
tested = getImmediateParent(e)
3536
)
3637
)
3738
}

0 commit comments

Comments
 (0)