Skip to content

Commit 202c0be

Browse files
committed
Add hasLocationInfo for Types
It returns a dummy location except for named types with a type declaration in the source.
1 parent d55e9d5 commit 202c0be

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,23 @@ 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+
filepath = "" and
169+
startline = 0 and
170+
startcolumn = 0 and
171+
endline = 0 and
172+
endcolumn = 0
173+
}
157174
}
158175

159176
/** An invalid type. */
@@ -997,6 +1014,17 @@ class NamedType extends @namedtype, CompositeType {
9971014
}
9981015

9991016
override Type getUnderlyingType() { result = this.getBaseType().getUnderlyingType() }
1017+
1018+
override predicate hasLocationInfo(
1019+
string filepath, int startline, int startcolumn, int endline, int endcolumn
1020+
) {
1021+
exists(DeclaredType dt |
1022+
dt.getType() = this and
1023+
// Note that if the type declaration isn't in the source that we have
1024+
// then we use a dummy location.
1025+
dt.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
1026+
)
1027+
}
10001028
}
10011029

10021030
/**

0 commit comments

Comments
 (0)