Files
codeql/cpp/ql/src/Metrics/Files/NumberOfPublicGlobals.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

52 lines
1.3 KiB
Plaintext

/**
* @name Public global variables
* @description The total number of global variables in each file with
* external (public) visibility.
* @kind treemap
* @id cpp/number-of-public-globals
* @treemap.warnOn highValues
* @metricType file
* @metricAggregate avg sum max
* @tags maintainability
* modularity
*/
import cpp
predicate macroLocation(File f, int startLine, int endLine) {
exists(MacroInvocation mi, Location l |
l = mi.getLocation() and
l.getFile() = f and
l.getStartLine() = startLine and
l.getEndLine() = endLine
)
}
pragma[nomagic]
Location getVariableLocation(Variable v) { result = v.getLocation() }
predicate globalLocation(GlobalVariable gv, File f, int startLine, int endLine) {
exists(Location l |
l = getVariableLocation(gv) and
l.hasLocationInfo(f.getAbsolutePath(), startLine, _, endLine, _)
)
}
predicate inMacro(GlobalVariable gv) {
exists(File f, int macroStart, int macroEnd, int varStart, int varEnd |
macroLocation(f, macroStart, macroEnd) and
globalLocation(gv, f, varStart, varEnd) and
varStart >= macroStart and
varEnd <= macroEnd
)
}
from File f
where f.fromSource()
select f,
count(GlobalVariable gv |
gv.getFile() = f and
not gv.isStatic() and
not inMacro(gv)
)