Skip to content

Commit c67122b

Browse files
committed
C++: Add expressions with type data to cpp/extraction-information
1 parent 9a4bc69 commit c67122b

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

cpp/ql/src/Telemetry/DatabaseQuality.qll

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
import cpp
22
import codeql.util.ReportStats
33

4+
/** A file that is included in the quality statistics. */
5+
private class RelevantFile extends File {
6+
RelevantFile() { this.fromSource() and exists(this.getRelativePath()) }
7+
}
8+
49
module CallTargetStats implements StatsSig {
510
private class RelevantCall extends Call {
6-
RelevantCall() { this.getFile() = any(File f | f.fromSource() and exists(f.getRelativePath())) }
11+
RelevantCall() { this.getFile() instanceof RelevantFile }
712
}
813

914
// We assume that calls with an implicit target are calls that could not be
@@ -22,4 +27,24 @@ module CallTargetStats implements StatsSig {
2227
string getNotOkText() { result = "calls with missing call target" }
2328
}
2429

30+
private class SourceExpr extends Expr {
31+
SourceExpr() { this.getFile() instanceof RelevantFile }
32+
}
33+
34+
predicate find(SourceExpr e) { not hasGoodType(e) }
35+
36+
private predicate hasGoodType(Expr e) { not e.getType() instanceof ErroneousType }
37+
38+
module ExprTypeStats implements StatsSig {
39+
int getNumberOfOk() { result = count(SourceExpr e | hasGoodType(e)) }
40+
41+
int getNumberOfNotOk() { result = count(SourceExpr e | not hasGoodType(e)) }
42+
43+
string getOkText() { result = "expressions with known type" }
44+
45+
string getNotOkText() { result = "expressions with unknown type" }
46+
}
47+
2548
module CallTargetStatsReport = ReportStats<CallTargetStats>;
49+
50+
module ExprTypeStatsReport = ReportStats<ExprTypeStats>;

cpp/ql/src/Telemetry/ExtractorInformation.ql

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ where
1414
(
1515
CallTargetStatsReport::numberOfOk(key, value) or
1616
CallTargetStatsReport::numberOfNotOk(key, value) or
17-
CallTargetStatsReport::percentageOfOk(key, value)
17+
CallTargetStatsReport::percentageOfOk(key, value) or
18+
ExprTypeStatsReport::numberOfOk(key, value) or
19+
ExprTypeStatsReport::numberOfNotOk(key, value) or
20+
ExprTypeStatsReport::percentageOfOk(key, value)
1821
) and
1922
/* Infinity */
2023
value != 1.0 / 0.0 and

0 commit comments

Comments
 (0)