Skip to content

Commit 29a8a82

Browse files
committed
Ruby: add more docs for splat flow
1 parent 97ed5b8 commit 29a8a82

File tree

1 file changed

+31
-4
lines changed

1 file changed

+31
-4
lines changed

ruby/ql/lib/codeql/ruby/dataflow/internal/DataFlowPrivate.qll

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1280,6 +1280,16 @@ module ArgumentNodes {
12801280
override string toStringImpl() { result = "*" }
12811281
}
12821282

1283+
/**
1284+
* A data-flow node that holds data from values inside splat arguments.
1285+
* For example, in the following call
1286+
*
1287+
* ```rb
1288+
* foo(1, 2, *[3, 4])
1289+
* ```
1290+
*
1291+
* We add read steps such that `3` flows into `SynthSplatArgumentElementNode(2)` and `4` flows into `SynthSplatArgumentElementNode(3)`.
1292+
*/
12831293
class SynthSplatArgumentElementNode extends NodeImpl, TSynthSplatArgumentElementNode {
12841294
CfgNodes::ExprNodes::CallCfgNode c;
12851295
int n;
@@ -1535,8 +1545,18 @@ predicate storeStepCommon(Node node1, ContentSet c, Node node2) {
15351545
)
15361546
}
15371547

1538-
// Store from TSynthSplatArgumentElementNode(n)
1539-
// into TSynthSplatArgumentNode[n]
1548+
/**
1549+
* A store step from a `SynthSplatArgumentElementNode` into a `SynthSplatArgumentNode`.
1550+
* For example in
1551+
*
1552+
* ```rb
1553+
* foo(1, 2, *[3, 4])
1554+
* ```
1555+
*
1556+
* We have flow from `3` into `SynthSplatArgumentElementNode(2)`. This step stores the value from this node into element `2` of the `SynthSplatArgumentNode`.
1557+
*
1558+
* This allows us to match values inside splat arguments to the correct parameter in the callable.
1559+
*/
15401560
predicate synthSplatArgumentElementStoreStep(
15411561
SynthSplatArgumentElementNode node1, ContentSet c, SynthSplatArgumentNode node2
15421562
) {
@@ -1606,7 +1626,15 @@ predicate readStepCommon(Node node1, ContentSet c, Node node2) {
16061626
node2 = node1.(SynthSplatParameterNode).getAParameter(c)
16071627
}
16081628

1609-
// read from splat arg to synth splat arg element
1629+
/**
1630+
* A read step from a splat argument to a `SynthSplatArgumentElementNode`.
1631+
* For example in
1632+
* ```rb
1633+
* foo(x, y, *[1, 2])
1634+
* ```
1635+
*
1636+
* we read `1` into `SynthSplatArgumentElementNode(2)` and `2` into `SynthSplatArgumentElementNode(3)`.
1637+
*/
16101638
predicate synthSplatArgumentElementReadStep(
16111639
Node node1, ContentSet c, SynthSplatArgumentElementNode node2
16121640
) {
@@ -1665,7 +1693,6 @@ predicate readStep(Node node1, ContentSet c, Node node2) {
16651693
c = getPositionalContent(e.getReadPosition())
16661694
)
16671695
or
1668-
// TODO: convert into the above form
16691696
synthSplatArgumentElementReadStep(node1, c, node2)
16701697
or
16711698
readStepCommon(node1, c, node2)

0 commit comments

Comments
 (0)