rbs 3.10.0 → 4.0.0.dev.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 (202) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/comments.yml +3 -3
  3. data/.github/workflows/ruby.yml +24 -35
  4. data/.github/workflows/typecheck.yml +3 -1
  5. data/.github/workflows/windows.yml +2 -2
  6. data/.gitignore +0 -4
  7. data/CHANGELOG.md +0 -88
  8. data/README.md +1 -38
  9. data/Rakefile +20 -142
  10. data/Steepfile +1 -0
  11. data/config.yml +43 -1
  12. data/core/array.rbs +46 -100
  13. data/core/complex.rbs +21 -32
  14. data/core/dir.rbs +2 -2
  15. data/core/encoding.rbs +9 -6
  16. data/core/enumerable.rbs +3 -90
  17. data/core/enumerator.rbs +1 -18
  18. data/core/errno.rbs +0 -8
  19. data/core/errors.rbs +1 -28
  20. data/core/exception.rbs +2 -2
  21. data/core/fiber.rbs +4 -5
  22. data/core/file.rbs +12 -27
  23. data/core/file_test.rbs +1 -1
  24. data/core/float.rbs +22 -209
  25. data/core/gc.rbs +281 -417
  26. data/core/hash.rbs +727 -1024
  27. data/core/integer.rbs +38 -78
  28. data/core/io/buffer.rbs +7 -18
  29. data/core/io/wait.rbs +33 -11
  30. data/core/io.rbs +12 -14
  31. data/core/kernel.rbs +51 -57
  32. data/core/marshal.rbs +1 -1
  33. data/core/match_data.rbs +1 -1
  34. data/core/math.rbs +3 -42
  35. data/core/method.rbs +6 -14
  36. data/core/module.rbs +17 -88
  37. data/core/nil_class.rbs +3 -3
  38. data/core/numeric.rbs +16 -16
  39. data/core/object.rbs +3 -3
  40. data/core/object_space.rbs +15 -21
  41. data/core/proc.rbs +8 -15
  42. data/core/process.rbs +2 -2
  43. data/core/ractor.rbs +437 -278
  44. data/core/range.rbs +8 -7
  45. data/core/rational.rbs +24 -37
  46. data/core/rbs/unnamed/argf.rbs +2 -2
  47. data/core/rbs/unnamed/env_class.rbs +1 -1
  48. data/core/rbs/unnamed/random.rbs +2 -4
  49. data/core/regexp.rbs +20 -25
  50. data/core/ruby_vm.rbs +4 -6
  51. data/core/rubygems/errors.rbs +70 -3
  52. data/core/rubygems/rubygems.rbs +79 -11
  53. data/core/rubygems/version.rbs +3 -2
  54. data/core/set.rbs +359 -488
  55. data/core/string.rbs +1228 -3153
  56. data/core/struct.rbs +1 -1
  57. data/core/symbol.rbs +4 -4
  58. data/core/thread.rbs +29 -92
  59. data/core/time.rbs +9 -35
  60. data/core/trace_point.rbs +4 -7
  61. data/core/unbound_method.rbs +6 -14
  62. data/docs/collection.md +2 -2
  63. data/docs/gem.md +1 -0
  64. data/docs/sigs.md +3 -3
  65. data/ext/rbs_extension/ast_translation.c +1077 -944
  66. data/ext/rbs_extension/ast_translation.h +0 -7
  67. data/ext/rbs_extension/class_constants.c +83 -71
  68. data/ext/rbs_extension/class_constants.h +7 -4
  69. data/ext/rbs_extension/extconf.rb +2 -24
  70. data/ext/rbs_extension/legacy_location.c +172 -173
  71. data/ext/rbs_extension/legacy_location.h +3 -8
  72. data/ext/rbs_extension/main.c +289 -239
  73. data/ext/rbs_extension/rbs_extension.h +0 -3
  74. data/ext/rbs_extension/rbs_string_bridging.h +0 -4
  75. data/include/rbs/ast.h +98 -37
  76. data/include/rbs/defines.h +12 -38
  77. data/include/rbs/lexer.h +114 -126
  78. data/include/rbs/location.h +14 -14
  79. data/include/rbs/parser.h +37 -21
  80. data/include/rbs/string.h +5 -3
  81. data/include/rbs/util/rbs_allocator.h +19 -40
  82. data/include/rbs/util/rbs_assert.h +1 -12
  83. data/include/rbs/util/rbs_constant_pool.h +3 -3
  84. data/include/rbs/util/rbs_encoding.h +1 -3
  85. data/include/rbs/util/rbs_unescape.h +1 -2
  86. data/lib/rbs/ast/ruby/annotations.rb +119 -0
  87. data/lib/rbs/ast/ruby/comment_block.rb +221 -0
  88. data/lib/rbs/ast/ruby/declarations.rb +86 -0
  89. data/lib/rbs/ast/ruby/helpers/constant_helper.rb +24 -0
  90. data/lib/rbs/ast/ruby/helpers/location_helper.rb +15 -0
  91. data/lib/rbs/ast/ruby/members.rb +213 -0
  92. data/lib/rbs/buffer.rb +104 -24
  93. data/lib/rbs/cli/validate.rb +40 -35
  94. data/lib/rbs/cli.rb +5 -6
  95. data/lib/rbs/collection/config/lockfile_generator.rb +0 -1
  96. data/lib/rbs/collection.rb +0 -1
  97. data/lib/rbs/definition.rb +6 -1
  98. data/lib/rbs/definition_builder/ancestor_builder.rb +65 -62
  99. data/lib/rbs/definition_builder/method_builder.rb +45 -30
  100. data/lib/rbs/definition_builder.rb +44 -9
  101. data/lib/rbs/environment/class_entry.rb +69 -0
  102. data/lib/rbs/environment/module_entry.rb +66 -0
  103. data/lib/rbs/environment.rb +244 -218
  104. data/lib/rbs/environment_loader.rb +3 -3
  105. data/lib/rbs/errors.rb +5 -4
  106. data/lib/rbs/inline_parser/comment_association.rb +117 -0
  107. data/lib/rbs/inline_parser.rb +206 -0
  108. data/lib/rbs/location_aux.rb +35 -3
  109. data/lib/rbs/parser_aux.rb +11 -6
  110. data/lib/rbs/prototype/runtime.rb +2 -2
  111. data/lib/rbs/resolver/constant_resolver.rb +2 -2
  112. data/lib/rbs/resolver/type_name_resolver.rb +38 -124
  113. data/lib/rbs/source.rb +99 -0
  114. data/lib/rbs/subtractor.rb +4 -3
  115. data/lib/rbs/test/type_check.rb +0 -14
  116. data/lib/rbs/types.rb +1 -3
  117. data/lib/rbs/version.rb +1 -1
  118. data/lib/rbs.rb +13 -1
  119. data/lib/rdoc/discover.rb +1 -1
  120. data/lib/rdoc_plugin/parser.rb +1 -1
  121. data/rbs.gemspec +1 -0
  122. data/sig/ancestor_builder.rbs +1 -1
  123. data/sig/ast/ruby/annotations.rbs +110 -0
  124. data/sig/ast/ruby/comment_block.rbs +119 -0
  125. data/sig/ast/ruby/declarations.rbs +60 -0
  126. data/sig/ast/ruby/helpers/constant_helper.rbs +11 -0
  127. data/sig/ast/ruby/helpers/location_helper.rbs +15 -0
  128. data/sig/ast/ruby/members.rbs +72 -0
  129. data/sig/buffer.rbs +63 -5
  130. data/sig/definition.rbs +1 -0
  131. data/sig/definition_builder.rbs +1 -1
  132. data/sig/environment/class_entry.rbs +50 -0
  133. data/sig/environment/module_entry.rbs +50 -0
  134. data/sig/environment.rbs +28 -133
  135. data/sig/errors.rbs +13 -6
  136. data/sig/inline_parser/comment_association.rbs +71 -0
  137. data/sig/inline_parser.rbs +87 -0
  138. data/sig/location.rbs +32 -7
  139. data/sig/manifest.yaml +1 -0
  140. data/sig/method_builder.rbs +7 -4
  141. data/sig/parser.rbs +16 -20
  142. data/sig/resolver/type_name_resolver.rbs +7 -38
  143. data/sig/source.rbs +48 -0
  144. data/sig/types.rbs +1 -4
  145. data/src/ast.c +290 -201
  146. data/src/lexer.c +2813 -2902
  147. data/src/lexer.re +4 -0
  148. data/src/lexstate.c +155 -169
  149. data/src/location.c +40 -40
  150. data/src/parser.c +2665 -2433
  151. data/src/string.c +48 -0
  152. data/src/util/rbs_allocator.c +77 -80
  153. data/src/util/rbs_assert.c +10 -10
  154. data/src/util/rbs_buffer.c +2 -2
  155. data/src/util/rbs_constant_pool.c +15 -13
  156. data/src/util/rbs_encoding.c +4062 -20097
  157. data/src/util/rbs_unescape.c +48 -85
  158. data/stdlib/bigdecimal/0/big_decimal.rbs +82 -100
  159. data/stdlib/bigdecimal-math/0/big_math.rbs +8 -169
  160. data/stdlib/cgi/0/core.rbs +396 -2
  161. data/stdlib/cgi/0/manifest.yaml +0 -1
  162. data/stdlib/coverage/0/coverage.rbs +1 -3
  163. data/stdlib/date/0/date.rbs +59 -67
  164. data/stdlib/date/0/date_time.rbs +1 -1
  165. data/stdlib/delegate/0/delegator.rbs +7 -10
  166. data/stdlib/erb/0/erb.rbs +347 -737
  167. data/stdlib/fileutils/0/fileutils.rbs +13 -18
  168. data/stdlib/forwardable/0/forwardable.rbs +0 -3
  169. data/stdlib/json/0/json.rbs +48 -68
  170. data/stdlib/net-http/0/net-http.rbs +0 -3
  171. data/stdlib/objspace/0/objspace.rbs +4 -9
  172. data/stdlib/open-uri/0/open-uri.rbs +0 -40
  173. data/stdlib/openssl/0/openssl.rbs +228 -331
  174. data/stdlib/optparse/0/optparse.rbs +3 -3
  175. data/{core → stdlib/pathname/0}/pathname.rbs +355 -255
  176. data/stdlib/psych/0/psych.rbs +3 -3
  177. data/stdlib/rdoc/0/rdoc.rbs +1 -1
  178. data/stdlib/resolv/0/resolv.rbs +68 -25
  179. data/stdlib/ripper/0/ripper.rbs +2 -5
  180. data/stdlib/singleton/0/singleton.rbs +0 -3
  181. data/stdlib/socket/0/socket.rbs +1 -13
  182. data/stdlib/socket/0/tcp_socket.rbs +2 -10
  183. data/stdlib/stringio/0/stringio.rbs +85 -1176
  184. data/stdlib/strscan/0/string_scanner.rbs +31 -31
  185. data/stdlib/tempfile/0/tempfile.rbs +3 -3
  186. data/stdlib/time/0/time.rbs +1 -1
  187. data/stdlib/timeout/0/timeout.rbs +7 -63
  188. data/stdlib/tsort/0/cyclic.rbs +0 -3
  189. data/stdlib/uri/0/common.rbs +2 -11
  190. data/stdlib/uri/0/file.rbs +1 -1
  191. data/stdlib/uri/0/generic.rbs +16 -17
  192. data/stdlib/uri/0/rfc2396_parser.rbs +7 -6
  193. data/stdlib/zlib/0/zstream.rbs +0 -1
  194. metadata +40 -12
  195. data/.clang-format +0 -74
  196. data/.clangd +0 -2
  197. data/.github/workflows/c-check.yml +0 -54
  198. data/core/ruby.rbs +0 -53
  199. data/docs/aliases.md +0 -79
  200. data/docs/encoding.md +0 -56
  201. data/ext/rbs_extension/compat.h +0 -10
  202. data/stdlib/cgi-escape/0/escape.rbs +0 -153
@@ -10,308 +10,307 @@ 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 = (rbs_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 = (rbs_loc_children *) realloc(loc->children, s);
54
- }
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);
55
54
  }
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
- rbs_loc *loc = (rbs_loc *) ptr;
90
- rb_gc_mark(loc->buffer);
88
+ static void rbs_loc_mark(void *ptr)
89
+ {
90
+ rbs_loc *loc = ptr;
91
+ rb_gc_mark(loc->buffer);
91
92
  }
92
93
 
93
94
  static size_t rbs_loc_memsize(const void *ptr) {
94
- const rbs_loc *loc = (const rbs_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
- }
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
+ }
100
101
  }
101
102
 
102
103
  static rb_data_type_t location_type = {
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
104
+ "RBS::Location",
105
+ {rbs_loc_mark, (RUBY_DATA_FUNC)rbs_loc_free, rbs_loc_memsize},
106
+ 0, 0, RUBY_TYPED_FREE_IMMEDIATELY
108
107
  };
109
108
 
110
109
  static VALUE location_s_allocate(VALUE klass) {
111
- rbs_loc *loc;
112
- VALUE obj = TypedData_Make_Struct(klass, rbs_loc, &location_type, loc);
110
+ rbs_loc *loc;
111
+ VALUE obj = TypedData_Make_Struct(klass, rbs_loc, &location_type, loc);
113
112
 
114
- rbs_loc_init(loc, Qnil, RBS_LOC_NULL_RANGE);
113
+ rbs_loc_init(loc, Qnil, RBS_LOC_NULL_RANGE);
115
114
 
116
- return obj;
115
+ return obj;
117
116
  }
118
117
 
119
118
  rbs_loc *rbs_check_location(VALUE obj) {
120
- return (rbs_loc *) rb_check_typeddata(obj, &location_type);
119
+ return rb_check_typeddata(obj, &location_type);
121
120
  }
122
121
 
123
122
  static VALUE location_initialize(VALUE self, VALUE buffer, VALUE start_pos, VALUE end_pos) {
124
- rbs_loc *loc = rbs_check_location(self);
123
+ rbs_loc *loc = rbs_check_location(self);
125
124
 
126
- int start = FIX2INT(start_pos);
127
- int end = FIX2INT(end_pos);
125
+ int start = FIX2INT(start_pos);
126
+ int end = FIX2INT(end_pos);
128
127
 
129
- *loc = (rbs_loc) {
130
- .buffer = buffer,
131
- .rg = (rbs_loc_range) { start, end },
132
- .children = NULL,
133
- };
128
+ *loc = (rbs_loc) {
129
+ .buffer = buffer,
130
+ .rg = (rbs_loc_range) { start, end },
131
+ .children = NULL,
132
+ };
134
133
 
135
- return Qnil;
134
+ return Qnil;
136
135
  }
137
136
 
138
137
  static VALUE location_initialize_copy(VALUE self, VALUE other) {
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
- }
138
+ rbs_loc *self_loc = rbs_check_location(self);
139
+ rbs_loc *other_loc = rbs_check_location(other);
152
140
 
153
- return Qnil;
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
+ }
151
+
152
+ return Qnil;
154
153
  }
155
154
 
156
155
  static VALUE location_buffer(VALUE self) {
157
- rbs_loc *loc = rbs_check_location(self);
158
- return loc->buffer;
156
+ rbs_loc *loc = rbs_check_location(self);
157
+ return loc->buffer;
159
158
  }
160
159
 
161
160
  static VALUE location_start_pos(VALUE self) {
162
- rbs_loc *loc = rbs_check_location(self);
163
- return INT2FIX(loc->rg.start);
161
+ rbs_loc *loc = rbs_check_location(self);
162
+ return INT2FIX(loc->rg.start);
164
163
  }
165
164
 
166
165
  static VALUE location_end_pos(VALUE self) {
167
- rbs_loc *loc = rbs_check_location(self);
168
- return INT2FIX(loc->rg.end);
166
+ rbs_loc *loc = rbs_check_location(self);
167
+ return INT2FIX(loc->rg.end);
169
168
  }
170
169
 
171
170
  static rbs_constant_id_t rbs_constant_pool_insert_ruby_symbol(VALUE symbol) {
172
- VALUE name = rb_sym2str(symbol);
171
+ VALUE name = rb_sym2str(symbol);
173
172
 
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));
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));
178
177
  }
179
178
 
180
179
  static VALUE location_add_required_child(VALUE self, VALUE name, VALUE start, VALUE end) {
181
- rbs_loc *loc = rbs_check_location(self);
180
+ rbs_loc *loc = rbs_check_location(self);
182
181
 
183
- rbs_range_t rg;
184
- rg.start = rbs_loc_position(FIX2INT(start));
185
- rg.end = rbs_loc_position(FIX2INT(end));
182
+ rbs_range_t rg;
183
+ rg.start = rbs_loc_position(FIX2INT(start));
184
+ rg.end = rbs_loc_position(FIX2INT(end));
186
185
 
187
- rbs_loc_legacy_add_required_child(loc, rbs_constant_pool_insert_ruby_symbol(name), rg);
186
+ rbs_loc_legacy_add_required_child(loc, rbs_constant_pool_insert_ruby_symbol(name), rg);
188
187
 
189
- return Qnil;
188
+ return Qnil;
190
189
  }
191
190
 
192
191
  static VALUE location_add_optional_child(VALUE self, VALUE name, VALUE start, VALUE end) {
193
- rbs_loc *loc = rbs_check_location(self);
192
+ rbs_loc *loc = rbs_check_location(self);
194
193
 
195
- rbs_range_t rg;
196
- rg.start = rbs_loc_position(FIX2INT(start));
197
- rg.end = rbs_loc_position(FIX2INT(end));
194
+ rbs_range_t rg;
195
+ rg.start = rbs_loc_position(FIX2INT(start));
196
+ rg.end = rbs_loc_position(FIX2INT(end));
198
197
 
199
- rbs_loc_legacy_add_optional_child(loc, rbs_constant_pool_insert_ruby_symbol(name), rg);
198
+ rbs_loc_legacy_add_optional_child(loc, rbs_constant_pool_insert_ruby_symbol(name), rg);
200
199
 
201
- return Qnil;
200
+ return Qnil;
202
201
  }
203
202
 
204
203
  static VALUE location_add_optional_no_child(VALUE self, VALUE name) {
205
- rbs_loc *loc = rbs_check_location(self);
204
+ rbs_loc *loc = rbs_check_location(self);
206
205
 
207
- rbs_loc_legacy_add_optional_child(loc, rbs_constant_pool_insert_ruby_symbol(name), NULL_RANGE);
206
+ rbs_loc_legacy_add_optional_child(loc, rbs_constant_pool_insert_ruby_symbol(name), NULL_RANGE);
208
207
 
209
- return Qnil;
208
+ return Qnil;
210
209
  }
211
210
 
212
211
  VALUE rbs_new_location(VALUE buffer, rbs_range_t rg) {
213
- rbs_loc *loc;
214
- VALUE obj = TypedData_Make_Struct(RBS_Location, rbs_loc, &location_type, loc);
212
+ rbs_loc *loc;
213
+ VALUE obj = TypedData_Make_Struct(RBS_Location, rbs_loc, &location_type, loc);
215
214
 
216
- rbs_loc_init(loc, buffer, rbs_new_loc_range(rg));
215
+ rbs_loc_init(loc, buffer, rbs_new_loc_range(rg));
217
216
 
218
- return obj;
217
+ return obj;
219
218
  }
220
219
 
221
220
  static VALUE rbs_new_location_from_loc_range(VALUE buffer, rbs_loc_range rg) {
222
- rbs_loc *loc;
223
- VALUE obj = TypedData_Make_Struct(RBS_Location, rbs_loc, &location_type, loc);
221
+ rbs_loc *loc;
222
+ VALUE obj = TypedData_Make_Struct(RBS_Location, rbs_loc, &location_type, loc);
224
223
 
225
- rbs_loc_init(loc, buffer, rg);
224
+ rbs_loc_init(loc, buffer, rg);
226
225
 
227
- return obj;
226
+ return obj;
228
227
  }
229
228
 
230
229
  static rbs_constant_id_t rbs_constant_pool_find_ruby_symbol(VALUE symbol) {
231
- VALUE name = rb_sym2str(symbol);
230
+ VALUE name = rb_sym2str(symbol);
232
231
 
233
- return rbs_constant_pool_find(RBS_GLOBAL_CONSTANT_POOL, (const uint8_t *) RSTRING_PTR(name), RSTRING_LEN(name));
232
+ return rbs_constant_pool_find(RBS_GLOBAL_CONSTANT_POOL, (const uint8_t *) RSTRING_PTR(name), RSTRING_LEN(name));
234
233
  }
235
234
 
236
235
  static VALUE location_aref(VALUE self, VALUE name) {
237
- rbs_loc *loc = rbs_check_location(self);
236
+ rbs_loc *loc = rbs_check_location(self);
238
237
 
239
- rbs_constant_id_t id = rbs_constant_pool_find_ruby_symbol(name);
238
+ rbs_constant_id_t id = rbs_constant_pool_find_ruby_symbol(name);
240
239
 
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;
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;
245
244
 
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
- }
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);
252
249
  }
250
+ }
253
251
  }
252
+ }
254
253
 
255
- VALUE string = rb_funcall(name, rb_intern("to_s"), 0);
256
- rb_raise(rb_eRuntimeError, "Unknown child name given: %s", RSTRING_PTR(string));
254
+ VALUE string = rb_funcall(name, rb_intern("to_s"), 0);
255
+ rb_raise(rb_eRuntimeError, "Unknown child name given: %s", RSTRING_PTR(string));
257
256
  }
258
257
 
259
258
  static VALUE rbs_constant_to_ruby_symbol(rbs_constant_t *constant) {
260
- return ID2SYM(rb_intern2((const char *) constant->start, constant->length));
259
+ return ID2SYM(rb_intern2((const char *) constant->start, constant->length));
261
260
  }
262
261
 
263
262
  static VALUE location_optional_keys(VALUE self) {
264
- VALUE keys = rb_ary_new();
263
+ VALUE keys = rb_ary_new();
265
264
 
266
- rbs_loc *loc = rbs_check_location(self);
267
- rbs_loc_children *children = loc->children;
268
- if (children == NULL) {
269
- return keys;
270
- }
265
+ rbs_loc *loc = rbs_check_location(self);
266
+ rbs_loc_children *children = loc->children;
267
+ if (children == NULL) {
268
+ return keys;
269
+ }
271
270
 
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
- }
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);
278
276
  }
277
+ }
279
278
 
280
- return keys;
279
+ return keys;
281
280
  }
282
281
 
283
282
  static VALUE location_required_keys(VALUE self) {
284
- VALUE keys = rb_ary_new();
283
+ VALUE keys = rb_ary_new();
285
284
 
286
- rbs_loc *loc = rbs_check_location(self);
287
- rbs_loc_children *children = loc->children;
288
- if (children == NULL) {
289
- return keys;
290
- }
285
+ rbs_loc *loc = rbs_check_location(self);
286
+ rbs_loc_children *children = loc->children;
287
+ if (children == NULL) {
288
+ return keys;
289
+ }
291
290
 
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
- }
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);
298
296
  }
297
+ }
299
298
 
300
- return keys;
299
+ return keys;
301
300
  }
302
301
 
303
302
  void rbs__init_location(void) {
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);
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);
317
316
  }
@@ -1,12 +1,7 @@
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
7
4
  #include "ruby.h"
8
- SUPPRESS_RUBY_HEADER_DIAGNOSTICS_END
9
-
10
5
  #include "rbs.h"
11
6
 
12
7
  /**
@@ -15,9 +10,9 @@ SUPPRESS_RUBY_HEADER_DIAGNOSTICS_END
15
10
  extern VALUE RBS_Location;
16
11
 
17
12
  typedef struct {
18
- VALUE buffer;
19
- rbs_loc_range rg;
20
- rbs_loc_children *children; // NULL when no children is allocated
13
+ VALUE buffer;
14
+ rbs_loc_range rg;
15
+ rbs_loc_children *children; // NULL when no children is allocated
21
16
  } rbs_loc;
22
17
 
23
18
  /**