Skip to content

Commit 8d656a9

Browse files
committed
Swift: add QLdoc to AST consistency checks
1 parent 63fb058 commit 8d656a9

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed
Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
1+
/** Provides a set of checks that the AST is actually a tree. */
2+
13
private import codeql.swift.printast.PrintAstNode
24

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. */
315
query predicate doubleChildren(
416
PrintAstNode parent, int index, string label1, PrintAstNode child1, string label2,
517
PrintAstNode child2
@@ -9,6 +21,7 @@ query predicate doubleChildren(
921
parent.hasChild(child2, index, label2)
1022
}
1123

24+
/** Checks that no child is under different indexes. */
1225
query predicate doubleIndexes(
1326
PrintAstNode parent, int index1, string label1, int index2, string label2, PrintAstNode child
1427
) {
@@ -17,18 +30,11 @@ query predicate doubleIndexes(
1730
parent.hasChild(child, index2, label2)
1831
}
1932

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-
2833
private predicate isChildOf(PrintAstNode parent, PrintAstNode child) {
2934
parent.hasChild(child, _, _)
3035
}
3136

37+
/** Checks that there is no back edge. */
3238
query predicate parentChildLoops(PrintAstNode parent, PrintAstNode child) {
3339
isChildOf(parent, child) and isChildOf*(child, parent)
3440
}

0 commit comments

Comments
 (0)