1+ /** Provides a set of checks that the AST is actually a tree. */
2+
13private 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. */
315query 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. */
1225query 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-
2833private predicate isChildOf ( PrintAstNode parent , PrintAstNode child ) {
2934 parent .hasChild ( child , _, _)
3035}
3136
37+ /** Checks that there is no back edge. */
3238query predicate parentChildLoops ( PrintAstNode parent , PrintAstNode child ) {
3339 isChildOf ( parent , child ) and isChildOf * ( child , parent )
3440}
0 commit comments