Skip to content

Commit d5e8a24

Browse files
committed
Add C++ query to extract the number of errors due to include file resolution failure
1 parent 975881c commit d5e8a24

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/**
2+
* @name Count of includes that failed to be resolved as well as compilation error due to undefined token
3+
* @description A count of all failed includes and compilation errors due to undefined tokens.
4+
* @kind table
5+
* @tags summary telemetry include resolution
6+
* @id cpp/telemetry/incliude-resolution-status
7+
*/
8+
9+
import cpp
10+
11+
/**
12+
* A cannot open file error.
13+
* Typically this is due to a missing include.
14+
*/
15+
class CannotOpenFileError extends CompilerError {
16+
CannotOpenFileError() { this.hasTag(["cannot_open_file", "cannot_open_file_reason"]) }
17+
}
18+
19+
/**
20+
* A compiler error happening in a project file.
21+
*/
22+
predicate local_compiler_error(CompilerError e) { exists(e.getFile().getRelativePath()) }
23+
24+
/**
25+
* A compiler error happening in a project file, where the error is due to a token being undefined.
26+
*/
27+
predicate undefined_token_error(CompilerError e) {
28+
// The following is a non-exaustive list of tags that indicate that a token
29+
// is undefined.
30+
e.hasTag("not_a_member") or
31+
e.hasTag("undefined_identifier") or
32+
e.hasTag("no_matching_function") or
33+
e.hasTag("too_many_arguments") or
34+
e.hasTag("not_a_class_or_struct_name") or
35+
e.hasTag("not_a_class_template")
36+
}
37+
38+
select count(CannotOpenFileError e) as failed_includes, count( | | 1) as total_files,
39+
count(Include i) as successful_includes,
40+
count(Include i) + count(CannotOpenFileError e) as total_includes,
41+
count(CompilerError e | local_compiler_error(e) and undefined_token_error(e)) as local_undefined_token_errors,
42+
count(CompilerError e | local_compiler_error(e)) as local_errors

0 commit comments

Comments
 (0)