mirror of
https://github.com/github/codeql.git
synced 2026-04-25 08:45:14 +02:00
C++: Separate int and float metrics
This commit is contained in:
@@ -7,9 +7,6 @@ import Diagnostics
|
||||
abstract class Metric extends string {
|
||||
bindingset[this]
|
||||
Metric() { any() }
|
||||
|
||||
/** Gets the value of this metric. */
|
||||
abstract float getValue();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -18,6 +15,9 @@ abstract class Metric extends string {
|
||||
abstract class ExtractionMetric extends Metric {
|
||||
bindingset[this]
|
||||
ExtractionMetric() { any() }
|
||||
|
||||
/** Gets the value of this metric. */
|
||||
abstract int getValue();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -54,9 +54,9 @@ class QualityMetric extends Metric {
|
||||
base_metric = relative_metric.getBaseline() and this = "Percentage of " + relative_metric
|
||||
}
|
||||
|
||||
override float getValue() {
|
||||
float getValue() {
|
||||
base_metric.getValue() > 0 and
|
||||
result = 100 * relative_metric.getValue() / base_metric.getValue()
|
||||
result = 100.0 * relative_metric.getValue() / base_metric.getValue()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,19 +65,19 @@ module CppMetrics {
|
||||
class CompilationUnits extends BaseMetric {
|
||||
CompilationUnits() { this = "compilation units" }
|
||||
|
||||
override float getValue() { result = count(Compilation c) }
|
||||
override int getValue() { result = count(Compilation c) }
|
||||
}
|
||||
|
||||
class SourceFiles extends BaseMetric {
|
||||
SourceFiles() { this = "source files" }
|
||||
|
||||
override float getValue() { result = count(File f | f.fromSource()) }
|
||||
override int getValue() { result = count(File f | f.fromSource()) }
|
||||
}
|
||||
|
||||
class SourceFilesWithoutErrors extends SuccessMetric {
|
||||
SourceFilesWithoutErrors() { this = "source files without errors" }
|
||||
|
||||
override float getValue() {
|
||||
override int getValue() {
|
||||
result = count(File f | f.fromSource() and not exists(CompilerError e | f = e.getFile()))
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ module CppMetrics {
|
||||
class CompilationUnitsWithoutErrors extends SuccessMetric {
|
||||
CompilationUnitsWithoutErrors() { this = "compilation units without errors" }
|
||||
|
||||
override float getValue() {
|
||||
override int getValue() {
|
||||
result = count(Compilation c | not exists(Diagnostic d | d.getFile() = c.getAFileCompiled()))
|
||||
}
|
||||
|
||||
@@ -97,13 +97,13 @@ module CppMetrics {
|
||||
class Expressions extends BaseMetric {
|
||||
Expressions() { this = "expressions" }
|
||||
|
||||
override float getValue() { result = count(Expr e) }
|
||||
override int getValue() { result = count(Expr e) }
|
||||
}
|
||||
|
||||
class SucceededExpressions extends SuccessMetric {
|
||||
SucceededExpressions() { this = "non-error expressions" }
|
||||
|
||||
override float getValue() { result = count(Expr e) - count(ErrorExpr e) }
|
||||
override int getValue() { result = count(Expr e) - count(ErrorExpr e) }
|
||||
|
||||
override Expressions getBaseline() { any() }
|
||||
}
|
||||
@@ -111,7 +111,7 @@ module CppMetrics {
|
||||
class TypedExpressions extends SuccessMetric {
|
||||
TypedExpressions() { this = "expressions with a known type" }
|
||||
|
||||
override float getValue() { result = count(Expr e | not e.getType() instanceof ErroneousType) }
|
||||
override int getValue() { result = count(Expr e | not e.getType() instanceof ErroneousType) }
|
||||
|
||||
override Expressions getBaseline() { any() }
|
||||
}
|
||||
@@ -119,13 +119,13 @@ module CppMetrics {
|
||||
class Calls extends BaseMetric {
|
||||
Calls() { this = "calls" }
|
||||
|
||||
override float getValue() { result = count(Call c) }
|
||||
override int getValue() { result = count(Call c) }
|
||||
}
|
||||
|
||||
class SucceededCalls extends SuccessMetric {
|
||||
SucceededCalls() { this = "calls with a target" }
|
||||
|
||||
override float getValue() {
|
||||
override int getValue() {
|
||||
result = count(Call c | not c.getTarget().getADeclarationEntry().isImplicit())
|
||||
}
|
||||
|
||||
@@ -135,13 +135,13 @@ module CppMetrics {
|
||||
class Variables extends BaseMetric {
|
||||
Variables() { this = "variables" }
|
||||
|
||||
override float getValue() { result = count(Variable v) }
|
||||
override int getValue() { result = count(Variable v) }
|
||||
}
|
||||
|
||||
class VariablesKnownType extends SuccessMetric {
|
||||
VariablesKnownType() { this = "variables with a known type" }
|
||||
|
||||
override float getValue() {
|
||||
override int getValue() {
|
||||
result = count(Variable v | not v.getType() instanceof ErroneousType)
|
||||
}
|
||||
|
||||
@@ -151,13 +151,13 @@ module CppMetrics {
|
||||
class LinesOfText extends BaseMetric {
|
||||
LinesOfText() { this = "lines of text" }
|
||||
|
||||
override float getValue() { result = sum(File f | | f.getMetrics().getNumberOfLines()) }
|
||||
override int getValue() { result = sum(File f | | f.getMetrics().getNumberOfLines()) }
|
||||
}
|
||||
|
||||
class LinesOfCode extends BaseMetric {
|
||||
LinesOfCode() { this = "lines of code" }
|
||||
|
||||
override float getValue() { result = sum(File f | | f.getMetrics().getNumberOfLinesOfCode()) }
|
||||
override int getValue() { result = sum(File f | | f.getMetrics().getNumberOfLinesOfCode()) }
|
||||
}
|
||||
|
||||
private predicate errorLine(File file, int line) {
|
||||
@@ -175,7 +175,7 @@ module CppMetrics {
|
||||
class SucceededLines extends SuccessMetric {
|
||||
SucceededLines() { this = "lines of code without errors" }
|
||||
|
||||
override float getValue() {
|
||||
override int getValue() {
|
||||
result =
|
||||
sum(File f | | f.getMetrics().getNumberOfLinesOfCode()) -
|
||||
count(File file, int line | errorLine(file, line))
|
||||
@@ -187,13 +187,13 @@ module CppMetrics {
|
||||
class Functions extends BaseMetric {
|
||||
Functions() { this = "functions" }
|
||||
|
||||
override float getValue() { result = count(Function f) }
|
||||
override int getValue() { result = count(Function f) }
|
||||
}
|
||||
|
||||
class SucceededFunctions extends SuccessMetric {
|
||||
SucceededFunctions() { this = "functions without errors" }
|
||||
|
||||
override float getValue() { result = count(Function f | not f.hasErrors()) }
|
||||
override int getValue() { result = count(Function f | not f.hasErrors()) }
|
||||
|
||||
override Functions getBaseline() { any() }
|
||||
}
|
||||
@@ -201,13 +201,13 @@ module CppMetrics {
|
||||
class Includes extends BaseMetric {
|
||||
Includes() { this = "#include directives" }
|
||||
|
||||
override float getValue() { result = count(Include i) + count(CannotOpenFile e) }
|
||||
override int getValue() { result = count(Include i) + count(CannotOpenFile e) }
|
||||
}
|
||||
|
||||
class SucceededIncludes extends SuccessMetric {
|
||||
SucceededIncludes() { this = "successfully resolved #include directives" }
|
||||
|
||||
override float getValue() { result = count(Include i) }
|
||||
override int getValue() { result = count(Include i) }
|
||||
|
||||
override Includes getBaseline() { any() }
|
||||
}
|
||||
@@ -223,7 +223,7 @@ module CppMetrics {
|
||||
this = "Successfully included " + include_text
|
||||
}
|
||||
|
||||
override float getValue() { result = count(Include i | i.getIncludeText() = include_text) }
|
||||
int getValue() { result = count(Include i | i.getIncludeText() = include_text) }
|
||||
|
||||
string getIncludeText() { result = include_text }
|
||||
}
|
||||
@@ -236,9 +236,7 @@ module CppMetrics {
|
||||
this = "Failed to include '" + include_text + "'"
|
||||
}
|
||||
|
||||
override float getValue() {
|
||||
result = count(CannotOpenFile e | e.getIncludedFile() = include_text)
|
||||
}
|
||||
int getValue() { result = count(CannotOpenFile e | e.getIncludedFile() = include_text) }
|
||||
|
||||
string getIncludeText() { result = include_text }
|
||||
}
|
||||
@@ -246,18 +244,18 @@ module CppMetrics {
|
||||
class CompilerErrors extends ExtractionMetric {
|
||||
CompilerErrors() { this = "compiler errors" }
|
||||
|
||||
override float getValue() { result = count(CompilerError e) }
|
||||
override int getValue() { result = count(CompilerError e) }
|
||||
}
|
||||
|
||||
class ErrorCount extends Metric {
|
||||
ErrorCount() { exists(CompilerError e | e.getMessage() = this) }
|
||||
|
||||
override float getValue() { result = count(CompilerError e | e.getMessage() = this) }
|
||||
int getValue() { result = count(CompilerError e | e.getMessage() = this) }
|
||||
}
|
||||
|
||||
class SyntaxErrorCount extends ExtractionMetric {
|
||||
SyntaxErrorCount() { this = "syntax errors" }
|
||||
|
||||
override float getValue() { result = count(SyntaxError e) }
|
||||
override int getValue() { result = count(SyntaxError e) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
| 'this' may only be used inside a nonstatic member function | 1.0 |
|
||||
| There was an error during this compilation | 1.0 |
|
||||
| expected a ')' | 1.0 |
|
||||
| expected a ';' | 1.0 |
|
||||
| expected an expression | 1.0 |
|
||||
| identifier 'no_such_function' is undefined | 1.0 |
|
||||
| identifier 'nsf2' is undefined | 1.0 |
|
||||
| identifier 'so_is_this' is undefined | 1.0 |
|
||||
| identifier 'uint32_t' is undefined | 1.0 |
|
||||
| too few arguments in function call | 1.0 |
|
||||
| 'this' may only be used inside a nonstatic member function | 1 |
|
||||
| There was an error during this compilation | 1 |
|
||||
| expected a ')' | 1 |
|
||||
| expected a ';' | 1 |
|
||||
| expected an expression | 1 |
|
||||
| identifier 'no_such_function' is undefined | 1 |
|
||||
| identifier 'nsf2' is undefined | 1 |
|
||||
| identifier 'so_is_this' is undefined | 1 |
|
||||
| identifier 'uint32_t' is undefined | 1 |
|
||||
| too few arguments in function call | 1 |
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
| #include directives | 2.0 |
|
||||
| calls | 2.0 |
|
||||
| calls with a target | 1.0 |
|
||||
| compilation units | 2.0 |
|
||||
| compilation units without errors | 1.0 |
|
||||
| compiler errors | 10.0 |
|
||||
| expressions | 10.0 |
|
||||
| expressions with a known type | 3.0 |
|
||||
| functions | 8.0 |
|
||||
| functions without errors | 6.0 |
|
||||
| lines of code | 19.0 |
|
||||
| lines of code without errors | 12.0 |
|
||||
| lines of text | 24.0 |
|
||||
| non-error expressions | 3.0 |
|
||||
| source files | 3.0 |
|
||||
| source files without errors | 2.0 |
|
||||
| successfully resolved #include directives | 2.0 |
|
||||
| syntax errors | 3.0 |
|
||||
| variables | 10.0 |
|
||||
| variables with a known type | 9.0 |
|
||||
| #include directives | 2 |
|
||||
| calls | 2 |
|
||||
| calls with a target | 1 |
|
||||
| compilation units | 2 |
|
||||
| compilation units without errors | 1 |
|
||||
| compiler errors | 10 |
|
||||
| expressions | 10 |
|
||||
| expressions with a known type | 3 |
|
||||
| functions | 8 |
|
||||
| functions without errors | 6 |
|
||||
| lines of code | 19 |
|
||||
| lines of code without errors | 12 |
|
||||
| lines of text | 24 |
|
||||
| non-error expressions | 3 |
|
||||
| source files | 3 |
|
||||
| source files without errors | 2 |
|
||||
| successfully resolved #include directives | 2 |
|
||||
| syntax errors | 3 |
|
||||
| variables | 10 |
|
||||
| variables with a known type | 9 |
|
||||
|
||||
@@ -1 +1 @@
|
||||
| "test.h" | 2.0 |
|
||||
| "test.h" | 2 |
|
||||
|
||||
Reference in New Issue
Block a user