Skip to content

Commit 0537579

Browse files
authored
Merge pull request github#12131 from owen-mc/go/named-type-location
Add `hasLocationInfo` for `Type`s
2 parents 2f404df + 685b8b4 commit 0537579

File tree

10 files changed

+364
-344
lines changed

10 files changed

+364
-344
lines changed

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,26 @@ class Type extends @type {
154154
* Gets a basic textual representation of this type.
155155
*/
156156
string toString() { result = this.getName() }
157+
158+
/**
159+
* Holds if this element is at the specified location.
160+
* The location spans column `startcolumn` of line `startline` to
161+
* column `endcolumn` of line `endline` in file `filepath`.
162+
* For more information, see
163+
* [Locations](https://codeql.github.com/docs/writing-codeql-queries/providing-locations-in-codeql-queries/).
164+
*/
165+
predicate hasLocationInfo(
166+
string filepath, int startline, int startcolumn, int endline, int endcolumn
167+
) {
168+
this.getEntity().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
169+
or
170+
not exists(this.getEntity()) and
171+
filepath = "" and
172+
startline = 0 and
173+
startcolumn = 0 and
174+
endline = 0 and
175+
endcolumn = 0
176+
}
157177
}
158178

159179
/** An invalid type. */
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
| pointer type |
1+
| file://:0:0:0:0 | pointer type |
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
| Request |
1+
| file://:0:0:0:0 | Request |
Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
| A | A | tst.go:4:2:4:2 | m |
2-
| AA | AA | tst.go:4:2:4:2 | m |
3-
| AB | AB | tst.go:4:2:4:2 | m |
4-
| AB | AB | tst.go:9:2:9:2 | n |
5-
| ABC | ABC | tst.go:4:2:4:2 | m |
6-
| ABC | ABC | tst.go:9:2:9:2 | n |
7-
| ABC | ABC | tst.go:14:2:14:2 | o |
8-
| AC | AC | tst.go:4:2:4:2 | m |
9-
| AC | AC | tst.go:13:2:13:2 | n |
10-
| AC | AC | tst.go:14:2:14:2 | o |
11-
| B | B | tst.go:8:2:8:2 | m |
12-
| B | B | tst.go:9:2:9:2 | n |
13-
| BC | BC | tst.go:8:2:8:2 | m |
14-
| BC | BC | tst.go:9:2:9:2 | n |
15-
| BC | BC | tst.go:14:2:14:2 | o |
16-
| C | C | tst.go:13:2:13:2 | n |
17-
| C | C | tst.go:14:2:14:2 | o |
1+
| tst.go:3:6:3:6 | A | A | tst.go:4:2:4:2 | m |
2+
| tst.go:7:6:7:6 | B | B | tst.go:8:2:8:2 | m |
3+
| tst.go:7:6:7:6 | B | B | tst.go:9:2:9:2 | n |
4+
| tst.go:12:6:12:6 | C | C | tst.go:13:2:13:2 | n |
5+
| tst.go:12:6:12:6 | C | C | tst.go:14:2:14:2 | o |
6+
| tst.go:17:6:17:7 | AA | AA | tst.go:4:2:4:2 | m |
7+
| tst.go:22:6:22:7 | AB | AB | tst.go:4:2:4:2 | m |
8+
| tst.go:22:6:22:7 | AB | AB | tst.go:9:2:9:2 | n |
9+
| tst.go:27:6:27:7 | BC | BC | tst.go:8:2:8:2 | m |
10+
| tst.go:27:6:27:7 | BC | BC | tst.go:9:2:9:2 | n |
11+
| tst.go:27:6:27:7 | BC | BC | tst.go:14:2:14:2 | o |
12+
| tst.go:32:6:32:7 | AC | AC | tst.go:4:2:4:2 | m |
13+
| tst.go:32:6:32:7 | AC | AC | tst.go:13:2:13:2 | n |
14+
| tst.go:32:6:32:7 | AC | AC | tst.go:14:2:14:2 | o |
15+
| tst.go:37:6:37:8 | ABC | ABC | tst.go:4:2:4:2 | m |
16+
| tst.go:37:6:37:8 | ABC | ABC | tst.go:9:2:9:2 | n |
17+
| tst.go:37:6:37:8 | ABC | ABC | tst.go:14:2:14:2 | o |
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
| test.go:9:2:9:16 | ... := ...[0] | bool |
2-
| test.go:9:2:9:16 | ... := ...[1] | bool |
3-
| test.go:15:2:15:20 | ... := ...[0] | string |
4-
| test.go:15:2:15:20 | ... := ...[1] | bool |
5-
| test.go:21:2:21:22 | ... := ...[0] | string |
6-
| test.go:21:2:21:22 | ... := ...[1] | bool |
1+
| test.go:9:2:9:16 | ... := ...[0] | file://:0:0:0:0 | bool |
2+
| test.go:9:2:9:16 | ... := ...[1] | file://:0:0:0:0 | bool |
3+
| test.go:15:2:15:20 | ... := ...[0] | file://:0:0:0:0 | string |
4+
| test.go:15:2:15:20 | ... := ...[1] | file://:0:0:0:0 | bool |
5+
| test.go:21:2:21:22 | ... := ...[0] | file://:0:0:0:0 | string |
6+
| test.go:21:2:21:22 | ... := ...[1] | file://:0:0:0:0 | bool |
Lines changed: 53 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,53 @@
1-
| A | m | func() |
2-
| A2 | m | func() |
3-
| AC | m | func() |
4-
| AC | n | func() |
5-
| AC | o | func() |
6-
| AEmbedded | m | func() |
7-
| AExtended | m | func() |
8-
| AExtended | n | func() |
9-
| B | m | func() |
10-
| B | n | func() |
11-
| C | n | func() |
12-
| C | o | func() |
13-
| GenericInterface | GetT | func() T |
14-
| MyInterface | clone | func() MyInterface |
15-
| MyInterface | dummy1 | func() [10]U |
16-
| MyInterface | dummy2 | func() * U |
17-
| MyInterface | dummy3 | func() []U |
18-
| MyInterface | dummy4 | func() [U]U |
19-
| MyInterface | dummy5 | func() chan<- U |
20-
| MyInterface | dummy6 | func() MyMapType |
21-
| MyInterface | dummy7 | func() MyFuncType2 |
22-
| MyInterface | dummy11 | func() GenericArray |
23-
| MyInterface | dummy12 | func() GenericPointer |
24-
| MyInterface | dummy13 | func() GenericSlice |
25-
| MyInterface | dummy14 | func() GenericMap1 |
26-
| MyInterface | dummy15 | func() GenericMap2 |
27-
| MyInterface | dummy17 | func() GenericChannel |
28-
| MyInterface | dummy18 | func() GenericNamed |
29-
| MyInterface | dummy19 | func() MyFuncType1 |
30-
| MyInterface | dummy20 | func() MyFuncType2 |
31-
| T | half | func() Foo |
32-
| T3 | half | func() Foo |
33-
| T4 | half | func() Foo |
34-
| embedder | f | func() int |
35-
| embedder2 | f | func() int |
36-
| embedder3 | f | func() int |
37-
| embedder4 | f | func() int |
38-
| i6 | String | func() string |
39-
| i7 | String | func() string |
40-
| i8 | String | func() string |
41-
| i8 | StringA | func() string |
42-
| i9 | String | func() string |
43-
| i9 | StringB | func() string |
44-
| i14 | String | func() string |
45-
| i14 | StringA | func() string |
46-
| i15 | String | func() string |
47-
| i15 | StringB | func() string |
48-
| i17 | StringA | func() string |
49-
| i18 | StringA | func() string |
50-
| i19 | StringB | func() string |
51-
| i20 | StringB | func() string |
52-
| ptrembedder | f | func() int |
53-
| ptrembedder | g | func() int |
1+
| generic.go:32:6:32:21 | GenericInterface | GetT | func() T |
2+
| generic.go:47:6:47:16 | MyInterface | clone | func() MyInterface |
3+
| generic.go:47:6:47:16 | MyInterface | dummy1 | func() [10]U |
4+
| generic.go:47:6:47:16 | MyInterface | dummy2 | func() * U |
5+
| generic.go:47:6:47:16 | MyInterface | dummy3 | func() []U |
6+
| generic.go:47:6:47:16 | MyInterface | dummy4 | func() [U]U |
7+
| generic.go:47:6:47:16 | MyInterface | dummy5 | func() chan<- U |
8+
| generic.go:47:6:47:16 | MyInterface | dummy6 | func() MyMapType |
9+
| generic.go:47:6:47:16 | MyInterface | dummy7 | func() MyFuncType2 |
10+
| generic.go:47:6:47:16 | MyInterface | dummy11 | func() GenericArray |
11+
| generic.go:47:6:47:16 | MyInterface | dummy12 | func() GenericPointer |
12+
| generic.go:47:6:47:16 | MyInterface | dummy13 | func() GenericSlice |
13+
| generic.go:47:6:47:16 | MyInterface | dummy14 | func() GenericMap1 |
14+
| generic.go:47:6:47:16 | MyInterface | dummy15 | func() GenericMap2 |
15+
| generic.go:47:6:47:16 | MyInterface | dummy17 | func() GenericChannel |
16+
| generic.go:47:6:47:16 | MyInterface | dummy18 | func() GenericNamed |
17+
| generic.go:47:6:47:16 | MyInterface | dummy19 | func() MyFuncType1 |
18+
| generic.go:47:6:47:16 | MyInterface | dummy20 | func() MyFuncType2 |
19+
| interface.go:28:6:28:7 | i6 | String | func() string |
20+
| interface.go:34:6:34:7 | i7 | String | func() string |
21+
| interface.go:41:6:41:7 | i8 | String | func() string |
22+
| interface.go:41:6:41:7 | i8 | StringA | func() string |
23+
| interface.go:47:6:47:7 | i9 | String | func() string |
24+
| interface.go:47:6:47:7 | i9 | StringB | func() string |
25+
| interface.go:75:6:75:8 | i14 | String | func() string |
26+
| interface.go:75:6:75:8 | i14 | StringA | func() string |
27+
| interface.go:81:6:81:8 | i15 | String | func() string |
28+
| interface.go:81:6:81:8 | i15 | StringB | func() string |
29+
| interface.go:91:6:91:8 | i17 | StringA | func() string |
30+
| interface.go:95:6:95:8 | i18 | StringA | func() string |
31+
| interface.go:101:6:101:8 | i19 | StringB | func() string |
32+
| interface.go:105:6:105:8 | i20 | StringB | func() string |
33+
| pkg1/embedding.go:19:6:19:13 | embedder | f | func() int |
34+
| pkg1/embedding.go:22:6:22:16 | ptrembedder | f | func() int |
35+
| pkg1/embedding.go:22:6:22:16 | ptrembedder | g | func() int |
36+
| pkg1/embedding.go:25:6:25:14 | embedder2 | f | func() int |
37+
| pkg1/embedding.go:28:6:28:14 | embedder3 | f | func() int |
38+
| pkg1/embedding.go:35:6:35:14 | embedder4 | f | func() int |
39+
| pkg1/interfaces.go:3:6:3:6 | A | m | func() |
40+
| pkg1/interfaces.go:7:6:7:6 | B | m | func() |
41+
| pkg1/interfaces.go:7:6:7:6 | B | n | func() |
42+
| pkg1/interfaces.go:12:6:12:6 | C | n | func() |
43+
| pkg1/interfaces.go:12:6:12:6 | C | o | func() |
44+
| pkg1/interfaces.go:17:6:17:14 | AEmbedded | m | func() |
45+
| pkg1/interfaces.go:21:6:21:7 | AC | m | func() |
46+
| pkg1/interfaces.go:21:6:21:7 | AC | n | func() |
47+
| pkg1/interfaces.go:21:6:21:7 | AC | o | func() |
48+
| pkg1/interfaces.go:26:6:26:14 | AExtended | m | func() |
49+
| pkg1/interfaces.go:26:6:26:14 | AExtended | n | func() |
50+
| pkg1/interfaces.go:31:6:31:7 | A2 | m | func() |
51+
| pkg1/tst.go:3:6:3:6 | T | half | func() Foo |
52+
| pkg1/tst.go:14:6:14:7 | T3 | half | func() Foo |
53+
| pkg1/tst.go:19:6:19:7 | T4 | half | func() Foo |

0 commit comments

Comments
 (0)