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:
Dave Bartolomeo
2021-02-25 12:53:39 -05:00
parent cea1049745
commit 2e02625f22
18 changed files with 190 additions and 0 deletions

View 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())

View 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())

View 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())

View 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()

View 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()

View File

@@ -0,0 +1 @@
| 3 |

View File

@@ -0,0 +1 @@
Diagnostics/Files.ql

View File

@@ -0,0 +1 @@
| 122 |

View File

@@ -0,0 +1 @@
Diagnostics/Lines.ql

View File

@@ -0,0 +1 @@
| 93 |

View File

@@ -0,0 +1 @@
Diagnostics/LinesOfCode.ql

View File

@@ -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 |

View File

@@ -0,0 +1 @@
Diagnostics/LinesOfCodePerFile.ql

View File

@@ -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 |

View File

@@ -0,0 +1 @@
Diagnostics/LinesPerFile.ql

View 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;
}

View File

@@ -0,0 +1,3 @@
int g(float x) {
return (int)x;
}