Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 61523bd

Browse files
authored
python: better names
- "Normal" instead of "NonSpecial" - "NonLibrary" instead of "2" I could not find a good replacement for "NonLibrary", nor for "Source", but I added QLDocs in a few places to help the reading.
1 parent a0db438 commit 61523bd

4 files changed

Lines changed: 40 additions & 30 deletions

File tree

python/ql/lib/semmle/python/dataflow/new/internal/DataFlowDispatchPointsTo.qll

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,10 @@ module ArgumentPassing {
103103
* Used to limit the size of predicates.
104104
*/
105105
predicate connects(CallNode call, CallableValue callable) {
106-
exists(NonLibraryDataFlowSourceCall c, NonLibraryDataFlowCallable k |
106+
exists(NonLibraryNormalCall c, NonLibraryDataFlowCallable k |
107107
call = c.getNode() and
108108
callable = k.getCallableValue() and
109-
k = c.getCallable2()
109+
k = c.getNonLibraryCallable()
110110
)
111111
}
112112

@@ -438,7 +438,7 @@ newtype TDataFlowCall =
438438
* Includes function calls, method calls, class calls and library calls.
439439
* All these will be associated with a `CallNode`.
440440
*/
441-
TNonSpecialCall(CallNode call) or
441+
TNormalCall(CallNode call) or
442442
/**
443443
* Includes calls to special methods.
444444
* These will be associated with a `SpecialMethodCallNode`.
@@ -449,7 +449,8 @@ newtype TDataFlowCall =
449449
FlowSummaryImpl::Private::summaryCallbackRange(c, receiver)
450450
}
451451

452-
class TDataFlowSourceCall = TSpecialCall or TNonSpecialCall;
452+
/** A call found in the program source (as opposed to a synthesised summary call). */
453+
class TDataFlowSourceCall = TSpecialCall or TNormalCall;
453454

454455
/** A call that is taken into account by the global data flow computation. */
455456
abstract class DataFlowCall extends TDataFlowCall {
@@ -500,10 +501,10 @@ abstract class DataFlowSourceCall extends DataFlowCall, TDataFlowSourceCall {
500501
}
501502

502503
/** A call associated with a `CallNode`. */
503-
class NonSpecialCall extends DataFlowSourceCall, TNonSpecialCall {
504+
class NormalCall extends DataFlowSourceCall, TNormalCall {
504505
CallNode call;
505506

506-
NonSpecialCall() { this = TNonSpecialCall(call) }
507+
NormalCall() { this = TNormalCall(call) }
507508

508509
override string toString() { result = call.toString() }
509510

@@ -516,14 +517,15 @@ class NonSpecialCall extends DataFlowSourceCall, TNonSpecialCall {
516517
override DataFlowCallable getEnclosingCallable() { result.getScope() = call.getNode().getScope() }
517518
}
518519

519-
abstract class NonLibraryDataFlowSourceCall extends NonSpecialCall {
520-
abstract Node getArg2(int n);
520+
/** A (non-special) call that does not go to a library callable. */
521+
abstract class NonLibraryNormalCall extends NormalCall {
522+
abstract Node getNonLibraryArg(int n);
521523

522-
final override Node getArg(int n) { result = this.getArg2(n) }
524+
final override Node getArg(int n) { result = this.getNonLibraryArg(n) }
523525

524-
abstract DataFlowCallable getCallable2();
526+
abstract DataFlowCallable getNonLibraryCallable();
525527

526-
final override DataFlowCallable getCallable() { result = this.getCallable2() }
528+
final override DataFlowCallable getCallable() { result = this.getNonLibraryCallable() }
527529
}
528530

529531
/**
@@ -532,51 +534,57 @@ abstract class NonLibraryDataFlowSourceCall extends NonSpecialCall {
532534
* Bound method calls and class calls insert an argument for the explicit
533535
* `self` parameter, and special method calls have special argument passing.
534536
*/
535-
class FunctionCall extends NonLibraryDataFlowSourceCall {
537+
class FunctionCall extends NonLibraryNormalCall {
536538
NonLibraryDataFlowCallable callable;
537539

538540
FunctionCall() {
539541
call = any(FunctionValue f).getAFunctionCall() and
540542
call = callable.getACall()
541543
}
542544

543-
override Node getArg2(int n) { result = getArg(call, TNoShift(), callable.getCallableValue(), n) }
545+
override Node getNonLibraryArg(int n) {
546+
result = getArg(call, TNoShift(), callable.getCallableValue(), n)
547+
}
544548

545-
override DataFlowCallable getCallable2() { result = callable }
549+
override DataFlowCallable getNonLibraryCallable() { result = callable }
546550
}
547551

548552
/** A call to a lambda. */
549-
class LambdaCall extends NonLibraryDataFlowSourceCall {
553+
class LambdaCall extends NonLibraryNormalCall {
550554
NonLibraryDataFlowCallable callable;
551555

552556
LambdaCall() {
553557
call = callable.getACall() and
554558
callable = TLambda(any(Function f))
555559
}
556560

557-
override Node getArg2(int n) { result = getArg(call, TNoShift(), callable.getCallableValue(), n) }
561+
override Node getNonLibraryArg(int n) {
562+
result = getArg(call, TNoShift(), callable.getCallableValue(), n)
563+
}
558564

559-
override DataFlowCallable getCallable2() { result = callable }
565+
override DataFlowCallable getNonLibraryCallable() { result = callable }
560566
}
561567

562568
/**
563569
* Represents a call to a bound method call.
564570
* The node representing the instance is inserted as argument to the `self` parameter.
565571
*/
566-
class MethodCall extends NonLibraryDataFlowSourceCall {
572+
class MethodCall extends NonLibraryNormalCall {
567573
FunctionValue bm;
568574

569575
MethodCall() { call = bm.getAMethodCall() }
570576

571577
private CallableValue getCallableValue() { result = bm }
572578

573-
override Node getArg2(int n) {
579+
override Node getNonLibraryArg(int n) {
574580
n > 0 and result = getArg(call, TShiftOneUp(), this.getCallableValue(), n)
575581
or
576582
n = 0 and result = TCfgNode(call.getFunction().(AttrNode).getObject())
577583
}
578584

579-
override DataFlowCallable getCallable2() { result = TCallableValue(this.getCallableValue()) }
585+
override DataFlowCallable getNonLibraryCallable() {
586+
result = TCallableValue(this.getCallableValue())
587+
}
580588
}
581589

582590
/**
@@ -585,7 +593,7 @@ class MethodCall extends NonLibraryDataFlowSourceCall {
585593
* That makes the call node be the post-update node holding the value of the object
586594
* after the constructor has run.
587595
*/
588-
class ClassCall extends NonLibraryDataFlowSourceCall {
596+
class ClassCall extends NonLibraryNormalCall {
589597
ClassValue c;
590598

591599
ClassCall() {
@@ -595,13 +603,15 @@ class ClassCall extends NonLibraryDataFlowSourceCall {
595603

596604
private CallableValue getCallableValue() { c.getScope().getInitMethod() = result.getScope() }
597605

598-
override Node getArg2(int n) {
606+
override Node getNonLibraryArg(int n) {
599607
n > 0 and result = getArg(call, TShiftOneUp(), this.getCallableValue(), n)
600608
or
601609
n = 0 and result = TSyntheticPreUpdateNode(TCfgNode(call))
602610
}
603611

604-
override DataFlowCallable getCallable2() { result = TCallableValue(this.getCallableValue()) }
612+
override DataFlowCallable getNonLibraryCallable() {
613+
result = TCallableValue(this.getCallableValue())
614+
}
605615
}
606616

607617
/** A call to a special method. */
@@ -626,7 +636,7 @@ class SpecialCall extends DataFlowSourceCall, TSpecialCall {
626636
}
627637

628638
/** A call to a summarized callable. */
629-
class LibraryCall extends NonSpecialCall {
639+
class LibraryCall extends NormalCall {
630640
LibraryCallable callable;
631641

632642
LibraryCall() { call.getNode() = callable.getACall() }

python/ql/lib/semmle/python/dataflow/new/internal/DataFlowPrivate.qll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,15 +137,15 @@ module SyntheticPostUpdateNode {
137137
* and should not have an extra node synthesised.
138138
*/
139139
Node argumentPreUpdateNode() {
140-
result = any(FunctionCall c).getArg2(_)
140+
result = any(FunctionCall c).getNonLibraryArg(_)
141141
or
142142
// Avoid argument 0 of method calls as those have read post-update nodes.
143-
exists(MethodCall c, int n | n > 0 | result = c.getArg2(n))
143+
exists(MethodCall c, int n | n > 0 | result = c.getNonLibraryArg(n))
144144
or
145145
result = any(SpecialCall c).getArg(_)
146146
or
147147
// Avoid argument 0 of class calls as those have non-synthetic post-update nodes.
148-
exists(ClassCall c, int n | n > 0 | result = c.getArg2(n))
148+
exists(ClassCall c, int n | n > 0 | result = c.getNonLibraryArg(n))
149149
or
150150
// any argument of any call that we have not been able to resolve
151151
exists(CallNode call | not resolvedCall(call) |

python/ql/test/experimental/dataflow/TestUtil/UnresolvedCalls.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class UnresolvedCallExpectations extends InlineExpectationsTest {
1313
exists(location.getFile().getRelativePath()) and
1414
exists(CallNode call |
1515
not exists(DataFlowPrivate::DataFlowCall dfc | dfc.getNode() = call |
16-
// For every `CallNode`, there is a `DataFlowCall` in the form of a `NonSpecialCall`.
16+
// For every `CallNode`, there is a `DataFlowCall` in the form of a `NormalCall`.
1717
// It does not really count, as it has some abstract overrides. For instance, it does not
1818
// define `getCallable`, so checking for the existence of this guarantees that we are in a
1919
// properly resolved call.

python/ql/test/experimental/dataflow/calls/test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def __getitem__(self, key):
3131
# `mypkg.foo` is a `missing module variable`, but `mypkg.subpkg.bar` is compeltely
3232
# ignored.
3333
import mypkg
34-
mypkg.foo(42) # $ call=mypkg.foo(..) qlclass=NonSpecialCall
35-
mypkg.subpkg.bar(43) # $ call=mypkg.subpkg.bar(..) qlclass=NonSpecialCall
34+
mypkg.foo(42) # $ call=mypkg.foo(..) qlclass=NormalCall
35+
mypkg.subpkg.bar(43) # $ call=mypkg.subpkg.bar(..) qlclass=NormalCall
3636
except:
3737
pass

0 commit comments

Comments
 (0)