1
+ /** Provides a set of checks that the AST is actually a tree. */
2
+
1
3
private import codeql.swift.printast.PrintAstNode
2
4
5
+ /** Checks that no child has more than one parent. */
6
+ query predicate doubleParents (
7
+ PrintAstNode parent1 , string label1 , PrintAstNode parent2 , string label2 , PrintAstNode child
8
+ ) {
9
+ parent1 != parent2 and
10
+ parent1 .hasChild ( child , _, label1 ) and
11
+ parent2 .hasChild ( child , _, label2 )
12
+ }
13
+
14
+ /** Checks that no two children share the same index. */
3
15
query predicate doubleChildren (
4
16
PrintAstNode parent , int index , string label1 , PrintAstNode child1 , string label2 ,
5
17
PrintAstNode child2
@@ -9,6 +21,7 @@ query predicate doubleChildren(
9
21
parent .hasChild ( child2 , index , label2 )
10
22
}
11
23
24
+ /** Checks that no child is under different indexes. */
12
25
query predicate doubleIndexes (
13
26
PrintAstNode parent , int index1 , string label1 , int index2 , string label2 , PrintAstNode child
14
27
) {
@@ -17,18 +30,11 @@ query predicate doubleIndexes(
17
30
parent .hasChild ( child , index2 , label2 )
18
31
}
19
32
20
- query predicate doubleParents (
21
- PrintAstNode parent1 , string label1 , PrintAstNode parent2 , string label2 , PrintAstNode child
22
- ) {
23
- parent1 != parent2 and
24
- parent1 .hasChild ( child , _, label1 ) and
25
- parent2 .hasChild ( child , _, label2 )
26
- }
27
-
28
33
private predicate isChildOf ( PrintAstNode parent , PrintAstNode child ) {
29
34
parent .hasChild ( child , _, _)
30
35
}
31
36
37
+ /** Checks that there is no back edge. */
32
38
query predicate parentChildLoops ( PrintAstNode parent , PrintAstNode child ) {
33
39
isChildOf ( parent , child ) and isChildOf * ( child , parent )
34
40
}
0 commit comments