Rust: Move the AST consistency logic to a .qll.

This commit is contained in:
Geoffrey White
2024-10-11 16:02:39 +01:00
parent 79c5adfc9a
commit 414fcf836e
2 changed files with 32 additions and 20 deletions

View File

@@ -1,21 +1,8 @@
import rust
import codeql.rust.elements.internal.generated.ParentChild
/**
* @name Abstract syntax tree inconsistencies
* @description Lists the abstract syntax tree inconsistencies in the database. This query is intended for internal use.
* @kind table
* @id rust/diagnostics/ast-consistency
*/
query predicate multipleToString(Element e, string s) {
s = strictconcat(e.toString(), ",") and
strictcount(e.toString()) > 1
}
query predicate multipleLocations(Locatable e) { strictcount(e.getLocation()) > 1 }
query predicate multiplePrimaryQlClasses(Element e, string s) {
s = e.getPrimaryQlClasses() and
strictcount(e.getAPrimaryQlClass()) > 1
}
private Element getParent(Element child) { child = getChildAndAccessor(result, _, _) }
query predicate multipleParents(Element child, Element parent) {
parent = getParent(child) and
strictcount(getParent(child)) > 1
}
import codeql.rust.AstConsistency

View File

@@ -0,0 +1,25 @@
/**
* Provides classes for recognizing control flow graph inconsistencies.
*/
private import rust
private import codeql.rust.elements.internal.generated.ParentChild
query predicate multipleToString(Element e, string s) {
s = strictconcat(e.toString(), ",") and
strictcount(e.toString()) > 1
}
query predicate multipleLocations(Locatable e) { strictcount(e.getLocation()) > 1 }
query predicate multiplePrimaryQlClasses(Element e, string s) {
s = e.getPrimaryQlClasses() and
strictcount(e.getAPrimaryQlClass()) > 1
}
private Element getParent(Element child) { child = getChildAndAccessor(result, _, _) }
query predicate multipleParents(Element child, Element parent) {
parent = getParent(child) and
strictcount(getParent(child)) > 1
}