Skip to content

Commit 2e02625

Browse files
author
Dave Bartolomeo
committed
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.
1 parent cea1049 commit 2e02625

18 files changed

+190
-0
lines changed

cpp/ql/src/Diagnostics/Files.ql

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/**
2+
* @name Total source files
3+
* @description The total number of source files.
4+
* @kind metric
5+
* @id cpp/metrics/files
6+
*/
7+
8+
import cpp
9+
10+
select count(File f | f.fromSource())

cpp/ql/src/Diagnostics/Lines.ql

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/**
2+
* @name Total lines of text
3+
* @description The total number of lines of text across all source files.
4+
* @kind metric
5+
* @id cpp/metrics/lines
6+
*/
7+
8+
import cpp
9+
10+
select sum(File f | f.fromSource() | f.getMetrics().getNumberOfLines())

cpp/ql/src/Diagnostics/LinesOfCode.ql

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/**
2+
* @name Total lines of code
3+
* @description The total number of lines of code across all source files.
4+
* @kind metric
5+
* @id cpp/metrics/lines-of-code
6+
*/
7+
8+
import cpp
9+
10+
select sum(File f | f.fromSource() | f.getMetrics().getNumberOfLinesOfCode())
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
* @name Lines of code per source file
3+
* @description The number of lines of code for each source file.
4+
* @kind metric
5+
* @id cpp/metrics/lines-of-code-per-file
6+
*/
7+
8+
import cpp
9+
10+
from File f
11+
where f.fromSource()
12+
select f, f.getMetrics().getNumberOfLinesOfCode()
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
* @name Lines of text per source file
3+
* @description The number of lines of text for each source file.
4+
* @kind metric
5+
* @id cpp/metrics/lines-per-file
6+
*/
7+
8+
import cpp
9+
10+
from File f
11+
where f.fromSource()
12+
select f, f.getMetrics().getNumberOfLines()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
| 3 |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Diagnostics/Files.ql
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
| 122 |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Diagnostics/Lines.ql
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
| 93 |

0 commit comments

Comments
 (0)