@@ -174,21 +174,21 @@ public RubyRootNode translate(Nodes.Node node) {
174
174
Split .HEURISTIC , null , Arity .NO_ARGUMENTS );
175
175
}
176
176
177
- public RubyNode visitAliasNode (Nodes .AliasNode node ) {
178
- RubyNode rubyNode ;
177
+ @ Override
178
+ public RubyNode visitAliasGlobalVariableNode (Nodes .AliasGlobalVariableNode node ) {
179
+ RubyNode rubyNode = new AliasGlobalVarNode (toString (node .old_name ), toString (node .new_name ));
179
180
180
- if (node .new_name instanceof Nodes .GlobalVariableReadNode &&
181
- node .old_name instanceof Nodes .GlobalVariableReadNode ) {
182
- rubyNode = new AliasGlobalVarNode (
183
- toString (node .old_name ),
184
- toString (node .new_name ));
185
- } else {
186
- // expected InterpolatedSymbolNode (that should be evaluated in runtime)
187
- // or SymbolNode
188
- rubyNode = new ModuleNodes .AliasKeywordNode (
189
- node .new_name .accept (this ),
190
- node .old_name .accept (this ));
191
- }
181
+ assignNodePositionInSource (node , rubyNode );
182
+ return rubyNode ;
183
+ }
184
+
185
+ @ Override
186
+ public RubyNode visitAliasMethodNode (Nodes .AliasMethodNode node ) {
187
+ // expected InterpolatedSymbolNode (that should be evaluated in runtime)
188
+ // or SymbolNode
189
+ RubyNode rubyNode = new ModuleNodes .AliasKeywordNode (
190
+ node .new_name .accept (this ),
191
+ node .old_name .accept (this ));
192
192
193
193
assignNodePositionInSource (node , rubyNode );
194
194
return rubyNode ;
@@ -452,14 +452,6 @@ public RubyNode visitCallNode(Nodes.CallNode node) {
452
452
return rubyCallNode ;
453
453
}
454
454
455
- public RubyNode visitCallOperatorAndWriteNode (Nodes .CallOperatorAndWriteNode node ) {
456
- return defaultVisit (node );
457
- }
458
-
459
- public RubyNode visitCallOperatorOrWriteNode (Nodes .CallOperatorOrWriteNode node ) {
460
- return defaultVisit (node );
461
- }
462
-
463
455
public RubyNode visitCallOperatorWriteNode (Nodes .CallOperatorWriteNode node ) {
464
456
return defaultVisit (node );
465
457
}
@@ -473,30 +465,21 @@ public RubyNode visitCaseNode(Nodes.CaseNode node) {
473
465
}
474
466
475
467
public RubyNode visitClassNode (Nodes .ClassNode node ) {
476
- final String name ;
477
468
final RubyNode lexicalParent = translateCPath (node .constant_path );
478
469
final RubyNode superClass ;
479
470
480
- if (node .constant_path instanceof Nodes .ConstantReadNode constantNode ) {
481
- name = toString (constantNode );
482
- } else if (node .constant_path instanceof Nodes .ConstantPathNode pathNode ) {
483
- name = toString (pathNode .child );
484
- } else {
485
- throw CompilerDirectives .shouldNotReachHere ();
486
- }
487
-
488
471
if (node .superclass != null ) {
489
472
superClass = node .superclass .accept (this );
490
473
} else {
491
474
superClass = null ;
492
475
}
493
476
494
- final DefineClassNode defineOrGetClass = new DefineClassNode (name , lexicalParent , superClass );
477
+ final DefineClassNode defineOrGetClass = new DefineClassNode (node . name , lexicalParent , superClass );
495
478
496
479
final RubyNode rubyNode = openModule (
497
480
node ,
498
481
defineOrGetClass ,
499
- name ,
482
+ node . name ,
500
483
node .body ,
501
484
OpenModule .CLASS ,
502
485
shouldUseDynamicConstantLookupForModuleBody (node ));
@@ -508,7 +491,7 @@ public RubyNode visitClassNode(Nodes.ClassNode node) {
508
491
public RubyNode visitClassVariableReadNode (Nodes .ClassVariableReadNode node ) {
509
492
final RubyNode rubyNode = new ReadClassVariableNode (
510
493
getLexicalScopeNode ("class variable lookup" , node ),
511
- toString ( node ) );
494
+ node . name );
512
495
513
496
assignNodePositionInSource (node , rubyNode );
514
497
return rubyNode ;
@@ -518,7 +501,7 @@ public RubyNode visitClassVariableWriteNode(Nodes.ClassVariableWriteNode node) {
518
501
final RubyNode rhs = node .value .accept (this );
519
502
final RubyNode rubyNode = new WriteClassVariableNode (
520
503
getLexicalScopeNode ("set dynamic class variable" , node ),
521
- toString ( node .name ) ,
504
+ node .name ,
522
505
rhs );
523
506
524
507
assignNodePositionInSource (node , rubyNode );
@@ -528,7 +511,7 @@ public RubyNode visitClassVariableWriteNode(Nodes.ClassVariableWriteNode node) {
528
511
public RubyNode visitClassVariableTargetNode (Nodes .ClassVariableTargetNode node ) {
529
512
final RubyNode rubyNode = new WriteClassVariableNode (
530
513
getLexicalScopeNode ("set dynamic class variable" , node ),
531
- toString ( node .name ) ,
514
+ node .name ,
532
515
null );
533
516
534
517
assignNodePositionInSource (node , rubyNode );
@@ -538,7 +521,7 @@ public RubyNode visitClassVariableTargetNode(Nodes.ClassVariableTargetNode node)
538
521
public RubyNode visitConstantPathNode (Nodes .ConstantPathNode node ) {
539
522
assert node .child instanceof Nodes .ConstantReadNode ;
540
523
541
- final String name = toString ( node .child );
524
+ final String name = (( Nodes . ConstantReadNode ) node .child ). name ;
542
525
final RubyNode moduleNode ;
543
526
544
527
if (node .parent != null ) {
@@ -567,7 +550,7 @@ public RubyNode visitConstantPathWriteNode(Nodes.ConstantPathWriteNode node) {
567
550
moduleNode = new ObjectClassLiteralNode ();
568
551
}
569
552
570
- final String name = toString ( constantPathNode .child );
553
+ final String name = (( Nodes . ConstantReadNode ) constantPathNode .child ). name ;
571
554
final RubyNode value = node .value .accept (this );
572
555
final RubyNode rubyNode = new WriteConstantNode (name , moduleNode , value );
573
556
@@ -585,7 +568,7 @@ public RubyNode visitConstantPathTargetNode(Nodes.ConstantPathTargetNode node) {
585
568
moduleNode = new ObjectClassLiteralNode ();
586
569
}
587
570
588
- final String name = toString ( node .child );
571
+ final String name = (( Nodes . ConstantReadNode ) node .child ). name ;
589
572
final RubyNode rubyNode = new WriteConstantNode (name , moduleNode , null );
590
573
591
574
assignNodePositionInSource (node , rubyNode );
@@ -594,38 +577,35 @@ public RubyNode visitConstantPathTargetNode(Nodes.ConstantPathTargetNode node) {
594
577
595
578
public RubyNode visitConstantReadNode (Nodes .ConstantReadNode node ) {
596
579
final RubyNode rubyNode ;
597
- final String name = toString (node );
598
580
599
581
if (environment .isDynamicConstantLookup ()) {
600
582
if (language .options .LOG_DYNAMIC_CONSTANT_LOOKUP ) {
601
583
RubyLanguage .LOGGER .info (() -> "dynamic constant lookup at " +
602
584
RubyLanguage .getCurrentContext ().fileLine (getSourceSection (node )));
603
585
}
604
586
605
- rubyNode = new ReadConstantWithDynamicScopeNode (name );
587
+ rubyNode = new ReadConstantWithDynamicScopeNode (node . name );
606
588
} else {
607
589
final LexicalScope lexicalScope = environment .getStaticLexicalScope ();
608
- rubyNode = new ReadConstantWithLexicalScopeNode (lexicalScope , name );
590
+ rubyNode = new ReadConstantWithLexicalScopeNode (lexicalScope , node . name );
609
591
}
610
592
611
593
assignNodePositionInSource (node , rubyNode );
612
594
return rubyNode ;
613
595
}
614
596
615
597
public RubyNode visitConstantWriteNode (Nodes .ConstantWriteNode node ) {
616
- final String name = toString (node .name_loc );
617
598
final RubyNode value = node .value .accept (this );
618
599
final RubyNode moduleNode = getLexicalScopeModuleNode ("set dynamic constant" , node );
619
- final RubyNode rubyNode = new WriteConstantNode (name , moduleNode , value );
600
+ final RubyNode rubyNode = new WriteConstantNode (node . name , moduleNode , value );
620
601
621
602
assignNodePositionInSource (node , rubyNode );
622
603
return rubyNode ;
623
604
}
624
605
625
606
public RubyNode visitConstantTargetNode (Nodes .ConstantTargetNode node ) {
626
- final String name = toString (node );
627
607
final RubyNode moduleNode = getLexicalScopeModuleNode ("set dynamic constant" , node );
628
- final RubyNode rubyNode = new WriteConstantNode (name , moduleNode , null );
608
+ final RubyNode rubyNode = new WriteConstantNode (node . name , moduleNode , null );
629
609
630
610
assignNodePositionInSource (node , rubyNode );
631
611
return rubyNode ;
@@ -725,23 +705,21 @@ public RubyNode visitForwardingSuperNode(Nodes.ForwardingSuperNode node) {
725
705
}
726
706
727
707
public RubyNode visitGlobalVariableReadNode (Nodes .GlobalVariableReadNode node ) {
728
- final RubyNode rubyNode = ReadGlobalVariableNodeGen .create (toString ( node ) );
708
+ final RubyNode rubyNode = ReadGlobalVariableNodeGen .create (node . name );
729
709
assignNodePositionInSource (node , rubyNode );
730
710
return rubyNode ;
731
711
}
732
712
733
713
public RubyNode visitGlobalVariableWriteNode (Nodes .GlobalVariableWriteNode node ) {
734
- final String name = toString (node .name );
735
714
final RubyNode value = node .value .accept (this );
736
- final RubyNode rubyNode = WriteGlobalVariableNodeGen .create (name , value );
715
+ final RubyNode rubyNode = WriteGlobalVariableNodeGen .create (node . name , value );
737
716
738
717
assignNodePositionInSource (node , rubyNode );
739
718
return rubyNode ;
740
719
}
741
720
742
721
public RubyNode visitGlobalVariableTargetNode (Nodes .GlobalVariableTargetNode node ) {
743
- final String name = toString (node .name );
744
- final RubyNode rubyNode = WriteGlobalVariableNodeGen .create (name , null );
722
+ final RubyNode rubyNode = WriteGlobalVariableNodeGen .create (node .name , null );
745
723
746
724
assignNodePositionInSource (node , rubyNode );
747
725
return rubyNode ;
@@ -848,25 +826,22 @@ public RubyNode visitInNode(Nodes.InNode node) {
848
826
}
849
827
850
828
public RubyNode visitInstanceVariableReadNode (Nodes .InstanceVariableReadNode node ) {
851
- final String name = toString (node );
852
- final RubyNode rubyNode = new ReadInstanceVariableNode (name );
829
+ final RubyNode rubyNode = new ReadInstanceVariableNode (node .name );
853
830
854
831
assignNodePositionInSource (node , rubyNode );
855
832
return rubyNode ;
856
833
}
857
834
858
835
public RubyNode visitInstanceVariableWriteNode (Nodes .InstanceVariableWriteNode node ) {
859
- final String name = toString (node .name );
860
836
final RubyNode value = node .value .accept (this );
861
- final RubyNode rubyNode = WriteInstanceVariableNodeGen .create (name , value );
837
+ final RubyNode rubyNode = WriteInstanceVariableNodeGen .create (node . name , value );
862
838
863
839
assignNodePositionInSource (node , rubyNode );
864
840
return rubyNode ;
865
841
}
866
842
867
843
public RubyNode visitInstanceVariableTargetNode (Nodes .InstanceVariableTargetNode node ) {
868
- final String name = toString (node .name );
869
- final RubyNode rubyNode = WriteInstanceVariableNodeGen .create (name , null );
844
+ final RubyNode rubyNode = WriteInstanceVariableNodeGen .create (node .name , null );
870
845
871
846
assignNodePositionInSource (node , rubyNode );
872
847
return rubyNode ;
@@ -954,8 +929,7 @@ public RubyNode visitInterpolatedSymbolNode(Nodes.InterpolatedSymbolNode node) {
954
929
}
955
930
956
931
public RubyNode visitInterpolatedXStringNode (Nodes .InterpolatedXStringNode node ) {
957
- final Nodes .InterpolatedStringNode stringNode = new Nodes .InterpolatedStringNode (
958
- node .opening_loc , node .parts , node .closing_loc , node .startOffset , node .length );
932
+ var stringNode = new Nodes .InterpolatedStringNode (node .parts , node .startOffset , node .length );
959
933
final RubyNode string = stringNode .accept (this );
960
934
final RubyNode rubyNode = createCallNode (new SelfNode (), "`" , string );
961
935
@@ -972,7 +946,7 @@ public RubyNode visitLambdaNode(Nodes.LambdaNode node) {
972
946
}
973
947
974
948
public RubyNode visitLocalVariableReadNode (Nodes .LocalVariableReadNode node ) {
975
- final String name = toString ( node ) ;
949
+ final String name = node . name ;
976
950
977
951
final RubyNode rubyNode = environment .findLocalVarNode (name , null );
978
952
assert rubyNode != null : name ;
@@ -982,7 +956,7 @@ public RubyNode visitLocalVariableReadNode(Nodes.LocalVariableReadNode node) {
982
956
}
983
957
984
958
public RubyNode visitLocalVariableWriteNode (Nodes .LocalVariableWriteNode node ) {
985
- final String name = toString ( node .name ) ;
959
+ final String name = node .name ;
986
960
987
961
if (environment .getNeverAssignInParentScope ()) {
988
962
environment .declareVar (name );
@@ -1016,8 +990,7 @@ public RubyNode visitLocalVariableWriteNode(Nodes.LocalVariableWriteNode node) {
1016
990
public RubyNode visitLocalVariableTargetNode (Nodes .LocalVariableTargetNode node ) {
1017
991
// TODO: this could be done more directly but the logic of visitLocalVariableWriteNode() needs to be simpler first
1018
992
return visitLocalVariableWriteNode (
1019
- new Nodes .LocalVariableWriteNode (node .name , node .depth , null , null , null , node .startOffset ,
1020
- node .length ));
993
+ new Nodes .LocalVariableWriteNode (node .name , node .depth , null , node .startOffset , node .length ));
1021
994
}
1022
995
1023
996
public RubyNode visitMatchPredicateNode (Nodes .MatchPredicateNode node ) {
@@ -1033,23 +1006,14 @@ public RubyNode visitMissingNode(Nodes.MissingNode node) {
1033
1006
}
1034
1007
1035
1008
public RubyNode visitModuleNode (Nodes .ModuleNode node ) {
1036
- final String name ;
1037
1009
final RubyNode lexicalParent = translateCPath (node .constant_path );
1038
1010
1039
- if (node .constant_path instanceof Nodes .ConstantReadNode constantNode ) {
1040
- name = toString (constantNode );
1041
- } else if (node .constant_path instanceof Nodes .ConstantPathNode pathNode ) {
1042
- name = toString (pathNode .child );
1043
- } else {
1044
- throw CompilerDirectives .shouldNotReachHere ();
1045
- }
1046
-
1047
- final DefineModuleNode defineModuleNode = DefineModuleNodeGen .create (name , lexicalParent );
1011
+ final DefineModuleNode defineModuleNode = DefineModuleNodeGen .create (node .name , lexicalParent );
1048
1012
1049
1013
final RubyNode rubyNode = openModule (
1050
1014
node ,
1051
1015
defineModuleNode ,
1052
- name ,
1016
+ node . name ,
1053
1017
node .body ,
1054
1018
OpenModule .MODULE ,
1055
1019
shouldUseDynamicConstantLookupForModuleBody (node ));
@@ -1348,8 +1312,8 @@ public RubyNode visitWhileNode(Nodes.WhileNode node) {
1348
1312
}
1349
1313
1350
1314
public RubyNode visitXStringNode (Nodes .XStringNode node ) {
1351
- final Nodes . StringNode stringNode = new Nodes . StringNode (
1352
- node . opening_loc , node . content_loc , node . closing_loc , node .unescaped , node .startOffset , node .length );
1315
+ // TODO: pass flags, needs https://github.com/ruby/yarp/issues/1567
1316
+ var stringNode = new Nodes . StringNode (( short ) 0 , null , null , node .unescaped , node .startOffset , node .length );
1353
1317
final RubyNode string = stringNode .accept (this );
1354
1318
final RubyNode rubyNode = createCallNode (new SelfNode (), "`" , string );
1355
1319
@@ -1694,16 +1658,6 @@ protected boolean isSideEffectFreeRescueExpression(Nodes.Node node) {
1694
1658
node instanceof Nodes .NilNode ;
1695
1659
}
1696
1660
1697
- private String toString (byte [] bytes ) {
1698
- return TStringUtils .toJavaStringOrThrow (
1699
- TruffleString .fromByteArrayUncached (bytes , sourceEncoding .tencoding , false ), sourceEncoding );
1700
- }
1701
-
1702
- private String toString (Nodes .Location location ) {
1703
- return TStringUtils .toJavaStringOrThrow (TruffleString .fromByteArrayUncached (sourceBytes , location .startOffset ,
1704
- location .length , sourceEncoding .tencoding , false ), sourceEncoding );
1705
- }
1706
-
1707
1661
private String toString (Nodes .Node node ) {
1708
1662
return TStringUtils .toJavaStringOrThrow (TruffleString .fromByteArrayUncached (sourceBytes , node .startOffset ,
1709
1663
node .length , sourceEncoding .tencoding , false ), sourceEncoding );
0 commit comments