rbs 4.0.0.dev.1 → 4.0.0.dev.3

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 (64) 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 +51 -0
  5. data/.github/workflows/dependabot.yml +1 -1
  6. data/.github/workflows/ruby.yml +28 -17
  7. data/.github/workflows/typecheck.yml +0 -2
  8. data/.gitignore +4 -0
  9. data/.rubocop.yml +1 -1
  10. data/.vscode/extensions.json +5 -0
  11. data/.vscode/settings.json +19 -0
  12. data/README.md +37 -0
  13. data/Rakefile +90 -0
  14. data/config.yml +1 -1
  15. data/core/enumerable.rbs +9 -0
  16. data/core/io.rbs +4 -4
  17. data/core/thread.rbs +0 -7
  18. data/ext/rbs_extension/ast_translation.c +1010 -1074
  19. data/ext/rbs_extension/ast_translation.h +4 -0
  20. data/ext/rbs_extension/class_constants.c +78 -74
  21. data/ext/rbs_extension/class_constants.h +4 -0
  22. data/ext/rbs_extension/compat.h +10 -0
  23. data/ext/rbs_extension/extconf.rb +15 -1
  24. data/ext/rbs_extension/legacy_location.c +173 -172
  25. data/ext/rbs_extension/legacy_location.h +8 -3
  26. data/ext/rbs_extension/main.c +315 -273
  27. data/ext/rbs_extension/rbs_extension.h +3 -0
  28. data/ext/rbs_extension/rbs_string_bridging.h +4 -0
  29. data/include/rbs/ast.h +11 -12
  30. data/include/rbs/defines.h +11 -12
  31. data/include/rbs/lexer.h +108 -108
  32. data/include/rbs/location.h +14 -14
  33. data/include/rbs/parser.h +21 -19
  34. data/include/rbs/string.h +3 -3
  35. data/include/rbs/util/rbs_allocator.h +14 -14
  36. data/include/rbs/util/rbs_constant_pool.h +3 -3
  37. data/include/rbs/util/rbs_encoding.h +1 -1
  38. data/lib/rbs/environment.rb +4 -0
  39. data/lib/rbs/namespace.rb +0 -7
  40. data/lib/rbs/parser_aux.rb +5 -0
  41. data/lib/rbs/type_name.rb +0 -7
  42. data/lib/rbs/types.rb +3 -1
  43. data/lib/rbs/unit_test/convertibles.rb +1 -0
  44. data/lib/rbs/version.rb +1 -1
  45. data/sig/environment.rbs +3 -0
  46. data/sig/namespace.rbs +0 -5
  47. data/sig/parser.rbs +20 -0
  48. data/sig/typename.rbs +0 -5
  49. data/sig/types.rbs +4 -1
  50. data/src/ast.c +216 -214
  51. data/src/lexer.c +2923 -2675
  52. data/src/lexstate.c +157 -157
  53. data/src/location.c +40 -40
  54. data/src/parser.c +2591 -2586
  55. data/src/string.c +2 -2
  56. data/src/util/rbs_allocator.c +7 -9
  57. data/src/util/rbs_assert.c +9 -9
  58. data/src/util/rbs_constant_pool.c +5 -7
  59. data/src/util/rbs_encoding.c +20095 -4056
  60. data/src/util/rbs_unescape.c +33 -32
  61. data/stdlib/json/0/json.rbs +9 -43
  62. data/stdlib/ripper/0/ripper.rbs +3 -0
  63. data/stdlib/socket/0/addrinfo.rbs +2 -2
  64. metadata +8 -2
@@ -10,307 +10,308 @@ rbs_loc_range RBS_LOC_NULL_RANGE = { -1, -1 };
10
10
  VALUE RBS_Location;
11
11
 
12
12
  rbs_position_t rbs_loc_position(int char_pos) {
13
- return (rbs_position_t) { 0, char_pos, -1, -1 };
13
+ return (rbs_position_t) { 0, char_pos, -1, -1 };
14
14
  }
15
15
 
16
16
  rbs_position_t rbs_loc_position3(int char_pos, int line, int column) {
17
- return (rbs_position_t) { 0, char_pos, line, column };
17
+ return (rbs_position_t) { 0, char_pos, line, column };
18
18
  }
19
19
 
20
20
  static rbs_loc_range rbs_new_loc_range(rbs_range_t rg) {
21
- rbs_loc_range r = { rg.start.char_pos, rg.end.char_pos };
22
- return r;
21
+ rbs_loc_range r = { rg.start.char_pos, rg.end.char_pos };
22
+ return r;
23
23
  }
24
24
 
25
25
  static void check_children_max(unsigned short n) {
26
- size_t max = sizeof(rbs_loc_entry_bitmap) * 8;
27
- if (n > max) {
28
- rb_raise(rb_eRuntimeError, "Too many children added to location: %d", n);
29
- }
26
+ size_t max = sizeof(rbs_loc_entry_bitmap) * 8;
27
+ if (n > max) {
28
+ rb_raise(rb_eRuntimeError, "Too many children added to location: %d", n);
29
+ }
30
30
  }
31
31
 
32
32
  void rbs_loc_legacy_alloc_children(rbs_loc *loc, unsigned short cap) {
33
- check_children_max(cap);
33
+ check_children_max(cap);
34
34
 
35
- size_t s = RBS_LOC_CHILDREN_SIZE(cap);
36
- loc->children = malloc(s);
35
+ size_t s = RBS_LOC_CHILDREN_SIZE(cap);
36
+ loc->children = malloc(s);
37
37
 
38
- *loc->children = (rbs_loc_children) {
39
- .len = 0,
40
- .required_p = 0,
41
- .cap = cap,
42
- .entries = {{ 0 }},
43
- };
38
+ *loc->children = (rbs_loc_children) {
39
+ .len = 0,
40
+ .required_p = 0,
41
+ .cap = cap,
42
+ .entries = { { 0 } },
43
+ };
44
44
  }
45
45
 
46
46
  static void check_children_cap(rbs_loc *loc) {
47
- if (loc->children == NULL) {
48
- rbs_loc_legacy_alloc_children(loc, 1);
49
- } else {
50
- if (loc->children->len == loc->children->cap) {
51
- check_children_max(loc->children->cap + 1);
52
- size_t s = RBS_LOC_CHILDREN_SIZE(++loc->children->cap);
53
- loc->children = realloc(loc->children, s);
47
+ if (loc->children == NULL) {
48
+ rbs_loc_legacy_alloc_children(loc, 1);
49
+ } else {
50
+ if (loc->children->len == loc->children->cap) {
51
+ check_children_max(loc->children->cap + 1);
52
+ size_t s = RBS_LOC_CHILDREN_SIZE(++loc->children->cap);
53
+ loc->children = realloc(loc->children, s);
54
+ }
54
55
  }
55
- }
56
56
  }
57
57
 
58
58
  void rbs_loc_legacy_add_optional_child(rbs_loc *loc, rbs_constant_id_t name, rbs_range_t r) {
59
- check_children_cap(loc);
59
+ check_children_cap(loc);
60
60
 
61
- unsigned short i = loc->children->len++;
62
- loc->children->entries[i] = (rbs_loc_entry) {
63
- .name = name,
64
- .rg = rbs_new_loc_range(r),
65
- };
61
+ unsigned short i = loc->children->len++;
62
+ loc->children->entries[i] = (rbs_loc_entry) {
63
+ .name = name,
64
+ .rg = rbs_new_loc_range(r),
65
+ };
66
66
  }
67
67
 
68
68
  void rbs_loc_legacy_add_required_child(rbs_loc *loc, rbs_constant_id_t name, rbs_range_t r) {
69
- rbs_loc_legacy_add_optional_child(loc, name, r);
69
+ rbs_loc_legacy_add_optional_child(loc, name, r);
70
70
 
71
- unsigned short last_index = loc->children->len - 1;
72
- loc->children->required_p |= 1 << last_index;
71
+ unsigned short last_index = loc->children->len - 1;
72
+ loc->children->required_p |= 1 << last_index;
73
73
  }
74
74
 
75
75
  void rbs_loc_init(rbs_loc *loc, VALUE buffer, rbs_loc_range rg) {
76
- *loc = (rbs_loc) {
77
- .buffer = buffer,
78
- .rg = rg,
79
- .children = NULL,
80
- };
76
+ *loc = (rbs_loc) {
77
+ .buffer = buffer,
78
+ .rg = rg,
79
+ .children = NULL,
80
+ };
81
81
  }
82
82
 
83
83
  void rbs_loc_free(rbs_loc *loc) {
84
- free(loc->children);
85
- ruby_xfree(loc);
84
+ free(loc->children);
85
+ ruby_xfree(loc);
86
86
  }
87
87
 
88
- static void rbs_loc_mark(void *ptr)
89
- {
90
- rbs_loc *loc = ptr;
91
- rb_gc_mark(loc->buffer);
88
+ static void rbs_loc_mark(void *ptr) {
89
+ rbs_loc *loc = ptr;
90
+ rb_gc_mark(loc->buffer);
92
91
  }
93
92
 
94
93
  static size_t rbs_loc_memsize(const void *ptr) {
95
- const rbs_loc *loc = ptr;
96
- if (loc->children == NULL) {
97
- return sizeof(rbs_loc);
98
- } else {
99
- return sizeof(rbs_loc) + RBS_LOC_CHILDREN_SIZE(loc->children->cap);
100
- }
94
+ const rbs_loc *loc = ptr;
95
+ if (loc->children == NULL) {
96
+ return sizeof(rbs_loc);
97
+ } else {
98
+ return sizeof(rbs_loc) + RBS_LOC_CHILDREN_SIZE(loc->children->cap);
99
+ }
101
100
  }
102
101
 
103
102
  static rb_data_type_t location_type = {
104
- "RBS::Location",
105
- {rbs_loc_mark, (RUBY_DATA_FUNC)rbs_loc_free, rbs_loc_memsize},
106
- 0, 0, RUBY_TYPED_FREE_IMMEDIATELY
103
+ "RBS::Location",
104
+ { rbs_loc_mark, (RUBY_DATA_FUNC) rbs_loc_free, rbs_loc_memsize },
105
+ 0,
106
+ 0,
107
+ RUBY_TYPED_FREE_IMMEDIATELY
107
108
  };
108
109
 
109
110
  static VALUE location_s_allocate(VALUE klass) {
110
- rbs_loc *loc;
111
- VALUE obj = TypedData_Make_Struct(klass, rbs_loc, &location_type, loc);
111
+ rbs_loc *loc;
112
+ VALUE obj = TypedData_Make_Struct(klass, rbs_loc, &location_type, loc);
112
113
 
113
- rbs_loc_init(loc, Qnil, RBS_LOC_NULL_RANGE);
114
+ rbs_loc_init(loc, Qnil, RBS_LOC_NULL_RANGE);
114
115
 
115
- return obj;
116
+ return obj;
116
117
  }
117
118
 
118
119
  rbs_loc *rbs_check_location(VALUE obj) {
119
- return rb_check_typeddata(obj, &location_type);
120
+ return rb_check_typeddata(obj, &location_type);
120
121
  }
121
122
 
122
123
  static VALUE location_initialize(VALUE self, VALUE buffer, VALUE start_pos, VALUE end_pos) {
123
- rbs_loc *loc = rbs_check_location(self);
124
+ rbs_loc *loc = rbs_check_location(self);
124
125
 
125
- int start = FIX2INT(start_pos);
126
- int end = FIX2INT(end_pos);
126
+ int start = FIX2INT(start_pos);
127
+ int end = FIX2INT(end_pos);
127
128
 
128
- *loc = (rbs_loc) {
129
- .buffer = buffer,
130
- .rg = (rbs_loc_range) { start, end },
131
- .children = NULL,
132
- };
129
+ *loc = (rbs_loc) {
130
+ .buffer = buffer,
131
+ .rg = (rbs_loc_range) { start, end },
132
+ .children = NULL,
133
+ };
133
134
 
134
- return Qnil;
135
+ return Qnil;
135
136
  }
136
137
 
137
138
  static VALUE location_initialize_copy(VALUE self, VALUE other) {
138
- rbs_loc *self_loc = rbs_check_location(self);
139
- rbs_loc *other_loc = rbs_check_location(other);
140
-
141
- *self_loc = (rbs_loc) {
142
- .buffer = other_loc->buffer,
143
- .rg = other_loc->rg,
144
- .children = NULL,
145
- };
146
-
147
- if (other_loc->children != NULL) {
148
- rbs_loc_legacy_alloc_children(self_loc, other_loc->children->cap);
149
- memcpy(self_loc->children, other_loc->children, RBS_LOC_CHILDREN_SIZE(other_loc->children->cap));
150
- }
139
+ rbs_loc *self_loc = rbs_check_location(self);
140
+ rbs_loc *other_loc = rbs_check_location(other);
141
+
142
+ *self_loc = (rbs_loc) {
143
+ .buffer = other_loc->buffer,
144
+ .rg = other_loc->rg,
145
+ .children = NULL,
146
+ };
147
+
148
+ if (other_loc->children != NULL) {
149
+ rbs_loc_legacy_alloc_children(self_loc, other_loc->children->cap);
150
+ memcpy(self_loc->children, other_loc->children, RBS_LOC_CHILDREN_SIZE(other_loc->children->cap));
151
+ }
151
152
 
152
- return Qnil;
153
+ return Qnil;
153
154
  }
154
155
 
155
156
  static VALUE location_buffer(VALUE self) {
156
- rbs_loc *loc = rbs_check_location(self);
157
- return loc->buffer;
157
+ rbs_loc *loc = rbs_check_location(self);
158
+ return loc->buffer;
158
159
  }
159
160
 
160
161
  static VALUE location_start_pos(VALUE self) {
161
- rbs_loc *loc = rbs_check_location(self);
162
- return INT2FIX(loc->rg.start);
162
+ rbs_loc *loc = rbs_check_location(self);
163
+ return INT2FIX(loc->rg.start);
163
164
  }
164
165
 
165
166
  static VALUE location_end_pos(VALUE self) {
166
- rbs_loc *loc = rbs_check_location(self);
167
- return INT2FIX(loc->rg.end);
167
+ rbs_loc *loc = rbs_check_location(self);
168
+ return INT2FIX(loc->rg.end);
168
169
  }
169
170
 
170
171
  static rbs_constant_id_t rbs_constant_pool_insert_ruby_symbol(VALUE symbol) {
171
- VALUE name = rb_sym2str(symbol);
172
+ VALUE name = rb_sym2str(symbol);
172
173
 
173
- // Constants inserted here will never be freed, but that's acceptable because:
174
- // 1. Most symbols passed into here will be the ones already inserted into the constant pool by `parser.c`.
175
- // 2. Methods like `add_required_child` and `add_optional_child` will usually only get called with a few different symbols.
176
- return rbs_constant_pool_insert_constant(RBS_GLOBAL_CONSTANT_POOL, (const uint8_t *) RSTRING_PTR(name), RSTRING_LEN(name));
174
+ // Constants inserted here will never be freed, but that's acceptable because:
175
+ // 1. Most symbols passed into here will be the ones already inserted into the constant pool by `parser.c`.
176
+ // 2. Methods like `add_required_child` and `add_optional_child` will usually only get called with a few different symbols.
177
+ return rbs_constant_pool_insert_constant(RBS_GLOBAL_CONSTANT_POOL, (const uint8_t *) RSTRING_PTR(name), RSTRING_LEN(name));
177
178
  }
178
179
 
179
180
  static VALUE location_add_required_child(VALUE self, VALUE name, VALUE start, VALUE end) {
180
- rbs_loc *loc = rbs_check_location(self);
181
+ rbs_loc *loc = rbs_check_location(self);
181
182
 
182
- rbs_range_t rg;
183
- rg.start = rbs_loc_position(FIX2INT(start));
184
- rg.end = rbs_loc_position(FIX2INT(end));
183
+ rbs_range_t rg;
184
+ rg.start = rbs_loc_position(FIX2INT(start));
185
+ rg.end = rbs_loc_position(FIX2INT(end));
185
186
 
186
- rbs_loc_legacy_add_required_child(loc, rbs_constant_pool_insert_ruby_symbol(name), rg);
187
+ rbs_loc_legacy_add_required_child(loc, rbs_constant_pool_insert_ruby_symbol(name), rg);
187
188
 
188
- return Qnil;
189
+ return Qnil;
189
190
  }
190
191
 
191
192
  static VALUE location_add_optional_child(VALUE self, VALUE name, VALUE start, VALUE end) {
192
- rbs_loc *loc = rbs_check_location(self);
193
+ rbs_loc *loc = rbs_check_location(self);
193
194
 
194
- rbs_range_t rg;
195
- rg.start = rbs_loc_position(FIX2INT(start));
196
- rg.end = rbs_loc_position(FIX2INT(end));
195
+ rbs_range_t rg;
196
+ rg.start = rbs_loc_position(FIX2INT(start));
197
+ rg.end = rbs_loc_position(FIX2INT(end));
197
198
 
198
- rbs_loc_legacy_add_optional_child(loc, rbs_constant_pool_insert_ruby_symbol(name), rg);
199
+ rbs_loc_legacy_add_optional_child(loc, rbs_constant_pool_insert_ruby_symbol(name), rg);
199
200
 
200
- return Qnil;
201
+ return Qnil;
201
202
  }
202
203
 
203
204
  static VALUE location_add_optional_no_child(VALUE self, VALUE name) {
204
- rbs_loc *loc = rbs_check_location(self);
205
+ rbs_loc *loc = rbs_check_location(self);
205
206
 
206
- rbs_loc_legacy_add_optional_child(loc, rbs_constant_pool_insert_ruby_symbol(name), NULL_RANGE);
207
+ rbs_loc_legacy_add_optional_child(loc, rbs_constant_pool_insert_ruby_symbol(name), NULL_RANGE);
207
208
 
208
- return Qnil;
209
+ return Qnil;
209
210
  }
210
211
 
211
212
  VALUE rbs_new_location(VALUE buffer, rbs_range_t rg) {
212
- rbs_loc *loc;
213
- VALUE obj = TypedData_Make_Struct(RBS_Location, rbs_loc, &location_type, loc);
213
+ rbs_loc *loc;
214
+ VALUE obj = TypedData_Make_Struct(RBS_Location, rbs_loc, &location_type, loc);
214
215
 
215
- rbs_loc_init(loc, buffer, rbs_new_loc_range(rg));
216
+ rbs_loc_init(loc, buffer, rbs_new_loc_range(rg));
216
217
 
217
- return obj;
218
+ return obj;
218
219
  }
219
220
 
220
221
  static VALUE rbs_new_location_from_loc_range(VALUE buffer, rbs_loc_range rg) {
221
- rbs_loc *loc;
222
- VALUE obj = TypedData_Make_Struct(RBS_Location, rbs_loc, &location_type, loc);
222
+ rbs_loc *loc;
223
+ VALUE obj = TypedData_Make_Struct(RBS_Location, rbs_loc, &location_type, loc);
223
224
 
224
- rbs_loc_init(loc, buffer, rg);
225
+ rbs_loc_init(loc, buffer, rg);
225
226
 
226
- return obj;
227
+ return obj;
227
228
  }
228
229
 
229
230
  static rbs_constant_id_t rbs_constant_pool_find_ruby_symbol(VALUE symbol) {
230
- VALUE name = rb_sym2str(symbol);
231
+ VALUE name = rb_sym2str(symbol);
231
232
 
232
- return rbs_constant_pool_find(RBS_GLOBAL_CONSTANT_POOL, (const uint8_t *) RSTRING_PTR(name), RSTRING_LEN(name));
233
+ return rbs_constant_pool_find(RBS_GLOBAL_CONSTANT_POOL, (const uint8_t *) RSTRING_PTR(name), RSTRING_LEN(name));
233
234
  }
234
235
 
235
236
  static VALUE location_aref(VALUE self, VALUE name) {
236
- rbs_loc *loc = rbs_check_location(self);
237
+ rbs_loc *loc = rbs_check_location(self);
237
238
 
238
- rbs_constant_id_t id = rbs_constant_pool_find_ruby_symbol(name);
239
+ rbs_constant_id_t id = rbs_constant_pool_find_ruby_symbol(name);
239
240
 
240
- if (loc->children != NULL && id != RBS_CONSTANT_ID_UNSET) {
241
- for (unsigned short i = 0; i < loc->children->len; i++) {
242
- if (loc->children->entries[i].name == id) {
243
- rbs_loc_range result = loc->children->entries[i].rg;
241
+ if (loc->children != NULL && id != RBS_CONSTANT_ID_UNSET) {
242
+ for (unsigned short i = 0; i < loc->children->len; i++) {
243
+ if (loc->children->entries[i].name == id) {
244
+ rbs_loc_range result = loc->children->entries[i].rg;
244
245
 
245
- if (RBS_LOC_OPTIONAL_P(loc, i) && NULL_LOC_RANGE_P(result)) {
246
- return Qnil;
247
- } else {
248
- return rbs_new_location_from_loc_range(loc->buffer, result);
246
+ if (RBS_LOC_OPTIONAL_P(loc, i) && NULL_LOC_RANGE_P(result)) {
247
+ return Qnil;
248
+ } else {
249
+ return rbs_new_location_from_loc_range(loc->buffer, result);
250
+ }
251
+ }
249
252
  }
250
- }
251
253
  }
252
- }
253
254
 
254
- VALUE string = rb_funcall(name, rb_intern("to_s"), 0);
255
- rb_raise(rb_eRuntimeError, "Unknown child name given: %s", RSTRING_PTR(string));
255
+ VALUE string = rb_funcall(name, rb_intern("to_s"), 0);
256
+ rb_raise(rb_eRuntimeError, "Unknown child name given: %s", RSTRING_PTR(string));
256
257
  }
257
258
 
258
259
  static VALUE rbs_constant_to_ruby_symbol(rbs_constant_t *constant) {
259
- return ID2SYM(rb_intern2((const char *) constant->start, constant->length));
260
+ return ID2SYM(rb_intern2((const char *) constant->start, constant->length));
260
261
  }
261
262
 
262
263
  static VALUE location_optional_keys(VALUE self) {
263
- VALUE keys = rb_ary_new();
264
+ VALUE keys = rb_ary_new();
264
265
 
265
- rbs_loc *loc = rbs_check_location(self);
266
- rbs_loc_children *children = loc->children;
267
- if (children == NULL) {
268
- return keys;
269
- }
266
+ rbs_loc *loc = rbs_check_location(self);
267
+ rbs_loc_children *children = loc->children;
268
+ if (children == NULL) {
269
+ return keys;
270
+ }
270
271
 
271
- for (unsigned short i = 0; i < children->len; i++) {
272
- if (RBS_LOC_OPTIONAL_P(loc, i)) {
273
- rbs_constant_t *key_id = rbs_constant_pool_id_to_constant(RBS_GLOBAL_CONSTANT_POOL, children->entries[i].name);
274
- VALUE key_sym = rbs_constant_to_ruby_symbol(key_id);
275
- rb_ary_push(keys, key_sym);
272
+ for (unsigned short i = 0; i < children->len; i++) {
273
+ if (RBS_LOC_OPTIONAL_P(loc, i)) {
274
+ rbs_constant_t *key_id = rbs_constant_pool_id_to_constant(RBS_GLOBAL_CONSTANT_POOL, children->entries[i].name);
275
+ VALUE key_sym = rbs_constant_to_ruby_symbol(key_id);
276
+ rb_ary_push(keys, key_sym);
277
+ }
276
278
  }
277
- }
278
279
 
279
- return keys;
280
+ return keys;
280
281
  }
281
282
 
282
283
  static VALUE location_required_keys(VALUE self) {
283
- VALUE keys = rb_ary_new();
284
+ VALUE keys = rb_ary_new();
284
285
 
285
- rbs_loc *loc = rbs_check_location(self);
286
- rbs_loc_children *children = loc->children;
287
- if (children == NULL) {
288
- return keys;
289
- }
286
+ rbs_loc *loc = rbs_check_location(self);
287
+ rbs_loc_children *children = loc->children;
288
+ if (children == NULL) {
289
+ return keys;
290
+ }
290
291
 
291
- for (unsigned short i = 0; i < children->len; i++) {
292
- if (RBS_LOC_REQUIRED_P(loc, i)) {
293
- rbs_constant_t *key_id = rbs_constant_pool_id_to_constant(RBS_GLOBAL_CONSTANT_POOL, children->entries[i].name);
294
- VALUE key_sym = rbs_constant_to_ruby_symbol(key_id);
295
- rb_ary_push(keys, key_sym);
292
+ for (unsigned short i = 0; i < children->len; i++) {
293
+ if (RBS_LOC_REQUIRED_P(loc, i)) {
294
+ rbs_constant_t *key_id = rbs_constant_pool_id_to_constant(RBS_GLOBAL_CONSTANT_POOL, children->entries[i].name);
295
+ VALUE key_sym = rbs_constant_to_ruby_symbol(key_id);
296
+ rb_ary_push(keys, key_sym);
297
+ }
296
298
  }
297
- }
298
299
 
299
- return keys;
300
+ return keys;
300
301
  }
301
302
 
302
303
  void rbs__init_location(void) {
303
- RBS_Location = rb_define_class_under(RBS, "Location", rb_cObject);
304
- rb_define_alloc_func(RBS_Location, location_s_allocate);
305
- rb_define_private_method(RBS_Location, "initialize", location_initialize, 3);
306
- rb_define_private_method(RBS_Location, "initialize_copy", location_initialize_copy, 1);
307
- rb_define_method(RBS_Location, "buffer", location_buffer, 0);
308
- rb_define_method(RBS_Location, "_start_pos", location_start_pos, 0);
309
- rb_define_method(RBS_Location, "_end_pos", location_end_pos, 0);
310
- rb_define_method(RBS_Location, "_add_required_child", location_add_required_child, 3);
311
- rb_define_method(RBS_Location, "_add_optional_child", location_add_optional_child, 3);
312
- rb_define_method(RBS_Location, "_add_optional_no_child", location_add_optional_no_child, 1);
313
- rb_define_method(RBS_Location, "_optional_keys", location_optional_keys, 0);
314
- rb_define_method(RBS_Location, "_required_keys", location_required_keys, 0);
315
- rb_define_method(RBS_Location, "[]", location_aref, 1);
304
+ RBS_Location = rb_define_class_under(RBS, "Location", rb_cObject);
305
+ rb_define_alloc_func(RBS_Location, location_s_allocate);
306
+ rb_define_private_method(RBS_Location, "initialize", location_initialize, 3);
307
+ rb_define_private_method(RBS_Location, "initialize_copy", location_initialize_copy, 1);
308
+ rb_define_method(RBS_Location, "buffer", location_buffer, 0);
309
+ rb_define_method(RBS_Location, "_start_pos", location_start_pos, 0);
310
+ rb_define_method(RBS_Location, "_end_pos", location_end_pos, 0);
311
+ rb_define_method(RBS_Location, "_add_required_child", location_add_required_child, 3);
312
+ rb_define_method(RBS_Location, "_add_optional_child", location_add_optional_child, 3);
313
+ rb_define_method(RBS_Location, "_add_optional_no_child", location_add_optional_no_child, 1);
314
+ rb_define_method(RBS_Location, "_optional_keys", location_optional_keys, 0);
315
+ rb_define_method(RBS_Location, "_required_keys", location_required_keys, 0);
316
+ rb_define_method(RBS_Location, "[]", location_aref, 1);
316
317
  }
@@ -1,7 +1,12 @@
1
1
  #ifndef RBS_LOCATION_H
2
2
  #define RBS_LOCATION_H
3
3
 
4
+ #include "compat.h"
5
+
6
+ SUPPRESS_RUBY_HEADER_DIAGNOSTICS_BEGIN
4
7
  #include "ruby.h"
8
+ SUPPRESS_RUBY_HEADER_DIAGNOSTICS_END
9
+
5
10
  #include "rbs.h"
6
11
 
7
12
  /**
@@ -10,9 +15,9 @@
10
15
  extern VALUE RBS_Location;
11
16
 
12
17
  typedef struct {
13
- VALUE buffer;
14
- rbs_loc_range rg;
15
- rbs_loc_children *children; // NULL when no children is allocated
18
+ VALUE buffer;
19
+ rbs_loc_range rg;
20
+ rbs_loc_children *children; // NULL when no children is allocated
16
21
  } rbs_loc;
17
22
 
18
23
  /**