@@ -184,7 +184,7 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
184184 /** Gets the length of this path, assuming the length is at least 2. */
185185 bindingset [ this ]
186186 pragma [ inline_late]
187- private int length2 ( ) {
187+ private int lengthAtLeast2 ( ) {
188188 // Same as
189189 // `result = strictcount(this.indexOf(".")) + 1`
190190 // but performs better because it doesn't use an aggregate
@@ -200,7 +200,7 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
200200 else
201201 if exists ( TypeParameter:: decode ( this ) )
202202 then result = 1
203- else result = this .length2 ( )
203+ else result = this .lengthAtLeast2 ( )
204204 }
205205
206206 /** Gets the path obtained by appending `suffix` onto this path. */
@@ -216,7 +216,7 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
216216 (
217217 not exists ( getTypePathLimit ( ) )
218218 or
219- result .length2 ( ) <= getTypePathLimit ( )
219+ result .lengthAtLeast2 ( ) <= getTypePathLimit ( )
220220 )
221221 )
222222 }
@@ -228,22 +228,26 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
228228 * so there is no need to check the length of `result`.
229229 */
230230 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+ )
242244 }
243245
244246 /** Holds if this path starts with `tp`, followed by `suffix`. */
245247 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+ }
247251 }
248252
249253 /** Provides predicates for constructing `TypePath`s. */
@@ -260,15 +264,6 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
260264 */
261265 bindingset [ suffix]
262266 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- }
272267 }
273268
274269 /**
0 commit comments