forked from github/codeql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDatabaseQuality.qll
More file actions
96 lines (75 loc) · 2.94 KB
/
DatabaseQuality.qll
File metadata and controls
96 lines (75 loc) · 2.94 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/**
* Provides database quality statistics that are reported by
* `rust/telemetry/extractor-information`
* and perhaps warned about by `rust/diagnostic/database-quality`.
*/
import rust
import codeql.util.ReportStats
import codeql.rust.elements.internal.CallExprImpl::Impl as CallExprImpl
import codeql.rust.internal.typeinference.TypeInference as TypeInference
import codeql.rust.internal.typeinference.Type
/**
* A file that is included in the quality statistics.
*/
private class RelevantFile extends File {
RelevantFile() {
// files that are not skipped by the compilation
not this.(ExtractedFile).isSkippedByCompilation()
}
}
module CallTargetStats implements StatsSig {
/**
* A call-like expression that is relevant for call target statistics.
*
* Note that this also includes tuple struct instantiations and tuple
* variant instantiations.
*/
private class RelevantInvocationExpr extends InvocationExpr {
RelevantInvocationExpr() {
this.getFile() instanceof RelevantFile and
not this instanceof CallExprImpl::DynamicCallExpr and
not this = any(Operation o | not o.isOverloaded(_, _, _)) and
not this = any(DerefExpr de | TypeInference::inferType(de.getExpr()) instanceof PtrType)
}
}
int getNumberOfOk() { result = count(RelevantInvocationExpr e | exists(e.getResolvedTarget())) }
additional predicate isNotOkCall(RelevantInvocationExpr e) { not exists(e.getResolvedTarget()) }
int getNumberOfNotOk() { result = count(RelevantInvocationExpr e | isNotOkCall(e)) }
string getOkText() { result = "calls with call target" }
string getNotOkText() { result = "calls with missing call target" }
}
module MacroCallTargetStats implements StatsSig {
int getNumberOfOk() {
result = count(MacroCall c | c.getFile() instanceof RelevantFile and c.hasMacroCallExpansion())
}
additional predicate isNotOkCall(MacroCall c) {
c.getFile() instanceof RelevantFile and not c.hasMacroCallExpansion()
}
int getNumberOfNotOk() { result = count(MacroCall c | isNotOkCall(c)) }
string getOkText() { result = "macro calls with call target" }
string getNotOkText() { result = "macro calls with missing call target" }
}
private predicate hasGoodType(Expr e) { exists(TypeInference::inferType(e, _)) }
module ExprTypeStats implements StatsSig {
int getNumberOfOk() {
result =
count(Expr e |
e.getFile() instanceof RelevantFile and
e.fromSource() and
hasGoodType(e)
)
}
int getNumberOfNotOk() {
result =
count(Expr e |
e.getFile() instanceof RelevantFile and
e.fromSource() and
not hasGoodType(e)
)
}
string getOkText() { result = "expressions with known type" }
string getNotOkText() { result = "expressions with unknown type" }
}
module CallTargetStatsReport = ReportStats<CallTargetStats>;
module MacroCallTargetStatsReport = ReportStats<MacroCallTargetStats>;
module ExprTypeStatsReport = ReportStats<ExprTypeStats>;