-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathAstConsistency.qll
More file actions
63 lines (53 loc) · 1.84 KB
/
AstConsistency.qll
File metadata and controls
63 lines (53 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/**
* Provides classes for recognizing control flow graph inconsistencies.
*/
private import rust
private import codeql.rust.elements.internal.generated.ParentChild
private predicate multipleToStrings(Element e) { strictcount(e.toString()) > 1 }
/**
* Holds if `e` has more than one `toString()` result.
*/
query predicate multipleToStrings(Element e, string s) {
multipleToStrings(e) and
s = strictconcat(e.toString(), ", ")
}
/**
* Holds if `e` has more than one `Location`.
*/
query predicate multipleLocations(Locatable e) { strictcount(e.getLocation()) > 1 }
private predicate multiplePrimaryQlClasses(Element e) {
strictcount(string cls | cls = e.getAPrimaryQlClass() and cls != "VariableAccess") > 1
}
/**
* Holds if `e` has more than one `getPrimaryQlClasses()` result.
*/
query predicate multiplePrimaryQlClasses(Element e, string s) {
multiplePrimaryQlClasses(e) and
s = strictconcat(e.getPrimaryQlClasses(), ", ")
}
private Element getParent(Element child) { child = getChildAndAccessor(result, _, _) }
private predicate multipleParents(Element child) { strictcount(getParent(child)) > 1 }
/**
* Holds if `child` has more than one AST parent.
*/
query predicate multipleParents(Element child, Element parent) {
multipleParents(child) and
parent = getParent(child)
}
/**
* Gets counts of abstract syntax tree inconsistencies of each type.
*/
int getAstInconsistencyCounts(string type) {
// total results from all the AST consistency query predicates.
type = "Multiple toStrings" and
result = count(Element e | multipleToStrings(e) | e)
or
type = "Multiple locations" and
result = count(Element e | multipleLocations(e) | e)
or
type = "Multiple primary QL classes" and
result = count(Element e | multiplePrimaryQlClasses(e) | e)
or
type = "Multiple parents" and
result = count(Element e | multipleParents(e) | e)
}