Fix CallExprCfgNode.getKeywordArgument

This predicate now produces results.
This commit is contained in:
Harry Maclean
2021-10-19 15:55:40 +01:00
committed by Harry Maclean
parent 0caea17118
commit 8fd8c9b04d
2 changed files with 22 additions and 1 deletions

View File

@@ -320,7 +320,11 @@ module ExprNodes {
/** Gets the the keyword argument whose key is `keyword` of this call. */
final ExprCfgNode getKeywordArgument(string keyword) {
e.hasCfgChild(e.getKeywordArgument(keyword), this, result)
exists(PairCfgNode n |
e.hasCfgChild(e.getAnArgument(), this, n) and
n.getKey().getExpr().(SymbolLiteral).getValueText() = keyword and
result = n.getValue()
)
}
/** Gets the number of arguments of this call. */
@@ -426,6 +430,21 @@ module ExprNodes {
ParenthesizedExprCfgNode() { this.getExpr() instanceof ParenthesizedExpr }
}
private class PairChildMapping extends ExprChildMapping, Pair {
override predicate relevantChild(Expr e) { e = this.getKey() or e = this.getValue() }
}
/** A control-flow node that wraps a `Pair` AST expression. */
class PairCfgNode extends ExprCfgNode {
override PairChildMapping e;
final override Pair getExpr() { result = ExprCfgNode.super.getExpr() }
final ExprCfgNode getKey() { e.hasCfgChild(e.getKey(), this, result) }
final ExprCfgNode getValue() { e.hasCfgChild(e.getValue(), this, result) }
}
/** A control-flow node that wraps a `VariableReadAccess` AST expression. */
class VariableReadAccessCfgNode extends ExprCfgNode {
override VariableReadAccess e;

View File

@@ -319,3 +319,5 @@ positionalArguments
| raise.rb:161:7:161:14 | call to raise | raise.rb:161:13:161:14 | "" |
| raise.rb:168:5:168:12 | call to raise | raise.rb:168:11:168:12 | "" |
keywordArguments
| cfg.html.erb:6:9:6:58 | call to stylesheet_link_tag | media | cfg.html.erb:6:54:6:58 | "all" |
| cfg.html.erb:12:11:12:33 | call to link_to | id | cfg.html.erb:12:31:12:33 | "a" |