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.
- checksums.yaml +4 -4
- data/.github/workflows/comments.yml +3 -3
- data/.github/workflows/ruby.yml +24 -35
- data/.github/workflows/typecheck.yml +3 -1
- data/.github/workflows/windows.yml +2 -2
- data/.gitignore +0 -4
- data/CHANGELOG.md +0 -88
- data/README.md +1 -38
- data/Rakefile +20 -142
- data/Steepfile +1 -0
- data/config.yml +43 -1
- data/core/array.rbs +46 -100
- data/core/complex.rbs +21 -32
- data/core/dir.rbs +2 -2
- data/core/encoding.rbs +9 -6
- data/core/enumerable.rbs +3 -90
- data/core/enumerator.rbs +1 -18
- data/core/errno.rbs +0 -8
- data/core/errors.rbs +1 -28
- data/core/exception.rbs +2 -2
- data/core/fiber.rbs +4 -5
- data/core/file.rbs +12 -27
- data/core/file_test.rbs +1 -1
- data/core/float.rbs +22 -209
- data/core/gc.rbs +281 -417
- data/core/hash.rbs +727 -1024
- data/core/integer.rbs +38 -78
- data/core/io/buffer.rbs +7 -18
- data/core/io/wait.rbs +33 -11
- data/core/io.rbs +12 -14
- data/core/kernel.rbs +51 -57
- data/core/marshal.rbs +1 -1
- data/core/match_data.rbs +1 -1
- data/core/math.rbs +3 -42
- data/core/method.rbs +6 -14
- data/core/module.rbs +17 -88
- data/core/nil_class.rbs +3 -3
- data/core/numeric.rbs +16 -16
- data/core/object.rbs +3 -3
- data/core/object_space.rbs +15 -21
- data/core/proc.rbs +8 -15
- data/core/process.rbs +2 -2
- data/core/ractor.rbs +437 -278
- data/core/range.rbs +8 -7
- data/core/rational.rbs +24 -37
- data/core/rbs/unnamed/argf.rbs +2 -2
- data/core/rbs/unnamed/env_class.rbs +1 -1
- data/core/rbs/unnamed/random.rbs +2 -4
- data/core/regexp.rbs +20 -25
- data/core/ruby_vm.rbs +4 -6
- data/core/rubygems/errors.rbs +70 -3
- data/core/rubygems/rubygems.rbs +79 -11
- data/core/rubygems/version.rbs +3 -2
- data/core/set.rbs +359 -488
- data/core/string.rbs +1228 -3153
- data/core/struct.rbs +1 -1
- data/core/symbol.rbs +4 -4
- data/core/thread.rbs +29 -92
- data/core/time.rbs +9 -35
- data/core/trace_point.rbs +4 -7
- data/core/unbound_method.rbs +6 -14
- data/docs/collection.md +2 -2
- data/docs/gem.md +1 -0
- data/docs/sigs.md +3 -3
- data/ext/rbs_extension/ast_translation.c +1077 -944
- data/ext/rbs_extension/ast_translation.h +0 -7
- data/ext/rbs_extension/class_constants.c +83 -71
- data/ext/rbs_extension/class_constants.h +7 -4
- data/ext/rbs_extension/extconf.rb +2 -24
- data/ext/rbs_extension/legacy_location.c +172 -173
- data/ext/rbs_extension/legacy_location.h +3 -8
- data/ext/rbs_extension/main.c +289 -239
- data/ext/rbs_extension/rbs_extension.h +0 -3
- data/ext/rbs_extension/rbs_string_bridging.h +0 -4
- data/include/rbs/ast.h +98 -37
- data/include/rbs/defines.h +12 -38
- data/include/rbs/lexer.h +114 -126
- data/include/rbs/location.h +14 -14
- data/include/rbs/parser.h +37 -21
- data/include/rbs/string.h +5 -3
- data/include/rbs/util/rbs_allocator.h +19 -40
- data/include/rbs/util/rbs_assert.h +1 -12
- data/include/rbs/util/rbs_constant_pool.h +3 -3
- data/include/rbs/util/rbs_encoding.h +1 -3
- data/include/rbs/util/rbs_unescape.h +1 -2
- data/lib/rbs/ast/ruby/annotations.rb +119 -0
- data/lib/rbs/ast/ruby/comment_block.rb +221 -0
- data/lib/rbs/ast/ruby/declarations.rb +86 -0
- data/lib/rbs/ast/ruby/helpers/constant_helper.rb +24 -0
- data/lib/rbs/ast/ruby/helpers/location_helper.rb +15 -0
- data/lib/rbs/ast/ruby/members.rb +213 -0
- data/lib/rbs/buffer.rb +104 -24
- data/lib/rbs/cli/validate.rb +40 -35
- data/lib/rbs/cli.rb +5 -6
- data/lib/rbs/collection/config/lockfile_generator.rb +0 -1
- data/lib/rbs/collection.rb +0 -1
- data/lib/rbs/definition.rb +6 -1
- data/lib/rbs/definition_builder/ancestor_builder.rb +65 -62
- data/lib/rbs/definition_builder/method_builder.rb +45 -30
- data/lib/rbs/definition_builder.rb +44 -9
- data/lib/rbs/environment/class_entry.rb +69 -0
- data/lib/rbs/environment/module_entry.rb +66 -0
- data/lib/rbs/environment.rb +244 -218
- data/lib/rbs/environment_loader.rb +3 -3
- data/lib/rbs/errors.rb +5 -4
- data/lib/rbs/inline_parser/comment_association.rb +117 -0
- data/lib/rbs/inline_parser.rb +206 -0
- data/lib/rbs/location_aux.rb +35 -3
- data/lib/rbs/parser_aux.rb +11 -6
- data/lib/rbs/prototype/runtime.rb +2 -2
- data/lib/rbs/resolver/constant_resolver.rb +2 -2
- data/lib/rbs/resolver/type_name_resolver.rb +38 -124
- data/lib/rbs/source.rb +99 -0
- data/lib/rbs/subtractor.rb +4 -3
- data/lib/rbs/test/type_check.rb +0 -14
- data/lib/rbs/types.rb +1 -3
- data/lib/rbs/version.rb +1 -1
- data/lib/rbs.rb +13 -1
- data/lib/rdoc/discover.rb +1 -1
- data/lib/rdoc_plugin/parser.rb +1 -1
- data/rbs.gemspec +1 -0
- data/sig/ancestor_builder.rbs +1 -1
- data/sig/ast/ruby/annotations.rbs +110 -0
- data/sig/ast/ruby/comment_block.rbs +119 -0
- data/sig/ast/ruby/declarations.rbs +60 -0
- data/sig/ast/ruby/helpers/constant_helper.rbs +11 -0
- data/sig/ast/ruby/helpers/location_helper.rbs +15 -0
- data/sig/ast/ruby/members.rbs +72 -0
- data/sig/buffer.rbs +63 -5
- data/sig/definition.rbs +1 -0
- data/sig/definition_builder.rbs +1 -1
- data/sig/environment/class_entry.rbs +50 -0
- data/sig/environment/module_entry.rbs +50 -0
- data/sig/environment.rbs +28 -133
- data/sig/errors.rbs +13 -6
- data/sig/inline_parser/comment_association.rbs +71 -0
- data/sig/inline_parser.rbs +87 -0
- data/sig/location.rbs +32 -7
- data/sig/manifest.yaml +1 -0
- data/sig/method_builder.rbs +7 -4
- data/sig/parser.rbs +16 -20
- data/sig/resolver/type_name_resolver.rbs +7 -38
- data/sig/source.rbs +48 -0
- data/sig/types.rbs +1 -4
- data/src/ast.c +290 -201
- data/src/lexer.c +2813 -2902
- data/src/lexer.re +4 -0
- data/src/lexstate.c +155 -169
- data/src/location.c +40 -40
- data/src/parser.c +2665 -2433
- data/src/string.c +48 -0
- data/src/util/rbs_allocator.c +77 -80
- data/src/util/rbs_assert.c +10 -10
- data/src/util/rbs_buffer.c +2 -2
- data/src/util/rbs_constant_pool.c +15 -13
- data/src/util/rbs_encoding.c +4062 -20097
- data/src/util/rbs_unescape.c +48 -85
- data/stdlib/bigdecimal/0/big_decimal.rbs +82 -100
- data/stdlib/bigdecimal-math/0/big_math.rbs +8 -169
- data/stdlib/cgi/0/core.rbs +396 -2
- data/stdlib/cgi/0/manifest.yaml +0 -1
- data/stdlib/coverage/0/coverage.rbs +1 -3
- data/stdlib/date/0/date.rbs +59 -67
- data/stdlib/date/0/date_time.rbs +1 -1
- data/stdlib/delegate/0/delegator.rbs +7 -10
- data/stdlib/erb/0/erb.rbs +347 -737
- data/stdlib/fileutils/0/fileutils.rbs +13 -18
- data/stdlib/forwardable/0/forwardable.rbs +0 -3
- data/stdlib/json/0/json.rbs +48 -68
- data/stdlib/net-http/0/net-http.rbs +0 -3
- data/stdlib/objspace/0/objspace.rbs +4 -9
- data/stdlib/open-uri/0/open-uri.rbs +0 -40
- data/stdlib/openssl/0/openssl.rbs +228 -331
- data/stdlib/optparse/0/optparse.rbs +3 -3
- data/{core → stdlib/pathname/0}/pathname.rbs +355 -255
- data/stdlib/psych/0/psych.rbs +3 -3
- data/stdlib/rdoc/0/rdoc.rbs +1 -1
- data/stdlib/resolv/0/resolv.rbs +68 -25
- data/stdlib/ripper/0/ripper.rbs +2 -5
- data/stdlib/singleton/0/singleton.rbs +0 -3
- data/stdlib/socket/0/socket.rbs +1 -13
- data/stdlib/socket/0/tcp_socket.rbs +2 -10
- data/stdlib/stringio/0/stringio.rbs +85 -1176
- data/stdlib/strscan/0/string_scanner.rbs +31 -31
- data/stdlib/tempfile/0/tempfile.rbs +3 -3
- data/stdlib/time/0/time.rbs +1 -1
- data/stdlib/timeout/0/timeout.rbs +7 -63
- data/stdlib/tsort/0/cyclic.rbs +0 -3
- data/stdlib/uri/0/common.rbs +2 -11
- data/stdlib/uri/0/file.rbs +1 -1
- data/stdlib/uri/0/generic.rbs +16 -17
- data/stdlib/uri/0/rfc2396_parser.rbs +7 -6
- data/stdlib/zlib/0/zstream.rbs +0 -1
- metadata +40 -12
- data/.clang-format +0 -74
- data/.clangd +0 -2
- data/.github/workflows/c-check.yml +0 -54
- data/core/ruby.rbs +0 -53
- data/docs/aliases.md +0 -79
- data/docs/encoding.md +0 -56
- data/ext/rbs_extension/compat.h +0 -10
- 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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
22
|
-
|
|
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
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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
|
-
|
|
33
|
+
check_children_max(cap);
|
|
34
34
|
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
size_t s = RBS_LOC_CHILDREN_SIZE(cap);
|
|
36
|
+
loc->children = malloc(s);
|
|
37
37
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
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
|
-
|
|
59
|
+
check_children_cap(loc);
|
|
60
60
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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
|
-
|
|
69
|
+
rbs_loc_legacy_add_optional_child(loc, name, r);
|
|
70
70
|
|
|
71
|
-
|
|
72
|
-
|
|
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
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
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
|
-
|
|
85
|
-
|
|
84
|
+
free(loc->children);
|
|
85
|
+
ruby_xfree(loc);
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
-
static void rbs_loc_mark(void *ptr)
|
|
89
|
-
|
|
90
|
-
|
|
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
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
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
|
-
|
|
104
|
-
|
|
105
|
-
|
|
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
|
-
|
|
112
|
-
|
|
110
|
+
rbs_loc *loc;
|
|
111
|
+
VALUE obj = TypedData_Make_Struct(klass, rbs_loc, &location_type, loc);
|
|
113
112
|
|
|
114
|
-
|
|
113
|
+
rbs_loc_init(loc, Qnil, RBS_LOC_NULL_RANGE);
|
|
115
114
|
|
|
116
|
-
|
|
115
|
+
return obj;
|
|
117
116
|
}
|
|
118
117
|
|
|
119
118
|
rbs_loc *rbs_check_location(VALUE obj) {
|
|
120
|
-
|
|
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
|
-
|
|
123
|
+
rbs_loc *loc = rbs_check_location(self);
|
|
125
124
|
|
|
126
|
-
|
|
127
|
-
|
|
125
|
+
int start = FIX2INT(start_pos);
|
|
126
|
+
int end = FIX2INT(end_pos);
|
|
128
127
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
128
|
+
*loc = (rbs_loc) {
|
|
129
|
+
.buffer = buffer,
|
|
130
|
+
.rg = (rbs_loc_range) { start, end },
|
|
131
|
+
.children = NULL,
|
|
132
|
+
};
|
|
134
133
|
|
|
135
|
-
|
|
134
|
+
return Qnil;
|
|
136
135
|
}
|
|
137
136
|
|
|
138
137
|
static VALUE location_initialize_copy(VALUE self, VALUE other) {
|
|
139
|
-
|
|
140
|
-
|
|
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
|
-
|
|
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
|
-
|
|
158
|
-
|
|
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
|
-
|
|
163
|
-
|
|
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
|
-
|
|
168
|
-
|
|
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
|
-
|
|
171
|
+
VALUE name = rb_sym2str(symbol);
|
|
173
172
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
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
|
-
|
|
180
|
+
rbs_loc *loc = rbs_check_location(self);
|
|
182
181
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
182
|
+
rbs_range_t rg;
|
|
183
|
+
rg.start = rbs_loc_position(FIX2INT(start));
|
|
184
|
+
rg.end = rbs_loc_position(FIX2INT(end));
|
|
186
185
|
|
|
187
|
-
|
|
186
|
+
rbs_loc_legacy_add_required_child(loc, rbs_constant_pool_insert_ruby_symbol(name), rg);
|
|
188
187
|
|
|
189
|
-
|
|
188
|
+
return Qnil;
|
|
190
189
|
}
|
|
191
190
|
|
|
192
191
|
static VALUE location_add_optional_child(VALUE self, VALUE name, VALUE start, VALUE end) {
|
|
193
|
-
|
|
192
|
+
rbs_loc *loc = rbs_check_location(self);
|
|
194
193
|
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
194
|
+
rbs_range_t rg;
|
|
195
|
+
rg.start = rbs_loc_position(FIX2INT(start));
|
|
196
|
+
rg.end = rbs_loc_position(FIX2INT(end));
|
|
198
197
|
|
|
199
|
-
|
|
198
|
+
rbs_loc_legacy_add_optional_child(loc, rbs_constant_pool_insert_ruby_symbol(name), rg);
|
|
200
199
|
|
|
201
|
-
|
|
200
|
+
return Qnil;
|
|
202
201
|
}
|
|
203
202
|
|
|
204
203
|
static VALUE location_add_optional_no_child(VALUE self, VALUE name) {
|
|
205
|
-
|
|
204
|
+
rbs_loc *loc = rbs_check_location(self);
|
|
206
205
|
|
|
207
|
-
|
|
206
|
+
rbs_loc_legacy_add_optional_child(loc, rbs_constant_pool_insert_ruby_symbol(name), NULL_RANGE);
|
|
208
207
|
|
|
209
|
-
|
|
208
|
+
return Qnil;
|
|
210
209
|
}
|
|
211
210
|
|
|
212
211
|
VALUE rbs_new_location(VALUE buffer, rbs_range_t rg) {
|
|
213
|
-
|
|
214
|
-
|
|
212
|
+
rbs_loc *loc;
|
|
213
|
+
VALUE obj = TypedData_Make_Struct(RBS_Location, rbs_loc, &location_type, loc);
|
|
215
214
|
|
|
216
|
-
|
|
215
|
+
rbs_loc_init(loc, buffer, rbs_new_loc_range(rg));
|
|
217
216
|
|
|
218
|
-
|
|
217
|
+
return obj;
|
|
219
218
|
}
|
|
220
219
|
|
|
221
220
|
static VALUE rbs_new_location_from_loc_range(VALUE buffer, rbs_loc_range rg) {
|
|
222
|
-
|
|
223
|
-
|
|
221
|
+
rbs_loc *loc;
|
|
222
|
+
VALUE obj = TypedData_Make_Struct(RBS_Location, rbs_loc, &location_type, loc);
|
|
224
223
|
|
|
225
|
-
|
|
224
|
+
rbs_loc_init(loc, buffer, rg);
|
|
226
225
|
|
|
227
|
-
|
|
226
|
+
return obj;
|
|
228
227
|
}
|
|
229
228
|
|
|
230
229
|
static rbs_constant_id_t rbs_constant_pool_find_ruby_symbol(VALUE symbol) {
|
|
231
|
-
|
|
230
|
+
VALUE name = rb_sym2str(symbol);
|
|
232
231
|
|
|
233
|
-
|
|
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
|
-
|
|
236
|
+
rbs_loc *loc = rbs_check_location(self);
|
|
238
237
|
|
|
239
|
-
|
|
238
|
+
rbs_constant_id_t id = rbs_constant_pool_find_ruby_symbol(name);
|
|
240
239
|
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
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
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
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
|
-
|
|
256
|
-
|
|
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
|
-
|
|
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
|
-
|
|
263
|
+
VALUE keys = rb_ary_new();
|
|
265
264
|
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
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
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
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
|
-
|
|
279
|
+
return keys;
|
|
281
280
|
}
|
|
282
281
|
|
|
283
282
|
static VALUE location_required_keys(VALUE self) {
|
|
284
|
-
|
|
283
|
+
VALUE keys = rb_ary_new();
|
|
285
284
|
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
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
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
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
|
-
|
|
299
|
+
return keys;
|
|
301
300
|
}
|
|
302
301
|
|
|
303
302
|
void rbs__init_location(void) {
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
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
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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
|
/**
|