rbs 3.9.5 → 3.10.0.pre.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (171) hide show
  1. checksums.yaml +4 -4
  2. data/.clang-format +74 -0
  3. data/.clangd +2 -0
  4. data/.github/workflows/c-check.yml +54 -0
  5. data/.github/workflows/comments.yml +3 -3
  6. data/.github/workflows/ruby.yml +34 -19
  7. data/.github/workflows/typecheck.yml +1 -1
  8. data/.github/workflows/windows.yml +1 -1
  9. data/.gitignore +4 -0
  10. data/README.md +38 -1
  11. data/Rakefile +152 -23
  12. data/config.yml +190 -62
  13. data/core/array.rbs +44 -43
  14. data/core/dir.rbs +2 -2
  15. data/core/encoding.rbs +3 -2
  16. data/core/enumerable.rbs +89 -2
  17. data/core/errno.rbs +8 -0
  18. data/core/errors.rbs +28 -1
  19. data/core/exception.rbs +2 -2
  20. data/core/fiber.rbs +3 -3
  21. data/core/file.rbs +26 -11
  22. data/core/float.rbs +1 -1
  23. data/core/gc.rbs +422 -281
  24. data/core/hash.rbs +1024 -727
  25. data/core/io/wait.rbs +11 -33
  26. data/core/io.rbs +6 -4
  27. data/core/kernel.rbs +49 -43
  28. data/core/marshal.rbs +1 -1
  29. data/core/match_data.rbs +1 -1
  30. data/core/math.rbs +42 -3
  31. data/core/method.rbs +14 -6
  32. data/core/module.rbs +71 -11
  33. data/core/nil_class.rbs +3 -3
  34. data/core/numeric.rbs +8 -8
  35. data/core/object.rbs +3 -3
  36. data/core/object_space.rbs +13 -0
  37. data/{stdlib/pathname/0 → core}/pathname.rbs +253 -352
  38. data/core/proc.rbs +15 -8
  39. data/core/process.rbs +2 -2
  40. data/core/ractor.rbs +278 -437
  41. data/core/range.rbs +6 -7
  42. data/core/rbs/unnamed/argf.rbs +1 -1
  43. data/core/rbs/unnamed/env_class.rbs +1 -1
  44. data/core/rbs/unnamed/random.rbs +4 -2
  45. data/core/regexp.rbs +22 -17
  46. data/core/ruby_vm.rbs +6 -4
  47. data/core/rubygems/errors.rbs +3 -70
  48. data/core/rubygems/rubygems.rbs +11 -79
  49. data/core/set.rbs +439 -332
  50. data/core/string.rbs +2897 -1117
  51. data/core/struct.rbs +1 -1
  52. data/core/symbol.rbs +4 -4
  53. data/core/thread.rbs +83 -20
  54. data/core/time.rbs +35 -9
  55. data/core/unbound_method.rbs +14 -6
  56. data/docs/aliases.md +79 -0
  57. data/docs/collection.md +2 -2
  58. data/docs/gem.md +0 -1
  59. data/docs/sigs.md +3 -3
  60. data/ext/rbs_extension/ast_translation.c +1016 -0
  61. data/ext/rbs_extension/ast_translation.h +37 -0
  62. data/ext/rbs_extension/class_constants.c +157 -0
  63. data/{include/rbs/constants.h → ext/rbs_extension/class_constants.h} +7 -1
  64. data/ext/rbs_extension/compat.h +10 -0
  65. data/ext/rbs_extension/extconf.rb +25 -1
  66. data/ext/rbs_extension/legacy_location.c +317 -0
  67. data/ext/rbs_extension/legacy_location.h +45 -0
  68. data/ext/rbs_extension/main.c +365 -14
  69. data/ext/rbs_extension/rbs_extension.h +6 -21
  70. data/ext/rbs_extension/rbs_string_bridging.c +9 -0
  71. data/ext/rbs_extension/rbs_string_bridging.h +24 -0
  72. data/include/rbs/ast.h +687 -0
  73. data/include/rbs/defines.h +86 -0
  74. data/include/rbs/lexer.h +199 -0
  75. data/include/rbs/location.h +59 -0
  76. data/include/rbs/parser.h +135 -0
  77. data/include/rbs/string.h +49 -0
  78. data/include/rbs/util/rbs_allocator.h +59 -0
  79. data/include/rbs/util/rbs_assert.h +20 -0
  80. data/include/rbs/util/rbs_buffer.h +83 -0
  81. data/include/rbs/util/rbs_constant_pool.h +6 -67
  82. data/include/rbs/util/rbs_encoding.h +282 -0
  83. data/include/rbs/util/rbs_unescape.h +23 -0
  84. data/include/rbs.h +1 -2
  85. data/lib/rbs/annotate/formatter.rb +3 -13
  86. data/lib/rbs/annotate/rdoc_annotator.rb +3 -1
  87. data/lib/rbs/annotate/rdoc_source.rb +1 -1
  88. data/lib/rbs/cli/validate.rb +2 -2
  89. data/lib/rbs/cli.rb +1 -1
  90. data/lib/rbs/collection/config/lockfile_generator.rb +1 -0
  91. data/lib/rbs/definition_builder/ancestor_builder.rb +5 -5
  92. data/lib/rbs/environment.rb +64 -59
  93. data/lib/rbs/environment_loader.rb +1 -1
  94. data/lib/rbs/errors.rb +1 -1
  95. data/lib/rbs/parser_aux.rb +5 -0
  96. data/lib/rbs/resolver/constant_resolver.rb +2 -2
  97. data/lib/rbs/resolver/type_name_resolver.rb +124 -38
  98. data/lib/rbs/test/type_check.rb +13 -0
  99. data/lib/rbs/types.rb +3 -1
  100. data/lib/rbs/version.rb +1 -1
  101. data/lib/rbs.rb +1 -1
  102. data/lib/rdoc/discover.rb +1 -1
  103. data/lib/rdoc_plugin/parser.rb +3 -3
  104. data/sig/annotate/formatter.rbs +2 -2
  105. data/sig/annotate/rdoc_annotater.rbs +1 -1
  106. data/sig/environment.rbs +57 -6
  107. data/sig/manifest.yaml +0 -1
  108. data/sig/parser.rbs +20 -0
  109. data/sig/resolver/type_name_resolver.rbs +38 -7
  110. data/sig/types.rbs +4 -1
  111. data/src/ast.c +1256 -0
  112. data/src/lexer.c +2956 -0
  113. data/src/lexer.re +147 -0
  114. data/src/lexstate.c +205 -0
  115. data/src/location.c +71 -0
  116. data/src/parser.c +3495 -0
  117. data/src/string.c +90 -0
  118. data/src/util/rbs_allocator.c +152 -0
  119. data/src/util/rbs_assert.c +21 -0
  120. data/src/util/rbs_buffer.c +54 -0
  121. data/src/util/rbs_constant_pool.c +16 -86
  122. data/src/util/rbs_encoding.c +21308 -0
  123. data/src/util/rbs_unescape.c +131 -0
  124. data/stdlib/cgi/0/core.rbs +2 -396
  125. data/stdlib/cgi/0/manifest.yaml +1 -0
  126. data/stdlib/cgi-escape/0/escape.rbs +153 -0
  127. data/stdlib/coverage/0/coverage.rbs +3 -1
  128. data/stdlib/delegate/0/delegator.rbs +10 -7
  129. data/stdlib/erb/0/erb.rbs +737 -347
  130. data/stdlib/fileutils/0/fileutils.rbs +18 -13
  131. data/stdlib/forwardable/0/forwardable.rbs +3 -0
  132. data/stdlib/json/0/json.rbs +67 -48
  133. data/stdlib/net-http/0/net-http.rbs +3 -0
  134. data/stdlib/objspace/0/objspace.rbs +8 -3
  135. data/stdlib/open-uri/0/open-uri.rbs +40 -0
  136. data/stdlib/openssl/0/openssl.rbs +182 -149
  137. data/stdlib/optparse/0/optparse.rbs +3 -3
  138. data/stdlib/rdoc/0/code_object.rbs +2 -2
  139. data/stdlib/rdoc/0/comment.rbs +2 -0
  140. data/stdlib/rdoc/0/options.rbs +76 -0
  141. data/stdlib/rdoc/0/rdoc.rbs +7 -5
  142. data/stdlib/rdoc/0/store.rbs +1 -1
  143. data/stdlib/resolv/0/resolv.rbs +25 -68
  144. data/stdlib/ripper/0/ripper.rbs +5 -2
  145. data/stdlib/singleton/0/singleton.rbs +3 -0
  146. data/stdlib/socket/0/socket.rbs +13 -1
  147. data/stdlib/socket/0/tcp_socket.rbs +10 -2
  148. data/stdlib/stringio/0/stringio.rbs +412 -80
  149. data/stdlib/strscan/0/string_scanner.rbs +31 -31
  150. data/stdlib/tempfile/0/tempfile.rbs +1 -1
  151. data/stdlib/tsort/0/cyclic.rbs +3 -0
  152. data/stdlib/uri/0/common.rbs +11 -2
  153. data/stdlib/uri/0/file.rbs +1 -1
  154. data/stdlib/uri/0/generic.rbs +16 -15
  155. data/stdlib/uri/0/rfc2396_parser.rbs +6 -7
  156. data/stdlib/zlib/0/zstream.rbs +1 -0
  157. metadata +41 -18
  158. data/ext/rbs_extension/lexer.c +0 -2728
  159. data/ext/rbs_extension/lexer.h +0 -179
  160. data/ext/rbs_extension/lexer.re +0 -147
  161. data/ext/rbs_extension/lexstate.c +0 -175
  162. data/ext/rbs_extension/location.c +0 -325
  163. data/ext/rbs_extension/location.h +0 -85
  164. data/ext/rbs_extension/parser.c +0 -2982
  165. data/ext/rbs_extension/parser.h +0 -18
  166. data/ext/rbs_extension/parserstate.c +0 -411
  167. data/ext/rbs_extension/parserstate.h +0 -163
  168. data/ext/rbs_extension/unescape.c +0 -32
  169. data/include/rbs/ruby_objs.h +0 -72
  170. data/src/constants.c +0 -153
  171. data/src/ruby_objs.c +0 -799
@@ -0,0 +1,1016 @@
1
+ /*----------------------------------------------------------------------------*/
2
+ /* This file is generated by the templates/template.rb script and should not */
3
+ /* be modified manually. */
4
+ /* To change the template see */
5
+ /* templates/ext/rbs_extension/ast_translation.c.erb */
6
+ /*----------------------------------------------------------------------------*/
7
+
8
+ #include "ast_translation.h"
9
+
10
+ #include "class_constants.h"
11
+ #include "rbs_string_bridging.h"
12
+ #include "legacy_location.h"
13
+
14
+ VALUE EMPTY_ARRAY;
15
+ VALUE EMPTY_HASH;
16
+
17
+ #define RBS_LOC_CHILDREN_SIZE(cap) (sizeof(rbs_loc_children) + sizeof(rbs_loc_entry) * ((cap) - 1))
18
+
19
+ rbs_translation_context_t rbs_translation_context_create(rbs_constant_pool_t *constant_pool, VALUE buffer, rb_encoding *ruby_encoding) {
20
+ return (rbs_translation_context_t) {
21
+ .constant_pool = constant_pool,
22
+ .buffer = buffer,
23
+ .encoding = ruby_encoding,
24
+ };
25
+ }
26
+
27
+ VALUE rbs_node_list_to_ruby_array(rbs_translation_context_t ctx, rbs_node_list_t *list) {
28
+ VALUE ruby_array = rb_ary_new();
29
+
30
+ for (rbs_node_list_node_t *n = list->head; n != NULL; n = n->next) {
31
+ rb_ary_push(ruby_array, rbs_struct_to_ruby_value(ctx, n->node));
32
+ }
33
+
34
+ return ruby_array;
35
+ }
36
+
37
+ VALUE rbs_hash_to_ruby_hash(rbs_translation_context_t ctx, rbs_hash_t *rbs_hash) {
38
+ if (!rbs_hash->head) {
39
+ return EMPTY_HASH;
40
+ }
41
+
42
+ VALUE ruby_hash = rb_hash_new();
43
+
44
+ for (rbs_hash_node_t *n = rbs_hash->head; n != NULL; n = n->next) {
45
+ VALUE key = rbs_struct_to_ruby_value(ctx, n->key);
46
+ VALUE value = rbs_struct_to_ruby_value(ctx, n->value);
47
+ rb_hash_aset(ruby_hash, key, value);
48
+ }
49
+
50
+ return ruby_hash;
51
+ }
52
+
53
+ VALUE rbs_loc_to_ruby_location(rbs_translation_context_t ctx, rbs_location_t *source_loc) {
54
+ if (source_loc == NULL) {
55
+ return Qnil;
56
+ }
57
+
58
+ VALUE new_loc = rbs_new_location(ctx.buffer, source_loc->rg);
59
+ rbs_loc *new_loc_struct = rbs_check_location(new_loc);
60
+
61
+ if (source_loc->children != NULL) {
62
+ rbs_loc_legacy_alloc_children(new_loc_struct, source_loc->children->cap);
63
+ memcpy(new_loc_struct->children, source_loc->children, RBS_LOC_CHILDREN_SIZE(source_loc->children->cap));
64
+ }
65
+
66
+ return new_loc;
67
+ }
68
+
69
+ VALUE rbs_location_list_to_ruby_array(rbs_translation_context_t ctx, rbs_location_list_t *list) {
70
+ if (list == NULL) {
71
+ return EMPTY_ARRAY;
72
+ }
73
+
74
+ VALUE ruby_array = rb_ary_new();
75
+
76
+ for (rbs_location_list_node_t *n = list->head; n != NULL; n = n->next) {
77
+ rb_ary_push(ruby_array, rbs_loc_to_ruby_location(ctx, n->loc));
78
+ }
79
+
80
+ return ruby_array;
81
+ }
82
+
83
+ #ifdef RB_PASS_KEYWORDS
84
+ // Ruby 2.7 or later
85
+ #define CLASS_NEW_INSTANCE(klass, argc, argv) \
86
+ rb_class_new_instance_kw(argc, argv, klass, RB_PASS_KEYWORDS)
87
+ #else
88
+ // Ruby 2.6
89
+ #define CLASS_NEW_INSTANCE(receiver, argc, argv) \
90
+ rb_class_new_instance(argc, argv, receiver)
91
+ #endif
92
+
93
+ VALUE rbs_struct_to_ruby_value(rbs_translation_context_t ctx, rbs_node_t *instance) {
94
+ if (instance == NULL) return Qnil;
95
+
96
+ switch (instance->type) {
97
+ case RBS_AST_ANNOTATION: {
98
+ rbs_ast_annotation_t *node = (rbs_ast_annotation_t *) instance;
99
+
100
+ VALUE h = rb_hash_new();
101
+ rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location));
102
+ rb_hash_aset(h, ID2SYM(rb_intern("string")), rbs_string_to_ruby_string(&node->string, ctx.encoding));
103
+
104
+ return CLASS_NEW_INSTANCE(
105
+ RBS_AST_Annotation,
106
+ 1,
107
+ &h
108
+ );
109
+ }
110
+ case RBS_AST_BOOL: {
111
+ return ((rbs_ast_bool_t *) instance)->value ? Qtrue : Qfalse;
112
+ }
113
+ case RBS_AST_COMMENT: {
114
+ rbs_ast_comment_t *node = (rbs_ast_comment_t *) instance;
115
+
116
+ VALUE h = rb_hash_new();
117
+ rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location));
118
+ rb_hash_aset(h, ID2SYM(rb_intern("string")), rbs_string_to_ruby_string(&node->string, ctx.encoding));
119
+
120
+ return CLASS_NEW_INSTANCE(
121
+ RBS_AST_Comment,
122
+ 1,
123
+ &h
124
+ );
125
+ }
126
+ case RBS_AST_DECLARATIONS_CLASS: {
127
+ rbs_ast_declarations_class_t *node = (rbs_ast_declarations_class_t *) instance;
128
+
129
+ VALUE h = rb_hash_new();
130
+ rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location));
131
+ rb_hash_aset(h, ID2SYM(rb_intern("name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->name)); // rbs_type_name
132
+ rb_hash_aset(h, ID2SYM(rb_intern("type_params")), rbs_node_list_to_ruby_array(ctx, node->type_params));
133
+ rb_hash_aset(h, ID2SYM(rb_intern("super_class")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->super_class)); // rbs_ast_declarations_class_super
134
+ rb_hash_aset(h, ID2SYM(rb_intern("members")), rbs_node_list_to_ruby_array(ctx, node->members));
135
+ rb_hash_aset(h, ID2SYM(rb_intern("annotations")), rbs_node_list_to_ruby_array(ctx, node->annotations));
136
+ rb_hash_aset(h, ID2SYM(rb_intern("comment")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->comment)); // rbs_ast_comment
137
+
138
+ rb_funcall(
139
+ RBS_AST_TypeParam,
140
+ rb_intern("resolve_variables"),
141
+ 1,
142
+ rb_hash_lookup(h, ID2SYM(rb_intern("type_params")))
143
+ );
144
+ return CLASS_NEW_INSTANCE(
145
+ RBS_AST_Declarations_Class,
146
+ 1,
147
+ &h
148
+ );
149
+ }
150
+ case RBS_AST_DECLARATIONS_CLASS_SUPER: {
151
+ rbs_ast_declarations_class_super_t *node = (rbs_ast_declarations_class_super_t *) instance;
152
+
153
+ VALUE h = rb_hash_new();
154
+ rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location));
155
+ rb_hash_aset(h, ID2SYM(rb_intern("name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->name)); // rbs_type_name
156
+ rb_hash_aset(h, ID2SYM(rb_intern("args")), rbs_node_list_to_ruby_array(ctx, node->args));
157
+
158
+ return CLASS_NEW_INSTANCE(
159
+ RBS_AST_Declarations_Class_Super,
160
+ 1,
161
+ &h
162
+ );
163
+ }
164
+ case RBS_AST_DECLARATIONS_CLASS_ALIAS: {
165
+ rbs_ast_declarations_class_alias_t *node = (rbs_ast_declarations_class_alias_t *) instance;
166
+
167
+ VALUE h = rb_hash_new();
168
+ rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location));
169
+ rb_hash_aset(h, ID2SYM(rb_intern("new_name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->new_name)); // rbs_type_name
170
+ rb_hash_aset(h, ID2SYM(rb_intern("old_name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->old_name)); // rbs_type_name
171
+ rb_hash_aset(h, ID2SYM(rb_intern("comment")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->comment)); // rbs_ast_comment
172
+ rb_hash_aset(h, ID2SYM(rb_intern("annotations")), rbs_node_list_to_ruby_array(ctx, node->annotations));
173
+
174
+ return CLASS_NEW_INSTANCE(
175
+ RBS_AST_Declarations_ClassAlias,
176
+ 1,
177
+ &h
178
+ );
179
+ }
180
+ case RBS_AST_DECLARATIONS_CONSTANT: {
181
+ rbs_ast_declarations_constant_t *node = (rbs_ast_declarations_constant_t *) instance;
182
+
183
+ VALUE h = rb_hash_new();
184
+ rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location));
185
+ rb_hash_aset(h, ID2SYM(rb_intern("name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->name)); // rbs_type_name
186
+ rb_hash_aset(h, ID2SYM(rb_intern("type")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->type)); // rbs_node
187
+ rb_hash_aset(h, ID2SYM(rb_intern("comment")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->comment)); // rbs_ast_comment
188
+ rb_hash_aset(h, ID2SYM(rb_intern("annotations")), rbs_node_list_to_ruby_array(ctx, node->annotations));
189
+
190
+ return CLASS_NEW_INSTANCE(
191
+ RBS_AST_Declarations_Constant,
192
+ 1,
193
+ &h
194
+ );
195
+ }
196
+ case RBS_AST_DECLARATIONS_GLOBAL: {
197
+ rbs_ast_declarations_global_t *node = (rbs_ast_declarations_global_t *) instance;
198
+
199
+ VALUE h = rb_hash_new();
200
+ rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location));
201
+ rb_hash_aset(h, ID2SYM(rb_intern("name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->name)); // rbs_ast_symbol
202
+ rb_hash_aset(h, ID2SYM(rb_intern("type")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->type)); // rbs_node
203
+ rb_hash_aset(h, ID2SYM(rb_intern("comment")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->comment)); // rbs_ast_comment
204
+ rb_hash_aset(h, ID2SYM(rb_intern("annotations")), rbs_node_list_to_ruby_array(ctx, node->annotations));
205
+
206
+ return CLASS_NEW_INSTANCE(
207
+ RBS_AST_Declarations_Global,
208
+ 1,
209
+ &h
210
+ );
211
+ }
212
+ case RBS_AST_DECLARATIONS_INTERFACE: {
213
+ rbs_ast_declarations_interface_t *node = (rbs_ast_declarations_interface_t *) instance;
214
+
215
+ VALUE h = rb_hash_new();
216
+ rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location));
217
+ rb_hash_aset(h, ID2SYM(rb_intern("name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->name)); // rbs_type_name
218
+ rb_hash_aset(h, ID2SYM(rb_intern("type_params")), rbs_node_list_to_ruby_array(ctx, node->type_params));
219
+ rb_hash_aset(h, ID2SYM(rb_intern("members")), rbs_node_list_to_ruby_array(ctx, node->members));
220
+ rb_hash_aset(h, ID2SYM(rb_intern("annotations")), rbs_node_list_to_ruby_array(ctx, node->annotations));
221
+ rb_hash_aset(h, ID2SYM(rb_intern("comment")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->comment)); // rbs_ast_comment
222
+
223
+ rb_funcall(
224
+ RBS_AST_TypeParam,
225
+ rb_intern("resolve_variables"),
226
+ 1,
227
+ rb_hash_lookup(h, ID2SYM(rb_intern("type_params")))
228
+ );
229
+ return CLASS_NEW_INSTANCE(
230
+ RBS_AST_Declarations_Interface,
231
+ 1,
232
+ &h
233
+ );
234
+ }
235
+ case RBS_AST_DECLARATIONS_MODULE: {
236
+ rbs_ast_declarations_module_t *node = (rbs_ast_declarations_module_t *) instance;
237
+
238
+ VALUE h = rb_hash_new();
239
+ rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location));
240
+ rb_hash_aset(h, ID2SYM(rb_intern("name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->name)); // rbs_type_name
241
+ rb_hash_aset(h, ID2SYM(rb_intern("type_params")), rbs_node_list_to_ruby_array(ctx, node->type_params));
242
+ rb_hash_aset(h, ID2SYM(rb_intern("self_types")), rbs_node_list_to_ruby_array(ctx, node->self_types));
243
+ rb_hash_aset(h, ID2SYM(rb_intern("members")), rbs_node_list_to_ruby_array(ctx, node->members));
244
+ rb_hash_aset(h, ID2SYM(rb_intern("annotations")), rbs_node_list_to_ruby_array(ctx, node->annotations));
245
+ rb_hash_aset(h, ID2SYM(rb_intern("comment")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->comment)); // rbs_ast_comment
246
+
247
+ rb_funcall(
248
+ RBS_AST_TypeParam,
249
+ rb_intern("resolve_variables"),
250
+ 1,
251
+ rb_hash_lookup(h, ID2SYM(rb_intern("type_params")))
252
+ );
253
+ return CLASS_NEW_INSTANCE(
254
+ RBS_AST_Declarations_Module,
255
+ 1,
256
+ &h
257
+ );
258
+ }
259
+ case RBS_AST_DECLARATIONS_MODULE_SELF: {
260
+ rbs_ast_declarations_module_self_t *node = (rbs_ast_declarations_module_self_t *) instance;
261
+
262
+ VALUE h = rb_hash_new();
263
+ rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location));
264
+ rb_hash_aset(h, ID2SYM(rb_intern("name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->name)); // rbs_type_name
265
+ rb_hash_aset(h, ID2SYM(rb_intern("args")), rbs_node_list_to_ruby_array(ctx, node->args));
266
+
267
+ return CLASS_NEW_INSTANCE(
268
+ RBS_AST_Declarations_Module_Self,
269
+ 1,
270
+ &h
271
+ );
272
+ }
273
+ case RBS_AST_DECLARATIONS_MODULE_ALIAS: {
274
+ rbs_ast_declarations_module_alias_t *node = (rbs_ast_declarations_module_alias_t *) instance;
275
+
276
+ VALUE h = rb_hash_new();
277
+ rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location));
278
+ rb_hash_aset(h, ID2SYM(rb_intern("new_name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->new_name)); // rbs_type_name
279
+ rb_hash_aset(h, ID2SYM(rb_intern("old_name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->old_name)); // rbs_type_name
280
+ rb_hash_aset(h, ID2SYM(rb_intern("comment")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->comment)); // rbs_ast_comment
281
+ rb_hash_aset(h, ID2SYM(rb_intern("annotations")), rbs_node_list_to_ruby_array(ctx, node->annotations));
282
+
283
+ return CLASS_NEW_INSTANCE(
284
+ RBS_AST_Declarations_ModuleAlias,
285
+ 1,
286
+ &h
287
+ );
288
+ }
289
+ case RBS_AST_DECLARATIONS_TYPE_ALIAS: {
290
+ rbs_ast_declarations_type_alias_t *node = (rbs_ast_declarations_type_alias_t *) instance;
291
+
292
+ VALUE h = rb_hash_new();
293
+ rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location));
294
+ rb_hash_aset(h, ID2SYM(rb_intern("name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->name)); // rbs_type_name
295
+ rb_hash_aset(h, ID2SYM(rb_intern("type_params")), rbs_node_list_to_ruby_array(ctx, node->type_params));
296
+ rb_hash_aset(h, ID2SYM(rb_intern("type")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->type)); // rbs_node
297
+ rb_hash_aset(h, ID2SYM(rb_intern("annotations")), rbs_node_list_to_ruby_array(ctx, node->annotations));
298
+ rb_hash_aset(h, ID2SYM(rb_intern("comment")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->comment)); // rbs_ast_comment
299
+
300
+ rb_funcall(
301
+ RBS_AST_TypeParam,
302
+ rb_intern("resolve_variables"),
303
+ 1,
304
+ rb_hash_lookup(h, ID2SYM(rb_intern("type_params")))
305
+ );
306
+ return CLASS_NEW_INSTANCE(
307
+ RBS_AST_Declarations_TypeAlias,
308
+ 1,
309
+ &h
310
+ );
311
+ }
312
+ case RBS_AST_DIRECTIVES_USE: {
313
+ rbs_ast_directives_use_t *node = (rbs_ast_directives_use_t *) instance;
314
+
315
+ VALUE h = rb_hash_new();
316
+ rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location));
317
+ rb_hash_aset(h, ID2SYM(rb_intern("clauses")), rbs_node_list_to_ruby_array(ctx, node->clauses));
318
+
319
+ return CLASS_NEW_INSTANCE(
320
+ RBS_AST_Directives_Use,
321
+ 1,
322
+ &h
323
+ );
324
+ }
325
+ case RBS_AST_DIRECTIVES_USE_SINGLE_CLAUSE: {
326
+ rbs_ast_directives_use_single_clause_t *node = (rbs_ast_directives_use_single_clause_t *) instance;
327
+
328
+ VALUE h = rb_hash_new();
329
+ rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location));
330
+ rb_hash_aset(h, ID2SYM(rb_intern("type_name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->type_name)); // rbs_type_name
331
+ rb_hash_aset(h, ID2SYM(rb_intern("new_name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->new_name)); // rbs_ast_symbol
332
+
333
+ return CLASS_NEW_INSTANCE(
334
+ RBS_AST_Directives_Use_SingleClause,
335
+ 1,
336
+ &h
337
+ );
338
+ }
339
+ case RBS_AST_DIRECTIVES_USE_WILDCARD_CLAUSE: {
340
+ rbs_ast_directives_use_wildcard_clause_t *node = (rbs_ast_directives_use_wildcard_clause_t *) instance;
341
+
342
+ VALUE h = rb_hash_new();
343
+ rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location));
344
+ rb_hash_aset(h, ID2SYM(rb_intern("namespace")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->rbs_namespace)); // rbs_namespace
345
+
346
+ return CLASS_NEW_INSTANCE(
347
+ RBS_AST_Directives_Use_WildcardClause,
348
+ 1,
349
+ &h
350
+ );
351
+ }
352
+ case RBS_AST_INTEGER: {
353
+ rbs_ast_integer_t *integer_node = (rbs_ast_integer_t *) instance;
354
+ rbs_string_t string_repr = integer_node->string_representation;
355
+
356
+ VALUE str = rb_enc_str_new(string_repr.start, rbs_string_len(string_repr), rb_utf8_encoding());
357
+
358
+ return rb_funcall(str, rb_intern("to_i"), 0);
359
+ }
360
+ case RBS_AST_MEMBERS_ALIAS: {
361
+ rbs_ast_members_alias_t *node = (rbs_ast_members_alias_t *) instance;
362
+
363
+ VALUE h = rb_hash_new();
364
+ rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location));
365
+ rb_hash_aset(h, ID2SYM(rb_intern("new_name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->new_name)); // rbs_ast_symbol
366
+ rb_hash_aset(h, ID2SYM(rb_intern("old_name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->old_name)); // rbs_ast_symbol
367
+ rb_hash_aset(h, ID2SYM(rb_intern("kind")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->kind)); // rbs_keyword
368
+ rb_hash_aset(h, ID2SYM(rb_intern("annotations")), rbs_node_list_to_ruby_array(ctx, node->annotations));
369
+ rb_hash_aset(h, ID2SYM(rb_intern("comment")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->comment)); // rbs_ast_comment
370
+
371
+ return CLASS_NEW_INSTANCE(
372
+ RBS_AST_Members_Alias,
373
+ 1,
374
+ &h
375
+ );
376
+ }
377
+ case RBS_AST_MEMBERS_ATTR_ACCESSOR: {
378
+ rbs_ast_members_attr_accessor_t *node = (rbs_ast_members_attr_accessor_t *) instance;
379
+
380
+ VALUE h = rb_hash_new();
381
+ rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location));
382
+ rb_hash_aset(h, ID2SYM(rb_intern("name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->name)); // rbs_ast_symbol
383
+ rb_hash_aset(h, ID2SYM(rb_intern("type")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->type)); // rbs_node
384
+ rb_hash_aset(h, ID2SYM(rb_intern("ivar_name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->ivar_name)); // rbs_node
385
+ rb_hash_aset(h, ID2SYM(rb_intern("kind")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->kind)); // rbs_keyword
386
+ rb_hash_aset(h, ID2SYM(rb_intern("annotations")), rbs_node_list_to_ruby_array(ctx, node->annotations));
387
+ rb_hash_aset(h, ID2SYM(rb_intern("comment")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->comment)); // rbs_ast_comment
388
+ rb_hash_aset(h, ID2SYM(rb_intern("visibility")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->visibility)); // rbs_keyword
389
+
390
+ return CLASS_NEW_INSTANCE(
391
+ RBS_AST_Members_AttrAccessor,
392
+ 1,
393
+ &h
394
+ );
395
+ }
396
+ case RBS_AST_MEMBERS_ATTR_READER: {
397
+ rbs_ast_members_attr_reader_t *node = (rbs_ast_members_attr_reader_t *) instance;
398
+
399
+ VALUE h = rb_hash_new();
400
+ rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location));
401
+ rb_hash_aset(h, ID2SYM(rb_intern("name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->name)); // rbs_ast_symbol
402
+ rb_hash_aset(h, ID2SYM(rb_intern("type")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->type)); // rbs_node
403
+ rb_hash_aset(h, ID2SYM(rb_intern("ivar_name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->ivar_name)); // rbs_node
404
+ rb_hash_aset(h, ID2SYM(rb_intern("kind")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->kind)); // rbs_keyword
405
+ rb_hash_aset(h, ID2SYM(rb_intern("annotations")), rbs_node_list_to_ruby_array(ctx, node->annotations));
406
+ rb_hash_aset(h, ID2SYM(rb_intern("comment")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->comment)); // rbs_ast_comment
407
+ rb_hash_aset(h, ID2SYM(rb_intern("visibility")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->visibility)); // rbs_keyword
408
+
409
+ return CLASS_NEW_INSTANCE(
410
+ RBS_AST_Members_AttrReader,
411
+ 1,
412
+ &h
413
+ );
414
+ }
415
+ case RBS_AST_MEMBERS_ATTR_WRITER: {
416
+ rbs_ast_members_attr_writer_t *node = (rbs_ast_members_attr_writer_t *) instance;
417
+
418
+ VALUE h = rb_hash_new();
419
+ rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location));
420
+ rb_hash_aset(h, ID2SYM(rb_intern("name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->name)); // rbs_ast_symbol
421
+ rb_hash_aset(h, ID2SYM(rb_intern("type")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->type)); // rbs_node
422
+ rb_hash_aset(h, ID2SYM(rb_intern("ivar_name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->ivar_name)); // rbs_node
423
+ rb_hash_aset(h, ID2SYM(rb_intern("kind")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->kind)); // rbs_keyword
424
+ rb_hash_aset(h, ID2SYM(rb_intern("annotations")), rbs_node_list_to_ruby_array(ctx, node->annotations));
425
+ rb_hash_aset(h, ID2SYM(rb_intern("comment")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->comment)); // rbs_ast_comment
426
+ rb_hash_aset(h, ID2SYM(rb_intern("visibility")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->visibility)); // rbs_keyword
427
+
428
+ return CLASS_NEW_INSTANCE(
429
+ RBS_AST_Members_AttrWriter,
430
+ 1,
431
+ &h
432
+ );
433
+ }
434
+ case RBS_AST_MEMBERS_CLASS_INSTANCE_VARIABLE: {
435
+ rbs_ast_members_class_instance_variable_t *node = (rbs_ast_members_class_instance_variable_t *) instance;
436
+
437
+ VALUE h = rb_hash_new();
438
+ rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location));
439
+ rb_hash_aset(h, ID2SYM(rb_intern("name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->name)); // rbs_ast_symbol
440
+ rb_hash_aset(h, ID2SYM(rb_intern("type")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->type)); // rbs_node
441
+ rb_hash_aset(h, ID2SYM(rb_intern("comment")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->comment)); // rbs_ast_comment
442
+
443
+ return CLASS_NEW_INSTANCE(
444
+ RBS_AST_Members_ClassInstanceVariable,
445
+ 1,
446
+ &h
447
+ );
448
+ }
449
+ case RBS_AST_MEMBERS_CLASS_VARIABLE: {
450
+ rbs_ast_members_class_variable_t *node = (rbs_ast_members_class_variable_t *) instance;
451
+
452
+ VALUE h = rb_hash_new();
453
+ rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location));
454
+ rb_hash_aset(h, ID2SYM(rb_intern("name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->name)); // rbs_ast_symbol
455
+ rb_hash_aset(h, ID2SYM(rb_intern("type")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->type)); // rbs_node
456
+ rb_hash_aset(h, ID2SYM(rb_intern("comment")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->comment)); // rbs_ast_comment
457
+
458
+ return CLASS_NEW_INSTANCE(
459
+ RBS_AST_Members_ClassVariable,
460
+ 1,
461
+ &h
462
+ );
463
+ }
464
+ case RBS_AST_MEMBERS_EXTEND: {
465
+ rbs_ast_members_extend_t *node = (rbs_ast_members_extend_t *) instance;
466
+
467
+ VALUE h = rb_hash_new();
468
+ rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location));
469
+ rb_hash_aset(h, ID2SYM(rb_intern("name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->name)); // rbs_type_name
470
+ rb_hash_aset(h, ID2SYM(rb_intern("args")), rbs_node_list_to_ruby_array(ctx, node->args));
471
+ rb_hash_aset(h, ID2SYM(rb_intern("annotations")), rbs_node_list_to_ruby_array(ctx, node->annotations));
472
+ rb_hash_aset(h, ID2SYM(rb_intern("comment")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->comment)); // rbs_ast_comment
473
+
474
+ return CLASS_NEW_INSTANCE(
475
+ RBS_AST_Members_Extend,
476
+ 1,
477
+ &h
478
+ );
479
+ }
480
+ case RBS_AST_MEMBERS_INCLUDE: {
481
+ rbs_ast_members_include_t *node = (rbs_ast_members_include_t *) instance;
482
+
483
+ VALUE h = rb_hash_new();
484
+ rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location));
485
+ rb_hash_aset(h, ID2SYM(rb_intern("name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->name)); // rbs_type_name
486
+ rb_hash_aset(h, ID2SYM(rb_intern("args")), rbs_node_list_to_ruby_array(ctx, node->args));
487
+ rb_hash_aset(h, ID2SYM(rb_intern("annotations")), rbs_node_list_to_ruby_array(ctx, node->annotations));
488
+ rb_hash_aset(h, ID2SYM(rb_intern("comment")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->comment)); // rbs_ast_comment
489
+
490
+ return CLASS_NEW_INSTANCE(
491
+ RBS_AST_Members_Include,
492
+ 1,
493
+ &h
494
+ );
495
+ }
496
+ case RBS_AST_MEMBERS_INSTANCE_VARIABLE: {
497
+ rbs_ast_members_instance_variable_t *node = (rbs_ast_members_instance_variable_t *) instance;
498
+
499
+ VALUE h = rb_hash_new();
500
+ rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location));
501
+ rb_hash_aset(h, ID2SYM(rb_intern("name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->name)); // rbs_ast_symbol
502
+ rb_hash_aset(h, ID2SYM(rb_intern("type")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->type)); // rbs_node
503
+ rb_hash_aset(h, ID2SYM(rb_intern("comment")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->comment)); // rbs_ast_comment
504
+
505
+ return CLASS_NEW_INSTANCE(
506
+ RBS_AST_Members_InstanceVariable,
507
+ 1,
508
+ &h
509
+ );
510
+ }
511
+ case RBS_AST_MEMBERS_METHOD_DEFINITION: {
512
+ rbs_ast_members_method_definition_t *node = (rbs_ast_members_method_definition_t *) instance;
513
+
514
+ VALUE h = rb_hash_new();
515
+ rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location));
516
+ rb_hash_aset(h, ID2SYM(rb_intern("name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->name)); // rbs_ast_symbol
517
+ rb_hash_aset(h, ID2SYM(rb_intern("kind")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->kind)); // rbs_keyword
518
+ rb_hash_aset(h, ID2SYM(rb_intern("overloads")), rbs_node_list_to_ruby_array(ctx, node->overloads));
519
+ rb_hash_aset(h, ID2SYM(rb_intern("annotations")), rbs_node_list_to_ruby_array(ctx, node->annotations));
520
+ rb_hash_aset(h, ID2SYM(rb_intern("comment")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->comment)); // rbs_ast_comment
521
+ rb_hash_aset(h, ID2SYM(rb_intern("overloading")), node->overloading ? Qtrue : Qfalse);
522
+ rb_hash_aset(h, ID2SYM(rb_intern("visibility")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->visibility)); // rbs_keyword
523
+
524
+ return CLASS_NEW_INSTANCE(
525
+ RBS_AST_Members_MethodDefinition,
526
+ 1,
527
+ &h
528
+ );
529
+ }
530
+ case RBS_AST_MEMBERS_METHOD_DEFINITION_OVERLOAD: {
531
+ rbs_ast_members_method_definition_overload_t *node = (rbs_ast_members_method_definition_overload_t *) instance;
532
+
533
+ VALUE h = rb_hash_new();
534
+ rb_hash_aset(h, ID2SYM(rb_intern("annotations")), rbs_node_list_to_ruby_array(ctx, node->annotations));
535
+ rb_hash_aset(h, ID2SYM(rb_intern("method_type")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->method_type)); // rbs_node
536
+
537
+ return CLASS_NEW_INSTANCE(
538
+ RBS_AST_Members_MethodDefinition_Overload,
539
+ 1,
540
+ &h
541
+ );
542
+ }
543
+ case RBS_AST_MEMBERS_PREPEND: {
544
+ rbs_ast_members_prepend_t *node = (rbs_ast_members_prepend_t *) instance;
545
+
546
+ VALUE h = rb_hash_new();
547
+ rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location));
548
+ rb_hash_aset(h, ID2SYM(rb_intern("name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->name)); // rbs_type_name
549
+ rb_hash_aset(h, ID2SYM(rb_intern("args")), rbs_node_list_to_ruby_array(ctx, node->args));
550
+ rb_hash_aset(h, ID2SYM(rb_intern("annotations")), rbs_node_list_to_ruby_array(ctx, node->annotations));
551
+ rb_hash_aset(h, ID2SYM(rb_intern("comment")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->comment)); // rbs_ast_comment
552
+
553
+ return CLASS_NEW_INSTANCE(
554
+ RBS_AST_Members_Prepend,
555
+ 1,
556
+ &h
557
+ );
558
+ }
559
+ case RBS_AST_MEMBERS_PRIVATE: {
560
+ rbs_ast_members_private_t *node = (rbs_ast_members_private_t *) instance;
561
+
562
+ VALUE h = rb_hash_new();
563
+ rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location));
564
+
565
+ return CLASS_NEW_INSTANCE(
566
+ RBS_AST_Members_Private,
567
+ 1,
568
+ &h
569
+ );
570
+ }
571
+ case RBS_AST_MEMBERS_PUBLIC: {
572
+ rbs_ast_members_public_t *node = (rbs_ast_members_public_t *) instance;
573
+
574
+ VALUE h = rb_hash_new();
575
+ rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location));
576
+
577
+ return CLASS_NEW_INSTANCE(
578
+ RBS_AST_Members_Public,
579
+ 1,
580
+ &h
581
+ );
582
+ }
583
+ case RBS_AST_STRING: {
584
+ rbs_ast_string_t *string_node = (rbs_ast_string_t *) instance;
585
+ rbs_string_t s = string_node->string;
586
+
587
+ return rb_enc_str_new(s.start, rbs_string_len(s), rb_utf8_encoding());
588
+ }
589
+ case RBS_AST_TYPE_PARAM: {
590
+ rbs_ast_type_param_t *node = (rbs_ast_type_param_t *) instance;
591
+
592
+ VALUE h = rb_hash_new();
593
+ rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location));
594
+ rb_hash_aset(h, ID2SYM(rb_intern("name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->name)); // rbs_ast_symbol
595
+ rb_hash_aset(h, ID2SYM(rb_intern("variance")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->variance)); // rbs_keyword
596
+ rb_hash_aset(h, ID2SYM(rb_intern("upper_bound")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->upper_bound)); // rbs_node
597
+ rb_hash_aset(h, ID2SYM(rb_intern("default_type")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->default_type)); // rbs_node
598
+ rb_hash_aset(h, ID2SYM(rb_intern("unchecked")), node->unchecked ? Qtrue : Qfalse);
599
+
600
+ return CLASS_NEW_INSTANCE(
601
+ RBS_AST_TypeParam,
602
+ 1,
603
+ &h
604
+ );
605
+ }
606
+ case RBS_METHOD_TYPE: {
607
+ rbs_method_type_t *node = (rbs_method_type_t *) instance;
608
+
609
+ VALUE h = rb_hash_new();
610
+ rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location));
611
+ rb_hash_aset(h, ID2SYM(rb_intern("type_params")), rbs_node_list_to_ruby_array(ctx, node->type_params));
612
+ rb_hash_aset(h, ID2SYM(rb_intern("type")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->type)); // rbs_node
613
+ rb_hash_aset(h, ID2SYM(rb_intern("block")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->block)); // rbs_types_block
614
+
615
+ rb_funcall(
616
+ RBS_AST_TypeParam,
617
+ rb_intern("resolve_variables"),
618
+ 1,
619
+ rb_hash_lookup(h, ID2SYM(rb_intern("type_params")))
620
+ );
621
+ return CLASS_NEW_INSTANCE(
622
+ RBS_MethodType,
623
+ 1,
624
+ &h
625
+ );
626
+ }
627
+ case RBS_NAMESPACE: {
628
+ rbs_namespace_t *node = (rbs_namespace_t *) instance;
629
+
630
+ VALUE h = rb_hash_new();
631
+ rb_hash_aset(h, ID2SYM(rb_intern("path")), rbs_node_list_to_ruby_array(ctx, node->path));
632
+ rb_hash_aset(h, ID2SYM(rb_intern("absolute")), node->absolute ? Qtrue : Qfalse);
633
+
634
+ return CLASS_NEW_INSTANCE(
635
+ RBS_Namespace,
636
+ 1,
637
+ &h
638
+ );
639
+ }
640
+ case RBS_SIGNATURE: {
641
+ rbs_signature_t *signature = (rbs_signature_t *) instance;
642
+
643
+ VALUE array = rb_ary_new();
644
+ rb_ary_push(array, rbs_node_list_to_ruby_array(ctx, signature->directives));
645
+ rb_ary_push(array, rbs_node_list_to_ruby_array(ctx, signature->declarations));
646
+ return array;
647
+ }
648
+ case RBS_TYPE_NAME: {
649
+ rbs_type_name_t *node = (rbs_type_name_t *) instance;
650
+
651
+ VALUE h = rb_hash_new();
652
+ rb_hash_aset(h, ID2SYM(rb_intern("namespace")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->rbs_namespace)); // rbs_namespace
653
+ rb_hash_aset(h, ID2SYM(rb_intern("name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->name)); // rbs_ast_symbol
654
+
655
+ return CLASS_NEW_INSTANCE(
656
+ RBS_TypeName,
657
+ 1,
658
+ &h
659
+ );
660
+ }
661
+ case RBS_TYPES_ALIAS: {
662
+ rbs_types_alias_t *node = (rbs_types_alias_t *) instance;
663
+
664
+ VALUE h = rb_hash_new();
665
+ rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location));
666
+ rb_hash_aset(h, ID2SYM(rb_intern("name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->name)); // rbs_type_name
667
+ rb_hash_aset(h, ID2SYM(rb_intern("args")), rbs_node_list_to_ruby_array(ctx, node->args));
668
+
669
+ return CLASS_NEW_INSTANCE(
670
+ RBS_Types_Alias,
671
+ 1,
672
+ &h
673
+ );
674
+ }
675
+ case RBS_TYPES_BASES_ANY: {
676
+ rbs_types_bases_any_t *node = (rbs_types_bases_any_t *) instance;
677
+
678
+ VALUE h = rb_hash_new();
679
+ rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location));
680
+ rb_hash_aset(h, ID2SYM(rb_intern("todo")), node->todo ? Qtrue : Qfalse);
681
+
682
+ return CLASS_NEW_INSTANCE(
683
+ RBS_Types_Bases_Any,
684
+ 1,
685
+ &h
686
+ );
687
+ }
688
+ case RBS_TYPES_BASES_BOOL: {
689
+ rbs_types_bases_bool_t *node = (rbs_types_bases_bool_t *) instance;
690
+
691
+ VALUE h = rb_hash_new();
692
+ rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location));
693
+
694
+ return CLASS_NEW_INSTANCE(
695
+ RBS_Types_Bases_Bool,
696
+ 1,
697
+ &h
698
+ );
699
+ }
700
+ case RBS_TYPES_BASES_BOTTOM: {
701
+ rbs_types_bases_bottom_t *node = (rbs_types_bases_bottom_t *) instance;
702
+
703
+ VALUE h = rb_hash_new();
704
+ rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location));
705
+
706
+ return CLASS_NEW_INSTANCE(
707
+ RBS_Types_Bases_Bottom,
708
+ 1,
709
+ &h
710
+ );
711
+ }
712
+ case RBS_TYPES_BASES_CLASS: {
713
+ rbs_types_bases_class_t *node = (rbs_types_bases_class_t *) instance;
714
+
715
+ VALUE h = rb_hash_new();
716
+ rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location));
717
+
718
+ return CLASS_NEW_INSTANCE(
719
+ RBS_Types_Bases_Class,
720
+ 1,
721
+ &h
722
+ );
723
+ }
724
+ case RBS_TYPES_BASES_INSTANCE: {
725
+ rbs_types_bases_instance_t *node = (rbs_types_bases_instance_t *) instance;
726
+
727
+ VALUE h = rb_hash_new();
728
+ rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location));
729
+
730
+ return CLASS_NEW_INSTANCE(
731
+ RBS_Types_Bases_Instance,
732
+ 1,
733
+ &h
734
+ );
735
+ }
736
+ case RBS_TYPES_BASES_NIL: {
737
+ rbs_types_bases_nil_t *node = (rbs_types_bases_nil_t *) instance;
738
+
739
+ VALUE h = rb_hash_new();
740
+ rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location));
741
+
742
+ return CLASS_NEW_INSTANCE(
743
+ RBS_Types_Bases_Nil,
744
+ 1,
745
+ &h
746
+ );
747
+ }
748
+ case RBS_TYPES_BASES_SELF: {
749
+ rbs_types_bases_self_t *node = (rbs_types_bases_self_t *) instance;
750
+
751
+ VALUE h = rb_hash_new();
752
+ rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location));
753
+
754
+ return CLASS_NEW_INSTANCE(
755
+ RBS_Types_Bases_Self,
756
+ 1,
757
+ &h
758
+ );
759
+ }
760
+ case RBS_TYPES_BASES_TOP: {
761
+ rbs_types_bases_top_t *node = (rbs_types_bases_top_t *) instance;
762
+
763
+ VALUE h = rb_hash_new();
764
+ rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location));
765
+
766
+ return CLASS_NEW_INSTANCE(
767
+ RBS_Types_Bases_Top,
768
+ 1,
769
+ &h
770
+ );
771
+ }
772
+ case RBS_TYPES_BASES_VOID: {
773
+ rbs_types_bases_void_t *node = (rbs_types_bases_void_t *) instance;
774
+
775
+ VALUE h = rb_hash_new();
776
+ rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location));
777
+
778
+ return CLASS_NEW_INSTANCE(
779
+ RBS_Types_Bases_Void,
780
+ 1,
781
+ &h
782
+ );
783
+ }
784
+ case RBS_TYPES_BLOCK: {
785
+ rbs_types_block_t *node = (rbs_types_block_t *) instance;
786
+
787
+ VALUE h = rb_hash_new();
788
+ rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location));
789
+ rb_hash_aset(h, ID2SYM(rb_intern("type")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->type)); // rbs_node
790
+ rb_hash_aset(h, ID2SYM(rb_intern("required")), node->required ? Qtrue : Qfalse);
791
+ rb_hash_aset(h, ID2SYM(rb_intern("self_type")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->self_type)); // rbs_node
792
+
793
+ return CLASS_NEW_INSTANCE(
794
+ RBS_Types_Block,
795
+ 1,
796
+ &h
797
+ );
798
+ }
799
+ case RBS_TYPES_CLASS_INSTANCE: {
800
+ rbs_types_class_instance_t *node = (rbs_types_class_instance_t *) instance;
801
+
802
+ VALUE h = rb_hash_new();
803
+ rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location));
804
+ rb_hash_aset(h, ID2SYM(rb_intern("name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->name)); // rbs_type_name
805
+ rb_hash_aset(h, ID2SYM(rb_intern("args")), rbs_node_list_to_ruby_array(ctx, node->args));
806
+
807
+ return CLASS_NEW_INSTANCE(
808
+ RBS_Types_ClassInstance,
809
+ 1,
810
+ &h
811
+ );
812
+ }
813
+ case RBS_TYPES_CLASS_SINGLETON: {
814
+ rbs_types_class_singleton_t *node = (rbs_types_class_singleton_t *) instance;
815
+
816
+ VALUE h = rb_hash_new();
817
+ rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location));
818
+ rb_hash_aset(h, ID2SYM(rb_intern("name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->name)); // rbs_type_name
819
+
820
+ return CLASS_NEW_INSTANCE(
821
+ RBS_Types_ClassSingleton,
822
+ 1,
823
+ &h
824
+ );
825
+ }
826
+ case RBS_TYPES_FUNCTION: {
827
+ rbs_types_function_t *node = (rbs_types_function_t *) instance;
828
+
829
+ VALUE h = rb_hash_new();
830
+ rb_hash_aset(h, ID2SYM(rb_intern("required_positionals")), rbs_node_list_to_ruby_array(ctx, node->required_positionals));
831
+ rb_hash_aset(h, ID2SYM(rb_intern("optional_positionals")), rbs_node_list_to_ruby_array(ctx, node->optional_positionals));
832
+ rb_hash_aset(h, ID2SYM(rb_intern("rest_positionals")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->rest_positionals)); // rbs_node
833
+ rb_hash_aset(h, ID2SYM(rb_intern("trailing_positionals")), rbs_node_list_to_ruby_array(ctx, node->trailing_positionals));
834
+ rb_hash_aset(h, ID2SYM(rb_intern("required_keywords")), rbs_hash_to_ruby_hash(ctx, node->required_keywords));
835
+ rb_hash_aset(h, ID2SYM(rb_intern("optional_keywords")), rbs_hash_to_ruby_hash(ctx, node->optional_keywords));
836
+ rb_hash_aset(h, ID2SYM(rb_intern("rest_keywords")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->rest_keywords)); // rbs_node
837
+ rb_hash_aset(h, ID2SYM(rb_intern("return_type")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->return_type)); // rbs_node
838
+
839
+ return CLASS_NEW_INSTANCE(
840
+ RBS_Types_Function,
841
+ 1,
842
+ &h
843
+ );
844
+ }
845
+ case RBS_TYPES_FUNCTION_PARAM: {
846
+ rbs_types_function_param_t *node = (rbs_types_function_param_t *) instance;
847
+
848
+ VALUE h = rb_hash_new();
849
+ rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location));
850
+ rb_hash_aset(h, ID2SYM(rb_intern("type")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->type)); // rbs_node
851
+ rb_hash_aset(h, ID2SYM(rb_intern("name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->name)); // rbs_ast_symbol
852
+
853
+ return CLASS_NEW_INSTANCE(
854
+ RBS_Types_Function_Param,
855
+ 1,
856
+ &h
857
+ );
858
+ }
859
+ case RBS_TYPES_INTERFACE: {
860
+ rbs_types_interface_t *node = (rbs_types_interface_t *) instance;
861
+
862
+ VALUE h = rb_hash_new();
863
+ rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location));
864
+ rb_hash_aset(h, ID2SYM(rb_intern("name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->name)); // rbs_type_name
865
+ rb_hash_aset(h, ID2SYM(rb_intern("args")), rbs_node_list_to_ruby_array(ctx, node->args));
866
+
867
+ return CLASS_NEW_INSTANCE(
868
+ RBS_Types_Interface,
869
+ 1,
870
+ &h
871
+ );
872
+ }
873
+ case RBS_TYPES_INTERSECTION: {
874
+ rbs_types_intersection_t *node = (rbs_types_intersection_t *) instance;
875
+
876
+ VALUE h = rb_hash_new();
877
+ rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location));
878
+ rb_hash_aset(h, ID2SYM(rb_intern("types")), rbs_node_list_to_ruby_array(ctx, node->types));
879
+
880
+ return CLASS_NEW_INSTANCE(
881
+ RBS_Types_Intersection,
882
+ 1,
883
+ &h
884
+ );
885
+ }
886
+ case RBS_TYPES_LITERAL: {
887
+ rbs_types_literal_t *node = (rbs_types_literal_t *) instance;
888
+
889
+ VALUE h = rb_hash_new();
890
+ rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location));
891
+ rb_hash_aset(h, ID2SYM(rb_intern("literal")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->literal)); // rbs_node
892
+
893
+ return CLASS_NEW_INSTANCE(
894
+ RBS_Types_Literal,
895
+ 1,
896
+ &h
897
+ );
898
+ }
899
+ case RBS_TYPES_OPTIONAL: {
900
+ rbs_types_optional_t *node = (rbs_types_optional_t *) instance;
901
+
902
+ VALUE h = rb_hash_new();
903
+ rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location));
904
+ rb_hash_aset(h, ID2SYM(rb_intern("type")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->type)); // rbs_node
905
+
906
+ return CLASS_NEW_INSTANCE(
907
+ RBS_Types_Optional,
908
+ 1,
909
+ &h
910
+ );
911
+ }
912
+ case RBS_TYPES_PROC: {
913
+ rbs_types_proc_t *node = (rbs_types_proc_t *) instance;
914
+
915
+ VALUE h = rb_hash_new();
916
+ rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location));
917
+ rb_hash_aset(h, ID2SYM(rb_intern("type")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->type)); // rbs_node
918
+ rb_hash_aset(h, ID2SYM(rb_intern("block")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->block)); // rbs_types_block
919
+ rb_hash_aset(h, ID2SYM(rb_intern("self_type")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->self_type)); // rbs_node
920
+
921
+ return CLASS_NEW_INSTANCE(
922
+ RBS_Types_Proc,
923
+ 1,
924
+ &h
925
+ );
926
+ }
927
+ case RBS_TYPES_RECORD: {
928
+ rbs_types_record_t *node = (rbs_types_record_t *) instance;
929
+
930
+ VALUE h = rb_hash_new();
931
+ rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location));
932
+ rb_hash_aset(h, ID2SYM(rb_intern("all_fields")), rbs_hash_to_ruby_hash(ctx, node->all_fields));
933
+
934
+ return CLASS_NEW_INSTANCE(
935
+ RBS_Types_Record,
936
+ 1,
937
+ &h
938
+ );
939
+ }
940
+ case RBS_TYPES_RECORD_FIELD_TYPE: {
941
+ rbs_types_record_field_type_t *record_fieldtype = (rbs_types_record_field_type_t *) instance;
942
+
943
+ VALUE array = rb_ary_new();
944
+ rb_ary_push(array, rbs_struct_to_ruby_value(ctx, record_fieldtype->type));
945
+ rb_ary_push(array, record_fieldtype->required ? Qtrue : Qfalse);
946
+ return array;
947
+ }
948
+ case RBS_TYPES_TUPLE: {
949
+ rbs_types_tuple_t *node = (rbs_types_tuple_t *) instance;
950
+
951
+ VALUE h = rb_hash_new();
952
+ rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location));
953
+ rb_hash_aset(h, ID2SYM(rb_intern("types")), rbs_node_list_to_ruby_array(ctx, node->types));
954
+
955
+ return CLASS_NEW_INSTANCE(
956
+ RBS_Types_Tuple,
957
+ 1,
958
+ &h
959
+ );
960
+ }
961
+ case RBS_TYPES_UNION: {
962
+ rbs_types_union_t *node = (rbs_types_union_t *) instance;
963
+
964
+ VALUE h = rb_hash_new();
965
+ rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location));
966
+ rb_hash_aset(h, ID2SYM(rb_intern("types")), rbs_node_list_to_ruby_array(ctx, node->types));
967
+
968
+ return CLASS_NEW_INSTANCE(
969
+ RBS_Types_Union,
970
+ 1,
971
+ &h
972
+ );
973
+ }
974
+ case RBS_TYPES_UNTYPED_FUNCTION: {
975
+ rbs_types_untyped_function_t *node = (rbs_types_untyped_function_t *) instance;
976
+
977
+ VALUE h = rb_hash_new();
978
+ rb_hash_aset(h, ID2SYM(rb_intern("return_type")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->return_type)); // rbs_node
979
+
980
+ return CLASS_NEW_INSTANCE(
981
+ RBS_Types_UntypedFunction,
982
+ 1,
983
+ &h
984
+ );
985
+ }
986
+ case RBS_TYPES_VARIABLE: {
987
+ rbs_types_variable_t *node = (rbs_types_variable_t *) instance;
988
+
989
+ VALUE h = rb_hash_new();
990
+ rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location));
991
+ rb_hash_aset(h, ID2SYM(rb_intern("name")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->name)); // rbs_ast_symbol
992
+
993
+ return CLASS_NEW_INSTANCE(
994
+ RBS_Types_Variable,
995
+ 1,
996
+ &h
997
+ );
998
+ }
999
+ case RBS_KEYWORD: {
1000
+ rbs_constant_t *constant = rbs_constant_pool_id_to_constant(RBS_GLOBAL_CONSTANT_POOL, ((rbs_keyword_t *) instance)->constant_id);
1001
+ assert(constant != NULL && "constant is NULL");
1002
+ assert(constant->start != NULL && "constant->start is NULL");
1003
+
1004
+ return ID2SYM(rb_intern2((const char *) constant->start, constant->length));
1005
+ }
1006
+ case RBS_AST_SYMBOL: {
1007
+ rbs_constant_t *constant = rbs_constant_pool_id_to_constant(ctx.constant_pool, ((rbs_keyword_t *) instance)->constant_id);
1008
+ assert(constant != NULL && "constant is NULL");
1009
+ assert(constant->start != NULL && "constant->start is NULL");
1010
+
1011
+ return ID2SYM(rb_intern3((const char *) constant->start, constant->length, ctx.encoding));
1012
+ }
1013
+ }
1014
+
1015
+ rb_raise(rb_eRuntimeError, "Unknown node type: %d", instance->type);
1016
+ }