Skip to content

Commit f322cb7

Browse files
committed
Use getLocation instead of hasLocationInfo
1 parent ca0b363 commit f322cb7

File tree

101 files changed

+413
-654
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

101 files changed

+413
-654
lines changed

go/ql/lib/semmle/go/DiagnosticsReporting.qll

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,10 @@ private class Diagnostic extends @diagnostic {
1919
string getMessage() { diagnostics(this, _, _, result, _, _) }
2020

2121
/** Gets the file that this error is associated with, if any. */
22-
File getFile() { this.hasLocationInfo(result.getAbsolutePath(), _, _, _, _) }
22+
File getFile() { result = this.getLocation().getFile() }
2323

24-
/**
25-
* Holds if this element is at the specified location.
26-
* The location spans column `startcolumn` of line `startline` to
27-
* column `endcolumn` of line `endline` in file `filepath`.
28-
* For more information, see
29-
* [Locations](https://codeql.github.com/docs/writing-codeql-queries/providing-locations-in-codeql-queries/).
30-
*/
31-
predicate hasLocationInfo(string path, int sl, int sc, int el, int ec) {
32-
exists(Location loc | diagnostics(this, _, _, _, _, loc) |
33-
loc.hasLocationInfo(path, sl, sc, el, ec)
34-
)
35-
}
24+
/** Gets the location for this error. */
25+
Location getLocation() { diagnostics(this, _, _, _, _, result) }
3626

3727
string toString() { result = this.getMessage() }
3828
}
@@ -69,7 +59,7 @@ predicate reportableDiagnostics(Diagnostic d, string msg, int sev) {
6959
exists(File f | f = d.getFile() |
7060
exists(f.getAChild()) and
7161
msg =
72-
"Extraction failed in " + d.getFile().getRelativePath() + " with error " +
62+
"Extraction failed in " + f.getRelativePath() + " with error " +
7363
removeAbsolutePaths(d.getMessage())
7464
)
7565
or

go/ql/lib/semmle/go/Scopes.qll

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -144,36 +144,34 @@ class Entity extends @object {
144144
/** Gets a textual representation of this entity. */
145145
string toString() { result = this.getName() }
146146

147-
private predicate hasRealLocationInfo(
148-
string filepath, int startline, int startcolumn, int endline, int endcolumn
149-
) {
150-
// take the location of the declaration if there is one
151-
this.getDeclaration().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) or
152-
any(CaseClause cc | this = cc.getImplicitlyDeclaredVariable())
153-
.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
147+
/** Gets the location of this entity. */
148+
Location getLocation() {
149+
result = this.getDeclaration().getLocation()
150+
or
151+
result = any(CaseClause cc | this = cc.getImplicitlyDeclaredVariable()).getLocation()
154152
}
155153

156154
/**
155+
* DEPRECATED: Use `getLocation()` instead.
156+
*
157157
* Holds if this element is at the specified location.
158158
* The location spans column `startcolumn` of line `startline` to
159159
* column `endcolumn` of line `endline` in file `filepath`.
160160
* For more information, see
161161
* [Locations](https://codeql.github.com/docs/writing-codeql-queries/providing-locations-in-codeql-queries/).
162162
*/
163-
predicate hasLocationInfo(
163+
deprecated predicate hasLocationInfo(
164164
string filepath, int startline, int startcolumn, int endline, int endcolumn
165165
) {
166-
// take the location of the declaration if there is one
167-
if this.hasRealLocationInfo(_, _, _, _, _)
168-
then this.hasRealLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
169-
else (
170-
// otherwise fall back on dummy location
171-
filepath = "" and
172-
startline = 0 and
173-
startcolumn = 0 and
174-
endline = 0 and
175-
endcolumn = 0
176-
)
166+
this.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
167+
or
168+
// otherwise fall back on dummy location
169+
not exists(this.getLocation()) and
170+
filepath = "" and
171+
startline = 0 and
172+
startcolumn = 0 and
173+
endline = 0 and
174+
endcolumn = 0
177175
}
178176
}
179177

@@ -680,16 +678,22 @@ class Callable extends TCallable {
680678
result = this.asFuncLit().getName()
681679
}
682680

681+
/** Gets the location of this callable. */
682+
Location getLocation() {
683+
result = this.asFunction().getLocation() or result = this.asFuncLit().getLocation()
684+
}
685+
683686
/**
687+
* DEPRECATED: Use `getLocation()` instead.
688+
*
684689
* Holds if this element is at the specified location.
685690
* The location spans column `sc` of line `sl` to
686691
* column `ec` of line `el` in file `fp`.
687692
* For more information, see
688693
* [Locations](https://codeql.github.com/docs/writing-codeql-queries/providing-locations-in-codeql-queries/).
689694
*/
690-
predicate hasLocationInfo(string fp, int sl, int sc, int el, int ec) {
691-
this.asFunction().hasLocationInfo(fp, sl, sc, el, ec) or
692-
this.asFuncLit().hasLocationInfo(fp, sl, sc, el, ec)
695+
deprecated predicate hasLocationInfo(string fp, int sl, int sc, int el, int ec) {
696+
this.getLocation().hasLocationInfo(fp, sl, sc, el, ec)
693697
}
694698
}
695699

go/ql/lib/semmle/go/StringOps.qll

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -548,20 +548,25 @@ module StringOps {
548548
else result = "concatenation element"
549549
}
550550

551+
/** Gets the location of this element. */
552+
Location getLocation() { result = this.asNode().getLocation() }
553+
551554
/**
555+
* DEPRECATED: Use `getLocation()` instead.
556+
*
552557
* Holds if this element is at the specified location.
553558
* The location spans column `startcolumn` of line `startline` to
554559
* column `endcolumn` of line `endline` in file `filepath`.
555560
* For more information, see
556561
* [Locations](https://codeql.github.com/docs/writing-codeql-queries/providing-locations-in-codeql-queries/).
557562
*/
558-
predicate hasLocationInfo(
563+
deprecated predicate hasLocationInfo(
559564
string filepath, int startline, int startcolumn, int endline, int endcolumn
560565
) {
561-
this.asNode().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
566+
this.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
562567
or
563568
// use dummy location for elements that don't have a corresponding node
564-
not exists(this.asNode()) and
569+
not exists(this.getLocation()) and
565570
filepath = "" and
566571
startline = 0 and
567572
startcolumn = 0 and

go/ql/lib/semmle/go/Types.qll

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,19 +144,24 @@ class Type extends @type {
144144
*/
145145
string toString() { result = this.getName() }
146146

147+
/** Gets the location of this type. */
148+
Location getLocation() { result = this.getEntity().getLocation() }
149+
147150
/**
151+
* DEPRECATED: Use `getLocation()` instead.
152+
*
148153
* Holds if this element is at the specified location.
149154
* The location spans column `startcolumn` of line `startline` to
150155
* column `endcolumn` of line `endline` in file `filepath`.
151156
* For more information, see
152157
* [Locations](https://codeql.github.com/docs/writing-codeql-queries/providing-locations-in-codeql-queries/).
153158
*/
154-
predicate hasLocationInfo(
159+
deprecated predicate hasLocationInfo(
155160
string filepath, int startline, int startcolumn, int endline, int endcolumn
156161
) {
157-
this.getEntity().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
162+
this.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
158163
or
159-
not exists(this.getEntity()) and
164+
not exists(this.getLocation()) and
160165
filepath = "" and
161166
startline = 0 and
162167
startcolumn = 0 and

go/ql/lib/semmle/go/VariableWithFields.qll

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,16 +183,21 @@ class VariableWithFields extends TVariableWithFields {
183183
*/
184184
string getElement() { this = TVariableElementStep(_, result) }
185185

186+
/** Gets the location of this variable with fields. */
187+
Location getLocation() { result = this.getBaseVariable().getLocation() }
188+
186189
/**
190+
* DEPRECATED: Use `getLocation()` instead.
191+
*
187192
* Holds if this element is at the specified location.
188193
* The location spans column `startcolumn` of line `startline` to
189194
* column `endcolumn` of line `endline` in file `filepath`.
190195
* For more information, see
191196
* [Locations](https://codeql.github.com/docs/writing-codeql-queries/providing-locations-in-codeql-queries/).
192197
*/
193-
predicate hasLocationInfo(
198+
deprecated predicate hasLocationInfo(
194199
string filepath, int startline, int startcolumn, int endline, int endcolumn
195200
) {
196-
this.getBaseVariable().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
201+
this.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
197202
}
198203
}

go/ql/lib/semmle/go/controlflow/BasicBlocks.qll

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,17 +114,22 @@ class BasicBlock extends TControlFlowNode {
114114
/** Gets a textual representation of this basic block. */
115115
string toString() { result = "basic block" }
116116

117+
/** Gets the source location for this element. */
118+
Location getLocation() { result = this.getFirstNode().getLocation() }
119+
117120
/**
121+
* DEPRECATED: Use `getLocation()` instead.
122+
*
118123
* Holds if this basic block is at the specified location.
119124
* The location spans column `startcolumn` of line `startline` to
120125
* column `endcolumn` of line `endline` in file `filepath`.
121126
* For more information, see
122127
* [Locations](https://codeql.github.com/docs/writing-codeql-queries/providing-locations-in-codeql-queries/).
123128
*/
124-
predicate hasLocationInfo(
129+
deprecated predicate hasLocationInfo(
125130
string filepath, int startline, int startcolumn, int endline, int endcolumn
126131
) {
127-
this.getFirstNode().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
132+
this.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
128133
}
129134
}
130135

go/ql/lib/semmle/go/controlflow/ControlFlowGraph.qll

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,23 +77,31 @@ module ControlFlow {
7777
Root getRoot() { none() }
7878

7979
/** Gets the file to which this node belongs. */
80-
File getFile() { this.hasLocationInfo(result.getAbsolutePath(), _, _, _, _) }
80+
File getFile() { result = this.getLocation().getFile() }
8181

8282
/**
8383
* Gets a textual representation of this control flow node.
8484
*/
8585
string toString() { result = "control-flow node" }
8686

87+
/** Gets the source location for this element. */
88+
Location getLocation() { none() }
89+
8790
/**
91+
* DEPRECATED: Use `getLocation()` instead.
92+
*
8893
* Holds if this element is at the specified location.
8994
* The location spans column `startcolumn` of line `startline` to
9095
* column `endcolumn` of line `endline` in file `filepath`.
9196
* For more information, see
9297
* [Locations](https://codeql.github.com/docs/writing-codeql-queries/providing-locations-in-codeql-queries/).
9398
*/
94-
predicate hasLocationInfo(
99+
deprecated predicate hasLocationInfo(
95100
string filepath, int startline, int startcolumn, int endline, int endcolumn
96101
) {
102+
this.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
103+
or
104+
not exists(this.getLocation()) and
97105
filepath = "" and
98106
startline = 0 and
99107
startcolumn = 0 and
@@ -244,11 +252,7 @@ module ControlFlow {
244252

245253
override string toString() { result = cond + " is " + outcome }
246254

247-
override predicate hasLocationInfo(
248-
string filepath, int startline, int startcolumn, int endline, int endcolumn
249-
) {
250-
cond.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
251-
}
255+
override Location getLocation() { result = cond.getLocation() }
252256
}
253257

254258
/**

go/ql/lib/semmle/go/controlflow/ControlFlowGraphImpl.qll

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -418,11 +418,7 @@ class SkipNode extends ControlFlow::Node, MkSkipNode {
418418

419419
override string toString() { result = "skip" }
420420

421-
override predicate hasLocationInfo(
422-
string filepath, int startline, int startcolumn, int endline, int endcolumn
423-
) {
424-
skip.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
425-
}
421+
override Location getLocation() { result = skip.getLocation() }
426422
}
427423

428424
/**
@@ -437,11 +433,7 @@ class EntryNode extends ControlFlow::Node, MkEntryNode {
437433

438434
override string toString() { result = "entry" }
439435

440-
override predicate hasLocationInfo(
441-
string filepath, int startline, int startcolumn, int endline, int endcolumn
442-
) {
443-
root.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
444-
}
436+
override Location getLocation() { result = root.getLocation() }
445437
}
446438

447439
/**
@@ -456,11 +448,7 @@ class ExitNode extends ControlFlow::Node, MkExitNode {
456448

457449
override string toString() { result = "exit" }
458450

459-
override predicate hasLocationInfo(
460-
string filepath, int startline, int startcolumn, int endline, int endcolumn
461-
) {
462-
root.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
463-
}
451+
override Location getLocation() { result = root.getLocation() }
464452
}
465453

466454
/**

0 commit comments

Comments
 (0)