mirror of
https://github.com/github/codeql.git
synced 2026-04-28 18:25:24 +02:00
Python: Add MethodCallNode class
Roughly patterned after the JS equivalent.
This commit is contained in:
@@ -180,6 +180,30 @@ class CallCfgNode extends CfgNode, LocalSourceNode {
|
||||
Node getArgByName(string name) { result.asCfgNode() = node.getArgByName(name) }
|
||||
}
|
||||
|
||||
/**
|
||||
* A data-flow node corresponding to a method call, that is `foo.bar(...)`.
|
||||
*
|
||||
* Also covers the case where the method lookup is done separately from the call itself, as in
|
||||
* `temp = foo.bar; temp(...)`.
|
||||
*/
|
||||
class MethodCallNode extends CallCfgNode {
|
||||
AttrRead method_lookup;
|
||||
|
||||
MethodCallNode() { method_lookup = this.getFunction().getALocalSource() }
|
||||
|
||||
/** Gets the name of the method being invoked (the `bar` in `foo.bar(...)`, if it can be determined. */
|
||||
string getMethodName() { result = method_lookup.getAttributeName() }
|
||||
|
||||
/** Gets the data-flow node corresponding to the receiver of this call. That is, the `foo` in `foo.bar(...)`. */
|
||||
Node getReceiver() { result = method_lookup.getObject() }
|
||||
|
||||
/** Holds if this data-flow node calls method `methodName` on receiver node `receiver`. */
|
||||
predicate calls(Node receiver, string methodName) {
|
||||
receiver = this.getReceiver() and
|
||||
methodName = this.getMethodName()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* An expression, viewed as a node in a data flow graph.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user