Skip to content

Commit adbfbd8

Browse files
kddnewtonmatzbot
authored andcommitted
[ruby/prism] Ignore visibility flag
ruby/prism@55b049ddac
1 parent 380c218 commit adbfbd8

File tree

542 files changed

+2234
-2222
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

542 files changed

+2234
-2222
lines changed

prism/config.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,8 @@ flags:
347347
comment: "a call that could have been a local variable"
348348
- name: ATTRIBUTE_WRITE
349349
comment: "a call that is an attribute write, so the value being written should be returned"
350+
- name: IGNORE_VISIBILITY
351+
comment: "a call that ignores method visibility"
350352
comment: Flags for call nodes.
351353
- name: EncodingFlags
352354
values:

prism/prism.c

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1653,12 +1653,13 @@ pm_break_node_create(pm_parser_t *parser, const pm_token_t *keyword, pm_argument
16531653
* in the various specializations of this function.
16541654
*/
16551655
static pm_call_node_t *
1656-
pm_call_node_create(pm_parser_t *parser) {
1656+
pm_call_node_create(pm_parser_t *parser, pm_node_flags_t flags) {
16571657
pm_call_node_t *node = PM_ALLOC_NODE(parser, pm_call_node_t);
16581658

16591659
*node = (pm_call_node_t) {
16601660
{
16611661
.type = PM_CALL_NODE,
1662+
.flags = flags,
16621663
.location = PM_LOCATION_NULL_VALUE(parser),
16631664
},
16641665
.receiver = NULL,
@@ -1674,6 +1675,15 @@ pm_call_node_create(pm_parser_t *parser) {
16741675
return node;
16751676
}
16761677

1678+
/**
1679+
* Returns the value that the ignore visibility flag should be set to for the
1680+
* given receiver.
1681+
*/
1682+
static inline pm_node_flags_t
1683+
pm_call_node_ignore_visibility_flag(const pm_node_t *receiver) {
1684+
return PM_NODE_TYPE_P(receiver, PM_SELF_NODE) ? PM_CALL_NODE_FLAGS_IGNORE_VISIBILITY : 0;
1685+
}
1686+
16771687
/**
16781688
* Allocate and initialize a new CallNode node from an aref or an aset
16791689
* expression.
@@ -1682,7 +1692,7 @@ static pm_call_node_t *
16821692
pm_call_node_aref_create(pm_parser_t *parser, pm_node_t *receiver, pm_arguments_t *arguments) {
16831693
pm_assert_value_expression(parser, receiver);
16841694

1685-
pm_call_node_t *node = pm_call_node_create(parser);
1695+
pm_call_node_t *node = pm_call_node_create(parser, pm_call_node_ignore_visibility_flag(receiver));
16861696

16871697
node->base.location.start = receiver->location.start;
16881698
node->base.location.end = pm_arguments_end(arguments);
@@ -1708,7 +1718,7 @@ pm_call_node_binary_create(pm_parser_t *parser, pm_node_t *receiver, pm_token_t
17081718
pm_assert_value_expression(parser, receiver);
17091719
pm_assert_value_expression(parser, argument);
17101720

1711-
pm_call_node_t *node = pm_call_node_create(parser);
1721+
pm_call_node_t *node = pm_call_node_create(parser, pm_call_node_ignore_visibility_flag(receiver));
17121722

17131723
node->base.location.start = MIN(receiver->location.start, argument->location.start);
17141724
node->base.location.end = MAX(receiver->location.end, argument->location.end);
@@ -1731,7 +1741,7 @@ static pm_call_node_t *
17311741
pm_call_node_call_create(pm_parser_t *parser, pm_node_t *receiver, pm_token_t *operator, pm_token_t *message, pm_arguments_t *arguments) {
17321742
pm_assert_value_expression(parser, receiver);
17331743

1734-
pm_call_node_t *node = pm_call_node_create(parser);
1744+
pm_call_node_t *node = pm_call_node_create(parser, pm_call_node_ignore_visibility_flag(receiver));
17351745

17361746
node->base.location.start = receiver->location.start;
17371747
const uint8_t *end = pm_arguments_end(arguments);
@@ -1762,7 +1772,7 @@ pm_call_node_call_create(pm_parser_t *parser, pm_node_t *receiver, pm_token_t *o
17621772
*/
17631773
static pm_call_node_t *
17641774
pm_call_node_fcall_create(pm_parser_t *parser, pm_token_t *message, pm_arguments_t *arguments) {
1765-
pm_call_node_t *node = pm_call_node_create(parser);
1775+
pm_call_node_t *node = pm_call_node_create(parser, PM_CALL_NODE_FLAGS_IGNORE_VISIBILITY);
17661776

17671777
node->base.location.start = message->start;
17681778
node->base.location.end = pm_arguments_end(arguments);
@@ -1784,7 +1794,7 @@ static pm_call_node_t *
17841794
pm_call_node_not_create(pm_parser_t *parser, pm_node_t *receiver, pm_token_t *message, pm_arguments_t *arguments) {
17851795
pm_assert_value_expression(parser, receiver);
17861796

1787-
pm_call_node_t *node = pm_call_node_create(parser);
1797+
pm_call_node_t *node = pm_call_node_create(parser, receiver == NULL ? 0 : pm_call_node_ignore_visibility_flag(receiver));
17881798

17891799
node->base.location.start = message->start;
17901800
if (arguments->closing_loc.start != NULL) {
@@ -1810,7 +1820,7 @@ static pm_call_node_t *
18101820
pm_call_node_shorthand_create(pm_parser_t *parser, pm_node_t *receiver, pm_token_t *operator, pm_arguments_t *arguments) {
18111821
pm_assert_value_expression(parser, receiver);
18121822

1813-
pm_call_node_t *node = pm_call_node_create(parser);
1823+
pm_call_node_t *node = pm_call_node_create(parser, pm_call_node_ignore_visibility_flag(receiver));
18141824

18151825
node->base.location.start = receiver->location.start;
18161826
node->base.location.end = pm_arguments_end(arguments);
@@ -1837,7 +1847,7 @@ static pm_call_node_t *
18371847
pm_call_node_unary_create(pm_parser_t *parser, pm_token_t *operator, pm_node_t *receiver, const char *name) {
18381848
pm_assert_value_expression(parser, receiver);
18391849

1840-
pm_call_node_t *node = pm_call_node_create(parser);
1850+
pm_call_node_t *node = pm_call_node_create(parser, pm_call_node_ignore_visibility_flag(receiver));
18411851

18421852
node->base.location.start = operator->start;
18431853
node->base.location.end = receiver->location.end;
@@ -1855,7 +1865,7 @@ pm_call_node_unary_create(pm_parser_t *parser, pm_token_t *operator, pm_node_t *
18551865
*/
18561866
static pm_call_node_t *
18571867
pm_call_node_variable_call_create(pm_parser_t *parser, pm_token_t *message) {
1858-
pm_call_node_t *node = pm_call_node_create(parser);
1868+
pm_call_node_t *node = pm_call_node_create(parser, PM_CALL_NODE_FLAGS_IGNORE_VISIBILITY);
18591869

18601870
node->base.location = PM_LOCATION_TOKEN_VALUE(message);
18611871
node->message_loc = PM_OPTIONAL_LOCATION_TOKEN_VALUE(message);

test/prism/errors_test.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ def test_block_beginning_with_brace_and_ending_with_end
360360

361361
def test_double_splat_followed_by_splat_argument
362362
expected = CallNode(
363-
0,
363+
CallNodeFlags::IGNORE_VISIBILITY,
364364
nil,
365365
nil,
366366
:a,
@@ -381,7 +381,7 @@ def test_double_splat_followed_by_splat_argument
381381

382382
def test_arguments_after_block
383383
expected = CallNode(
384-
0,
384+
CallNodeFlags::IGNORE_VISIBILITY,
385385
nil,
386386
nil,
387387
:a,
@@ -407,7 +407,7 @@ def test_arguments_binding_power_for_and
407407

408408
def test_splat_argument_after_keyword_argument
409409
expected = CallNode(
410-
0,
410+
CallNodeFlags::IGNORE_VISIBILITY,
411411
nil,
412412
nil,
413413
:a,
@@ -462,7 +462,7 @@ def test_module_definition_in_method_body_within_block
462462
nil,
463463
StatementsNode(
464464
[CallNode(
465-
0,
465+
CallNodeFlags::IGNORE_VISIBILITY,
466466
nil,
467467
nil,
468468
:bar,
@@ -1070,7 +1070,7 @@ def test_do_not_allow_forward_arguments_in_lambda_literals
10701070

10711071
def test_do_not_allow_forward_arguments_in_blocks
10721072
expected = CallNode(
1073-
0,
1073+
CallNodeFlags::IGNORE_VISIBILITY,
10741074
nil,
10751075
nil,
10761076
:a,

test/prism/snapshots/arithmetic.txt

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
@ StatementsNode (location: (1,0)-(13,8))
55
└── body: (length: 7)
66
├── @ CallNode (location: (1,0)-(1,8))
7-
│ ├── flags:
7+
│ ├── flags: ignore_visibility
88
│ ├── receiver: ∅
99
│ ├── call_operator_loc: ∅
1010
│ ├── name: :foo
@@ -18,7 +18,7 @@
1818
│ │ ├── flags: ∅
1919
│ │ ├── receiver:
2020
│ │ │ @ CallNode (location: (1,5)-(1,8))
21-
│ │ │ ├── flags: variable_call
21+
│ │ │ ├── flags: variable_call, ignore_visibility
2222
│ │ │ ├── receiver: ∅
2323
│ │ │ ├── call_operator_loc: ∅
2424
│ │ │ ├── name: :bar
@@ -43,7 +43,7 @@
4343
│ │ ├── flags: ∅
4444
│ │ ├── receiver:
4545
│ │ │ @ CallNode (location: (3,1)-(3,4))
46-
│ │ │ ├── flags: variable_call
46+
│ │ │ ├── flags: variable_call, ignore_visibility
4747
│ │ │ ├── receiver: ∅
4848
│ │ │ ├── call_operator_loc: ∅
4949
│ │ │ ├── name: :foo
@@ -68,7 +68,7 @@
6868
│ │ ├── flags: ∅
6969
│ │ └── arguments: (length: 1)
7070
│ │ └── @ CallNode (location: (3,5)-(3,8))
71-
│ │ ├── flags: variable_call
71+
│ │ ├── flags: variable_call, ignore_visibility
7272
│ │ ├── receiver: ∅
7373
│ │ ├── call_operator_loc: ∅
7474
│ │ ├── name: :bar
@@ -86,7 +86,7 @@
8686
│ │ ├── flags: ∅
8787
│ │ ├── receiver:
8888
│ │ │ @ CallNode (location: (5,1)-(5,4))
89-
│ │ │ ├── flags: variable_call
89+
│ │ │ ├── flags: variable_call, ignore_visibility
9090
│ │ │ ├── receiver: ∅
9191
│ │ │ ├── call_operator_loc: ∅
9292
│ │ │ ├── name: :foo
@@ -111,7 +111,7 @@
111111
│ │ ├── flags: ∅
112112
│ │ └── arguments: (length: 1)
113113
│ │ └── @ CallNode (location: (5,6)-(5,9))
114-
│ │ ├── flags: variable_call
114+
│ │ ├── flags: variable_call, ignore_visibility
115115
│ │ ├── receiver: ∅
116116
│ │ ├── call_operator_loc: ∅
117117
│ │ ├── name: :bar
@@ -123,7 +123,7 @@
123123
│ ├── closing_loc: ∅
124124
│ └── block: ∅
125125
├── @ CallNode (location: (7,0)-(7,8))
126-
│ ├── flags:
126+
│ ├── flags: ignore_visibility
127127
│ ├── receiver: ∅
128128
│ ├── call_operator_loc: ∅
129129
│ ├── name: :foo
@@ -137,7 +137,7 @@
137137
│ │ ├── flags: ∅
138138
│ │ ├── receiver:
139139
│ │ │ @ CallNode (location: (7,5)-(7,8))
140-
│ │ │ ├── flags: variable_call
140+
│ │ │ ├── flags: variable_call, ignore_visibility
141141
│ │ │ ├── receiver: ∅
142142
│ │ │ ├── call_operator_loc: ∅
143143
│ │ │ ├── name: :bar
@@ -162,7 +162,7 @@
162162
│ │ ├── flags: ∅
163163
│ │ ├── receiver:
164164
│ │ │ @ CallNode (location: (9,0)-(9,3))
165-
│ │ │ ├── flags: variable_call
165+
│ │ │ ├── flags: variable_call, ignore_visibility
166166
│ │ │ ├── receiver: ∅
167167
│ │ │ ├── call_operator_loc: ∅
168168
│ │ │ ├── name: :foo
@@ -180,7 +180,7 @@
180180
│ │ │ ├── flags: ∅
181181
│ │ │ └── arguments: (length: 1)
182182
│ │ │ └── @ CallNode (location: (9,7)-(9,10))
183-
│ │ │ ├── flags: variable_call
183+
│ │ │ ├── flags: variable_call, ignore_visibility
184184
│ │ │ ├── receiver: ∅
185185
│ │ │ ├── call_operator_loc: ∅
186186
│ │ │ ├── name: :bar
@@ -200,7 +200,7 @@
200200
│ │ ├── flags: ∅
201201
│ │ └── arguments: (length: 1)
202202
│ │ └── @ CallNode (location: (9,14)-(9,17))
203-
│ │ ├── flags: variable_call
203+
│ │ ├── flags: variable_call, ignore_visibility
204204
│ │ ├── receiver: ∅
205205
│ │ ├── call_operator_loc: ∅
206206
│ │ ├── name: :baz

0 commit comments

Comments
 (0)