@@ -44,6 +44,10 @@ VALUE rbs_hash_to_ruby_hash(rbs_translation_context_t ctx, rbs_hash_t *rbs_hash)
44
44
}
45
45
46
46
VALUE rbs_loc_to_ruby_location (rbs_translation_context_t ctx , rbs_location_t * source_loc ) {
47
+ if (source_loc == NULL ) {
48
+ return Qnil ;
49
+ }
50
+
47
51
VALUE new_loc = rbs_new_location (ctx .buffer , source_loc -> rg );
48
52
rbs_loc * new_loc_struct = rbs_check_location (new_loc );
49
53
@@ -55,6 +59,20 @@ VALUE rbs_loc_to_ruby_location(rbs_translation_context_t ctx, rbs_location_t *so
55
59
return new_loc ;
56
60
}
57
61
62
+ VALUE rbs_location_list_to_ruby_array (rbs_translation_context_t ctx , rbs_location_list_t * list ) {
63
+ VALUE ruby_array = rb_ary_new ();
64
+
65
+ if (list == NULL ) {
66
+ return ruby_array ;
67
+ }
68
+
69
+ for (rbs_location_list_node_t * n = list -> head ; n != NULL ; n = n -> next ) {
70
+ rb_ary_push (ruby_array , rbs_loc_to_ruby_location (ctx , n -> loc ));
71
+ }
72
+
73
+ return ruby_array ;
74
+ }
75
+
58
76
#ifdef RB_PASS_KEYWORDS
59
77
// Ruby 2.7 or later
60
78
#define CLASS_NEW_INSTANCE (klass , argc , argv )\
@@ -586,6 +604,87 @@ VALUE rbs_struct_to_ruby_value(rbs_translation_context_t ctx, rbs_node_t *instan
586
604
& h
587
605
);
588
606
}
607
+ case RBS_AST_RUBY_ANNOTATIONS_COLON_METHOD_TYPE_ANNOTATION : {
608
+ rbs_ast_ruby_annotations_colon_method_type_annotation_t * node = (rbs_ast_ruby_annotations_colon_method_type_annotation_t * )instance ;
609
+
610
+ VALUE h = rb_hash_new ();
611
+ rb_hash_aset (h , ID2SYM (rb_intern ("location" )), rbs_loc_to_ruby_location (ctx , node -> base .location ));
612
+ rb_hash_aset (h , ID2SYM (rb_intern ("prefix_location" )), rbs_loc_to_ruby_location (ctx , node -> prefix_location ));
613
+ rb_hash_aset (h , ID2SYM (rb_intern ("annotations" )), rbs_node_list_to_ruby_array (ctx , node -> annotations ));
614
+ rb_hash_aset (h , ID2SYM (rb_intern ("method_type" )), rbs_struct_to_ruby_value (ctx , (rbs_node_t * ) node -> method_type )); // rbs_node
615
+
616
+
617
+ return CLASS_NEW_INSTANCE (
618
+ RBS_AST_Ruby_Annotations_ColonMethodTypeAnnotation ,
619
+ 1 ,
620
+ & h
621
+ );
622
+ }
623
+ case RBS_AST_RUBY_ANNOTATIONS_METHOD_TYPES_ANNOTATION : {
624
+ rbs_ast_ruby_annotations_method_types_annotation_t * node = (rbs_ast_ruby_annotations_method_types_annotation_t * )instance ;
625
+
626
+ VALUE h = rb_hash_new ();
627
+ rb_hash_aset (h , ID2SYM (rb_intern ("location" )), rbs_loc_to_ruby_location (ctx , node -> base .location ));
628
+ rb_hash_aset (h , ID2SYM (rb_intern ("prefix_location" )), rbs_loc_to_ruby_location (ctx , node -> prefix_location ));
629
+ rb_hash_aset (h , ID2SYM (rb_intern ("overloads" )), rbs_node_list_to_ruby_array (ctx , node -> overloads ));
630
+ rb_hash_aset (h , ID2SYM (rb_intern ("vertical_bar_locations" )), rbs_location_list_to_ruby_array (ctx , node -> vertical_bar_locations ));
631
+
632
+
633
+ return CLASS_NEW_INSTANCE (
634
+ RBS_AST_Ruby_Annotations_MethodTypesAnnotation ,
635
+ 1 ,
636
+ & h
637
+ );
638
+ }
639
+ case RBS_AST_RUBY_ANNOTATIONS_NODE_TYPE_ASSERTION : {
640
+ rbs_ast_ruby_annotations_node_type_assertion_t * node = (rbs_ast_ruby_annotations_node_type_assertion_t * )instance ;
641
+
642
+ VALUE h = rb_hash_new ();
643
+ rb_hash_aset (h , ID2SYM (rb_intern ("location" )), rbs_loc_to_ruby_location (ctx , node -> base .location ));
644
+ rb_hash_aset (h , ID2SYM (rb_intern ("prefix_location" )), rbs_loc_to_ruby_location (ctx , node -> prefix_location ));
645
+ rb_hash_aset (h , ID2SYM (rb_intern ("type" )), rbs_struct_to_ruby_value (ctx , (rbs_node_t * ) node -> type )); // rbs_node
646
+
647
+
648
+ return CLASS_NEW_INSTANCE (
649
+ RBS_AST_Ruby_Annotations_NodeTypeAssertion ,
650
+ 1 ,
651
+ & h
652
+ );
653
+ }
654
+ case RBS_AST_RUBY_ANNOTATIONS_RETURN_TYPE_ANNOTATION : {
655
+ rbs_ast_ruby_annotations_return_type_annotation_t * node = (rbs_ast_ruby_annotations_return_type_annotation_t * )instance ;
656
+
657
+ VALUE h = rb_hash_new ();
658
+ rb_hash_aset (h , ID2SYM (rb_intern ("location" )), rbs_loc_to_ruby_location (ctx , node -> base .location ));
659
+ rb_hash_aset (h , ID2SYM (rb_intern ("prefix_location" )), rbs_loc_to_ruby_location (ctx , node -> prefix_location ));
660
+ rb_hash_aset (h , ID2SYM (rb_intern ("return_location" )), rbs_loc_to_ruby_location (ctx , node -> return_location ));
661
+ rb_hash_aset (h , ID2SYM (rb_intern ("colon_location" )), rbs_loc_to_ruby_location (ctx , node -> colon_location ));
662
+ rb_hash_aset (h , ID2SYM (rb_intern ("return_type" )), rbs_struct_to_ruby_value (ctx , (rbs_node_t * ) node -> return_type )); // rbs_node
663
+ rb_hash_aset (h , ID2SYM (rb_intern ("comment_location" )), rbs_loc_to_ruby_location (ctx , node -> comment_location ));
664
+
665
+
666
+ return CLASS_NEW_INSTANCE (
667
+ RBS_AST_Ruby_Annotations_ReturnTypeAnnotation ,
668
+ 1 ,
669
+ & h
670
+ );
671
+ }
672
+ case RBS_AST_RUBY_ANNOTATIONS_SKIP_ANNOTATION : {
673
+ rbs_ast_ruby_annotations_skip_annotation_t * node = (rbs_ast_ruby_annotations_skip_annotation_t * )instance ;
674
+
675
+ VALUE h = rb_hash_new ();
676
+ rb_hash_aset (h , ID2SYM (rb_intern ("location" )), rbs_loc_to_ruby_location (ctx , node -> base .location ));
677
+ rb_hash_aset (h , ID2SYM (rb_intern ("prefix_location" )), rbs_loc_to_ruby_location (ctx , node -> prefix_location ));
678
+ rb_hash_aset (h , ID2SYM (rb_intern ("skip_location" )), rbs_loc_to_ruby_location (ctx , node -> skip_location ));
679
+ rb_hash_aset (h , ID2SYM (rb_intern ("comment_location" )), rbs_loc_to_ruby_location (ctx , node -> comment_location ));
680
+
681
+
682
+ return CLASS_NEW_INSTANCE (
683
+ RBS_AST_Ruby_Annotations_SkipAnnotation ,
684
+ 1 ,
685
+ & h
686
+ );
687
+ }
589
688
case RBS_AST_STRING : {
590
689
rbs_ast_string_t * string_node = (rbs_ast_string_t * ) instance ;
591
690
rbs_string_t s = string_node -> string ;
0 commit comments