Skip to content

Commit 8cbd497

Browse files
authored
Merge pull request github#3981 from yoff/SharedDataflow_Classes
Python: Dataflow, test magic methods
2 parents e01e702 + 9556937 commit 8cbd497

File tree

14 files changed

+1698
-51
lines changed

14 files changed

+1698
-51
lines changed

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

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,65 @@ predicate simpleLocalFlowStep(Node nodeFrom, Node nodeTo) {
9797
//--------
9898
// Global flow
9999
//--------
100+
/**
101+
* IPA type for DataFlowCallable.
102+
* A callable is either a callable value or a class.
103+
*/
104+
newtype TDataFlowCallable =
105+
TCallableValue(CallableValue callable) or
106+
TClassValue(ClassValue c)
107+
100108
/** Represents a callable */
101-
class DataFlowCallable = CallableValue;
109+
abstract class DataFlowCallable extends TDataFlowCallable {
110+
/** Gets a textual representation of this element. */
111+
abstract string toString();
112+
113+
/** Gets a call to this callable. */
114+
abstract CallNode getACall();
115+
116+
/** Gets the scope of this callable */
117+
abstract Scope getScope();
118+
119+
/** Gets the specified parameter of this callable */
120+
abstract NameNode getParameter(int n);
121+
122+
/** Gets the name of this callable. */
123+
abstract string getName();
124+
}
125+
126+
class DataFlowCallableValue extends DataFlowCallable, TCallableValue {
127+
CallableValue callable;
128+
129+
DataFlowCallableValue() { this = TCallableValue(callable) }
130+
131+
override string toString() { result = callable.toString() }
132+
133+
override CallNode getACall() { result = callable.getACall() }
134+
135+
override Scope getScope() { result = callable.getScope() }
136+
137+
override NameNode getParameter(int n) { result = callable.getParameter(n) }
138+
139+
override string getName() { result = callable.getName() }
140+
}
141+
142+
class DataFlowClassValue extends DataFlowCallable, TClassValue {
143+
ClassValue c;
144+
145+
DataFlowClassValue() { this = TClassValue(c) }
146+
147+
override string toString() { result = c.toString() }
148+
149+
override CallNode getACall() { result = c.getACall() }
150+
151+
override Scope getScope() { result = c.getScope() }
152+
153+
override NameNode getParameter(int n) {
154+
result.getNode() = c.getScope().getInitMethod().getArg(n + 1).asName()
155+
}
156+
157+
override string getName() { result = c.getName() }
158+
}
102159

103160
/** Represents a call to a callable */
104161
class DataFlowCall extends CallNode {

python/ql/test/experimental/dataflow/basic/callGraph.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import callGraphConfig
1+
import experimental.dataflow.callGraphConfig
22

33
from DataFlow::Node source, DataFlow::Node sink
44
where exists(CallGraphConfig cfg | cfg.hasFlow(source, sink))

python/ql/test/experimental/dataflow/basic/callGraphSinks.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import callGraphConfig
1+
import experimental.dataflow.callGraphConfig
22

33
from DataFlow::Node sink
44
where exists(CallGraphConfig cfg | cfg.isSink(sink))

python/ql/test/experimental/dataflow/basic/callGraphSources.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import callGraphConfig
1+
import experimental.dataflow.callGraphConfig
22

33
from DataFlow::Node source
44
where exists(CallGraphConfig cfg | cfg.isSource(source))

python/ql/test/experimental/dataflow/consistency/dataflow-consistency.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,5 @@ argHasPostUpdate
101101
| test.py:74:17:74:17 | ControlFlowNode for t | ArgumentNode is missing PostUpdateNode. |
102102
| test.py:81:13:81:13 | ControlFlowNode for t | ArgumentNode is missing PostUpdateNode. |
103103
| test.py:86:13:86:13 | ControlFlowNode for t | ArgumentNode is missing PostUpdateNode. |
104+
| test.py:158:15:158:15 | ControlFlowNode for l | ArgumentNode is missing PostUpdateNode. |
105+
| test.py:159:15:159:15 | ControlFlowNode for d | ArgumentNode is missing PostUpdateNode. |

0 commit comments

Comments
 (0)