Ruby: factor out isProcCreationCall

This commit is contained in:
Asger F
2023-06-29 15:08:34 +02:00
parent 8d2dba18c0
commit 18762db0fb

View File

@@ -1333,16 +1333,20 @@ predicate lambdaCreation(Node creation, LambdaCallKind kind, DataFlowCallable c)
creation.asExpr() =
any(CfgNodes::ExprNodes::MethodCallCfgNode mc |
c.asCallable() = mc.getBlock().getExpr() and
(
mc.getExpr().getMethodName() = ["lambda", "proc"]
or
mc.getExpr().getMethodName() = "new" and
mc.getReceiver().getExpr().(ConstantReadAccess).getAQualifiedName() = "Proc"
)
isProcCreationCall(mc.getExpr())
)
)
}
/** Holds if `call` is a call to `lambda`, `proc`, or `Proc.new` */
pragma[nomagic]
private predicate isProcCreationCall(MethodCall call) {
call.getMethodName() = ["proc", "lambda"]
or
call.getMethodName() = "new" and
call.getReceiver().(ConstantReadAccess).getAQualifiedName() = "Proc"
}
/**
* Holds if `call` is a from-source lambda call of kind `kind` where `receiver`
* is the lambda expression.