rbs 3.5.3 → 3.6.0.pre.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/dependabot.yml +5 -1
- data/.github/workflows/ruby.yml +2 -18
- data/.github/workflows/windows.yml +26 -0
- data/.rubocop.yml +28 -1
- data/CHANGELOG.md +58 -0
- data/Rakefile +8 -2
- data/core/array.rbs +10 -10
- data/core/basic_object.rbs +4 -4
- data/core/builtin.rbs +4 -4
- data/core/dir.rbs +1 -1
- data/core/enumerable.rbs +17 -11
- data/core/enumerator/product.rbs +1 -1
- data/core/enumerator.rbs +9 -2
- data/core/errors.rbs +1 -1
- data/core/exception.rbs +1 -1
- data/core/fiber.rbs +1 -1
- data/core/file.rbs +1 -1
- data/core/global_variables.rbs +2 -2
- data/core/integer.rbs +4 -4
- data/core/kernel.rbs +69 -40
- data/core/method.rbs +98 -7
- data/core/module.rbs +3 -3
- data/core/proc.rbs +184 -23
- data/core/ractor.rbs +1 -1
- data/core/random.rbs +1 -1
- data/core/range.rbs +30 -0
- data/core/rbs/unnamed/env_class.rbs +7 -7
- data/core/rbs/unnamed/random.rbs +14 -14
- data/core/refinement.rbs +16 -26
- data/core/regexp.rbs +2 -2
- data/core/symbol.rbs +34 -26
- data/core/thread.rbs +8 -7
- data/core/trace_point.rbs +12 -12
- data/core/unbound_method.rbs +1 -1
- data/docs/syntax.md +26 -12
- data/ext/rbs_extension/lexer.c +1 -1
- data/ext/rbs_extension/lexer.h +5 -0
- data/ext/rbs_extension/lexer.re +1 -1
- data/ext/rbs_extension/lexstate.c +16 -0
- data/ext/rbs_extension/location.c +27 -39
- data/ext/rbs_extension/location.h +7 -2
- data/ext/rbs_extension/parser.c +119 -51
- data/ext/rbs_extension/ruby_objs.c +2 -1
- data/ext/rbs_extension/ruby_objs.h +1 -1
- data/lib/rbs/ast/declarations.rb +36 -0
- data/lib/rbs/ast/type_param.rb +71 -15
- data/lib/rbs/ast/visitor.rb +137 -0
- data/lib/rbs/buffer.rb +5 -0
- data/lib/rbs/cli/validate.rb +81 -7
- data/lib/rbs/cli.rb +3 -3
- data/lib/rbs/definition.rb +2 -1
- data/lib/rbs/definition_builder/ancestor_builder.rb +30 -4
- data/lib/rbs/definition_builder.rb +21 -6
- data/lib/rbs/environment_loader.rb +1 -1
- data/lib/rbs/errors.rb +8 -3
- data/lib/rbs/file_finder.rb +9 -12
- data/lib/rbs/location_aux.rb +2 -6
- data/lib/rbs/locator.rb +8 -5
- data/lib/rbs/prototype/rbi.rb +2 -1
- data/lib/rbs/prototype/runtime.rb +3 -2
- data/lib/rbs/sorter.rb +9 -6
- data/lib/rbs/test/type_check.rb +13 -0
- data/lib/rbs/types.rb +11 -0
- data/lib/rbs/validator.rb +2 -2
- data/lib/rbs/vendorer.rb +3 -3
- data/lib/rbs/version.rb +1 -1
- data/lib/rbs.rb +1 -0
- data/sig/declarations.rbs +6 -0
- data/sig/definition.rbs +1 -1
- data/sig/definition_builder.rbs +3 -1
- data/sig/errors.rbs +3 -2
- data/sig/file_finder.rbs +24 -2
- data/sig/location.rbs +0 -3
- data/sig/method_types.rbs +1 -1
- data/sig/sorter.rbs +1 -1
- data/sig/type_param.rbs +41 -9
- data/sig/types.rbs +12 -0
- data/sig/visitor.rbs +47 -0
- data/stdlib/csv/0/csv.rbs +44 -6
- data/stdlib/digest/0/digest.rbs +22 -28
- data/stdlib/ipaddr/0/ipaddr.rbs +1 -1
- data/stdlib/kconv/0/kconv.rbs +166 -0
- data/stdlib/net-http/0/net-http.rbs +2 -2
- data/stdlib/psych/0/store.rbs +1 -1
- data/stdlib/uri/0/ldap.rbs +1 -1
- data/stdlib/zlib/0/deflate.rbs +1 -1
- data/stdlib/zlib/0/gzip_reader.rbs +5 -1
- metadata +6 -2
data/core/thread.rbs
CHANGED
@@ -382,7 +382,7 @@ class Thread < Object
|
|
382
382
|
# If you're going to subclass Thread, be sure to call super in your `initialize`
|
383
383
|
# method, otherwise a ThreadError will be raised.
|
384
384
|
#
|
385
|
-
def initialize: (*untyped) { (
|
385
|
+
def initialize: (*untyped) { (?) -> void } -> void
|
386
386
|
|
387
387
|
# <!--
|
388
388
|
# rdoc-file=thread.c
|
@@ -1178,7 +1178,7 @@ class Thread < Object
|
|
1178
1178
|
# calling `start` in that subclass will not invoke the subclass's `initialize`
|
1179
1179
|
# method.
|
1180
1180
|
#
|
1181
|
-
def self.start: (*untyped args) { (
|
1181
|
+
def self.start: (*untyped args) { (?) -> void } -> instance
|
1182
1182
|
|
1183
1183
|
# <!--
|
1184
1184
|
# rdoc-file=thread.c
|
@@ -1545,7 +1545,7 @@ end
|
|
1545
1545
|
#
|
1546
1546
|
# consumer.join
|
1547
1547
|
#
|
1548
|
-
class Thread::Queue < Object
|
1548
|
+
class Thread::Queue[Elem = untyped] < Object
|
1549
1549
|
# <!-- rdoc-file=thread_sync.c -->
|
1550
1550
|
# Pushes the given `object` to the queue.
|
1551
1551
|
#
|
@@ -1661,7 +1661,7 @@ class Thread::Queue < Object
|
|
1661
1661
|
# If `timeout` seconds have passed and no data is available `nil` is returned.
|
1662
1662
|
# If `timeout` is `0` it returns immediately.
|
1663
1663
|
#
|
1664
|
-
def pop: (?boolish non_block, ?timeout: _ToF?) ->
|
1664
|
+
def pop: (?boolish non_block, ?timeout: _ToF?) -> Elem?
|
1665
1665
|
|
1666
1666
|
# <!--
|
1667
1667
|
# rdoc-file=thread_sync.c
|
@@ -1671,7 +1671,7 @@ class Thread::Queue < Object
|
|
1671
1671
|
# -->
|
1672
1672
|
# Pushes the given `object` to the queue.
|
1673
1673
|
#
|
1674
|
-
def push: (
|
1674
|
+
def push: (Elem obj) -> void
|
1675
1675
|
|
1676
1676
|
# <!--
|
1677
1677
|
# rdoc-file=thread_sync.rb
|
@@ -1692,7 +1692,7 @@ end
|
|
1692
1692
|
#
|
1693
1693
|
# See Thread::Queue for an example of how a Thread::SizedQueue works.
|
1694
1694
|
#
|
1695
|
-
class Thread::SizedQueue < Thread::Queue
|
1695
|
+
class Thread::SizedQueue[Elem = untyped] < Thread::Queue[Elem]
|
1696
1696
|
# <!--
|
1697
1697
|
# rdoc-file=thread_sync.rb
|
1698
1698
|
# - <<(object, non_block = false, timeout: nil)
|
@@ -1755,7 +1755,8 @@ class Thread::SizedQueue < Thread::Queue
|
|
1755
1755
|
# If `timeout` seconds have passed and no space is available `nil` is returned.
|
1756
1756
|
# If `timeout` is `0` it returns immediately. Otherwise it returns `self`.
|
1757
1757
|
#
|
1758
|
-
def push: (
|
1758
|
+
def push: (Elem obj, ?boolish non_block) -> void
|
1759
|
+
| (Elem obj, timeout: _ToF?) -> self?
|
1759
1760
|
end
|
1760
1761
|
|
1761
1762
|
class ConditionVariable = Thread::ConditionVariable
|
data/core/trace_point.rbs
CHANGED
@@ -63,7 +63,7 @@
|
|
63
63
|
# `:script_compiled`
|
64
64
|
# : new Ruby code compiled (with `eval`, `load` or `require`)
|
65
65
|
#
|
66
|
-
class TracePoint
|
66
|
+
class TracePoint
|
67
67
|
# <!--
|
68
68
|
# rdoc-file=trace_point.rb
|
69
69
|
# - TracePoint.new(*events) { |obj| block } -> obj
|
@@ -110,7 +110,7 @@ class TracePoint < Object
|
|
110
110
|
#
|
111
111
|
# Access from other threads is also forbidden.
|
112
112
|
#
|
113
|
-
def
|
113
|
+
def self.new: (*_ToSym events) { (instance tp) -> void } -> instance
|
114
114
|
|
115
115
|
# <!--
|
116
116
|
# rdoc-file=trace_point.rb
|
@@ -172,7 +172,7 @@ class TracePoint < Object
|
|
172
172
|
# (note that we needed to filter out calls by itself from :line handler,
|
173
173
|
# otherwise it will call itself infinitely).
|
174
174
|
#
|
175
|
-
def self.allow_reentry: () { () ->
|
175
|
+
def self.allow_reentry: [T] () { (nil) -> T } -> T
|
176
176
|
|
177
177
|
# <!--
|
178
178
|
# rdoc-file=trace_point.rb
|
@@ -199,7 +199,7 @@ class TracePoint < Object
|
|
199
199
|
#
|
200
200
|
# trace.enabled? #=> true
|
201
201
|
#
|
202
|
-
def self.trace: (*
|
202
|
+
def self.trace: (*_ToSym events) { (instance tp) -> void } -> instance
|
203
203
|
|
204
204
|
# <!--
|
205
205
|
# rdoc-file=trace_point.rb
|
@@ -218,7 +218,7 @@ class TracePoint < Object
|
|
218
218
|
# -->
|
219
219
|
# Return the called name of the method being called
|
220
220
|
#
|
221
|
-
def callee_id: () -> Symbol
|
221
|
+
def callee_id: () -> Symbol?
|
222
222
|
|
223
223
|
# <!--
|
224
224
|
# rdoc-file=trace_point.rb
|
@@ -257,7 +257,7 @@ class TracePoint < Object
|
|
257
257
|
# C.foo
|
258
258
|
# end
|
259
259
|
#
|
260
|
-
def defined_class: () -> Module
|
260
|
+
def defined_class: () -> (Class | Module)?
|
261
261
|
|
262
262
|
# <!--
|
263
263
|
# rdoc-file=trace_point.rb
|
@@ -293,7 +293,7 @@ class TracePoint < Object
|
|
293
293
|
# #=> RuntimeError: access from outside
|
294
294
|
#
|
295
295
|
def disable: () -> bool
|
296
|
-
| () { () ->
|
296
|
+
| [T] () { () -> T } -> T
|
297
297
|
|
298
298
|
# <!--
|
299
299
|
# rdoc-file=trace_point.rb
|
@@ -352,8 +352,8 @@ class TracePoint < Object
|
|
352
352
|
# trace.enable { p tp.lineno }
|
353
353
|
# #=> RuntimeError: access from outside
|
354
354
|
#
|
355
|
-
def enable:
|
356
|
-
| [
|
355
|
+
def enable: (?target: Method | RubyVM::InstructionSequence | Proc | nil, ?target_line: int?, ?target_thread: Thread | :default | nil) -> bool
|
356
|
+
| [T] (?target: Method | RubyVM::InstructionSequence | Proc | nil, ?target_line: int?, ?target_thread: Thread | :default | nil) { () -> T } -> T
|
357
357
|
|
358
358
|
# <!--
|
359
359
|
# rdoc-file=trace_point.rb
|
@@ -395,7 +395,7 @@ class TracePoint < Object
|
|
395
395
|
# -->
|
396
396
|
# Return the name at the definition of the method being called
|
397
397
|
#
|
398
|
-
def method_id: () -> Symbol
|
398
|
+
def method_id: () -> Symbol?
|
399
399
|
|
400
400
|
# <!--
|
401
401
|
# rdoc-file=trace_point.rb
|
@@ -412,7 +412,7 @@ class TracePoint < Object
|
|
412
412
|
# Return the parameters definition of the method or block that the current hook
|
413
413
|
# belongs to. Format is the same as for Method#parameters
|
414
414
|
#
|
415
|
-
def parameters: () -> ::
|
415
|
+
def parameters: () -> Method::param_types?
|
416
416
|
|
417
417
|
# <!--
|
418
418
|
# rdoc-file=trace_point.rb
|
@@ -421,7 +421,7 @@ class TracePoint < Object
|
|
421
421
|
# Value from exception raised on the `:raise` event, or rescued on the `:rescue`
|
422
422
|
# event.
|
423
423
|
#
|
424
|
-
def raised_exception: () ->
|
424
|
+
def raised_exception: () -> Exception
|
425
425
|
|
426
426
|
# <!--
|
427
427
|
# rdoc-file=trace_point.rb
|
data/core/unbound_method.rbs
CHANGED
@@ -325,5 +325,5 @@ class UnboundMethod
|
|
325
325
|
# arguments. This is semantically equivalent to `umeth.bind(recv).call(args,
|
326
326
|
# ...)`.
|
327
327
|
#
|
328
|
-
def bind_call: (untyped recv, *untyped, **untyped) ?{ (
|
328
|
+
def bind_call: (untyped recv, *untyped, **untyped) ?{ (?) -> untyped } -> untyped
|
329
329
|
end
|
data/docs/syntax.md
CHANGED
@@ -64,7 +64,7 @@ Interface type denotes _type of a value which can be a subtype of the interface_
|
|
64
64
|
|
65
65
|
```rbs
|
66
66
|
_ToS # _ToS interface
|
67
|
-
::
|
67
|
+
::Enumerator::_Each[String] # Interface name with namespace and type application
|
68
68
|
```
|
69
69
|
|
70
70
|
### Alias type
|
@@ -424,8 +424,10 @@ _visibility_ ::= `public` | `private`
|
|
424
424
|
|
425
425
|
_attribute-type_ ::= `attr_reader` | `attr_writer` | `attr_accessor`
|
426
426
|
|
427
|
-
_include-member_ ::=
|
428
|
-
|
|
427
|
+
_include-member_ ::= _include-class-member_
|
428
|
+
| _include-interface-member_
|
429
|
+
_include-class-member_ ::= `include` _class-name_ _type-arguments_
|
430
|
+
_include-interface-member_ :== `include` _interface-name_ _type-arguments_
|
429
431
|
_extend-member_ ::= `extend` _class-name_ _type-arguments_
|
430
432
|
| `extend` _interface-name_ _type-arguments_
|
431
433
|
_prepend-member_ ::= `prepend` _class-name_ _type-arguments_
|
@@ -621,7 +623,7 @@ _module-self-types_ ::= _class-name_ _type-arguments_ `,` _module-self-types_
|
|
621
623
|
_interface-decl_ ::= `interface` _interface-name_ _module-type-parameters_ _interface-members_ `end`
|
622
624
|
|
623
625
|
_interface-members_ ::= _method-member_ # Method
|
624
|
-
| _include-member_
|
626
|
+
| _include-interface-member_ # Mixin (include)
|
625
627
|
| _alias-member_ # Alias
|
626
628
|
|
627
629
|
_type-alias-decl_ ::= `type` _alias-name_ _module-type-parameters_ `=` _type_
|
@@ -750,16 +752,15 @@ $LOAD_PATH: Array[String]
|
|
750
752
|
### Generics
|
751
753
|
|
752
754
|
```markdown
|
753
|
-
_module-type-parameter_ ::= _generics-unchecked_ _generics-variance_ _type-variable_ _generics-bound_
|
755
|
+
_module-type-parameter_ ::= _generics-unchecked_ _generics-variance_ _type-variable_ _generics-bound_ _default-type_
|
754
756
|
|
755
757
|
_method-type-param_ ::= _type-variable_ _generics-bound_
|
756
758
|
|
757
|
-
_generics-bound_ ::=
|
758
|
-
| `<`
|
759
|
+
_generics-bound_ ::= (No type bound)
|
760
|
+
| `<` _type_ (The generics parameter is bounded)
|
759
761
|
|
760
|
-
|
761
|
-
|
762
|
-
| `singleton(` _class-name_ `)` (Class singleton type)
|
762
|
+
_default-type_ ::= (No default type)
|
763
|
+
| `=` _type_ (The generics parameter has default type)
|
763
764
|
|
764
765
|
_generics-variance_ ::= (Invariant)
|
765
766
|
| `out` (Covariant)
|
@@ -826,14 +827,27 @@ class PrettyPrint[T < _Output]
|
|
826
827
|
end
|
827
828
|
```
|
828
829
|
|
829
|
-
If a type parameter has an upper bound, the type parameter must be instantiated with types that is a
|
830
|
+
If a type parameter has an upper bound, the type parameter must be instantiated with types that is a subtype of the upper bound.
|
830
831
|
|
831
832
|
```rbs
|
832
833
|
type str_printer = PrettyPrint[String] # OK
|
833
834
|
type int_printer = PrettyPrint[Integer] # Type error
|
834
835
|
```
|
835
836
|
|
836
|
-
The
|
837
|
+
The generics type parameter of modules, classes, interfaces, or type aliases can have a default type.
|
838
|
+
|
839
|
+
```rbs
|
840
|
+
interface _Foo[T = untyped]
|
841
|
+
end
|
842
|
+
|
843
|
+
interface _Bar[T, S = untyped]
|
844
|
+
end
|
845
|
+
|
846
|
+
type foo = _Foo # equivalent to _Foo[untyped]
|
847
|
+
type bar = _Bar[String] # equivalent to _Bar[String, untyped]
|
848
|
+
```
|
849
|
+
|
850
|
+
Type parameters with default types cannot appear before type parameters without default types. The generic method type parameters cannot have the default types.
|
837
851
|
|
838
852
|
### Directives
|
839
853
|
|
data/ext/rbs_extension/lexer.c
CHANGED
@@ -116,7 +116,7 @@ token rbsparser_next_token(lexstate *state) {
|
|
116
116
|
yy1:
|
117
117
|
rbs_skip(state);
|
118
118
|
#line 144 "ext/rbs_extension/lexer.re"
|
119
|
-
{ return
|
119
|
+
{ return next_eof_token(state); }
|
120
120
|
#line 121 "ext/rbs_extension/lexer.c"
|
121
121
|
yy2:
|
122
122
|
rbs_skip(state);
|
data/ext/rbs_extension/lexer.h
CHANGED
@@ -167,6 +167,11 @@ void skipn(lexstate *state, size_t size);
|
|
167
167
|
* */
|
168
168
|
token next_token(lexstate *state, enum TokenType type);
|
169
169
|
|
170
|
+
/**
|
171
|
+
* Return new token with EOF type.
|
172
|
+
* */
|
173
|
+
token next_eof_token(lexstate *state);
|
174
|
+
|
170
175
|
token rbsparser_next_token(lexstate *state);
|
171
176
|
|
172
177
|
void print_token(token tok);
|
data/ext/rbs_extension/lexer.re
CHANGED
@@ -141,7 +141,7 @@ token rbsparser_next_token(lexstate *state) {
|
|
141
141
|
skip = ([ \t]+|[\r\n]);
|
142
142
|
|
143
143
|
skip { return next_token(state, tTRIVIA); }
|
144
|
-
"\x00" { return
|
144
|
+
"\x00" { return next_eof_token(state); }
|
145
145
|
* { return next_token(state, ErrorToken); }
|
146
146
|
*/
|
147
147
|
}
|
@@ -129,6 +129,22 @@ token next_token(lexstate *state, enum TokenType type) {
|
|
129
129
|
return t;
|
130
130
|
}
|
131
131
|
|
132
|
+
token next_eof_token(lexstate *state) {
|
133
|
+
if (state->current.byte_pos == RSTRING_LEN(state->string)+1) {
|
134
|
+
// End of String
|
135
|
+
token t;
|
136
|
+
t.type = pEOF;
|
137
|
+
t.range.start = state->start;
|
138
|
+
t.range.end = state->start;
|
139
|
+
state->start = state->current;
|
140
|
+
|
141
|
+
return t;
|
142
|
+
} else {
|
143
|
+
// NULL byte in the middle of the string
|
144
|
+
return next_token(state, pEOF);
|
145
|
+
}
|
146
|
+
}
|
147
|
+
|
132
148
|
void rbs_skip(lexstate *state) {
|
133
149
|
if (!state->last_char) {
|
134
150
|
peek(state);
|
@@ -3,7 +3,9 @@
|
|
3
3
|
#define RBS_LOC_REQUIRED_P(loc, i) ((loc)->children->required_p & (1 << (i)))
|
4
4
|
#define RBS_LOC_OPTIONAL_P(loc, i) (!RBS_LOC_REQUIRED_P((loc), (i)))
|
5
5
|
#define RBS_LOC_CHILDREN_SIZE(cap) (sizeof(rbs_loc_children) + sizeof(rbs_loc_entry) * ((cap) - 1))
|
6
|
+
#define NULL_LOC_RANGE_P(rg) ((rg).start == -1)
|
6
7
|
|
8
|
+
rbs_loc_range RBS_LOC_NULL_RANGE = { -1, -1 };
|
7
9
|
VALUE RBS_Location;
|
8
10
|
|
9
11
|
position rbs_loc_position(int char_pos) {
|
@@ -16,6 +18,11 @@ position rbs_loc_position3(int char_pos, int line, int column) {
|
|
16
18
|
return pos;
|
17
19
|
}
|
18
20
|
|
21
|
+
rbs_loc_range rbs_new_loc_range(range rg) {
|
22
|
+
rbs_loc_range r = { rg.start.char_pos, rg.end.char_pos };
|
23
|
+
return r;
|
24
|
+
}
|
25
|
+
|
19
26
|
static void check_children_max(unsigned short n) {
|
20
27
|
size_t max = sizeof(rbs_loc_entry_bitmap) * 8;
|
21
28
|
if (n > max) {
|
@@ -51,7 +58,7 @@ void rbs_loc_add_required_child(rbs_loc *loc, ID name, range r) {
|
|
51
58
|
|
52
59
|
unsigned short i = loc->children->len++;
|
53
60
|
loc->children->entries[i].name = name;
|
54
|
-
loc->children->entries[i].rg = r;
|
61
|
+
loc->children->entries[i].rg = rbs_new_loc_range(r);
|
55
62
|
|
56
63
|
loc->children->required_p |= 1 << i;
|
57
64
|
}
|
@@ -61,10 +68,10 @@ void rbs_loc_add_optional_child(rbs_loc *loc, ID name, range r) {
|
|
61
68
|
|
62
69
|
unsigned short i = loc->children->len++;
|
63
70
|
loc->children->entries[i].name = name;
|
64
|
-
loc->children->entries[i].rg = r;
|
71
|
+
loc->children->entries[i].rg = rbs_new_loc_range(r);
|
65
72
|
}
|
66
73
|
|
67
|
-
void rbs_loc_init(rbs_loc *loc, VALUE buffer,
|
74
|
+
void rbs_loc_init(rbs_loc *loc, VALUE buffer, rbs_loc_range rg) {
|
68
75
|
loc->buffer = buffer;
|
69
76
|
loc->rg = rg;
|
70
77
|
loc->children = NULL;
|
@@ -100,7 +107,7 @@ static VALUE location_s_allocate(VALUE klass) {
|
|
100
107
|
rbs_loc *loc;
|
101
108
|
VALUE obj = TypedData_Make_Struct(klass, rbs_loc, &location_type, loc);
|
102
109
|
|
103
|
-
rbs_loc_init(loc, Qnil,
|
110
|
+
rbs_loc_init(loc, Qnil, RBS_LOC_NULL_RANGE);
|
104
111
|
|
105
112
|
return obj;
|
106
113
|
}
|
@@ -112,8 +119,8 @@ rbs_loc *rbs_check_location(VALUE obj) {
|
|
112
119
|
static VALUE location_initialize(VALUE self, VALUE buffer, VALUE start_pos, VALUE end_pos) {
|
113
120
|
rbs_loc *loc = rbs_check_location(self);
|
114
121
|
|
115
|
-
|
116
|
-
|
122
|
+
int start = FIX2INT(start_pos);
|
123
|
+
int end = FIX2INT(end_pos);
|
117
124
|
|
118
125
|
loc->buffer = buffer;
|
119
126
|
loc->rg.start = start;
|
@@ -143,38 +150,12 @@ static VALUE location_buffer(VALUE self) {
|
|
143
150
|
|
144
151
|
static VALUE location_start_pos(VALUE self) {
|
145
152
|
rbs_loc *loc = rbs_check_location(self);
|
146
|
-
return INT2FIX(loc->rg.start
|
153
|
+
return INT2FIX(loc->rg.start);
|
147
154
|
}
|
148
155
|
|
149
156
|
static VALUE location_end_pos(VALUE self) {
|
150
157
|
rbs_loc *loc = rbs_check_location(self);
|
151
|
-
return INT2FIX(loc->rg.end
|
152
|
-
}
|
153
|
-
|
154
|
-
static VALUE location_start_loc(VALUE self) {
|
155
|
-
rbs_loc *loc = rbs_check_location(self);
|
156
|
-
|
157
|
-
if (loc->rg.start.line >= 0) {
|
158
|
-
VALUE pair = rb_ary_new_capa(2);
|
159
|
-
rb_ary_push(pair, INT2FIX(loc->rg.start.line));
|
160
|
-
rb_ary_push(pair, INT2FIX(loc->rg.start.column));
|
161
|
-
return pair;
|
162
|
-
} else {
|
163
|
-
return Qnil;
|
164
|
-
}
|
165
|
-
}
|
166
|
-
|
167
|
-
static VALUE location_end_loc(VALUE self) {
|
168
|
-
rbs_loc *loc = rbs_check_location(self);
|
169
|
-
|
170
|
-
if (loc->rg.end.line >= 0) {
|
171
|
-
VALUE pair = rb_ary_new_capa(2);
|
172
|
-
rb_ary_push(pair, INT2FIX(loc->rg.end.line));
|
173
|
-
rb_ary_push(pair, INT2FIX(loc->rg.end.column));
|
174
|
-
return pair;
|
175
|
-
} else {
|
176
|
-
return Qnil;
|
177
|
-
}
|
158
|
+
return INT2FIX(loc->rg.end);
|
178
159
|
}
|
179
160
|
|
180
161
|
static VALUE location_add_required_child(VALUE self, VALUE name, VALUE start, VALUE end) {
|
@@ -213,6 +194,15 @@ VALUE rbs_new_location(VALUE buffer, range rg) {
|
|
213
194
|
rbs_loc *loc;
|
214
195
|
VALUE obj = TypedData_Make_Struct(RBS_Location, rbs_loc, &location_type, loc);
|
215
196
|
|
197
|
+
rbs_loc_init(loc, buffer, rbs_new_loc_range(rg));
|
198
|
+
|
199
|
+
return obj;
|
200
|
+
}
|
201
|
+
|
202
|
+
static VALUE rbs_new_location_from_loc_range(VALUE buffer, rbs_loc_range rg) {
|
203
|
+
rbs_loc *loc;
|
204
|
+
VALUE obj = TypedData_Make_Struct(RBS_Location, rbs_loc, &location_type, loc);
|
205
|
+
|
216
206
|
rbs_loc_init(loc, buffer, rg);
|
217
207
|
|
218
208
|
return obj;
|
@@ -226,12 +216,12 @@ static VALUE location_aref(VALUE self, VALUE name) {
|
|
226
216
|
if (loc->children != NULL) {
|
227
217
|
for (unsigned short i = 0; i < loc->children->len; i++) {
|
228
218
|
if (loc->children->entries[i].name == id) {
|
229
|
-
|
219
|
+
rbs_loc_range result = loc->children->entries[i].rg;
|
230
220
|
|
231
|
-
if (RBS_LOC_OPTIONAL_P(loc, i) &&
|
221
|
+
if (RBS_LOC_OPTIONAL_P(loc, i) && NULL_LOC_RANGE_P(result)) {
|
232
222
|
return Qnil;
|
233
223
|
} else {
|
234
|
-
return
|
224
|
+
return rbs_new_location_from_loc_range(loc->buffer, result);
|
235
225
|
}
|
236
226
|
}
|
237
227
|
}
|
@@ -294,8 +284,6 @@ void rbs__init_location(void) {
|
|
294
284
|
rb_define_method(RBS_Location, "buffer", location_buffer, 0);
|
295
285
|
rb_define_method(RBS_Location, "start_pos", location_start_pos, 0);
|
296
286
|
rb_define_method(RBS_Location, "end_pos", location_end_pos, 0);
|
297
|
-
rb_define_private_method(RBS_Location, "_start_loc", location_start_loc, 0);
|
298
|
-
rb_define_private_method(RBS_Location, "_end_loc", location_end_loc, 0);
|
299
287
|
rb_define_method(RBS_Location, "_add_required_child", location_add_required_child, 3);
|
300
288
|
rb_define_method(RBS_Location, "_add_optional_child", location_add_optional_child, 3);
|
301
289
|
rb_define_method(RBS_Location, "_add_optional_no_child", location_add_optional_no_child, 1);
|
@@ -9,9 +9,14 @@
|
|
9
9
|
* */
|
10
10
|
extern VALUE RBS_Location;
|
11
11
|
|
12
|
+
typedef struct {
|
13
|
+
int start;
|
14
|
+
int end;
|
15
|
+
} rbs_loc_range;
|
16
|
+
|
12
17
|
typedef struct {
|
13
18
|
ID name;
|
14
|
-
|
19
|
+
rbs_loc_range rg;
|
15
20
|
} rbs_loc_entry;
|
16
21
|
|
17
22
|
typedef unsigned int rbs_loc_entry_bitmap;
|
@@ -27,7 +32,7 @@ typedef struct {
|
|
27
32
|
|
28
33
|
typedef struct {
|
29
34
|
VALUE buffer;
|
30
|
-
|
35
|
+
rbs_loc_range rg;
|
31
36
|
rbs_loc_children *children; // NULL when no children is allocated
|
32
37
|
} rbs_loc;
|
33
38
|
|