@@ -184,7 +184,7 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
184
184
/** Gets the length of this path, assuming the length is at least 2. */
185
185
bindingset [ this ]
186
186
pragma [ inline_late]
187
- private int length2 ( ) {
187
+ private int lengthAtLeast2 ( ) {
188
188
// Same as
189
189
// `result = strictcount(this.indexOf(".")) + 1`
190
190
// but performs better because it doesn't use an aggregate
@@ -200,7 +200,7 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
200
200
else
201
201
if exists ( TypeParameter:: decode ( this ) )
202
202
then result = 1
203
- else result = this .length2 ( )
203
+ else result = this .lengthAtLeast2 ( )
204
204
}
205
205
206
206
/** Gets the path obtained by appending `suffix` onto this path. */
@@ -216,7 +216,7 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
216
216
(
217
217
not exists ( getTypePathLimit ( ) )
218
218
or
219
- result .length2 ( ) <= getTypePathLimit ( )
219
+ result .lengthAtLeast2 ( ) <= getTypePathLimit ( )
220
220
)
221
221
)
222
222
}
@@ -228,22 +228,26 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
228
228
* so there is no need to check the length of `result`.
229
229
*/
230
230
bindingset [ this , result ]
231
- TypePath appendInverse ( TypePath suffix ) {
232
- if result .isEmpty ( )
233
- then this .isEmpty ( ) and suffix .isEmpty ( )
234
- else
235
- if this .isEmpty ( )
236
- then suffix = result
237
- else (
238
- result = this and suffix .isEmpty ( )
239
- or
240
- result = this + "." + suffix
241
- )
231
+ TypePath appendInverse ( TypePath suffix ) { suffix = result .stripPrefix ( this ) }
232
+
233
+ /** Gets the path obtained by removing `prefix` from this path. */
234
+ bindingset [ this , prefix]
235
+ TypePath stripPrefix ( TypePath prefix ) {
236
+ if prefix .isEmpty ( )
237
+ then result = this
238
+ else (
239
+ this = prefix and
240
+ result .isEmpty ( )
241
+ or
242
+ this = prefix + "." + result
243
+ )
242
244
}
243
245
244
246
/** Holds if this path starts with `tp`, followed by `suffix`. */
245
247
bindingset [ this ]
246
- predicate isCons ( TypeParameter tp , TypePath suffix ) { this = TypePath:: consInverse ( tp , suffix ) }
248
+ predicate isCons ( TypeParameter tp , TypePath suffix ) {
249
+ suffix = this .stripPrefix ( TypePath:: singleton ( tp ) )
250
+ }
247
251
}
248
252
249
253
/** Provides predicates for constructing `TypePath`s. */
@@ -260,15 +264,6 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
260
264
*/
261
265
bindingset [ suffix]
262
266
TypePath cons ( TypeParameter tp , TypePath suffix ) { result = singleton ( tp ) .append ( suffix ) }
263
-
264
- /**
265
- * Gets the type path obtained by appending the singleton type path `tp`
266
- * onto `suffix`.
267
- */
268
- bindingset [ result ]
269
- TypePath consInverse ( TypeParameter tp , TypePath suffix ) {
270
- result = singleton ( tp ) .appendInverse ( suffix )
271
- }
272
267
}
273
268
274
269
/**
0 commit comments