56
56
* the type is related to the `foo` package but is not intended to match a static type.
57
57
*/
58
58
59
- private import Impl as Impl
60
- import AccessPathSyntax
59
+ private import ApiGraphModelsSpecific as Specific
61
60
62
- private class Unit = Impl :: Unit ;
61
+ private class Unit = Specific :: Unit ;
63
62
64
- private module API = Impl:: API;
63
+ private module API = Specific:: API;
64
+
65
+ private import Specific:: AccessPathSyntax
65
66
66
67
/** Module containing hooks for providing input data to be interpreted as a model. */
67
68
module ModelInput {
@@ -230,7 +231,7 @@ string getAPackageAlias(string package) {
230
231
* Holds if CSV rows involving `package` might be relevant for the analysis of this database.
231
232
*/
232
233
private predicate isRelevantPackage ( string package ) {
233
- Impl :: isPackageUsed ( package )
234
+ Specific :: isPackageUsed ( package )
234
235
or
235
236
exists ( string other |
236
237
isRelevantPackage ( other ) and
@@ -268,28 +269,25 @@ private class AccessPathRange extends AccessPath::Range {
268
269
* Gets a successor of `node` in the API graph.
269
270
*/
270
271
bindingset [ token]
271
- private API:: Node getSuccessorFromNode ( API:: Node node , AccessPathToken token ) {
272
+ API:: Node getSuccessorFromNode ( API:: Node node , AccessPathToken token ) {
272
273
// API graphs use the same label for arguments and parameters. An edge originating from a
273
274
// use-node represents be an argument, and an edge originating from a def-node represents a parameter.
274
275
// We just map both to the same thing.
275
276
token .getName ( ) = [ "Argument" , "Parameter" ] and
276
277
result = node .getParameter ( getAnIntFromStringUnbounded ( token .getAnArgument ( ) ) )
277
278
or
278
- token .getName ( ) = "Member" and
279
- result = node .getMember ( token .getAnArgument ( ) )
280
- or
281
279
token .getName ( ) = "ReturnValue" and
282
280
result = node .getReturn ( )
283
281
or
284
282
// Language-specific tokens
285
- result = Impl :: getExtraSuccessorFromNode ( node , token )
283
+ result = Specific :: getExtraSuccessorFromNode ( node , token )
286
284
}
287
285
288
286
/**
289
287
* Gets an API-graph successor for the given invocation.
290
288
*/
291
289
bindingset [ token]
292
- private API:: Node getSuccessorFromInvoke ( API :: InvokeNode invoke , AccessPathToken token ) {
290
+ API:: Node getSuccessorFromInvoke ( Specific :: InvokeNode invoke , AccessPathToken token ) {
293
291
token .getName ( ) = "Argument" and
294
292
(
295
293
result = invoke .getParameter ( getAnIntFromStringUnbounded ( token .getAnArgument ( ) ) )
@@ -303,18 +301,18 @@ private API::Node getSuccessorFromInvoke(API::InvokeNode invoke, AccessPathToken
303
301
result = invoke .getReturn ( )
304
302
or
305
303
// Language-specific tokens
306
- result = Impl :: getExtraSuccessorFromInvoke ( invoke , token )
304
+ result = Specific :: getExtraSuccessorFromInvoke ( invoke , token )
307
305
}
308
306
309
307
/**
310
308
* Holds if `invoke` invokes a call-site filter given by `token`.
311
309
*/
312
310
pragma [ inline]
313
- private predicate invocationMatchesCallSiteFilter ( API :: InvokeNode invoke , AccessPathToken token ) {
311
+ private predicate invocationMatchesCallSiteFilter ( Specific :: InvokeNode invoke , AccessPathToken token ) {
314
312
token .getName ( ) = "WithArity" and
315
313
invoke .getNumArgument ( ) = getAnIntFromStringUnbounded ( token .getAnArgument ( ) )
316
314
or
317
- Impl :: invocationMatchesExtraCallSiteFilter ( invoke , token )
315
+ Specific :: invocationMatchesExtraCallSiteFilter ( invoke , token )
318
316
}
319
317
320
318
/**
@@ -324,18 +322,14 @@ pragma[nomagic]
324
322
API:: Node getNodeFromPath ( string package , string type , AccessPath path , int n ) {
325
323
isRelevantFullPath ( package , type , path ) and
326
324
(
327
- type = "" and
328
- n = 0 and
329
- result = API:: moduleImport ( package )
330
- or
331
325
n = 0 and
332
326
exists ( string package2 , string type2 , AccessPath path2 |
333
327
typeModel ( package , type , package2 , type2 , path2 ) and
334
328
result = getNodeFromPath ( package2 , type2 , path2 , path2 .getNumToken ( ) )
335
329
)
336
330
or
337
331
// Language-specific cases, such as handling of global variables
338
- result = Impl :: getExtraNodeFromPath ( package , type , path , n )
332
+ result = Specific :: getExtraNodeFromPath ( package , type , path , n )
339
333
)
340
334
or
341
335
result = getSuccessorFromNode ( getNodeFromPath ( package , type , path , n - 1 ) , path .getToken ( n - 1 ) )
@@ -355,62 +349,18 @@ API::Node getNodeFromPath(string package, string type, AccessPath path) {
355
349
*
356
350
* Unlike `getNodeFromPath`, the `path` may end with one or more call-site filters.
357
351
*/
358
- API :: InvokeNode getInvocationFromPath ( string package , string type , AccessPath path , int n ) {
359
- result = getNodeFromPath ( package , type , path , n ) . getAnInvocation ( )
352
+ Specific :: InvokeNode getInvocationFromPath ( string package , string type , AccessPath path , int n ) {
353
+ result = Specific :: getAnInvocationOf ( getNodeFromPath ( package , type , path , n ) )
360
354
or
361
355
result = getInvocationFromPath ( package , type , path , n - 1 ) and
362
356
invocationMatchesCallSiteFilter ( result , path .getToken ( n - 1 ) )
363
357
}
364
358
365
359
/** Gets an invocation identified by the given `(package, type, path)` tuple. */
366
- API :: InvokeNode getInvocationFromPath ( string package , string type , AccessPath path ) {
360
+ Specific :: InvokeNode getInvocationFromPath ( string package , string type , AccessPath path ) {
367
361
result = getInvocationFromPath ( package , type , path , path .getNumToken ( ) )
368
362
}
369
363
370
- /**
371
- * Holds if a summary edge with the given `input, output, kind` columns have a `package, type, path` tuple
372
- * that resolves to `baseNode`.
373
- */
374
- private predicate resolvedSummaryBase (
375
- API:: InvokeNode baseNode , AccessPath input , AccessPath output , string kind
376
- ) {
377
- exists ( string package , string type , AccessPath path |
378
- summaryModel ( package , type , path , input , output , kind ) and
379
- baseNode = getInvocationFromPath ( package , type , path )
380
- )
381
- }
382
-
383
- /**
384
- * Holds if `path` is an input or output spec for a summary with the given `base` node.
385
- */
386
- pragma [ nomagic]
387
- private predicate relevantInputOutputPath ( API:: InvokeNode base , AccessPath path ) {
388
- resolvedSummaryBase ( base , path , _, _)
389
- or
390
- resolvedSummaryBase ( base , _, path , _)
391
- }
392
-
393
- /**
394
- * Gets the API node for the first `n` tokens of the given input/output path, evaluated relative to `baseNode`.
395
- */
396
- private API:: Node getNodeFromInputOutputPath ( API:: InvokeNode baseNode , AccessPath path , int n ) {
397
- relevantInputOutputPath ( baseNode , path ) and
398
- (
399
- n = 1 and
400
- result = getSuccessorFromInvoke ( baseNode , path .getToken ( 0 ) )
401
- or
402
- result =
403
- getSuccessorFromNode ( getNodeFromInputOutputPath ( baseNode , path , n - 1 ) , path .getToken ( n - 1 ) )
404
- )
405
- }
406
-
407
- /**
408
- * Gets the API node for the given input/output path, evaluated relative to `baseNode`.
409
- */
410
- private API:: Node getNodeFromInputOutputPath ( API:: InvokeNode baseNode , AccessPath path ) {
411
- result = getNodeFromInputOutputPath ( baseNode , path , path .getNumToken ( ) )
412
- }
413
-
414
364
/**
415
365
* Convenience-predicate for extracting two capture groups at once.
416
366
*/
@@ -519,13 +469,25 @@ module ModelOutput {
519
469
}
520
470
521
471
/**
522
- * Holds if a CSV summary contributed the step `pred -> succ` of the given `kind`.
472
+ * Holds if a relevant CSV summary row has the given `kind`, `input` and `output`.
473
+ */
474
+ predicate summaryModel ( string input , string output , string kind ) {
475
+ exists ( string package |
476
+ isRelevantPackage ( package ) and
477
+ summaryModel ( package , _, _, input , output , kind )
478
+ )
479
+ }
480
+
481
+ /**
482
+ * Holds if a summary edge with the given `input, output, kind` columns have a `package, type, path` tuple
483
+ * that resolves to `baseNode`.
523
484
*/
524
- predicate summaryStep ( API:: Node pred , API:: Node succ , string kind ) {
525
- exists ( API:: InvokeNode base , AccessPath input , AccessPath output |
526
- resolvedSummaryBase ( base , input , output , kind ) and
527
- pred = getNodeFromInputOutputPath ( base , input ) and
528
- succ = getNodeFromInputOutputPath ( base , output )
485
+ predicate resolvedSummaryBase (
486
+ Specific:: InvokeNode baseNode , AccessPath input , AccessPath output , string kind
487
+ ) {
488
+ exists ( string package , string type , AccessPath path |
489
+ summaryModel ( package , type , path , input , output , kind ) and
490
+ baseNode = getInvocationFromPath ( package , type , path )
529
491
)
530
492
}
531
493
0 commit comments