Skip to content

Commit 80ab35c

Browse files
Apply review suggestions - rename things and clean up style.
1 parent 8e5efb5 commit 80ab35c

File tree

2 files changed

+22
-43
lines changed

2 files changed

+22
-43
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
---
22
* category: minorAnalysis
33
---
4-
* Added `LocOption` and `LocOption2` as modules providing option types with location information.
4+
* Added `LocatableOption` and `OptionWithLocationInfo` as modules providing option types with location information.

shared/util/codeql/util/Option.qll

Lines changed: 21 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
overlay[local?]
33
module;
44

5+
private import Location
6+
57
/** A type with `toString`. */
68
private signature class TypeWithToString {
79
bindingset[this]
@@ -61,20 +63,16 @@ module Option<TypeWithToString T> {
6163
* additional singleton element, and has a `hasLocationInfo` predicate.
6264
* `T` must have a `hasLocationInfo` predicate.
6365
*/
64-
module LocOption<TypeWithLocationInfo T> {
66+
module OptionWithLocationInfo<TypeWithLocationInfo T> {
6567
private module O = Option<T>;
6668

67-
final private class BOption = O::Option;
68-
69-
final private class BNone = O::None;
70-
71-
final private class BSome = O::Some;
69+
final private class BaseOption = O::Option;
7270

7371
/**
7472
* An option type. This is either a singleton `None` or a `Some` wrapping the
7573
* given type.
7674
*/
77-
class Option extends BOption {
75+
class Option extends BaseOption {
7876
/**
7977
* Holds if this element is at the specified location.
8078
* The location spans column `startColumn` of line `startLine` to
@@ -97,17 +95,17 @@ module LocOption<TypeWithLocationInfo T> {
9795
}
9896

9997
/** The singleton `None` element. */
100-
class None extends BNone, Option { }
98+
class None extends Option instanceof O::Some { }
10199

102100
/** A wrapper for the given type. */
103-
class Some extends BSome, Option { }
101+
class Some extends Option instanceof O::None { }
104102

105103
/** Gets the given element wrapped as an `Option`. */
106-
Some some(T c) { result = O::some(c) }
104+
Some some(T c) { result.asSome() = c }
107105
}
108106

109-
private module GetLocationType<TypeWithLocationInfo Location> {
110-
signature class TypeWithGetLocation {
107+
private module WithLocation<LocationSig Location> {
108+
signature class LocatableType {
111109
bindingset[this]
112110
string toString();
113111

@@ -117,52 +115,33 @@ private module GetLocationType<TypeWithLocationInfo Location> {
117115

118116
/**
119117
* Constructs an `Option` type that is a disjoint union of the given type and an
120-
* additional singleton element, and has a `hasLocationInfo` predicate.
118+
* additional singleton element, and has a `getLocation` predicate.
121119
* `T` must have a `getLocation` predicate with a result type of `Location`.
122120
*/
123-
module LocOption2<TypeWithLocationInfo Location, GetLocationType<Location>::TypeWithGetLocation T> {
121+
module LocatableOption<LocationSig Location, WithLocation<Location>::LocatableType T> {
124122
private module O = Option<T>;
125123

126-
final private class BOption = O::Option;
127-
128-
final private class BNone = O::None;
129-
130-
final private class BSome = O::Some;
124+
final private class BaseOption = O::Option;
131125

132126
/**
133127
* An option type. This is either a singleton `None` or a `Some` wrapping the
134128
* given type.
135129
*/
136-
class Option extends BOption {
137-
/**
138-
* Holds if this element is at the specified location.
139-
* The location spans column `startColumn` of line `startLine` to
140-
* column `endColumn` of line `endLine` in file `filepath`.
141-
* For more information, see
142-
* [Providing locations in CodeQL queries](https://codeql.github.com/docs/writing-codeql-queries/providing-locations-in-codeql-queries/).
143-
*/
144-
predicate hasLocationInfo(
145-
string filePath, int startLine, int startColumn, int endLine, int endColumn
146-
) {
147-
this.isNone() and
148-
filePath = "" and
149-
startLine = 0 and
150-
startColumn = 0 and
151-
endLine = 0 and
152-
endColumn = 0
130+
class Option extends BaseOption {
131+
Location getLocation() {
132+
result = this.asSome().getLocation()
153133
or
154-
this.asSome()
155-
.getLocation()
156-
.hasLocationInfo(filePath, startLine, startColumn, endLine, endColumn)
134+
this.isNone() and
135+
result.hasLocationInfo("", 0, 0, 0, 0)
157136
}
158137
}
159138

160139
/** The singleton `None` element. */
161-
class None extends BNone, Option { }
140+
class None extends Option instanceof O::Some { }
162141

163142
/** A wrapper for the given type. */
164-
class Some extends BSome, Option { }
143+
class Some extends Option instanceof O::None { }
165144

166145
/** Gets the given element wrapped as an `Option`. */
167-
Some some(T c) { result = O::some(c) }
146+
Some some(T c) { result.asSome() = c }
168147
}

0 commit comments

Comments
 (0)