@@ -3,12 +3,10 @@ import cpp
33/**
44 * Gets the line of the `ix`th `PreprocessorBranchDirective` in file `f`.
55 */
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 ( ) )
1210}
1311
1412/**
@@ -22,8 +20,7 @@ private PreprocessorBranchDirective getPreprocFromIndex(File f, int ix) {
2220/**
2321 * Get the index of a `PreprocessorBranchDirective` in its `file`.
2422 */
25- private int getPreprocIndex ( PreprocessorBranchDirective directive )
26- {
23+ private int getPreprocIndex ( PreprocessorBranchDirective directive ) {
2724 directive = getPreprocFromIndex ( directive .getFile ( ) , result )
2825}
2926
@@ -48,50 +45,50 @@ class PreprocessorBlock extends @element {
4845 * For more information, see
4946 * [Locations](https://codeql.github.com/docs/writing-codeql-queries/providing-locations-in-codeql-queries/).
5047 */
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+ ) {
5451 filepath = this .getFile ( ) .toString ( ) and
5552 startline = this .getStartLine ( ) and
5653 startcolumn = 0 and
5754 endline = this .getEndLine ( ) and
5855 endcolumn = 0
5956 }
6057
61- string toString ( ) {
62- result = mkElement ( this ) .toString ( )
63- }
58+ string toString ( ) { result = mkElement ( this ) .toString ( ) }
6459
65- cached File getFile ( ) {
66- result = mkElement ( this ) .getFile ( )
67- }
60+ cached
61+ File getFile ( ) { result = mkElement ( this ) .getFile ( ) }
6862
69- cached int getStartLine ( ) {
70- result = mkElement ( this ) .getLocation ( ) .getStartLine ( )
71- }
63+ cached
64+ int getStartLine ( ) { result = mkElement ( this ) .getLocation ( ) .getStartLine ( ) }
7265
73- cached int getEndLine ( ) {
66+ cached
67+ int getEndLine ( ) {
7468 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
7671 }
7772
78- private cached PreprocessorBlock getParentInternal ( ) {
73+ cached
74+ private PreprocessorBlock getParentInternal ( ) {
7975 // find the `#ifdef` corresponding to this block and the
8076 // PreprocessorBranchDirective `prev` that came directly
8177 // before it in the source.
8278 exists ( int ix , PreprocessorBranchDirective prev |
8379 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
8684 // if we follow an #endif, we have the same parent
8785 // as its corresponding `#if` has.
8886 result = unresolveElement ( prev .getIf ( ) ) .( PreprocessorBlock ) .getParentInternal ( )
89- ) else (
87+ else
9088 // otherwise we directly follow an #if / #ifdef / #ifndef /
9189 // #elif / #else that must be a level above and our parent
9290 // block.
9391 mkElement ( result ) = prev
94- )
9592 )
9693 }
9794
@@ -102,22 +99,20 @@ class PreprocessorBlock extends @element {
10299 PreprocessorBlock getParent ( ) {
103100 not mkElement ( this ) instanceof File and
104101 (
105- if exists ( getParentInternal ( ) ) then (
102+ if exists ( getParentInternal ( ) )
103+ then
106104 // found parent directive
107105 result = getParentInternal ( )
108- ) else (
106+ else
109107 // top level directive
110108 mkElement ( result ) = getFile ( )
111- )
112109 )
113110 }
114-
111+
115112 /**
116113 * Gets a `PreprocessorBlock` that's directly inside this one.
117114 */
118- PreprocessorBlock getAChild ( ) {
119- result .getParent ( ) = this
120- }
115+ PreprocessorBlock getAChild ( ) { result .getParent ( ) = this }
121116
122117 private Include getAnEnclosedInclude ( ) {
123118 result .getFile ( ) = getFile ( ) and
@@ -128,7 +123,7 @@ class PreprocessorBlock extends @element {
128123 /**
129124 * Gets an include directive that is directly in this
130125 * `PreprocessorBlock`.
131- */
126+ */
132127 Include getAnInclude ( ) {
133128 result = getAnEnclosedInclude ( ) and
134129 not result = getAChild ( ) .getAnEnclosedInclude ( )
@@ -143,7 +138,7 @@ class PreprocessorBlock extends @element {
143138 /**
144139 * Gets a macro definition that is directly in this
145140 * `PreprocessorBlock`.
146- */
141+ */
147142 Macro getAMacro ( ) {
148143 result = getAnEnclosedMacro ( ) and
149144 not result = getAChild ( ) .getAnEnclosedMacro ( )
0 commit comments