Ruby: Add getPositionalArgument

This gets positional arguments from a call. These are arguments which
are not keyword arguments.
This commit is contained in:
Harry Maclean
2022-07-19 13:06:57 +12:00
parent d4f7f2b75e
commit 21b4918904
2 changed files with 16 additions and 0 deletions

View File

@@ -357,6 +357,14 @@ module ExprNodes {
)
}
/**
* Gets the `nth` positional argument of this call.
* Unlike `getArgument`, this excludes keyword arguments.
*/
final ExprCfgNode getPositionalArgument(int n) {
result = this.getArgument(n) and not result instanceof PairCfgNode
}
/** Gets the number of arguments of this call. */
final int getNumberOfArguments() { result = e.getNumberOfArguments() }

View File

@@ -71,6 +71,14 @@ class CallNode extends LocalSourceNode, ExprNode {
/** Gets the data-flow node corresponding to the named argument of the call corresponding to this data-flow node */
ExprNode getKeywordArgument(string name) { result.getExprNode() = node.getKeywordArgument(name) }
/**
* Gets the `nth` positional argument of this call.
* Unlike `getArgument`, this excludes keyword arguments.
*/
final ExprNode getPositionalArgument(int n) {
result.getExprNode() = node.getPositionalArgument(n)
}
/** Gets the name of the the method called by the method call (if any) corresponding to this data-flow node */
string getMethodName() { result = node.getExpr().(MethodCall).getMethodName() }