Skip to content

Commit f25c4c5

Browse files
committed
add consistency test that parents are unique (and fix non-unique parents)
1 parent 14b5f84 commit f25c4c5

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

ql/ql/src/codeql_ql/ast/Ast.qll

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,8 @@ class QLDoc extends TQLDoc, AstNode {
162162
string getContents() { result = qldoc.getValue() }
163163

164164
override string getAPrimaryQlClass() { result = "QLDoc" }
165+
166+
override AstNode getParent() { result.getQLDoc() = this }
165167
}
166168

167169
class BlockComment extends TBlockComment, AstNode {
@@ -2313,7 +2315,7 @@ class Annotation extends TAnnotation, AstNode {
23132315
/** Gets the node corresponding to the field `name`. */
23142316
string getName() { result = annot.getName().getValue() }
23152317

2316-
override AstNode getParent() { result = AstNode.super.getParent() }
2318+
override AstNode getParent() { result.getAnAnnotation() = this }
23172319

23182320
override AstNode getAChild(string pred) {
23192321
result = super.getAChild(pred)

ql/ql/src/codeql_ql/ast/internal/AstNodes.qll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,4 +231,6 @@ module AstConsistency {
231231
not node instanceof YAML::YAMLNode and // parents for YAML doens't work
232232
not (node instanceof QLDoc and node.getLocation().getFile().getExtension() = "dbscheme") // qldoc in dbschemes are not hooked up
233233
}
234+
235+
query predicate nonUniqueParent(AstNode node) { count(node.getParent()) >= 2 }
234236
}

ql/ql/src/queries/diagnostics/EmptyConsistencies.ql

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ where
3131
TypeConsistency::multiplePrimitivesExpr(node, _, _) and
3232
msg = "TypeConsistency::multiplePrimitivesExpr"
3333
or
34-
AstConsistency::nonTotalGetParent(node) and msg = "AstConsistency::nonTotalGetParent" // TODO: unique parent
34+
AstConsistency::nonTotalGetParent(node) and msg = "AstConsistency::nonTotalGetParent"
35+
or
36+
AstConsistency::nonUniqueParent(node) and msg = "AstConsistency::nonUniqueParent"
3537
or
3638
TypeConsistency::noResolve(node) and msg = "TypeConsistency::noResolve"
3739
or
@@ -47,4 +49,3 @@ where
4749
or
4850
VarConsistency::noVarDef(node) and msg = "VarConsistency::noVarDef"
4951
select node, msg
50-
// TODO: vardef consistency.

0 commit comments

Comments
 (0)