add consistency test that parents are unique (and fix non-unique parents)

This commit is contained in:
Erik Krogh Kristensen
2022-06-16 09:16:29 +02:00
parent 14b5f8410f
commit f25c4c5fdf
3 changed files with 8 additions and 3 deletions

View File

@@ -162,6 +162,8 @@ class QLDoc extends TQLDoc, AstNode {
string getContents() { result = qldoc.getValue() }
override string getAPrimaryQlClass() { result = "QLDoc" }
override AstNode getParent() { result.getQLDoc() = this }
}
class BlockComment extends TBlockComment, AstNode {
@@ -2313,7 +2315,7 @@ class Annotation extends TAnnotation, AstNode {
/** Gets the node corresponding to the field `name`. */
string getName() { result = annot.getName().getValue() }
override AstNode getParent() { result = AstNode.super.getParent() }
override AstNode getParent() { result.getAnAnnotation() = this }
override AstNode getAChild(string pred) {
result = super.getAChild(pred)

View File

@@ -231,4 +231,6 @@ module AstConsistency {
not node instanceof YAML::YAMLNode and // parents for YAML doens't work
not (node instanceof QLDoc and node.getLocation().getFile().getExtension() = "dbscheme") // qldoc in dbschemes are not hooked up
}
query predicate nonUniqueParent(AstNode node) { count(node.getParent()) >= 2 }
}

View File

@@ -31,7 +31,9 @@ where
TypeConsistency::multiplePrimitivesExpr(node, _, _) and
msg = "TypeConsistency::multiplePrimitivesExpr"
or
AstConsistency::nonTotalGetParent(node) and msg = "AstConsistency::nonTotalGetParent" // TODO: unique parent
AstConsistency::nonTotalGetParent(node) and msg = "AstConsistency::nonTotalGetParent"
or
AstConsistency::nonUniqueParent(node) and msg = "AstConsistency::nonUniqueParent"
or
TypeConsistency::noResolve(node) and msg = "TypeConsistency::noResolve"
or
@@ -47,4 +49,3 @@ where
or
VarConsistency::noVarDef(node) and msg = "VarConsistency::noVarDef"
select node, msg
// TODO: vardef consistency.