Python: Add "enclosing callable" for ModuleVariableNode

I've named this `DataFlowModuleScope` since it's not really a
callable (and all of the relevant methods are empty anyway).
This commit is contained in:
Taus Brock-Nannestad
2020-09-15 14:23:20 +02:00
parent 3727c48227
commit d5e9f36747
10 changed files with 181 additions and 150 deletions

View File

@@ -185,7 +185,8 @@ private Node update(Node node) {
*/
newtype TDataFlowCallable =
TCallableValue(CallableValue callable) or
TClassValue(ClassValue c)
TClassValue(ClassValue c) or
TModule(Module m)
/** Represents a callable */
abstract class DataFlowCallable extends TDataFlowCallable {
@@ -239,6 +240,22 @@ class DataFlowClassValue extends DataFlowCallable, TClassValue {
override string getName() { result = c.getName() }
}
class DataFlowModuleScope extends DataFlowCallable, TModule {
Module mod;
DataFlowModuleScope() { this = TModule(mod) }
override string toString() { result = mod.toString() }
override CallNode getACall() { none() }
override Scope getScope() { result = mod }
override NameNode getParameter(int n) { none() }
override string getName() { result = mod.getName() }
}
newtype TDataFlowCall =
TCallNode(CallNode call) or
TSpecialCall(SpecialMethodCallNode special)

View File

@@ -177,6 +177,10 @@ class ModuleVariableNode extends Node, TModuleVariableNode {
result.asVar().getDefinition().(EssaNodeDefinition).definedBy(var, defn)
)
}
override DataFlowCallable getEnclosingCallable() { result.(DataFlowModuleScope).getScope() = mod }
override Location getLocation() { result = mod.getLocation() }
}
/**