Python: Separate callable for lambdas

Since lambdas are split, but their children are not,
we use the Function as the callable.
This commit is contained in:
Rasmus Lerchedahl Petersen
2021-01-26 20:38:45 +01:00
parent 4526a1dd2f
commit d3e0e84c37
2 changed files with 25 additions and 6 deletions

View File

@@ -498,10 +498,13 @@ import ArgumentPassing
*/
newtype TDataFlowCallable =
TCallableValue(CallableValue callable) {
callable instanceof FunctionValue
callable instanceof FunctionValue and
// TODO: push into FunctionValue
not callable.(FunctionValue).getOrigin().getNode() instanceof Lambda
or
callable instanceof ClassValue
} or
TLambda(Function lambda) { lambda.getName() = "lambda" } or
TModule(Module m)
/** Represents a callable. */
@@ -544,6 +547,27 @@ class DataFlowCallableValue extends DataFlowCallable, TCallableValue {
override CallableValue getCallableValue() { result = callable }
}
/** A class representing a callable lambda. */
class DataFlowLambda extends DataFlowCallable, TLambda {
Function lambda;
DataFlowLambda() { this = TLambda(lambda) }
override string toString() { result = lambda.toString() }
override CallNode getACall() { result = getCallableValue().getACall() }
override Scope getScope() { result = lambda.getEvaluatingScope() }
override NameNode getParameter(int n) { result = getParameter(getCallableValue(), n) }
override string getName() { result = "Lambda callable" }
override CallableValue getCallableValue() {
result.(FunctionValue).getOrigin().getNode() = lambda.getDefinition()
}
}
/** A class representing the scope in which a `ModuleVariableNode` appears. */
class DataFlowModuleScope extends DataFlowCallable, TModule {
Module mod;