Skip to content

Commit e01ecd1

Browse files
committed
Rust: Calculate a total of AST inconsistencies.
1 parent 2d019eb commit e01ecd1

File tree

4 files changed

+27
-0
lines changed

4 files changed

+27
-0
lines changed

rust/ql/lib/codeql/rust/AstConsistency.qll

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,21 @@ query predicate multipleParents(Element child, Element parent) {
3535
parent = getParent(child) and
3636
strictcount(getParent(child)) > 1
3737
}
38+
39+
/**
40+
* Gets counts of abstract syntax tree inconsistencies of each type.
41+
*/
42+
int getAstInconsistencyCounts(string type) {
43+
// total results from all the AST consistency query predicates.
44+
type = "Multiple toStrings" and
45+
result = count(Element e | multipleToStrings(e, _) | e)
46+
or
47+
type = "Multiple locations" and
48+
result = count(Element e | multipleLocations(e) | e)
49+
or
50+
type = "Multiple primary QL classes" and
51+
result = count(Element e | multiplePrimaryQlClasses(e, _) | e)
52+
or
53+
type = "Multiple parents" and
54+
result = count(Element e | multipleParents(e, _) | e)
55+
}

rust/ql/src/queries/summary/Stats.qll

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
*/
44

55
import rust
6+
import codeql.rust.AstConsistency as AstConsistency
67
private import codeql.rust.controlflow.internal.CfgConsistency as CfgConsistency
78

89
/**
@@ -17,6 +18,11 @@ int getLinesOfUserCode() {
1718
result = sum(File f | exists(f.getRelativePath()) | f.getNumberOfLinesOfCode())
1819
}
1920

21+
/**
22+
* Gets a count of the total number of abstract syntax tree inconsistencies in the database.
23+
*/
24+
int getTotalAstInconsistencies() { result = sum(AstConsistency::getAstInconsistencyCounts(_)) }
25+
2026
/**
2127
* Gets a count of the total number of control flow graph inconsistencies in the database.
2228
*/

rust/ql/src/queries/summary/SummaryStats.ql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,7 @@ where
3434
or
3535
key = "Lines of user code extracted" and value = getLinesOfUserCode().toString()
3636
or
37+
key = "Inconsistencies - AST" and value = getTotalAstInconsistencies().toString()
38+
or
3739
key = "Inconsistencies - CFG" and value = getTotalCfgInconsistencies().toString()
3840
select key, value

rust/ql/test/query-tests/diagnostics/SummaryStats.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
| Files extracted - total | 7 |
66
| Files extracted - with errors | 2 |
77
| Files extracted - without errors | 5 |
8+
| Inconsistencies - AST | 0 |
89
| Inconsistencies - CFG | 0 |
910
| Lines of code extracted | 59 |
1011
| Lines of user code extracted | 59 |

0 commit comments

Comments
 (0)