@@ -3,12 +3,10 @@ import cpp
3
3
/**
4
4
* Gets the line of the `ix`th `PreprocessorBranchDirective` in file `f`.
5
5
*/
6
- private cached int getPreprocLineFromIndex ( File f , int ix ) {
7
- result = rank [ ix ] (
8
- PreprocessorBranchDirective g |
9
- g .getFile ( ) = f |
10
- g .getLocation ( ) .getStartLine ( )
11
- )
6
+ cached
7
+ private int getPreprocLineFromIndex ( File f , int ix ) {
8
+ result =
9
+ rank [ ix ] ( PreprocessorBranchDirective g | g .getFile ( ) = f | g .getLocation ( ) .getStartLine ( ) )
12
10
}
13
11
14
12
/**
@@ -22,8 +20,7 @@ private PreprocessorBranchDirective getPreprocFromIndex(File f, int ix) {
22
20
/**
23
21
* Get the index of a `PreprocessorBranchDirective` in its `file`.
24
22
*/
25
- private int getPreprocIndex ( PreprocessorBranchDirective directive )
26
- {
23
+ private int getPreprocIndex ( PreprocessorBranchDirective directive ) {
27
24
directive = getPreprocFromIndex ( directive .getFile ( ) , result )
28
25
}
29
26
@@ -48,50 +45,50 @@ class PreprocessorBlock extends @element {
48
45
* For more information, see
49
46
* [Locations](https://codeql.github.com/docs/writing-codeql-queries/providing-locations-in-codeql-queries/).
50
47
*/
51
- predicate hasLocationInfo ( string filepath ,
52
- int startline , int startcolumn ,
53
- int endline , int endcolumn ) {
48
+ predicate hasLocationInfo (
49
+ string filepath , int startline , int startcolumn , int endline , int endcolumn
50
+ ) {
54
51
filepath = this .getFile ( ) .toString ( ) and
55
52
startline = this .getStartLine ( ) and
56
53
startcolumn = 0 and
57
54
endline = this .getEndLine ( ) and
58
55
endcolumn = 0
59
56
}
60
57
61
- string toString ( ) {
62
- result = mkElement ( this ) .toString ( )
63
- }
58
+ string toString ( ) { result = mkElement ( this ) .toString ( ) }
64
59
65
- cached File getFile ( ) {
66
- result = mkElement ( this ) .getFile ( )
67
- }
60
+ cached
61
+ File getFile ( ) { result = mkElement ( this ) .getFile ( ) }
68
62
69
- cached int getStartLine ( ) {
70
- result = mkElement ( this ) .getLocation ( ) .getStartLine ( )
71
- }
63
+ cached
64
+ int getStartLine ( ) { result = mkElement ( this ) .getLocation ( ) .getStartLine ( ) }
72
65
73
- cached int getEndLine ( ) {
66
+ cached
67
+ int getEndLine ( ) {
74
68
result = mkElement ( this ) .( File ) .getMetrics ( ) .getNumberOfLines ( ) or
75
- result = mkElement ( this ) .( PreprocessorBranchDirective ) .getNext ( ) .getLocation ( ) .getStartLine ( ) - 1
69
+ result =
70
+ mkElement ( this ) .( PreprocessorBranchDirective ) .getNext ( ) .getLocation ( ) .getStartLine ( ) - 1
76
71
}
77
72
78
- private cached PreprocessorBlock getParentInternal ( ) {
73
+ cached
74
+ private PreprocessorBlock getParentInternal ( ) {
79
75
// find the `#ifdef` corresponding to this block and the
80
76
// PreprocessorBranchDirective `prev` that came directly
81
77
// before it in the source.
82
78
exists ( int ix , PreprocessorBranchDirective prev |
83
79
ix = getPreprocIndex ( mkElement ( this ) .( PreprocessorBranchDirective ) .getIf ( ) ) and
84
- prev = getPreprocFromIndex ( getFile ( ) , ix - 1 ) |
85
- if ( prev instanceof PreprocessorEndif ) then (
80
+ prev = getPreprocFromIndex ( getFile ( ) , ix - 1 )
81
+ |
82
+ if prev instanceof PreprocessorEndif
83
+ then
86
84
// if we follow an #endif, we have the same parent
87
85
// as its corresponding `#if` has.
88
86
result = unresolveElement ( prev .getIf ( ) ) .( PreprocessorBlock ) .getParentInternal ( )
89
- ) else (
87
+ else
90
88
// otherwise we directly follow an #if / #ifdef / #ifndef /
91
89
// #elif / #else that must be a level above and our parent
92
90
// block.
93
91
mkElement ( result ) = prev
94
- )
95
92
)
96
93
}
97
94
@@ -102,22 +99,20 @@ class PreprocessorBlock extends @element {
102
99
PreprocessorBlock getParent ( ) {
103
100
not mkElement ( this ) instanceof File and
104
101
(
105
- if exists ( getParentInternal ( ) ) then (
102
+ if exists ( getParentInternal ( ) )
103
+ then
106
104
// found parent directive
107
105
result = getParentInternal ( )
108
- ) else (
106
+ else
109
107
// top level directive
110
108
mkElement ( result ) = getFile ( )
111
- )
112
109
)
113
110
}
114
-
111
+
115
112
/**
116
113
* Gets a `PreprocessorBlock` that's directly inside this one.
117
114
*/
118
- PreprocessorBlock getAChild ( ) {
119
- result .getParent ( ) = this
120
- }
115
+ PreprocessorBlock getAChild ( ) { result .getParent ( ) = this }
121
116
122
117
private Include getAnEnclosedInclude ( ) {
123
118
result .getFile ( ) = getFile ( ) and
@@ -128,7 +123,7 @@ class PreprocessorBlock extends @element {
128
123
/**
129
124
* Gets an include directive that is directly in this
130
125
* `PreprocessorBlock`.
131
- */
126
+ */
132
127
Include getAnInclude ( ) {
133
128
result = getAnEnclosedInclude ( ) and
134
129
not result = getAChild ( ) .getAnEnclosedInclude ( )
@@ -143,7 +138,7 @@ class PreprocessorBlock extends @element {
143
138
/**
144
139
* Gets a macro definition that is directly in this
145
140
* `PreprocessorBlock`.
146
- */
141
+ */
147
142
Macro getAMacro ( ) {
148
143
result = getAnEnclosedMacro ( ) and
149
144
not result = getAChild ( ) .getAnEnclosedMacro ( )
0 commit comments