3131 * Note: This hasn't been 100% realized yet, so we don't currently expose a predicate to
3232 * ask what targets any data-flow node has. But it's still the plan to do this!
3333 */
34+ overlay [ local?]
35+ module ;
3436
3537private import python
3638private import DataFlowPublic
@@ -39,6 +41,7 @@ private import FlowSummaryImpl as FlowSummaryImpl
3941private import semmle.python.internal.CachedStages
4042private import semmle.python.dataflow.new.internal.TypeTrackingImpl:: CallGraphConstruction as CallGraphConstruction
4143
44+ overlay [ local]
4245newtype TParameterPosition =
4346 /** Used for `self` in methods, and `cls` in classmethods. */
4447 TSelfParameterPosition ( ) or
@@ -84,6 +87,7 @@ newtype TParameterPosition =
8487 TSynthDictSplatParameterPosition ( )
8588
8689/** A parameter position. */
90+ overlay [ local]
8791class ParameterPosition extends TParameterPosition {
8892 /** Holds if this position represents a `self`/`cls` parameter. */
8993 predicate isSelf ( ) { this = TSelfParameterPosition ( ) }
@@ -146,6 +150,7 @@ class ParameterPosition extends TParameterPosition {
146150 }
147151}
148152
153+ overlay [ local]
149154newtype TArgumentPosition =
150155 /** Used for `self` in methods, and `cls` in classmethods. */
151156 TSelfArgumentPosition ( ) or
@@ -180,6 +185,7 @@ newtype TArgumentPosition =
180185 TDictSplatArgumentPosition ( )
181186
182187/** An argument position. */
188+ overlay [ local]
183189class ArgumentPosition extends TArgumentPosition {
184190 /** Holds if this position represents a `self`/`cls` argument. */
185191 predicate isSelf ( ) { this = TSelfArgumentPosition ( ) }
@@ -248,6 +254,7 @@ predicate parameterMatch(ParameterPosition ppos, ArgumentPosition apos) {
248254 * `@staticmethod` decorator or by convention
249255 * (like a `__new__` method on a class is a classmethod even without the decorator).
250256 */
257+ overlay [ local]
251258predicate isStaticmethod ( Function func ) {
252259 exists ( NameNode id | id .getId ( ) = "staticmethod" and id .isGlobal ( ) |
253260 func .getADecorator ( ) = id .getNode ( )
@@ -259,6 +266,7 @@ predicate isStaticmethod(Function func) {
259266 * `@classmethod` decorator or by convention
260267 * (like a `__new__` method on a class is a classmethod even without the decorator).
261268 */
269+ overlay [ local]
262270predicate isClassmethod ( Function func ) {
263271 exists ( NameNode id | id .getId ( ) = "classmethod" and id .isGlobal ( ) |
264272 func .getADecorator ( ) = id .getNode ( )
@@ -275,6 +283,7 @@ predicate isClassmethod(Function func) {
275283}
276284
277285/** Holds if the function `func` has a `property` decorator. */
286+ overlay [ local]
278287predicate hasPropertyDecorator ( Function func ) {
279288 exists ( NameNode id | id .getId ( ) = "property" and id .isGlobal ( ) |
280289 func .getADecorator ( ) = id .getNode ( )
@@ -284,6 +293,7 @@ predicate hasPropertyDecorator(Function func) {
284293/**
285294 * Holds if the function `func` has a `contextlib.contextmanager`.
286295 */
296+ overlay [ local]
287297predicate hasContextmanagerDecorator ( Function func ) {
288298 exists ( ControlFlowNode contextmanager |
289299 contextmanager .( NameNode ) .getId ( ) = "contextmanager" and contextmanager .( NameNode ) .isGlobal ( )
@@ -298,20 +308,25 @@ predicate hasContextmanagerDecorator(Function func) {
298308// Callables
299309// =============================================================================
300310/** A callable defined in library code, identified by a unique string. */
311+ overlay [ local]
301312abstract class LibraryCallable extends string {
302313 bindingset [ this ]
303314 LibraryCallable ( ) { any ( ) }
304315
305316 /** Gets a call to this library callable. */
317+ overlay [ global]
306318 abstract CallCfgNode getACall ( ) ;
307319
308320 /** Same as `getACall` but without referring to the call graph or API graph. */
321+ overlay [ global]
309322 CallCfgNode getACallSimple ( ) { none ( ) }
310323
311324 /** Gets a data-flow node, where this library callable is used as a call-back. */
325+ overlay [ global]
312326 abstract ArgumentNode getACallback ( ) ;
313327}
314328
329+ overlay [ local]
315330newtype TDataFlowCallable =
316331 /**
317332 * Is used as the target for all calls: plain functions, lambdas, methods on classes,
@@ -329,6 +344,7 @@ newtype TDataFlowCallable =
329344 TLibraryCallable ( LibraryCallable callable )
330345
331346/** A callable. */
347+ overlay [ local]
332348abstract class DataFlowCallable extends TDataFlowCallable {
333349 /** Gets a textual representation of this element. */
334350 abstract string toString ( ) ;
@@ -350,6 +366,7 @@ abstract class DataFlowCallable extends TDataFlowCallable {
350366}
351367
352368/** A callable function. */
369+ overlay [ local]
353370abstract class DataFlowFunction extends DataFlowCallable , TFunction {
354371 Function func ;
355372
@@ -370,6 +387,7 @@ abstract class DataFlowFunction extends DataFlowCallable, TFunction {
370387 /** Gets the positional parameter offset, to take into account self/cls parameters. */
371388 int positionalOffset ( ) { result = 0 }
372389
390+ overlay [ local]
373391 override ParameterNode getParameter ( ParameterPosition ppos ) {
374392 // Do not handle lower bound positions (such as `[1..]`) here
375393 // they are handled by parameter matching and would create
@@ -408,11 +426,13 @@ abstract class DataFlowFunction extends DataFlowCallable, TFunction {
408426}
409427
410428/** A plain (non-method) function. */
429+ overlay [ local]
411430class DataFlowPlainFunction extends DataFlowFunction {
412431 DataFlowPlainFunction ( ) { not this instanceof DataFlowMethod }
413432}
414433
415434/** A method. */
435+ overlay [ local]
416436class DataFlowMethod extends DataFlowFunction {
417437 Class cls ;
418438
@@ -431,11 +451,13 @@ class DataFlowMethod extends DataFlowFunction {
431451}
432452
433453/** A classmethod. */
454+ overlay [ local]
434455class DataFlowClassmethod extends DataFlowMethod {
435456 DataFlowClassmethod ( ) { isClassmethod ( func ) }
436457}
437458
438459/** A staticmethod. */
460+ overlay [ local]
439461class DataFlowStaticmethod extends DataFlowMethod , DataFlowFunction {
440462 DataFlowStaticmethod ( ) { isStaticmethod ( func ) }
441463
@@ -450,6 +472,7 @@ class DataFlowStaticmethod extends DataFlowMethod, DataFlowFunction {
450472 * A module. This is not actually a callable, but we need this so a
451473 * `ModuleVariableNode` have an enclosing callable.
452474 */
475+ overlay [ local]
453476class DataFlowModuleScope extends DataFlowCallable , TModule {
454477 Module mod ;
455478
@@ -466,6 +489,7 @@ class DataFlowModuleScope extends DataFlowCallable, TModule {
466489 override ParameterNode getParameter ( ParameterPosition ppos ) { none ( ) }
467490}
468491
492+ overlay [ local]
469493class LibraryCallableValue extends DataFlowCallable , TLibraryCallable {
470494 LibraryCallable callable ;
471495
@@ -476,6 +500,7 @@ class LibraryCallableValue extends DataFlowCallable, TLibraryCallable {
476500 override string getQualifiedName ( ) { result = callable .toString ( ) }
477501
478502 /** Gets a data-flow node, where this library callable is used as a call-back. */
503+ overlay [ global]
479504 ArgumentNode getACallback ( ) { result = callable .getACallback ( ) }
480505
481506 override Scope getScope ( ) { none ( ) }
@@ -1589,6 +1614,7 @@ class SummaryCall extends DataFlowCall, TSummaryCall {
15891614 * The value of a parameter at function entry, viewed as a node in a data
15901615 * flow graph.
15911616 */
1617+ overlay [ local]
15921618abstract class ParameterNodeImpl extends Node {
15931619 /** Gets the `Parameter` this `ParameterNode` represents. */
15941620 abstract Parameter getParameter ( ) ;
@@ -1610,6 +1636,7 @@ abstract class ParameterNodeImpl extends Node {
16101636 *
16111637 * This is used for tracking flow through captured variables.
16121638 */
1639+ overlay [ local]
16131640class SynthCapturedVariablesParameterNode extends ParameterNodeImpl ,
16141641 TSynthCapturedVariablesParameterNode
16151642{
@@ -1634,6 +1661,7 @@ class SynthCapturedVariablesParameterNode extends ParameterNodeImpl,
16341661}
16351662
16361663/** A parameter for a library callable with a flow summary. */
1664+ overlay [ local]
16371665class SummaryParameterNode extends ParameterNodeImpl , FlowSummaryNode {
16381666 SummaryParameterNode ( ) {
16391667 FlowSummaryImpl:: Private:: summaryParameterNode ( this .getSummaryNode ( ) , _)
@@ -1800,12 +1828,14 @@ DataFlowCallable viableCallable(DataFlowCall call) {
18001828// =============================================================================
18011829// Remaining required data-flow things
18021830// =============================================================================
1831+ overlay [ local]
18031832private newtype TReturnKind = TNormalReturnKind ( )
18041833
18051834/**
18061835 * A return kind. A return kind describes how a value can be returned
18071836 * from a callable. For Python, this is simply a method return.
18081837 */
1838+ overlay [ local]
18091839class ReturnKind extends TReturnKind {
18101840 /** Gets a textual representation of this element. */
18111841 string toString ( ) { result = "return" }
0 commit comments