C++: Add expressions with type data to cpp/extraction-information

This commit is contained in:
Simon Friis Vindum
2026-03-23 12:14:11 +01:00
parent 9a4bc69843
commit c67122b3f1
2 changed files with 30 additions and 2 deletions

View File

@@ -1,9 +1,14 @@
import cpp
import codeql.util.ReportStats
/** A file that is included in the quality statistics. */
private class RelevantFile extends File {
RelevantFile() { this.fromSource() and exists(this.getRelativePath()) }
}
module CallTargetStats implements StatsSig {
private class RelevantCall extends Call {
RelevantCall() { this.getFile() = any(File f | f.fromSource() and exists(f.getRelativePath())) }
RelevantCall() { this.getFile() instanceof RelevantFile }
}
// We assume that calls with an implicit target are calls that could not be
@@ -22,4 +27,24 @@ module CallTargetStats implements StatsSig {
string getNotOkText() { result = "calls with missing call target" }
}
private class SourceExpr extends Expr {
SourceExpr() { this.getFile() instanceof RelevantFile }
}
predicate find(SourceExpr e) { not hasGoodType(e) }
private predicate hasGoodType(Expr e) { not e.getType() instanceof ErroneousType }
module ExprTypeStats implements StatsSig {
int getNumberOfOk() { result = count(SourceExpr e | hasGoodType(e)) }
int getNumberOfNotOk() { result = count(SourceExpr e | not hasGoodType(e)) }
string getOkText() { result = "expressions with known type" }
string getNotOkText() { result = "expressions with unknown type" }
}
module CallTargetStatsReport = ReportStats<CallTargetStats>;
module ExprTypeStatsReport = ReportStats<ExprTypeStats>;

View File

@@ -14,7 +14,10 @@ where
(
CallTargetStatsReport::numberOfOk(key, value) or
CallTargetStatsReport::numberOfNotOk(key, value) or
CallTargetStatsReport::percentageOfOk(key, value)
CallTargetStatsReport::percentageOfOk(key, value) or
ExprTypeStatsReport::numberOfOk(key, value) or
ExprTypeStatsReport::numberOfNotOk(key, value) or
ExprTypeStatsReport::percentageOfOk(key, value)
) and
/* Infinity */
value != 1.0 / 0.0 and