Files
codeql/cpp/ql/src/Metrics/Files/ConditionalSegmentConditions.ql
Jonas Jensen 4ef5c9af62 C++: Autoformat everything
Some files that will change in #1736 have been spared.

    ./build -j4 target/jars/qlformat
    find ql/cpp/ql -name "*.ql"  -print0 | xargs -0 target/jars/qlformat --input
    find ql/cpp/ql -name "*.qll" -print0 | xargs -0 target/jars/qlformat --input
    (cd ql && git checkout 'cpp/ql/src/semmle/code/cpp/ir/implementation/**/*SSA*.qll')
    buildutils-internal/scripts/pr-checks/sync-identical-files.py --latest
2019-09-09 11:25:53 +02:00

39 lines
954 B
Plaintext

/**
* @name Number of distinct conditions used in #if, #ifdef, #ifndef etc. per file
* @description For each file, the number of unique conditions used by
* `#if`, `#ifdef`, and `#ifndef`.
* @kind treemap
* @id cpp/conditional-segment-conditions
* @treemap.warnOn highValues
* @metricType file
* @metricAggregate avg max
* @tags maintainability
* readability
*/
import cpp
predicate preprocessorOpenCondition(PreprocessorDirective d) {
d instanceof PreprocessorIf or
d instanceof PreprocessorIfdef or
d instanceof PreprocessorIfndef
}
predicate headerGuard(PreprocessorIfndef notdef) {
notdef.getHead().regexpMatch(".*_H_.*")
or
notdef.getHead().regexpMatch(".*_H")
}
from File f
where f.fromSource()
select f,
count(string s |
exists(PreprocessorDirective open |
preprocessorOpenCondition(open) and
not headerGuard(open) and
open.getFile() = f and
s = open.getHead()
)
)