Skip to content

Commit 478cfd7

Browse files
committed
Python: Small clean-up
1 parent f449da2 commit 478cfd7

File tree

1 file changed

+23
-23
lines changed

1 file changed

+23
-23
lines changed

python/ql/src/experimental/dataflow/internal/DataFlowPrivate.qll

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ class ArgumentPreUpdateNode extends NeedsSyntheticPostUpdateNode, ArgumentNode {
4848
// Certain arguments, such as implicit self arguments are already post-update nodes
4949
// and should not have an extra node synthesised.
5050
ArgumentPreUpdateNode() {
51-
this = any(CallNodeCall c).getArg(_)
51+
this = any(FunctionCall c).getArg(_)
5252
or
53-
// this = any(BoundMethodCall c).getArg(_)
54-
exists(BoundMethodCall c, int n | n > 0 | this = c.getArg(n))
53+
// Avoid argument 0 of method calls as those have read post-update nodes.
54+
exists(MethodCall c, int n | n > 0 | this = c.getArg(n))
5555
or
5656
this = any(SpecialCall c).getArg(_)
5757
or
@@ -311,6 +311,17 @@ private Node update(Node node) {
311311
* a clearing of content at key `y` for node `[**d]`, since that value has been unpacked.
312312
*/
313313
module ArgumentPassing {
314+
/**
315+
* Holds if `call` is a call to `callable`.
316+
* Used to limit the size of predicates.
317+
*/
318+
predicate connects(CallNode call, CallableValue callable) {
319+
exists(DataFlowCall c |
320+
call = c.getNode() and
321+
callable = c.getCallable().getCallableValue()
322+
)
323+
}
324+
314325
/**
315326
* Gets the `n`th parameter of `callable`.
316327
* If the callable has a starred parameter, say `*tuple`, that is matched with `n=-1`.
@@ -320,12 +331,8 @@ module ArgumentPassing {
320331
*/
321332
NameNode getParameter(CallableValue callable, int n) {
322333
// positional parameter
323-
// bound method values have their positional parameters shifted.
324-
not callable instanceof BoundMethodValue and
325334
result = callable.getParameter(n)
326335
or
327-
result = callable.(BoundMethodValue).getParameter(n - 1)
328-
or
329336
// starred parameter, `*tuple`
330337
exists(Function f |
331338
f = callable.getScope() and
@@ -341,13 +348,6 @@ module ArgumentPassing {
341348
)
342349
}
343350

344-
predicate connects(CallNode call, CallableValue callable) {
345-
exists(DataFlowCall c |
346-
call = c.getNode() and
347-
callable = c.getCallable().getCallableValue()
348-
)
349-
}
350-
351351
/**
352352
* Gets the argument to `call` that is passed to the `n`th parameter of `callable`.
353353
* If it is a positional argument, it must appear at position `argNr`.
@@ -435,7 +435,7 @@ import ArgumentPassing
435435
/**
436436
* IPA type for DataFlowCallable.
437437
*
438-
* A callable is either a callable value or a module (for enclosing `ModuleVariableNode`s).
438+
* A callable is either a function value, a class value, or a module (for enclosing `ModuleVariableNode`s).
439439
* A module has no calls.
440440
*/
441441
newtype TDataFlowCallable =
@@ -518,9 +518,9 @@ class DataFlowModuleScope extends DataFlowCallable, TModule {
518518
* A call corresponding to a special method call is handled by the corresponding `SpecialMethodCallNode`.
519519
*/
520520
newtype TDataFlowCall =
521-
TCallNode(CallNode call) { call = any(FunctionValue f).getAFunctionCall() } or
521+
TFunctionCall(CallNode call) { call = any(FunctionValue f).getAFunctionCall() } or
522522
/** Bound methods need to make room for the explicit self parameter */
523-
TBoundMethodCall(CallNode call) { call = any(FunctionValue f).getAMethodCall() } or
523+
TMethodCall(CallNode call) { call = any(FunctionValue f).getAMethodCall() } or
524524
TClassCall(CallNode call) { call = any(ClassValue c).getACall() } or
525525
TSpecialCall(SpecialMethodCallNode special)
526526

@@ -554,12 +554,12 @@ abstract class DataFlowCall extends TDataFlowCall {
554554
* Bound method calls and class calls insert an argument for the explicit
555555
* `self` parameter, and special method calls have special argument passing.
556556
*/
557-
class CallNodeCall extends DataFlowCall, TCallNode {
557+
class FunctionCall extends DataFlowCall, TFunctionCall {
558558
CallNode call;
559559
DataFlowCallable callable;
560560

561-
CallNodeCall() {
562-
this = TCallNode(call) and
561+
FunctionCall() {
562+
this = TFunctionCall(call) and
563563
call = callable.getACall()
564564
}
565565

@@ -578,12 +578,12 @@ class CallNodeCall extends DataFlowCall, TCallNode {
578578
* Represents a call to a bound method call.
579579
* The node representing the instance is inserted as argument to the `self` parameter.
580580
*/
581-
class BoundMethodCall extends DataFlowCall, TBoundMethodCall {
581+
class MethodCall extends DataFlowCall, TMethodCall {
582582
CallNode call;
583583
FunctionValue bm;
584584

585-
BoundMethodCall() {
586-
this = TBoundMethodCall(call) and
585+
MethodCall() {
586+
this = TMethodCall(call) and
587587
call = bm.getACall()
588588
}
589589

0 commit comments

Comments
 (0)