diff options
| author | Kevin Newton <kddnewton@gmail.com> | 2023-09-05 12:34:16 -0400 |
|---|---|---|
| committer | git <svn-admin@ruby-lang.org> | 2023-09-05 18:41:51 +0000 |
| commit | c384ef07991d08dc378bf6450363aaa654099813 (patch) | |
| tree | efdfd50f40e851765fa1680c39ca7f27a077dc2e /test | |
| parent | 9a8398a18f364d3bcfc8d2744162d3572d9491e4 (diff) | |
[ruby/yarp] Introduce a BlockLocalVariableNode
This is a tradeoff that I think is worth it. Right now we have a
location list that tracks the location of each of the block locals.
Instead, I'd like to make that a node list that has a proper node
in each spot in the list. In doing so, we eliminate the need to have
a location list at all, making it simpler on all of the various
consumers as we have one fewer field type. There should be minimal
memory implications here since this syntax is exceedingly rare.
https://github.com/ruby/yarp/commit/04d329ddf0
Diffstat (limited to 'test')
| -rw-r--r-- | test/yarp/location_test.rb | 6 | ||||
| -rw-r--r-- | test/yarp/snapshots/procs.txt | 4 | ||||
| -rw-r--r-- | test/yarp/snapshots/seattlerb/block_arg_scope.txt | 2 | ||||
| -rw-r--r-- | test/yarp/snapshots/seattlerb/block_arg_scope2.txt | 3 | ||||
| -rw-r--r-- | test/yarp/snapshots/seattlerb/block_scope.txt | 7 | ||||
| -rw-r--r-- | test/yarp/snapshots/seattlerb/pipe_semicolon.txt | 7 | ||||
| -rw-r--r-- | test/yarp/snapshots/seattlerb/stabby_proc_scope.txt | 2 | ||||
| -rw-r--r-- | test/yarp/snapshots/unparser/corpus/literal/block.txt | 9 | ||||
| -rw-r--r-- | test/yarp/snapshots/unparser/corpus/literal/lambda.txt | 2 | ||||
| -rw-r--r-- | test/yarp/snapshots/whitequark/arg_scope.txt | 7 | ||||
| -rw-r--r-- | test/yarp/snapshots/whitequark/blockargs.txt | 4 | ||||
| -rw-r--r-- | test/yarp/snapshots/whitequark/send_lambda_args_shadow.txt | 3 |
12 files changed, 41 insertions, 15 deletions
diff --git a/test/yarp/location_test.rb b/test/yarp/location_test.rb index 192cfdd716..6e544e86b0 100644 --- a/test/yarp/location_test.rb +++ b/test/yarp/location_test.rb @@ -67,6 +67,12 @@ module YARP assert_location(BlockArgumentNode, "foo(&bar)", 4...8) { |node| node.arguments.arguments.last } end + def test_BlockLocalVariableNode + assert_location(BlockLocalVariableNode, "foo { |;bar| }", 8...11) do |node| + node.block.parameters.locals.first + end + end + def test_BlockNode assert_location(BlockNode, "foo {}", 4...6, &:block) assert_location(BlockNode, "foo do end", 4...10, &:block) diff --git a/test/yarp/snapshots/procs.txt b/test/yarp/snapshots/procs.txt index adfb063707..4510160c44 100644 --- a/test/yarp/snapshots/procs.txt +++ b/test/yarp/snapshots/procs.txt @@ -16,7 +16,9 @@ ProgramNode(0...266)( nil, nil ), - [(7...8), (10...11), (13...14)], + [BlockLocalVariableNode(7...8)(:b), + BlockLocalVariableNode(10...11)(:c), + BlockLocalVariableNode(13...14)(:d)], (3...4), (14...15) ), diff --git a/test/yarp/snapshots/seattlerb/block_arg_scope.txt b/test/yarp/snapshots/seattlerb/block_arg_scope.txt index 498d41cbe3..be99e78eec 100644 --- a/test/yarp/snapshots/seattlerb/block_arg_scope.txt +++ b/test/yarp/snapshots/seattlerb/block_arg_scope.txt @@ -20,7 +20,7 @@ ProgramNode(0...12)( nil, nil ), - [(8...9)], + [BlockLocalVariableNode(8...9)(:c)], (4...5), (9...10) ), diff --git a/test/yarp/snapshots/seattlerb/block_arg_scope2.txt b/test/yarp/snapshots/seattlerb/block_arg_scope2.txt index 787e8cb10a..fcee4898aa 100644 --- a/test/yarp/snapshots/seattlerb/block_arg_scope2.txt +++ b/test/yarp/snapshots/seattlerb/block_arg_scope2.txt @@ -20,7 +20,8 @@ ProgramNode(0...14)( nil, nil ), - [(7...8), (10...11)], + [BlockLocalVariableNode(7...8)(:c), + BlockLocalVariableNode(10...11)(:d)], (3...4), (11...12) ), diff --git a/test/yarp/snapshots/seattlerb/block_scope.txt b/test/yarp/snapshots/seattlerb/block_scope.txt index 223268c471..bcdb26caa7 100644 --- a/test/yarp/snapshots/seattlerb/block_scope.txt +++ b/test/yarp/snapshots/seattlerb/block_scope.txt @@ -10,7 +10,12 @@ ProgramNode(0...10)( nil, BlockNode(2...10)( [:b], - BlockParametersNode(4...8)(nil, [(6...7)], (4...5), (7...8)), + BlockParametersNode(4...8)( + nil, + [BlockLocalVariableNode(6...7)(:b)], + (4...5), + (7...8) + ), nil, (2...3), (9...10) diff --git a/test/yarp/snapshots/seattlerb/pipe_semicolon.txt b/test/yarp/snapshots/seattlerb/pipe_semicolon.txt index cd40d9ac0b..14dc672e1c 100644 --- a/test/yarp/snapshots/seattlerb/pipe_semicolon.txt +++ b/test/yarp/snapshots/seattlerb/pipe_semicolon.txt @@ -10,7 +10,12 @@ ProgramNode(0...18)( nil, BlockNode(4...18)( [:c], - BlockParametersNode(7...14)(nil, [(11...12)], (7...8), (13...14)), + BlockParametersNode(7...14)( + nil, + [BlockLocalVariableNode(11...12)(:c)], + (7...8), + (13...14) + ), nil, (4...6), (15...18) diff --git a/test/yarp/snapshots/seattlerb/stabby_proc_scope.txt b/test/yarp/snapshots/seattlerb/stabby_proc_scope.txt index c4594997eb..d8e06afa0f 100644 --- a/test/yarp/snapshots/seattlerb/stabby_proc_scope.txt +++ b/test/yarp/snapshots/seattlerb/stabby_proc_scope.txt @@ -16,7 +16,7 @@ ProgramNode(0...11)( nil, nil ), - [(6...7)], + [BlockLocalVariableNode(6...7)(:b)], (2...3), (7...8) ), diff --git a/test/yarp/snapshots/unparser/corpus/literal/block.txt b/test/yarp/snapshots/unparser/corpus/literal/block.txt index a115e84135..6ee2fbb1fa 100644 --- a/test/yarp/snapshots/unparser/corpus/literal/block.txt +++ b/test/yarp/snapshots/unparser/corpus/literal/block.txt @@ -91,7 +91,7 @@ ProgramNode(0...737)( nil, nil ), - [(44...45)], + [BlockLocalVariableNode(44...45)(:x)], (39...40), (45...46) ), @@ -326,7 +326,7 @@ ProgramNode(0...737)( nil, nil ), - [(181...182)], + [BlockLocalVariableNode(181...182)(:b)], (176...177), (182...183) ), @@ -366,7 +366,7 @@ ProgramNode(0...737)( nil, nil ), - [(200...201)], + [BlockLocalVariableNode(200...201)(:b)], (196...197), (201...202) ), @@ -398,7 +398,8 @@ ProgramNode(0...737)( [:a, :b], BlockParametersNode(215...223)( nil, - [(218...219), (221...222)], + [BlockLocalVariableNode(218...219)(:a), + BlockLocalVariableNode(221...222)(:b)], (215...216), (222...223) ), diff --git a/test/yarp/snapshots/unparser/corpus/literal/lambda.txt b/test/yarp/snapshots/unparser/corpus/literal/lambda.txt index 13161f9c88..8c036bd70d 100644 --- a/test/yarp/snapshots/unparser/corpus/literal/lambda.txt +++ b/test/yarp/snapshots/unparser/corpus/literal/lambda.txt @@ -110,7 +110,7 @@ ProgramNode(0...80)( nil, nil ), - [(74...75)], + [BlockLocalVariableNode(74...75)(:c)], (67...68), (75...76) ), diff --git a/test/yarp/snapshots/whitequark/arg_scope.txt b/test/yarp/snapshots/whitequark/arg_scope.txt index fd5ae0f61d..baa33596be 100644 --- a/test/yarp/snapshots/whitequark/arg_scope.txt +++ b/test/yarp/snapshots/whitequark/arg_scope.txt @@ -10,7 +10,12 @@ ProgramNode(0...13)( nil, BlockNode(6...13)( [:a], - BlockParametersNode(7...11)(nil, [(9...10)], (7...8), (10...11)), + BlockParametersNode(7...11)( + nil, + [BlockLocalVariableNode(9...10)(:a)], + (7...8), + (10...11) + ), StatementsNode(11...12)([LocalVariableReadNode(11...12)(:a, 0)]), (6...7), (12...13) diff --git a/test/yarp/snapshots/whitequark/blockargs.txt b/test/yarp/snapshots/whitequark/blockargs.txt index 3115c58df1..76f9dd4c51 100644 --- a/test/yarp/snapshots/whitequark/blockargs.txt +++ b/test/yarp/snapshots/whitequark/blockargs.txt @@ -250,7 +250,7 @@ ProgramNode(0...550)( [:a], BlockParametersNode(117...123)( nil, - [(120...121)], + [BlockLocalVariableNode(120...121)(:a)], (117...118), (122...123) ), @@ -272,7 +272,7 @@ ProgramNode(0...550)( [:a], BlockParametersNode(130...134)( nil, - [(132...133)], + [BlockLocalVariableNode(132...133)(:a)], (130...131), (133...134) ), diff --git a/test/yarp/snapshots/whitequark/send_lambda_args_shadow.txt b/test/yarp/snapshots/whitequark/send_lambda_args_shadow.txt index 9a6c888a93..cee0016fa7 100644 --- a/test/yarp/snapshots/whitequark/send_lambda_args_shadow.txt +++ b/test/yarp/snapshots/whitequark/send_lambda_args_shadow.txt @@ -16,7 +16,8 @@ ProgramNode(0...19)( nil, nil ), - [(6...9), (11...14)], + [BlockLocalVariableNode(6...9)(:foo), + BlockLocalVariableNode(11...14)(:bar)], (2...3), (14...15) ), |
