Skip to content

Commit e212be4

Browse files
committed
C++: Add cpp/extraction-information query
1 parent 3fad6bd commit e212be4

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import cpp
2+
import codeql.util.ReportStats
3+
4+
module CallTargetStats implements StatsSig {
5+
private class RelevantCall extends Call {
6+
RelevantCall() { this.getFile() = any(File f | f.fromSource() and exists(f.getRelativePath())) }
7+
}
8+
9+
// We assume that calls with an implicit target are calls that could not be
10+
// resolved. This is accurate in the vast amount of cases, but is inaccurate
11+
// for calls that deliberately rely on implicitly declared functions.
12+
private predicate hasImplicitTarget(RelevantCall call) {
13+
call.getTarget().getADeclarationEntry().isImplicit()
14+
}
15+
16+
int getNumberOfOk() { result = count(RelevantCall call | not hasImplicitTarget(call)) }
17+
18+
int getNumberOfNotOk() { result = count(RelevantCall call | hasImplicitTarget(call)) }
19+
20+
string getOkText() { result = "calls with call target" }
21+
22+
string getNotOkText() { result = "calls with missing call target" }
23+
}
24+
25+
module CallTargetStatsReport = ReportStats<CallTargetStats>;
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* @name C/C++ extraction information
3+
* @description Information about the extraction for a C/C++ database
4+
* @kind metric
5+
* @tags summary telemetry
6+
* @id cpp/telemetry/extraction-information
7+
*/
8+
9+
import cpp
10+
import DatabaseQuality
11+
12+
from string key, float value
13+
where
14+
(
15+
CallTargetStatsReport::numberOfOk(key, value) or
16+
CallTargetStatsReport::numberOfNotOk(key, value) or
17+
CallTargetStatsReport::percentageOfOk(key, value)
18+
) and
19+
/* Infinity */
20+
value != 1.0 / 0.0 and
21+
/* -Infinity */
22+
value != -1.0 / 0.0 and
23+
/* NaN */
24+
value != 0.0 / 0.0
25+
select key, value

0 commit comments

Comments
 (0)