@@ -150,10 +150,28 @@ predicate simpleLocalFlowStep(Node nodeFrom, Node nodeTo) {
150150 // If there is ESSA-flow out of a node `node`, we want flow
151151 // both out of `node` and any post-update node of `node`.
152152 exists ( Node node |
153- not node .( EssaNode ) .getVar ( ) instanceof GlobalSsaVariable and
154- not nodeTo .( EssaNode ) .getVar ( ) instanceof GlobalSsaVariable and
155153 EssaFlow:: essaFlowStep ( node , nodeTo ) and
156- nodeFrom = update ( node )
154+ nodeFrom = update ( node ) and
155+ (
156+ not node instanceof EssaNode or
157+ not nodeTo instanceof EssaNode or
158+ localEssaStep ( node , nodeTo )
159+ )
160+ )
161+ }
162+
163+ /**
164+ * Holds if there is an Essa flow step from `nodeFrom` to `nodeTo` that does not switch between
165+ * local and global SSA variables.
166+ */
167+ private predicate localEssaStep ( EssaNode nodeFrom , EssaNode nodeTo ) {
168+ EssaFlow:: essaFlowStep ( nodeFrom , nodeTo ) and
169+ (
170+ nodeFrom .getVar ( ) instanceof GlobalSsaVariable and
171+ nodeTo .getVar ( ) instanceof GlobalSsaVariable
172+ or
173+ not nodeFrom .getVar ( ) instanceof GlobalSsaVariable and
174+ not nodeTo .getVar ( ) instanceof GlobalSsaVariable
157175 )
158176}
159177
@@ -179,7 +197,8 @@ private Node update(Node node) {
179197 */
180198newtype TDataFlowCallable =
181199 TCallableValue ( CallableValue callable ) or
182- TClassValue ( ClassValue c )
200+ TClassValue ( ClassValue c ) or
201+ TModule ( Module m )
183202
184203/** Represents a callable */
185204abstract class DataFlowCallable extends TDataFlowCallable {
@@ -233,6 +252,23 @@ class DataFlowClassValue extends DataFlowCallable, TClassValue {
233252 override string getName ( ) { result = c .getName ( ) }
234253}
235254
255+ /** A class representing the scope in which a `ModuleVariableNode` appears. */
256+ class DataFlowModuleScope extends DataFlowCallable , TModule {
257+ Module mod ;
258+
259+ DataFlowModuleScope ( ) { this = TModule ( mod ) }
260+
261+ override string toString ( ) { result = mod .toString ( ) }
262+
263+ override CallNode getACall ( ) { none ( ) }
264+
265+ override Scope getScope ( ) { result = mod }
266+
267+ override NameNode getParameter ( int n ) { none ( ) }
268+
269+ override string getName ( ) { result = mod .getName ( ) }
270+ }
271+
236272newtype TDataFlowCall =
237273 TCallNode ( CallNode call ) or
238274 TSpecialCall ( SpecialMethodCallNode special )
@@ -389,21 +425,11 @@ string ppReprType(DataFlowType t) { none() }
389425 * taken into account.
390426 */
391427predicate jumpStep ( Node nodeFrom , Node nodeTo ) {
392- // As we have ESSA variables for global variables,
393- // we include ESSA flow steps involving global variables.
394- (
395- nodeFrom .( EssaNode ) .getVar ( ) instanceof GlobalSsaVariable
396- or
397- nodeTo .( EssaNode ) .getVar ( ) instanceof GlobalSsaVariable
398- ) and
399- (
400- EssaFlow:: essaFlowStep ( nodeFrom , nodeTo )
401- or
402- // As jump steps do not respect chronology,
403- // we add jump steps for each def-use pair.
404- nodeFrom .asVar ( ) instanceof GlobalSsaVariable and
405- nodeTo .asCfgNode ( ) = nodeFrom .asVar ( ) .getASourceUse ( )
406- )
428+ // Module variable read
429+ nodeFrom .( ModuleVariableNode ) .getARead ( ) = nodeTo
430+ or
431+ // Module variable write
432+ nodeFrom = nodeTo .( ModuleVariableNode ) .getAWrite ( )
407433}
408434
409435//--------
0 commit comments