[ruby/yarp] Constants on classes and modules

(https://github.com/ruby/yarp/pull/1409)

https://github.com/ruby/yarp/commit/0a11ec579f
This commit is contained in:
Kevin Newton 2023-09-06 12:19:38 -04:00 committed by git
parent 1d4d9a016a
commit dee383b262
30 changed files with 87 additions and 87 deletions

View File

@ -19,10 +19,10 @@ module YARP
Location(), Location(),
ConstantReadNode(:Parent), ConstantReadNode(:Parent),
StatementsNode( StatementsNode(
[ModuleNode([], Location(), MissingNode(), nil, Location(), "", :"")] [ModuleNode([], Location(), MissingNode(), nil, Location(), :"", :"")]
), ),
Location(), Location(),
"Parent", :Parent,
:Parent :Parent
) )
@ -394,7 +394,7 @@ module YARP
Location(), Location(),
nil, nil,
nil, nil,
StatementsNode([ModuleNode([], Location(), ConstantReadNode(:A), nil, Location(), "A", :A)]), StatementsNode([ModuleNode([], Location(), ConstantReadNode(:A), nil, Location(), :A, :A)]),
[], [],
Location(), Location(),
nil, nil,
@ -425,7 +425,7 @@ module YARP
BlockNode( BlockNode(
[], [],
nil, nil,
StatementsNode([ModuleNode([], Location(), ConstantReadNode(:Foo), nil, Location(), "Foo", :Foo)]), StatementsNode([ModuleNode([], Location(), ConstantReadNode(:Foo), nil, Location(), :Foo, :Foo)]),
Location(), Location(),
Location() Location()
), ),
@ -465,7 +465,7 @@ module YARP
nil, nil,
nil, nil,
Location(), Location(),
"A", :A,
:A :A
)] )]
), ),
@ -981,7 +981,7 @@ module YARP
nil, nil,
StatementsNode([ReturnNode(Location(), nil)]), StatementsNode([ReturnNode(Location(), nil)]),
Location(), Location(),
"A", :A,
:A :A
) )
@ -997,7 +997,7 @@ module YARP
ConstantReadNode(:A), ConstantReadNode(:A),
StatementsNode([ReturnNode(Location(), nil)]), StatementsNode([ReturnNode(Location(), nil)]),
Location(), Location(),
"A", :A,
:A :A
) )

View File

@ -17,7 +17,7 @@ ProgramNode(0...370)(
)] )]
), ),
(14...17), (14...17),
"A", :A,
:A :A
), ),
ClassNode(19...39)( ClassNode(19...39)(
@ -35,7 +35,7 @@ ProgramNode(0...370)(
(36...39) (36...39)
), ),
(36...39), (36...39),
"A", :A,
:A :A
), ),
ClassNode(41...75)( ClassNode(41...75)(
@ -53,7 +53,7 @@ ProgramNode(0...370)(
(72...75) (72...75)
), ),
(72...75), (72...75),
"A", :A,
:A :A
), ),
ClassNode(77...98)( ClassNode(77...98)(
@ -72,7 +72,7 @@ ProgramNode(0...370)(
)] )]
), ),
(95...98), (95...98),
"A", :A,
:A :A
), ),
SingletonClassNode(100...120)( SingletonClassNode(100...120)(
@ -127,7 +127,7 @@ ProgramNode(0...370)(
)] )]
), ),
(159...162), (159...162),
"A", :A,
:A :A
), ),
ClassNode(164...218)( ClassNode(164...218)(
@ -154,7 +154,7 @@ ProgramNode(0...370)(
)] )]
), ),
(215...218), (215...218),
"A", :A,
:A :A
), ),
SingletonClassNode(220...240)( SingletonClassNode(220...240)(
@ -287,7 +287,7 @@ ProgramNode(0...370)(
), ),
nil, nil,
(367...370), (367...370),
"A", :A,
:A :A
)] )]
) )

View File

@ -1192,7 +1192,7 @@ ProgramNode(0...1237)(
)] )]
), ),
(926...929), (926...929),
"Bar", :Bar,
:Bar :Bar
)] )]
), ),
@ -1225,7 +1225,7 @@ ProgramNode(0...1237)(
)] )]
), ),
(957...960), (957...960),
"Bar", :Bar,
:Bar :Bar
)] )]
), ),

View File

@ -15,7 +15,7 @@ ProgramNode(0...140)(
)] )]
), ),
(15...18), (15...18),
"A", :A,
:A :A
), ),
InterpolatedStringNode(20...38)( InterpolatedStringNode(20...38)(
@ -51,7 +51,7 @@ ProgramNode(0...140)(
), ),
nil, nil,
(52...55), (52...55),
"M", :M,
:M :M
), ),
ModuleNode(57...85)( ModuleNode(57...85)(
@ -75,7 +75,7 @@ ProgramNode(0...140)(
(82...85) (82...85)
), ),
(82...85), (82...85),
"A", :A,
:A :A
), ),
ModuleNode(87...101)( ModuleNode(87...101)(
@ -88,7 +88,7 @@ ProgramNode(0...140)(
), ),
nil, nil,
(98...101), (98...101),
"A", :A,
:A :A
), ),
ModuleNode(103...120)( ModuleNode(103...120)(
@ -111,7 +111,7 @@ ProgramNode(0...140)(
), ),
nil, nil,
(117...120), (117...120),
"B", :B,
:B :B
), ),
ModuleNode(122...140)( ModuleNode(122...140)(
@ -134,7 +134,7 @@ ProgramNode(0...140)(
), ),
nil, nil,
(137...140), (137...140),
"B", :B,
:B :B
)] )]
) )

View File

@ -87,7 +87,7 @@ ProgramNode(0...689)(
)] )]
), ),
(266...269), (266...269),
"X", :X,
:X :X
), ),
ClassNode(293...376)( ClassNode(293...376)(
@ -112,12 +112,12 @@ ProgramNode(0...689)(
)] )]
), ),
(355...358), (355...358),
"Y", :Y,
:Y :Y
)] )]
), ),
(373...376), (373...376),
"X", :X,
:X :X
), ),
ClassNode(395...498)( ClassNode(395...498)(
@ -165,7 +165,7 @@ ProgramNode(0...689)(
)] )]
), ),
(495...498), (495...498),
"X", :X,
:X :X
), ),
ModuleNode(517...565)( ModuleNode(517...565)(
@ -186,7 +186,7 @@ ProgramNode(0...689)(
)] )]
), ),
(562...565), (562...565),
"X", :X,
:X :X
), ),
ModuleNode(568...651)( ModuleNode(568...651)(
@ -207,12 +207,12 @@ ProgramNode(0...689)(
)] )]
), ),
(630...633), (630...633),
"Y", :Y,
:Y :Y
)] )]
), ),
(648...651), (648...651),
"X", :X,
:X :X
), ),
CallNode(670...689)( CallNode(670...689)(

View File

@ -23,7 +23,7 @@ ProgramNode(19...71)(
)] )]
), ),
(68...71), (68...71),
"X", :X,
:X :X
)] )]
) )

View File

@ -31,7 +31,7 @@ ProgramNode(0...28)(
)] )]
), ),
(25...28), (25...28),
"X", :X,
:X :X
)] )]
) )

View File

@ -31,7 +31,7 @@ ProgramNode(0...33)(
)] )]
), ),
(30...33), (30...33),
"X", :X,
:X :X
)] )]
) )

View File

@ -31,7 +31,7 @@ ProgramNode(18...90)(
)] )]
), ),
(87...90), (87...90),
"ExampleUTF8ClassNameVarietà", :ExampleUTF8ClassNameVarietà,
:ExampleUTF8ClassNameVarietà :ExampleUTF8ClassNameVarietà
)] )]
) )

View File

@ -21,7 +21,7 @@ ProgramNode(24...77)(
)] )]
), ),
(74...77), (74...77),
"X", :X,
:X :X
)] )]
) )

View File

@ -19,7 +19,7 @@ ProgramNode(0...48)(
nil, nil,
nil, nil,
(45...48), (45...48),
"Foo", :Foo,
:Foo :Foo
)] )]
) )

View File

@ -9,7 +9,7 @@ ProgramNode(0...213)(
nil, nil,
nil, nil,
(8...11), (8...11),
"A", :A,
:A :A
), ),
SingletonClassNode(13...27)( SingletonClassNode(13...27)(
@ -42,7 +42,7 @@ ProgramNode(0...213)(
nil, nil,
nil, nil,
(60...63), (60...63),
"B", :B,
:B :B
), ),
ClassNode(65...82)( ClassNode(65...82)(
@ -61,7 +61,7 @@ ProgramNode(0...213)(
nil, nil,
nil, nil,
(79...82), (79...82),
"C", :C,
:C :C
), ),
ClassNode(84...99)( ClassNode(84...99)(
@ -72,7 +72,7 @@ ProgramNode(0...213)(
ConstantReadNode(94...95)(:B), ConstantReadNode(94...95)(:B),
nil, nil,
(96...99), (96...99),
"A", :A,
:A :A
), ),
ClassNode(101...119)( ClassNode(101...119)(
@ -87,7 +87,7 @@ ProgramNode(0...213)(
), ),
nil, nil,
(116...119), (116...119),
"A", :A,
:A :A
), ),
ClassNode(121...142)( ClassNode(121...142)(
@ -106,7 +106,7 @@ ProgramNode(0...213)(
), ),
nil, nil,
(139...142), (139...142),
"B", :B,
:B :B
), ),
ClassNode(144...198)( ClassNode(144...198)(
@ -156,7 +156,7 @@ ProgramNode(0...213)(
)] )]
), ),
(195...198), (195...198),
"A", :A,
:A :A
), ),
ClassNode(200...213)( ClassNode(200...213)(
@ -171,7 +171,7 @@ ProgramNode(0...213)(
nil, nil,
nil, nil,
(210...213), (210...213),
"A", :A,
:A :A
)] )]
) )

View File

@ -81,7 +81,7 @@ ProgramNode(0...246)(
)] )]
), ),
(130...133), (130...133),
"A", :A,
:A :A
), ),
ModuleNode(135...170)( ModuleNode(135...170)(
@ -116,7 +116,7 @@ ProgramNode(0...246)(
)] )]
), ),
(167...170), (167...170),
"B", :B,
:B :B
), ),
UnlessNode(171...197)( UnlessNode(171...197)(

View File

@ -7,7 +7,7 @@ ProgramNode(0...106)(
ConstantReadNode(7...8)(:A), ConstantReadNode(7...8)(:A),
nil, nil,
(9...12), (9...12),
"A", :A,
:A :A
), ),
ModuleNode(14...29)( ModuleNode(14...29)(
@ -20,7 +20,7 @@ ProgramNode(0...106)(
), ),
nil, nil,
(26...29), (26...29),
"B", :B,
:B :B
), ),
ModuleNode(31...49)( ModuleNode(31...49)(
@ -37,7 +37,7 @@ ProgramNode(0...106)(
), ),
nil, nil,
(46...49), (46...49),
"C", :C,
:C :C
), ),
ModuleNode(51...106)( ModuleNode(51...106)(
@ -85,7 +85,7 @@ ProgramNode(0...106)(
)] )]
), ),
(103...106), (103...106),
"A", :A,
:A :A
)] )]
) )

View File

@ -38,7 +38,7 @@ ProgramNode(0...999)(
)] )]
), ),
(32...35), (32...35),
"A", :A,
:A :A
), ),
ModuleNode(37...73)( ModuleNode(37...73)(
@ -66,7 +66,7 @@ ProgramNode(0...999)(
)] )]
), ),
(70...73), (70...73),
"A", :A,
:A :A
), ),
CallNode(74...89)( CallNode(74...89)(
@ -78,7 +78,7 @@ ProgramNode(0...999)(
nil, nil,
nil, nil,
(82...85), (82...85),
"A", :A,
:A :A
), ),
(85...86), (85...86),
@ -97,7 +97,7 @@ ProgramNode(0...999)(
ConstantReadNode(97...98)(:A), ConstantReadNode(97...98)(:A),
nil, nil,
(99...102), (99...102),
"A", :A,
:A :A
), ),
(102...103), (102...103),

View File

@ -64,7 +64,7 @@ ProgramNode(0...620)(
)] )]
), ),
(65...68), (65...68),
"A", :A,
:A :A
), ),
DefNode(70...110)( DefNode(70...110)(
@ -160,7 +160,7 @@ ProgramNode(0...620)(
)] )]
), ),
(143...146), (143...146),
"A", :A,
:A :A
), ),
ModuleNode(148...182)( ModuleNode(148...182)(
@ -195,7 +195,7 @@ ProgramNode(0...620)(
)] )]
), ),
(179...182), (179...182),
"A", :A,
:A :A
), ),
ModuleNode(184...228)( ModuleNode(184...228)(
@ -240,7 +240,7 @@ ProgramNode(0...620)(
)] )]
), ),
(225...228), (225...228),
"A", :A,
:A :A
), ),
ModuleNode(230...299)( ModuleNode(230...299)(
@ -316,7 +316,7 @@ ProgramNode(0...620)(
)] )]
), ),
(296...299), (296...299),
"A", :A,
:A :A
), ),
ModuleNode(301...370)( ModuleNode(301...370)(
@ -382,7 +382,7 @@ ProgramNode(0...620)(
)] )]
), ),
(367...370), (367...370),
"A", :A,
:A :A
), ),
LocalVariableWriteNode(371...402)( LocalVariableWriteNode(371...402)(

View File

@ -186,7 +186,7 @@ ProgramNode(0...188)(
)] )]
), ),
(185...188), (185...188),
"A", :A,
:A :A
)] )]
) )

View File

@ -139,7 +139,7 @@ ProgramNode(0...314)(
)] )]
), ),
(195...198), (195...198),
"Foo", :Foo,
:Foo :Foo
), ),
StatementsNode(200...205)([BreakNode(200...205)(nil, (200...205))]), StatementsNode(200...205)([BreakNode(200...205)(nil, (200...205))]),

View File

@ -9,7 +9,7 @@ ProgramNode(0...29)(
nil, nil,
nil, nil,
(10...13), (10...13),
"Foo", :Foo,
:Foo :Foo
), ),
ClassNode(15...29)( ClassNode(15...29)(
@ -20,7 +20,7 @@ ProgramNode(0...29)(
nil, nil,
nil, nil,
(26...29), (26...29),
"Foo", :Foo,
:Foo :Foo
)] )]
) )

View File

@ -88,7 +88,7 @@ ProgramNode(0...197)(
)] )]
), ),
(136...139), (136...139),
"Foo", :Foo,
:Foo :Foo
), ),
StatementsNode(141...146)([BreakNode(141...146)(nil, (141...146))]), StatementsNode(141...146)([BreakNode(141...146)(nil, (141...146))]),
@ -117,7 +117,7 @@ ProgramNode(0...197)(
)] )]
), ),
(182...185), (182...185),
"Foo", :Foo,
:Foo :Foo
), ),
StatementsNode(187...192)([BreakNode(187...192)(nil, (187...192))]), StatementsNode(187...192)([BreakNode(187...192)(nil, (187...192))]),

View File

@ -9,7 +9,7 @@ ProgramNode(0...20)(
ConstantReadNode(12...15)(:Bar), ConstantReadNode(12...15)(:Bar),
nil, nil,
(17...20), (17...20),
"Foo", :Foo,
:Foo :Foo
)] )]
) )

View File

@ -21,7 +21,7 @@ ProgramNode(0...20)(
), ),
nil, nil,
(17...20), (17...20),
"Foo", :Foo,
:Foo :Foo
)] )]
) )

View File

@ -7,7 +7,7 @@ ProgramNode(0...39)(
ConstantPathNode(7...12)(nil, ConstantReadNode(9...12)(:Foo), (7...9)), ConstantPathNode(7...12)(nil, ConstantReadNode(9...12)(:Foo), (7...9)),
nil, nil,
(14...17), (14...17),
"Foo", :Foo,
:Foo :Foo
), ),
ModuleNode(19...39)( ModuleNode(19...39)(
@ -20,7 +20,7 @@ ProgramNode(0...39)(
), ),
nil, nil,
(36...39), (36...39),
"Foo", :Foo,
:Foo :Foo
)] )]
) )

View File

@ -19,7 +19,7 @@ ProgramNode(0...178)(
nil, nil,
nil, nil,
(35...38), (35...38),
"Kernel", :Kernel,
:Kernel :Kernel
), ),
ClassNode(40...87)( ClassNode(40...87)(
@ -45,7 +45,7 @@ ProgramNode(0...178)(
nil, nil,
nil, nil,
(84...87), (84...87),
"Kernel", :Kernel,
:Kernel :Kernel
), ),
ModuleNode(89...128)( ModuleNode(89...128)(
@ -64,7 +64,7 @@ ProgramNode(0...178)(
), ),
nil, nil,
(125...128), (125...128),
"Kernel", :Kernel,
:Kernel :Kernel
), ),
ModuleNode(130...178)( ModuleNode(130...178)(
@ -90,7 +90,7 @@ ProgramNode(0...178)(
), ),
nil, nil,
(175...178), (175...178),
"Kernel", :Kernel,
:Kernel :Kernel
)] )]
) )

View File

@ -7,7 +7,7 @@ ProgramNode(0...15)(
ConstantReadNode(7...10)(:Foo), ConstantReadNode(7...10)(:Foo),
nil, nil,
(12...15), (12...15),
"Foo", :Foo,
:Foo :Foo
)] )]
) )

View File

@ -22,7 +22,7 @@ ProgramNode(0...83)(
[CallNode(36...38)(nil, nil, (36...38), nil, nil, nil, nil, 2, "_1")] [CallNode(36...38)(nil, nil, (36...38), nil, nil, nil, nil, 2, "_1")]
), ),
(40...43), (40...43),
"A", :A,
:A :A
), ),
DefNode(45...64)( DefNode(45...64)(
@ -48,7 +48,7 @@ ProgramNode(0...83)(
[CallNode(76...78)(nil, nil, (76...78), nil, nil, nil, nil, 2, "_1")] [CallNode(76...78)(nil, nil, (76...78), nil, nil, nil, nil, 2, "_1")]
), ),
(80...83), (80...83),
"A", :A,
:A :A
)] )]
) )

View File

@ -49,7 +49,7 @@ ProgramNode(0...132)(
nil, nil,
nil, nil,
(72...75), (72...75),
"C", :C,
:C :C
)] )]
), ),
@ -81,7 +81,7 @@ ProgramNode(0...132)(
ConstantReadNode(116...117)(:M), ConstantReadNode(116...117)(:M),
nil, nil,
(119...122), (119...122),
"M", :M,
:M :M
)] )]
), ),

View File

@ -9,7 +9,7 @@ ProgramNode(0...15)(
ConstantReadNode(10...11)(:B), ConstantReadNode(10...11)(:B),
nil, nil,
(12...15), (12...15),
"A", :A,
:A :A
)] )]
) )

View File

@ -779,7 +779,7 @@ nodes:
- name: end_keyword_loc - name: end_keyword_loc
type: location type: location
- name: name - name: name
type: string type: constant
- name: name_constant - name: name_constant
type: constant type: constant
comment: | comment: |
@ -1739,7 +1739,7 @@ nodes:
- name: end_keyword_loc - name: end_keyword_loc
type: location type: location
- name: name - name: name
type: string type: constant
- name: name_constant - name: name_constant
type: constant type: constant
comment: | comment: |

View File

@ -1647,6 +1647,7 @@ yp_case_node_end_keyword_loc_set(yp_case_node_t *node, const yp_token_t *end_key
static yp_class_node_t * static yp_class_node_t *
yp_class_node_create(yp_parser_t *parser, yp_constant_id_list_t *locals, const yp_token_t *class_keyword, yp_node_t *constant_path, const yp_token_t *name, const yp_token_t *inheritance_operator, yp_node_t *superclass, yp_node_t *body, const yp_token_t *end_keyword) { yp_class_node_create(yp_parser_t *parser, yp_constant_id_list_t *locals, const yp_token_t *class_keyword, yp_node_t *constant_path, const yp_token_t *name, const yp_token_t *inheritance_operator, yp_node_t *superclass, yp_node_t *body, const yp_token_t *end_keyword) {
yp_class_node_t *node = YP_ALLOC_NODE(parser, yp_class_node_t); yp_class_node_t *node = YP_ALLOC_NODE(parser, yp_class_node_t);
yp_constant_id_t name_constant = yp_parser_constant_id_token(parser, name);
*node = (yp_class_node_t) { *node = (yp_class_node_t) {
{ {
@ -1660,11 +1661,10 @@ yp_class_node_create(yp_parser_t *parser, yp_constant_id_list_t *locals, const y
.superclass = superclass, .superclass = superclass,
.body = body, .body = body,
.end_keyword_loc = YP_LOCATION_TOKEN_VALUE(end_keyword), .end_keyword_loc = YP_LOCATION_TOKEN_VALUE(end_keyword),
.name = YP_EMPTY_STRING, .name = name_constant,
.name_constant = yp_parser_constant_id_token(parser, name) .name_constant = name_constant
}; };
yp_string_shared_init(&node->name, name->start, name->end);
return node; return node;
} }
@ -3297,6 +3297,7 @@ yp_match_required_node_create(yp_parser_t *parser, yp_node_t *value, yp_node_t *
static yp_module_node_t * static yp_module_node_t *
yp_module_node_create(yp_parser_t *parser, yp_constant_id_list_t *locals, const yp_token_t *module_keyword, yp_node_t *constant_path, const yp_token_t *name, yp_node_t *body, const yp_token_t *end_keyword) { yp_module_node_create(yp_parser_t *parser, yp_constant_id_list_t *locals, const yp_token_t *module_keyword, yp_node_t *constant_path, const yp_token_t *name, yp_node_t *body, const yp_token_t *end_keyword) {
yp_module_node_t *node = YP_ALLOC_NODE(parser, yp_module_node_t); yp_module_node_t *node = YP_ALLOC_NODE(parser, yp_module_node_t);
yp_constant_id_t name_constant = yp_parser_constant_id_token(parser, name);
*node = (yp_module_node_t) { *node = (yp_module_node_t) {
{ {
@ -3311,11 +3312,10 @@ yp_module_node_create(yp_parser_t *parser, yp_constant_id_list_t *locals, const
.constant_path = constant_path, .constant_path = constant_path,
.body = body, .body = body,
.end_keyword_loc = YP_LOCATION_TOKEN_VALUE(end_keyword), .end_keyword_loc = YP_LOCATION_TOKEN_VALUE(end_keyword),
.name = YP_EMPTY_STRING, .name = name_constant,
.name_constant = yp_parser_constant_id_token(parser, name) .name_constant = name_constant
}; };
yp_string_shared_init(&node->name, name->start, name->end);
return node; return node;
} }