-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Variable capture: allow arbitrary data-flow nodes to be the source of a write #14048
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Variable capture: allow arbitrary data-flow nodes to be the source of a write #14048
Conversation
987ce9b
to
f17518a
Compare
Expr getSource() { | ||
result = this.(VariableAssign).getSource() or | ||
result = this.(AssignOp) | ||
Node getSource() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was about to write "I don't want to use DataFlow::Node
in the input to variable capture", but then I noticed that this is an additional
predicate (which apparently doesn't require the annotation since it's a member predicate). I'd like to move this predicate out of the input module to make this more clear. It can e.g. be inlined into asClosureNode
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
The predicate
VariableWrite.getSource()
returned anExpr
, which is problematic for cases where there does not exist an explicit expression for the right-hand side.Some cases where this happens:
for (String x : array) {...}
writes tox
but there is no expression for the right-hand side.let { x, y } = foo()
contains a write tox
andy
, but neither variable has anExpr
for its right-hand side.x++
it varies between languages exactly how this works, but at least for JS, there is no AST node corresponding to the value that gets assigned tox
.This PR replaces
Expr getSource()
with aclass VariableWriteSourceNode
to represent the source of a write. The language implementation is free to map this node to an arbitrary data-flow node, whereas before it was forced to map it to an expression node.