@@ -274,7 +274,7 @@ API::Node getSuccessorFromNode(API::Node node, AccessPathToken token) {
274
274
// use-node represents be an argument, and an edge originating from a def-node represents a parameter.
275
275
// We just map both to the same thing.
276
276
token .getName ( ) = [ "Argument" , "Parameter" ] and
277
- result = node .getParameter ( getAnIntFromStringUnbounded ( token .getAnArgument ( ) ) )
277
+ result = node .getParameter ( AccessPath :: parseIntUnbounded ( token .getAnArgument ( ) ) )
278
278
or
279
279
token .getName ( ) = "ReturnValue" and
280
280
result = node .getReturn ( )
@@ -289,13 +289,9 @@ API::Node getSuccessorFromNode(API::Node node, AccessPathToken token) {
289
289
bindingset [ token]
290
290
API:: Node getSuccessorFromInvoke ( Specific:: InvokeNode invoke , AccessPathToken token ) {
291
291
token .getName ( ) = "Argument" and
292
- (
293
- result = invoke .getParameter ( getAnIntFromStringUnbounded ( token .getAnArgument ( ) ) )
294
- or
295
- result =
296
- invoke
297
- .getParameter ( getAnIntFromStringWithArity ( token .getAnArgument ( ) , invoke .getNumArgument ( ) ) )
298
- )
292
+ result =
293
+ invoke
294
+ .getParameter ( AccessPath:: parseIntWithArity ( token .getAnArgument ( ) , invoke .getNumArgument ( ) ) )
299
295
or
300
296
token .getName ( ) = "ReturnValue" and
301
297
result = invoke .getReturn ( )
@@ -310,7 +306,7 @@ API::Node getSuccessorFromInvoke(Specific::InvokeNode invoke, AccessPathToken to
310
306
pragma [ inline]
311
307
private predicate invocationMatchesCallSiteFilter ( Specific:: InvokeNode invoke , AccessPathToken token ) {
312
308
token .getName ( ) = "WithArity" and
313
- invoke .getNumArgument ( ) = getAnIntFromStringUnbounded ( token .getAnArgument ( ) )
309
+ invoke .getNumArgument ( ) = AccessPath :: parseIntUnbounded ( token .getAnArgument ( ) )
314
310
or
315
311
Specific:: invocationMatchesExtraCallSiteFilter ( invoke , token )
316
312
}
@@ -361,89 +357,6 @@ Specific::InvokeNode getInvocationFromPath(string package, string type, AccessPa
361
357
result = getInvocationFromPath ( package , type , path , path .getNumToken ( ) )
362
358
}
363
359
364
- /**
365
- * Convenience-predicate for extracting two capture groups at once.
366
- */
367
- bindingset [ input, regexp]
368
- private predicate regexpCaptureTwo ( string input , string regexp , string capture1 , string capture2 ) {
369
- capture1 = input .regexpCapture ( regexp , 1 ) and
370
- capture2 = input .regexpCapture ( regexp , 2 )
371
- }
372
-
373
- /**
374
- * Parses an integer constant `n` or interval `n1..n2` (inclusive) and gets the value
375
- * of the constant or any value contained in the interval.
376
- */
377
- bindingset [ arg]
378
- private int getAnIntFromString ( string arg ) {
379
- result = arg .toInt ( )
380
- or
381
- // Match "n1..n2"
382
- exists ( string lo , string hi |
383
- regexpCaptureTwo ( arg , "(\\d+)\\.\\.(\\d+)" , lo , hi ) and
384
- result = [ lo .toInt ( ) .. hi .toInt ( ) ]
385
- )
386
- }
387
-
388
- /**
389
- * Parses a lower-bounded interval `n..` and gets the lower bound.
390
- */
391
- bindingset [ arg]
392
- private int getLowerBoundFromString ( string arg ) {
393
- // Match "n.."
394
- result = arg .regexpCapture ( "(\\d+)\\.\\." , 1 ) .toInt ( )
395
- }
396
-
397
- /**
398
- * Parses an integer constant or interval (bounded or unbounded) and gets any
399
- * of the integers contained within (of which there may be infinitely many).
400
- *
401
- * Has no result for arguments involving an explicit arity, such as `N-1`.
402
- */
403
- bindingset [ arg, result ]
404
- private int getAnIntFromStringUnbounded ( string arg ) {
405
- result = getAnIntFromString ( arg )
406
- or
407
- result >= getLowerBoundFromString ( arg )
408
- }
409
-
410
- /**
411
- * Parses an integer constant or interval (bounded or unbounded) that explicitly
412
- * references the arity, such as `N-1` or `N-3..N-1`.
413
- *
414
- * Note that such expressions will never resolve to a negative index, even if the
415
- * arity is zero (it will have no result in that case).
416
- */
417
- bindingset [ arg, arity]
418
- private int getAnIntFromStringWithArity ( string arg , int arity ) {
419
- result >= 0 and // do not allow N-1 to resolve to a negative index
420
- exists ( string lo |
421
- // N-x
422
- lo = arg .regexpCapture ( "N-(\\d+)" , 1 ) and
423
- result = arity - lo .toInt ( )
424
- or
425
- // N-x..
426
- lo = arg .regexpCapture ( "N-(\\d+)\\.\\." , 1 ) and
427
- result = [ arity - lo .toInt ( ) , arity - 1 ]
428
- )
429
- or
430
- exists ( string lo , string hi |
431
- // x..N-y
432
- regexpCaptureTwo ( arg , "(\\d+)\\.\\.N-(\\d+)" , lo , hi ) and
433
- result = [ lo .toInt ( ) .. arity - hi .toInt ( ) ]
434
- or
435
- // N-x..Ny
436
- regexpCaptureTwo ( arg , "N-(\\d+)\\.\\.N-(\\d+)" , lo , hi ) and
437
- result = [ arity - lo .toInt ( ) .. arity - hi .toInt ( ) ] and
438
- result >= 0
439
- or
440
- // N-x..y
441
- regexpCaptureTwo ( arg , "N-(\\d+)\\.\\.(\\d+)" , lo , hi ) and
442
- result = [ arity - lo .toInt ( ) .. hi .toInt ( ) ] and
443
- result >= 0
444
- )
445
- }
446
-
447
360
/**
448
361
* Module providing access to the imported models in terms of API graph nodes.
449
362
*/
0 commit comments