Skip to content

Ruby: add getMethodName predicate to DataFlow::CallNode class#7151

Merged
alexrford merged 2 commits into
mainfrom
ruby/methodcallnode
Nov 17, 2021
Merged

Ruby: add getMethodName predicate to DataFlow::CallNode class#7151
alexrford merged 2 commits into
mainfrom
ruby/methodcallnode

Conversation

@alexrford
Copy link
Copy Markdown
Contributor

This lets us tidy up a few places where we have a DataFlow::CallNode with an underlying MethodCall, but have to do a clumsy node.asExpr().getExpr().(MethodCall) cast in order to get the name of the called method.

@alexrford alexrford added the Ruby label Nov 16, 2021
@alexrford alexrford requested a review from a team as a code owner November 16, 2021 15:45

/** A data-flow node corresponding to a method call in the control-flow graph. */
class MethodCallNode extends CallNode {
private CfgNodes::ExprNodes::MethodCallCfgNode node;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make the super class field non-private and

Suggested change
private CfgNodes::ExprNodes::MethodCallCfgNode node;
override CfgNodes::ExprNodes::MethodCallCfgNode node;

Alternatively, just add the getMethodName method directly to CallNode. I think it is fine for that method to return none() in case the underlying Call is not a MethodCall.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the idea of moving getMethodName into CallNode, as the predicate name implies that we are interested in method calls.

@alexrford alexrford changed the title Ruby: add DataFlow::MethodCallNode class Ruby: add getMethodName predicate to DataFlow::CallNode class Nov 16, 2021
Copy link
Copy Markdown
Contributor

@nickrolfe nickrolfe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

@alexrford alexrford merged commit 08b6a17 into main Nov 17, 2021
@alexrford alexrford deleted the ruby/methodcallnode branch November 17, 2021 14:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants