@@ -357,45 +357,47 @@ private module ArgumentPassing {
357357 /**
358358 * A type representing a mapping from argument indices to parameter indices.
359359 * We currently use two mappings: NoShift, the identity, used for ordinary
360- * function calls, and ShiftOne which is used for calls where an extra argument
360+ * function calls, and ShiftOneUp which is used for calls where an extra argument
361361 * is inserted. These include method calls, constructor calls and class calls.
362362 * In these calls, the argument at index `n` is mapped to the parameter at position `n+1`.
363363 */
364364 newtype TArgParamMapping =
365365 TNoShift ( ) or
366- TShiftOne ( )
366+ TShiftOneUp ( )
367367
368368 /** A mapping used for parameter passing. */
369369 abstract class ArgParamMapping extends TArgParamMapping {
370- bindingset [ result ]
371- abstract int getArgN ( int paramN ) ;
370+ /** Gets the index of the parameter that corresponds to the argument at index `argN`. */
371+ bindingset [ argN]
372+ abstract int getParamN ( int argN ) ;
372373
373- string toString ( ) { none ( ) }
374+ /** Gets a textual representation of this element. */
375+ string toString ( ) { result = "ArgParamMapping" }
374376 }
375377
376378 /** A mapping that passes argument `n` to parameter `n`. */
377379 class NoShift extends ArgParamMapping , TNoShift {
378380 NoShift ( ) { this = TNoShift ( ) }
379381
380- bindingset [ result ]
381- override int getArgN ( int paramN ) { result = paramN }
382+ bindingset [ argN ]
383+ override int getParamN ( int argN ) { result = argN }
382384 }
383385
384386 /** A mapping that passes argument `n` to parameter `n+1`. */
385- class ShiftOne extends ArgParamMapping , TShiftOne {
386- ShiftOne ( ) { this = TShiftOne ( ) }
387+ class ShiftOneUp extends ArgParamMapping , TShiftOneUp {
388+ ShiftOneUp ( ) { this = TShiftOneUp ( ) }
387389
388- bindingset [ result ]
389- override int getArgN ( int paramN ) { result = paramN - 1 }
390+ bindingset [ argN ]
391+ override int getParamN ( int argN ) { result = argN + 1 }
390392 }
391393
392394 /**
393395 * Gets the node representing the argument to `call` that is passed to the parameter at
394396 * (zero-based) index `paramN` in `callable`. If this is a positional argument, it must appear
395- * at index `mapping.getArgN(paramN)` in `call`.
397+ * at an index, `argN`, in `call` wich satisfies `paramN = mapping.getParamN(argN) `.
396398 *
397- * `mapping.getArgN(paramN) ` will differ from `paramN` for method- or constructor calls, where the first parameter
398- * is `self` and the first positional argument is passed to the second positional parameter.
399+ * `mapping` will be the identity for function calls, but not for method- or constructor calls,
400+ * where the first parameter is `self` and the first positional argument is passed to the second positional parameter.
399401 * Similarly for classmethod calls, where the first parameter is `cls`.
400402 *
401403 * NOT SUPPORTED: Keyword-only parameters.
@@ -404,7 +406,10 @@ private module ArgumentPassing {
404406 connects ( call , callable ) and
405407 (
406408 // positional argument
407- result = TCfgNode ( call .getArg ( mapping .getArgN ( paramN ) ) )
409+ exists ( int argN |
410+ paramN = mapping .getParamN ( argN ) and
411+ result = TCfgNode ( call .getArg ( argN ) )
412+ )
408413 or
409414 // keyword argument
410415 // TODO: Since `getArgName` have no results for keyword-only parameters,
@@ -467,7 +472,7 @@ private module ArgumentPassing {
467472 connects ( call , callable ) and
468473 exists ( Function f |
469474 f = callable .getScope ( ) and
470- not exists ( call .getArg ( mapping . getArgN ( paramN ) ) ) and // no positional argument available
475+ not exists ( int argN | paramN = mapping . getParamN ( argN ) | exists ( call .getArg ( argN ) ) ) and // no positional argument available
471476 name = f .getArgName ( paramN ) and
472477 // not exists(call.getArgByName(name)) and // only matches keyword arguments not preceded by **
473478 // TODO: make the below logic respect control flow splitting (by not going to the AST).
@@ -643,7 +648,7 @@ class MethodCall extends DataFlowCall, TMethodCall {
643648 override string toString ( ) { result = call .toString ( ) }
644649
645650 override Node getArg ( int n ) {
646- n > 0 and result = getArg ( call , TShiftOne ( ) , this .getCallableValue ( ) , n )
651+ n > 0 and result = getArg ( call , TShiftOneUp ( ) , this .getCallableValue ( ) , n )
647652 or
648653 n = 0 and result = TCfgNode ( call .getFunction ( ) .( AttrNode ) .getObject ( ) )
649654 }
@@ -675,7 +680,7 @@ class ClassCall extends DataFlowCall, TClassCall {
675680 override string toString ( ) { result = call .toString ( ) }
676681
677682 override Node getArg ( int n ) {
678- n > 0 and result = getArg ( call , TShiftOne ( ) , this .getCallableValue ( ) , n )
683+ n > 0 and result = getArg ( call , TShiftOneUp ( ) , this .getCallableValue ( ) , n )
679684 or
680685 n = 0 and result = TSyntheticPreUpdateNode ( TCfgNode ( call ) )
681686 }
0 commit comments