forked from github/codeql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConditionalSegmentConditions.ql
More file actions
38 lines (34 loc) · 954 Bytes
/
ConditionalSegmentConditions.ql
File metadata and controls
38 lines (34 loc) · 954 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/**
* @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()
)
)