mirror of
https://github.com/github/codeql.git
synced 2026-05-01 03:35:13 +02:00
C++: Summary metrics queries
This is a first attempt at implementing, for C++, the set of summary queries that we expect all languages to implement to help diagnose extraction failures and build configuration problems. See the spec in [this document](https://docs.google.com/document/d/1V3zpkj0OGh8GEUVwACRx7fiafE5zklujAftZaYUyf9s/edit?usp=sharing). The five queries are: - Total number of source files (including .c/.cpp and header files) - Total number of lines of text across all text files - Total number of lines of code across all text files - Number of lines of text in each source file - Number of lines of code in each source file I've added some simple unit tests that cover all five of these.
This commit is contained in:
10
cpp/ql/src/Diagnostics/Files.ql
Normal file
10
cpp/ql/src/Diagnostics/Files.ql
Normal file
@@ -0,0 +1,10 @@
|
||||
/**
|
||||
* @name Total source files
|
||||
* @description The total number of source files.
|
||||
* @kind metric
|
||||
* @id cpp/metrics/files
|
||||
*/
|
||||
|
||||
import cpp
|
||||
|
||||
select count(File f | f.fromSource())
|
||||
10
cpp/ql/src/Diagnostics/Lines.ql
Normal file
10
cpp/ql/src/Diagnostics/Lines.ql
Normal file
@@ -0,0 +1,10 @@
|
||||
/**
|
||||
* @name Total lines of text
|
||||
* @description The total number of lines of text across all source files.
|
||||
* @kind metric
|
||||
* @id cpp/metrics/lines
|
||||
*/
|
||||
|
||||
import cpp
|
||||
|
||||
select sum(File f | f.fromSource() | f.getMetrics().getNumberOfLines())
|
||||
10
cpp/ql/src/Diagnostics/LinesOfCode.ql
Normal file
10
cpp/ql/src/Diagnostics/LinesOfCode.ql
Normal file
@@ -0,0 +1,10 @@
|
||||
/**
|
||||
* @name Total lines of code
|
||||
* @description The total number of lines of code across all source files.
|
||||
* @kind metric
|
||||
* @id cpp/metrics/lines-of-code
|
||||
*/
|
||||
|
||||
import cpp
|
||||
|
||||
select sum(File f | f.fromSource() | f.getMetrics().getNumberOfLinesOfCode())
|
||||
12
cpp/ql/src/Diagnostics/LinesOfCodePerFile.ql
Normal file
12
cpp/ql/src/Diagnostics/LinesOfCodePerFile.ql
Normal file
@@ -0,0 +1,12 @@
|
||||
/**
|
||||
* @name Lines of code per source file
|
||||
* @description The number of lines of code for each source file.
|
||||
* @kind metric
|
||||
* @id cpp/metrics/lines-of-code-per-file
|
||||
*/
|
||||
|
||||
import cpp
|
||||
|
||||
from File f
|
||||
where f.fromSource()
|
||||
select f, f.getMetrics().getNumberOfLinesOfCode()
|
||||
12
cpp/ql/src/Diagnostics/LinesPerFile.ql
Normal file
12
cpp/ql/src/Diagnostics/LinesPerFile.ql
Normal file
@@ -0,0 +1,12 @@
|
||||
/**
|
||||
* @name Lines of text per source file
|
||||
* @description The number of lines of text for each source file.
|
||||
* @kind metric
|
||||
* @id cpp/metrics/lines-per-file
|
||||
*/
|
||||
|
||||
import cpp
|
||||
|
||||
from File f
|
||||
where f.fromSource()
|
||||
select f, f.getMetrics().getNumberOfLines()
|
||||
1
cpp/ql/test/query-tests/Diagnostics/Files.expected
Normal file
1
cpp/ql/test/query-tests/Diagnostics/Files.expected
Normal file
@@ -0,0 +1 @@
|
||||
| 3 |
|
||||
1
cpp/ql/test/query-tests/Diagnostics/Files.qlref
Normal file
1
cpp/ql/test/query-tests/Diagnostics/Files.qlref
Normal file
@@ -0,0 +1 @@
|
||||
Diagnostics/Files.ql
|
||||
1
cpp/ql/test/query-tests/Diagnostics/Lines.expected
Normal file
1
cpp/ql/test/query-tests/Diagnostics/Lines.expected
Normal file
@@ -0,0 +1 @@
|
||||
| 122 |
|
||||
1
cpp/ql/test/query-tests/Diagnostics/Lines.qlref
Normal file
1
cpp/ql/test/query-tests/Diagnostics/Lines.qlref
Normal file
@@ -0,0 +1 @@
|
||||
Diagnostics/Lines.ql
|
||||
1
cpp/ql/test/query-tests/Diagnostics/LinesOfCode.expected
Normal file
1
cpp/ql/test/query-tests/Diagnostics/LinesOfCode.expected
Normal file
@@ -0,0 +1 @@
|
||||
| 93 |
|
||||
1
cpp/ql/test/query-tests/Diagnostics/LinesOfCode.qlref
Normal file
1
cpp/ql/test/query-tests/Diagnostics/LinesOfCode.qlref
Normal file
@@ -0,0 +1 @@
|
||||
Diagnostics/LinesOfCode.ql
|
||||
@@ -0,0 +1,3 @@
|
||||
| empty-file.cpp:0:0:0:0 | empty-file.cpp | 0 |
|
||||
| large-file.cpp:0:0:0:0 | large-file.cpp | 90 |
|
||||
| short-file.cpp:0:0:0:0 | short-file.cpp | 3 |
|
||||
@@ -0,0 +1 @@
|
||||
Diagnostics/LinesOfCodePerFile.ql
|
||||
@@ -0,0 +1,3 @@
|
||||
| empty-file.cpp:0:0:0:0 | empty-file.cpp | 0 |
|
||||
| large-file.cpp:0:0:0:0 | large-file.cpp | 119 |
|
||||
| short-file.cpp:0:0:0:0 | short-file.cpp | 3 |
|
||||
1
cpp/ql/test/query-tests/Diagnostics/LinesPerFile.qlref
Normal file
1
cpp/ql/test/query-tests/Diagnostics/LinesPerFile.qlref
Normal file
@@ -0,0 +1 @@
|
||||
Diagnostics/LinesPerFile.ql
|
||||
0
cpp/ql/test/query-tests/Diagnostics/empty-file.cpp
Normal file
0
cpp/ql/test/query-tests/Diagnostics/empty-file.cpp
Normal file
119
cpp/ql/test/query-tests/Diagnostics/large-file.cpp
Normal file
119
cpp/ql/test/query-tests/Diagnostics/large-file.cpp
Normal file
@@ -0,0 +1,119 @@
|
||||
int a00(float x) {
|
||||
return (int)x;
|
||||
}
|
||||
|
||||
int a01(float x) {
|
||||
return (int)x;
|
||||
}
|
||||
|
||||
int a02(float x) {
|
||||
return (int)x;
|
||||
}
|
||||
|
||||
int a03(float x) {
|
||||
return (int)x;
|
||||
}
|
||||
|
||||
int a04(float x) {
|
||||
return (int)x;
|
||||
}
|
||||
|
||||
int a05(float x) {
|
||||
return (int)x;
|
||||
}
|
||||
|
||||
int a06(float x) {
|
||||
return (int)x;
|
||||
}
|
||||
|
||||
int a07(float x) {
|
||||
return (int)x;
|
||||
}
|
||||
|
||||
int a08(float x) {
|
||||
return (int)x;
|
||||
}
|
||||
|
||||
int a09(float x) {
|
||||
return (int)x;
|
||||
}
|
||||
|
||||
int a10(float x) {
|
||||
return (int)x;
|
||||
}
|
||||
|
||||
int a11(float x) {
|
||||
return (int)x;
|
||||
}
|
||||
|
||||
int a12(float x) {
|
||||
return (int)x;
|
||||
}
|
||||
|
||||
int a13(float x) {
|
||||
return (int)x;
|
||||
}
|
||||
|
||||
int a14(float x) {
|
||||
return (int)x;
|
||||
}
|
||||
|
||||
int a15(float x) {
|
||||
return (int)x;
|
||||
}
|
||||
|
||||
int a16(float x) {
|
||||
return (int)x;
|
||||
}
|
||||
|
||||
int a17(float x) {
|
||||
return (int)x;
|
||||
}
|
||||
|
||||
int a18(float x) {
|
||||
return (int)x;
|
||||
}
|
||||
|
||||
int a19(float x) {
|
||||
return (int)x;
|
||||
}
|
||||
|
||||
int a20(float x) {
|
||||
return (int)x;
|
||||
}
|
||||
|
||||
int a21(float x) {
|
||||
return (int)x;
|
||||
}
|
||||
|
||||
int a22(float x) {
|
||||
return (int)x;
|
||||
}
|
||||
|
||||
int a23(float x) {
|
||||
return (int)x;
|
||||
}
|
||||
|
||||
int a24(float x) {
|
||||
return (int)x;
|
||||
}
|
||||
|
||||
int a25(float x) {
|
||||
return (int)x;
|
||||
}
|
||||
|
||||
int a26(float x) {
|
||||
return (int)x;
|
||||
}
|
||||
|
||||
int a27(float x) {
|
||||
return (int)x;
|
||||
}
|
||||
|
||||
int a28(float x) {
|
||||
return (int)x;
|
||||
}
|
||||
|
||||
int a29(float x) {
|
||||
return (int)x;
|
||||
}
|
||||
3
cpp/ql/test/query-tests/Diagnostics/short-file.cpp
Normal file
3
cpp/ql/test/query-tests/Diagnostics/short-file.cpp
Normal file
@@ -0,0 +1,3 @@
|
||||
int g(float x) {
|
||||
return (int)x;
|
||||
}
|
||||
Reference in New Issue
Block a user