rbs 4.0.0.dev.4 → 4.0.0.dev.5
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/dependabot.yml +14 -14
- data/.github/workflows/bundle-update.yml +60 -0
- data/.github/workflows/c-check.yml +11 -8
- data/.github/workflows/comments.yml +3 -3
- data/.github/workflows/dependabot.yml +1 -1
- data/.github/workflows/ruby.yml +17 -34
- data/.github/workflows/typecheck.yml +2 -2
- data/.github/workflows/valgrind.yml +42 -0
- data/.github/workflows/windows.yml +2 -2
- data/.rubocop.yml +1 -1
- data/README.md +1 -1
- data/Rakefile +32 -5
- data/config.yml +46 -0
- data/core/array.rbs +96 -46
- data/core/binding.rbs +0 -2
- data/core/builtin.rbs +2 -2
- data/core/comparable.rbs +13 -6
- data/core/complex.rbs +55 -41
- data/core/dir.rbs +4 -4
- data/core/encoding.rbs +7 -10
- data/core/enumerable.rbs +90 -3
- data/core/enumerator/arithmetic_sequence.rbs +70 -0
- data/core/enumerator.rbs +63 -1
- data/core/errno.rbs +8 -0
- data/core/errors.rbs +28 -1
- data/core/exception.rbs +2 -2
- data/core/fiber.rbs +40 -20
- data/core/file.rbs +108 -78
- data/core/file_test.rbs +1 -1
- data/core/float.rbs +225 -69
- data/core/gc.rbs +417 -281
- data/core/hash.rbs +1023 -727
- data/core/integer.rbs +104 -110
- data/core/io/buffer.rbs +21 -10
- data/core/io/wait.rbs +11 -33
- data/core/io.rbs +82 -19
- data/core/kernel.rbs +70 -59
- data/core/marshal.rbs +1 -1
- data/core/match_data.rbs +1 -1
- data/core/math.rbs +42 -3
- data/core/method.rbs +63 -27
- data/core/module.rbs +103 -26
- data/core/nil_class.rbs +3 -3
- data/core/numeric.rbs +43 -35
- data/core/object.rbs +3 -3
- data/core/object_space.rbs +21 -15
- data/core/pathname.rbs +1272 -0
- data/core/proc.rbs +30 -25
- data/core/process.rbs +4 -2
- data/core/ractor.rbs +361 -509
- data/core/random.rbs +17 -0
- data/core/range.rbs +113 -16
- data/core/rational.rbs +56 -85
- data/core/rbs/unnamed/argf.rbs +2 -2
- data/core/rbs/unnamed/env_class.rbs +1 -1
- data/core/rbs/unnamed/random.rbs +4 -113
- data/core/regexp.rbs +25 -20
- data/core/ruby.rbs +53 -0
- data/core/ruby_vm.rbs +6 -4
- data/core/rubygems/errors.rbs +3 -70
- data/core/rubygems/rubygems.rbs +11 -79
- data/core/rubygems/version.rbs +2 -3
- data/core/set.rbs +488 -359
- data/core/signal.rbs +24 -14
- data/core/string.rbs +3171 -1241
- data/core/struct.rbs +1 -1
- data/core/symbol.rbs +17 -11
- data/core/thread.rbs +95 -33
- data/core/time.rbs +35 -9
- data/core/trace_point.rbs +7 -4
- data/core/unbound_method.rbs +14 -6
- data/docs/aliases.md +79 -0
- data/docs/collection.md +2 -2
- data/docs/encoding.md +56 -0
- data/docs/gem.md +0 -1
- data/docs/inline.md +470 -0
- data/docs/sigs.md +3 -3
- data/docs/syntax.md +33 -4
- data/docs/type_fingerprint.md +21 -0
- data/exe/rbs +1 -1
- data/ext/rbs_extension/ast_translation.c +77 -3
- data/ext/rbs_extension/ast_translation.h +3 -0
- data/ext/rbs_extension/class_constants.c +8 -2
- data/ext/rbs_extension/class_constants.h +4 -0
- data/ext/rbs_extension/extconf.rb +5 -1
- data/ext/rbs_extension/legacy_location.c +5 -5
- data/ext/rbs_extension/main.c +37 -20
- data/include/rbs/ast.h +85 -38
- data/include/rbs/defines.h +27 -0
- data/include/rbs/lexer.h +30 -11
- data/include/rbs/parser.h +6 -6
- data/include/rbs/string.h +0 -2
- data/include/rbs/util/rbs_allocator.h +34 -13
- data/include/rbs/util/rbs_assert.h +12 -1
- data/include/rbs/util/rbs_encoding.h +2 -0
- data/include/rbs/util/rbs_unescape.h +2 -1
- data/lib/rbs/ast/annotation.rb +1 -1
- data/lib/rbs/ast/comment.rb +1 -1
- data/lib/rbs/ast/declarations.rb +10 -10
- data/lib/rbs/ast/members.rb +14 -14
- data/lib/rbs/ast/ruby/annotations.rb +137 -0
- data/lib/rbs/ast/ruby/comment_block.rb +24 -0
- data/lib/rbs/ast/ruby/declarations.rb +198 -3
- data/lib/rbs/ast/ruby/helpers/constant_helper.rb +4 -0
- data/lib/rbs/ast/ruby/members.rb +159 -1
- data/lib/rbs/ast/type_param.rb +24 -4
- data/lib/rbs/buffer.rb +20 -15
- data/lib/rbs/cli/diff.rb +16 -15
- data/lib/rbs/cli/validate.rb +38 -51
- data/lib/rbs/cli.rb +52 -19
- data/lib/rbs/collection/config/lockfile_generator.rb +8 -0
- data/lib/rbs/collection/sources/git.rb +1 -0
- data/lib/rbs/definition.rb +1 -1
- data/lib/rbs/definition_builder/ancestor_builder.rb +62 -9
- data/lib/rbs/definition_builder/method_builder.rb +20 -0
- data/lib/rbs/definition_builder.rb +91 -2
- data/lib/rbs/diff.rb +7 -1
- data/lib/rbs/environment.rb +227 -74
- data/lib/rbs/environment_loader.rb +0 -6
- data/lib/rbs/errors.rb +27 -7
- data/lib/rbs/inline_parser.rb +341 -5
- data/lib/rbs/location_aux.rb +1 -1
- data/lib/rbs/locator.rb +5 -1
- data/lib/rbs/method_type.rb +5 -3
- data/lib/rbs/parser_aux.rb +2 -2
- data/lib/rbs/prototype/rb.rb +2 -2
- data/lib/rbs/prototype/rbi.rb +2 -0
- data/lib/rbs/prototype/runtime.rb +8 -0
- data/lib/rbs/resolver/constant_resolver.rb +2 -2
- data/lib/rbs/resolver/type_name_resolver.rb +116 -38
- data/lib/rbs/subtractor.rb +3 -1
- data/lib/rbs/test/type_check.rb +16 -2
- data/lib/rbs/type_name.rb +1 -1
- data/lib/rbs/types.rb +27 -27
- data/lib/rbs/validator.rb +2 -2
- data/lib/rbs/version.rb +1 -1
- data/lib/rbs.rb +1 -1
- data/lib/rdoc/discover.rb +1 -1
- data/lib/rdoc_plugin/parser.rb +1 -1
- data/rbs.gemspec +3 -2
- data/schema/typeParam.json +17 -1
- data/sig/ast/ruby/annotations.rbs +124 -0
- data/sig/ast/ruby/comment_block.rbs +8 -0
- data/sig/ast/ruby/declarations.rbs +102 -4
- data/sig/ast/ruby/members.rbs +87 -1
- data/sig/cli/diff.rbs +5 -11
- data/sig/cli/validate.rbs +13 -4
- data/sig/cli.rbs +18 -18
- data/sig/definition.rbs +6 -1
- data/sig/environment.rbs +70 -12
- data/sig/errors.rbs +13 -6
- data/sig/inline_parser.rbs +39 -2
- data/sig/locator.rbs +0 -2
- data/sig/manifest.yaml +0 -1
- data/sig/method_builder.rbs +3 -1
- data/sig/method_types.rbs +1 -1
- data/sig/parser.rbs +16 -2
- data/sig/resolver/type_name_resolver.rbs +35 -7
- data/sig/source.rbs +3 -3
- data/sig/type_param.rbs +13 -8
- data/sig/types.rbs +4 -4
- data/src/ast.c +80 -1
- data/src/lexer.c +1392 -1313
- data/src/lexer.re +3 -0
- data/src/lexstate.c +58 -37
- data/src/location.c +4 -4
- data/src/parser.c +412 -145
- data/src/string.c +0 -48
- data/src/util/rbs_allocator.c +89 -71
- data/src/util/rbs_assert.c +1 -1
- data/src/util/rbs_buffer.c +2 -2
- data/src/util/rbs_constant_pool.c +10 -10
- data/src/util/rbs_encoding.c +4 -8
- data/src/util/rbs_unescape.c +56 -20
- data/stdlib/bigdecimal/0/big_decimal.rbs +100 -82
- data/stdlib/bigdecimal-math/0/big_math.rbs +169 -8
- data/stdlib/cgi/0/core.rbs +9 -393
- data/stdlib/cgi/0/manifest.yaml +1 -0
- data/stdlib/cgi-escape/0/escape.rbs +171 -0
- data/stdlib/coverage/0/coverage.rbs +3 -1
- data/stdlib/date/0/date.rbs +67 -59
- data/stdlib/date/0/date_time.rbs +1 -1
- data/stdlib/delegate/0/delegator.rbs +10 -7
- data/stdlib/digest/0/digest.rbs +110 -0
- data/stdlib/erb/0/erb.rbs +737 -347
- data/stdlib/fileutils/0/fileutils.rbs +20 -14
- data/stdlib/forwardable/0/forwardable.rbs +3 -0
- data/stdlib/json/0/json.rbs +82 -28
- data/stdlib/net-http/0/net-http.rbs +3 -0
- data/stdlib/objspace/0/objspace.rbs +9 -27
- data/stdlib/open-uri/0/open-uri.rbs +40 -0
- data/stdlib/open3/0/open3.rbs +459 -1
- data/stdlib/openssl/0/openssl.rbs +331 -228
- data/stdlib/optparse/0/optparse.rbs +8 -3
- data/stdlib/pathname/0/pathname.rbs +9 -1379
- data/stdlib/psych/0/psych.rbs +4 -4
- data/stdlib/random-formatter/0/random-formatter.rbs +277 -0
- data/stdlib/rdoc/0/code_object.rbs +2 -1
- data/stdlib/rdoc/0/parser.rbs +1 -1
- data/stdlib/rdoc/0/rdoc.rbs +1 -1
- data/stdlib/rdoc/0/store.rbs +1 -1
- data/stdlib/resolv/0/resolv.rbs +25 -68
- data/stdlib/ripper/0/ripper.rbs +2 -2
- data/stdlib/securerandom/0/manifest.yaml +2 -0
- data/stdlib/securerandom/0/securerandom.rbs +6 -19
- data/stdlib/singleton/0/singleton.rbs +3 -0
- data/stdlib/socket/0/socket.rbs +13 -1
- data/stdlib/socket/0/tcp_socket.rbs +10 -2
- data/stdlib/stringio/0/stringio.rbs +1176 -85
- 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 +63 -7
- data/stdlib/tsort/0/cyclic.rbs +3 -0
- data/stdlib/uri/0/common.rbs +16 -2
- data/stdlib/uri/0/file.rbs +1 -1
- data/stdlib/uri/0/generic.rbs +24 -16
- data/stdlib/uri/0/rfc2396_parser.rbs +6 -7
- data/stdlib/zlib/0/gzip_reader.rbs +2 -2
- data/stdlib/zlib/0/gzip_writer.rbs +1 -1
- data/stdlib/zlib/0/zstream.rbs +1 -0
- metadata +30 -4
data/include/rbs/lexer.h
CHANGED
|
@@ -30,6 +30,7 @@ enum RBSTokenType {
|
|
|
30
30
|
pBANG, /* ! */
|
|
31
31
|
pQUESTION, /* ? */
|
|
32
32
|
pLT, /* < */
|
|
33
|
+
pGT, /* > */
|
|
33
34
|
pEQ, /* = */
|
|
34
35
|
|
|
35
36
|
kALIAS, /* alias */
|
|
@@ -39,6 +40,7 @@ enum RBSTokenType {
|
|
|
39
40
|
kBOOL, /* bool */
|
|
40
41
|
kBOT, /* bot */
|
|
41
42
|
kCLASS, /* class */
|
|
43
|
+
kCLASSALIAS, /* class-alias */
|
|
42
44
|
kDEF, /* def */
|
|
43
45
|
kEND, /* end */
|
|
44
46
|
kEXTEND, /* extend */
|
|
@@ -48,6 +50,7 @@ enum RBSTokenType {
|
|
|
48
50
|
kINSTANCE, /* instance */
|
|
49
51
|
kINTERFACE, /* interface */
|
|
50
52
|
kMODULE, /* module */
|
|
53
|
+
kMODULEALIAS, /* module-alias */
|
|
51
54
|
kNIL, /* nil */
|
|
52
55
|
kOUT, /* out */
|
|
53
56
|
kPREPEND, /* prepend */
|
|
@@ -123,20 +126,26 @@ typedef struct {
|
|
|
123
126
|
* The lexer state is the curren token.
|
|
124
127
|
*
|
|
125
128
|
* ```
|
|
126
|
-
|
|
127
|
-
*
|
|
128
|
-
*
|
|
129
|
-
*
|
|
129
|
+
#. 0.1.2.3.4.5.6.7.8.9.0.1.2.3.4.5.6
|
|
130
|
+
* ... " a s t r i n g t o k e n "
|
|
131
|
+
* ^ start position (0)
|
|
132
|
+
* ^ current position (6)
|
|
133
|
+
* ^ current character ('i', bytes = 1)
|
|
134
|
+
* ~~~~~~~~~~~ Token => "a str
|
|
130
135
|
* ```
|
|
131
136
|
* */
|
|
132
137
|
typedef struct {
|
|
133
138
|
rbs_string_t string;
|
|
134
|
-
int start_pos;
|
|
135
|
-
int end_pos;
|
|
136
|
-
rbs_position_t current;
|
|
137
|
-
rbs_position_t start;
|
|
139
|
+
int start_pos; /* The character position that defines the start of the input */
|
|
140
|
+
int end_pos; /* The character position that defines the end of the input */
|
|
141
|
+
rbs_position_t current; /* The current position: just before the current_character */
|
|
142
|
+
rbs_position_t start; /* The start position of the current token */
|
|
143
|
+
|
|
144
|
+
unsigned int current_code_point; /* Current character code point */
|
|
145
|
+
size_t current_character_bytes; /* Current character byte length (0 or 1~4) */
|
|
146
|
+
|
|
138
147
|
bool first_token_of_line; /* This flag is used for tLINECOMMENT */
|
|
139
|
-
|
|
148
|
+
|
|
140
149
|
const rbs_encoding_t *encoding;
|
|
141
150
|
} rbs_lexer_t;
|
|
142
151
|
|
|
@@ -156,15 +165,23 @@ int rbs_token_bytes(rbs_token_t tok);
|
|
|
156
165
|
const char *rbs_token_type_str(enum RBSTokenType type);
|
|
157
166
|
|
|
158
167
|
/**
|
|
159
|
-
*
|
|
168
|
+
* Returns the next character.
|
|
160
169
|
* */
|
|
161
170
|
unsigned int rbs_peek(rbs_lexer_t *lexer);
|
|
162
171
|
|
|
163
172
|
/**
|
|
164
|
-
*
|
|
173
|
+
* Advances the current position by one character.
|
|
165
174
|
* */
|
|
166
175
|
void rbs_skip(rbs_lexer_t *lexer);
|
|
167
176
|
|
|
177
|
+
/**
|
|
178
|
+
* Read next character and store the codepoint and byte length to the given pointers.
|
|
179
|
+
*
|
|
180
|
+
* This doesn't update the lexer state.
|
|
181
|
+
* Returns `true` if succeeded, or `false` if reached to EOF.
|
|
182
|
+
* */
|
|
183
|
+
bool rbs_next_char(rbs_lexer_t *lexer, unsigned int *codepoint, size_t *bytes);
|
|
184
|
+
|
|
168
185
|
/**
|
|
169
186
|
* Skip n characters.
|
|
170
187
|
* */
|
|
@@ -184,4 +201,6 @@ rbs_token_t rbs_lexer_next_token(rbs_lexer_t *lexer);
|
|
|
184
201
|
|
|
185
202
|
void rbs_print_token(rbs_token_t tok);
|
|
186
203
|
|
|
204
|
+
void rbs_print_lexer(rbs_lexer_t *lexer);
|
|
205
|
+
|
|
187
206
|
#endif
|
data/include/rbs/parser.h
CHANGED
|
@@ -27,9 +27,9 @@ typedef struct rbs_comment_t {
|
|
|
27
27
|
rbs_position_t start;
|
|
28
28
|
rbs_position_t end;
|
|
29
29
|
|
|
30
|
-
size_t
|
|
31
|
-
size_t
|
|
32
|
-
rbs_token_t *
|
|
30
|
+
size_t line_tokens_capacity;
|
|
31
|
+
size_t line_tokens_count;
|
|
32
|
+
rbs_token_t *line_tokens;
|
|
33
33
|
|
|
34
34
|
struct rbs_comment_t *next_comment;
|
|
35
35
|
} rbs_comment_t;
|
|
@@ -44,7 +44,7 @@ typedef struct rbs_error_t {
|
|
|
44
44
|
* An RBS parser is a LL(3) parser.
|
|
45
45
|
* */
|
|
46
46
|
typedef struct {
|
|
47
|
-
rbs_lexer_t *
|
|
47
|
+
rbs_lexer_t *lexer;
|
|
48
48
|
|
|
49
49
|
rbs_token_t current_token;
|
|
50
50
|
rbs_token_t next_token; /* The first lookahead token */
|
|
@@ -126,8 +126,8 @@ rbs_ast_comment_t *rbs_parser_get_comment(rbs_parser_t *parser, int subject_line
|
|
|
126
126
|
|
|
127
127
|
void rbs_parser_set_error(rbs_parser_t *parser, rbs_token_t tok, bool syntax_error, const char *fmt, ...) RBS_ATTRIBUTE_FORMAT(4, 5);
|
|
128
128
|
|
|
129
|
-
bool rbs_parse_type(rbs_parser_t *parser, rbs_node_t **type);
|
|
130
|
-
bool rbs_parse_method_type(rbs_parser_t *parser, rbs_method_type_t **method_type);
|
|
129
|
+
bool rbs_parse_type(rbs_parser_t *parser, rbs_node_t **type, bool void_allowed, bool self_allowed);
|
|
130
|
+
bool rbs_parse_method_type(rbs_parser_t *parser, rbs_method_type_t **method_type, bool require_eof);
|
|
131
131
|
bool rbs_parse_signature(rbs_parser_t *parser, rbs_signature_t **signature);
|
|
132
132
|
|
|
133
133
|
bool rbs_parse_type_params(rbs_parser_t *parser, bool module_type_params, rbs_node_list_t **params);
|
data/include/rbs/string.h
CHANGED
|
@@ -3,19 +3,40 @@
|
|
|
3
3
|
|
|
4
4
|
#include <stddef.h>
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
#if defined(
|
|
8
|
-
#
|
|
6
|
+
/* Include stdalign.h for C11 and later for alignof support */
|
|
7
|
+
#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
|
|
8
|
+
#include <stdalign.h>
|
|
9
|
+
#endif
|
|
10
|
+
|
|
11
|
+
/*
|
|
12
|
+
* Define a portable alignment macro that works across all supported environments
|
|
13
|
+
*/
|
|
14
|
+
#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
|
|
15
|
+
/* C11 or later - use _Alignof directly (always available in C11+) */
|
|
16
|
+
#define rbs_alignof(type) _Alignof(type)
|
|
17
|
+
#elif defined(__cplusplus) && __cplusplus >= 201103L
|
|
18
|
+
/* C++11 or later has alignof keyword */
|
|
19
|
+
#define rbs_alignof(type) alignof(type)
|
|
20
|
+
#elif defined(__GNUC__) || defined(__clang__)
|
|
21
|
+
/* GCC and Clang provide __alignof__ */
|
|
22
|
+
#define rbs_alignof(type) __alignof__(type)
|
|
9
23
|
#elif defined(_MSC_VER)
|
|
10
|
-
|
|
24
|
+
/* MSVC provides __alignof */
|
|
25
|
+
#define rbs_alignof(type) __alignof(type)
|
|
11
26
|
#else
|
|
12
|
-
|
|
13
|
-
#define
|
|
14
|
-
|
|
27
|
+
/* Fallback using offset trick for other compilers */
|
|
28
|
+
#define rbs_alignof(type) offsetof( \
|
|
29
|
+
struct { char c; type member; }, \
|
|
30
|
+
member \
|
|
31
|
+
)
|
|
15
32
|
#endif
|
|
16
33
|
|
|
17
|
-
struct rbs_allocator
|
|
18
|
-
|
|
34
|
+
typedef struct rbs_allocator {
|
|
35
|
+
// The head of a linked list of pages, starting with the most recently allocated page.
|
|
36
|
+
struct rbs_allocator_page *page;
|
|
37
|
+
|
|
38
|
+
size_t default_page_payload_size;
|
|
39
|
+
} rbs_allocator_t;
|
|
19
40
|
|
|
20
41
|
rbs_allocator_t *rbs_allocator_init(void);
|
|
21
42
|
void rbs_allocator_free(rbs_allocator_t *);
|
|
@@ -26,13 +47,13 @@ void *rbs_allocator_calloc_impl(rbs_allocator_t *, size_t count, size_t size, si
|
|
|
26
47
|
void *rbs_allocator_realloc_impl(rbs_allocator_t *, void *ptr, size_t old_size, size_t new_size, size_t alignment);
|
|
27
48
|
|
|
28
49
|
// Use this when allocating memory for a single instance of a type.
|
|
29
|
-
#define rbs_allocator_alloc(allocator, type) ((type *) rbs_allocator_malloc_impl((allocator), sizeof(type),
|
|
50
|
+
#define rbs_allocator_alloc(allocator, type) ((type *) rbs_allocator_malloc_impl((allocator), sizeof(type), rbs_alignof(type)))
|
|
30
51
|
// Use this when allocating memory that will be immediately written to in full.
|
|
31
52
|
// Such as allocating strings
|
|
32
|
-
#define rbs_allocator_alloc_many(allocator, count, type) ((type *) rbs_allocator_malloc_many_impl((allocator), (count), sizeof(type),
|
|
53
|
+
#define rbs_allocator_alloc_many(allocator, count, type) ((type *) rbs_allocator_malloc_many_impl((allocator), (count), sizeof(type), rbs_alignof(type)))
|
|
33
54
|
// Use this when allocating memory that will NOT be immediately written to in full.
|
|
34
55
|
// Such as allocating buffers
|
|
35
|
-
#define rbs_allocator_calloc(allocator, count, type) ((type *) rbs_allocator_calloc_impl((allocator), (count), sizeof(type),
|
|
36
|
-
#define rbs_allocator_realloc(allocator, ptr, old_size, new_size, type) ((type *) rbs_allocator_realloc_impl((allocator), (ptr), (old_size), (new_size),
|
|
56
|
+
#define rbs_allocator_calloc(allocator, count, type) ((type *) rbs_allocator_calloc_impl((allocator), (count), sizeof(type), rbs_alignof(type)))
|
|
57
|
+
#define rbs_allocator_realloc(allocator, ptr, old_size, new_size, type) ((type *) rbs_allocator_realloc_impl((allocator), (ptr), (old_size), (new_size), rbs_alignof(type)))
|
|
37
58
|
|
|
38
59
|
#endif
|
|
@@ -4,6 +4,17 @@
|
|
|
4
4
|
#include "rbs/defines.h"
|
|
5
5
|
#include <stdbool.h>
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
/**
|
|
8
|
+
* RBS_ASSERT macro that calls rbs_assert in debug builds and is removed in release builds.
|
|
9
|
+
* In debug mode, it forwards all arguments to the rbs_assert function.
|
|
10
|
+
* In release mode, it expands to nothing.
|
|
11
|
+
*/
|
|
12
|
+
#ifdef NDEBUG
|
|
13
|
+
#define RBS_ASSERT(condition, ...) ((void) 0)
|
|
14
|
+
#else
|
|
15
|
+
#define RBS_ASSERT(condition, ...) rbs_assert_impl(condition, __VA_ARGS__)
|
|
16
|
+
#endif
|
|
17
|
+
|
|
18
|
+
void rbs_assert_impl(bool condition, const char *fmt, ...) RBS_ATTRIBUTE_FORMAT(2, 3);
|
|
8
19
|
|
|
9
20
|
#endif
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
#include <stddef.h>
|
|
5
5
|
#include "rbs/util/rbs_allocator.h"
|
|
6
6
|
#include "rbs/string.h"
|
|
7
|
+
#include "rbs/util/rbs_encoding.h"
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* Receives `rbs_parser_t` and `range`, which represents a string token or symbol token, and returns a string VALUE.
|
|
@@ -18,6 +19,6 @@
|
|
|
18
19
|
*
|
|
19
20
|
* @returns A new owned string that will be freed when the allocator is freed.
|
|
20
21
|
* */
|
|
21
|
-
rbs_string_t rbs_unquote_string(rbs_allocator_t *, const rbs_string_t input);
|
|
22
|
+
rbs_string_t rbs_unquote_string(rbs_allocator_t *, const rbs_string_t input, const rbs_encoding_t *encoding);
|
|
22
23
|
|
|
23
24
|
#endif // RBS_RBS_UNESCAPE_H
|
data/lib/rbs/ast/annotation.rb
CHANGED
data/lib/rbs/ast/comment.rb
CHANGED
data/lib/rbs/ast/declarations.rb
CHANGED
|
@@ -74,7 +74,7 @@ module RBS
|
|
|
74
74
|
self.class.hash ^ name.hash ^ args.hash
|
|
75
75
|
end
|
|
76
76
|
|
|
77
|
-
def to_json(state =
|
|
77
|
+
def to_json(state = nil)
|
|
78
78
|
{
|
|
79
79
|
name: name,
|
|
80
80
|
args: args,
|
|
@@ -130,7 +130,7 @@ module RBS
|
|
|
130
130
|
self.class.hash ^ name.hash ^ type_params.hash ^ super_class.hash ^ members.hash
|
|
131
131
|
end
|
|
132
132
|
|
|
133
|
-
def to_json(state =
|
|
133
|
+
def to_json(state = nil)
|
|
134
134
|
{
|
|
135
135
|
declaration: :class,
|
|
136
136
|
name: name,
|
|
@@ -166,7 +166,7 @@ module RBS
|
|
|
166
166
|
self.class.hash ^ name.hash ^ args.hash ^ location.hash
|
|
167
167
|
end
|
|
168
168
|
|
|
169
|
-
def to_json(state =
|
|
169
|
+
def to_json(state = nil)
|
|
170
170
|
{
|
|
171
171
|
name: name,
|
|
172
172
|
args: args,
|
|
@@ -231,7 +231,7 @@ module RBS
|
|
|
231
231
|
self.class.hash ^ name.hash ^ type_params.hash ^ self_types.hash ^ members.hash
|
|
232
232
|
end
|
|
233
233
|
|
|
234
|
-
def to_json(state =
|
|
234
|
+
def to_json(state = nil)
|
|
235
235
|
{
|
|
236
236
|
declaration: :module,
|
|
237
237
|
name: name,
|
|
@@ -288,7 +288,7 @@ module RBS
|
|
|
288
288
|
self.class.hash ^ type_params.hash ^ members.hash
|
|
289
289
|
end
|
|
290
290
|
|
|
291
|
-
def to_json(state =
|
|
291
|
+
def to_json(state = nil)
|
|
292
292
|
{
|
|
293
293
|
declaration: :interface,
|
|
294
294
|
name: name,
|
|
@@ -331,7 +331,7 @@ module RBS
|
|
|
331
331
|
self.class.hash ^ name.hash ^ type_params.hash ^ type.hash
|
|
332
332
|
end
|
|
333
333
|
|
|
334
|
-
def to_json(state =
|
|
334
|
+
def to_json(state = nil)
|
|
335
335
|
{
|
|
336
336
|
declaration: :alias,
|
|
337
337
|
name: name,
|
|
@@ -371,7 +371,7 @@ module RBS
|
|
|
371
371
|
self.class.hash ^ name.hash ^ type.hash
|
|
372
372
|
end
|
|
373
373
|
|
|
374
|
-
def to_json(state =
|
|
374
|
+
def to_json(state = nil)
|
|
375
375
|
{
|
|
376
376
|
declaration: :constant,
|
|
377
377
|
name: name,
|
|
@@ -409,7 +409,7 @@ module RBS
|
|
|
409
409
|
self.class.hash ^ name.hash ^ type.hash
|
|
410
410
|
end
|
|
411
411
|
|
|
412
|
-
def to_json(state =
|
|
412
|
+
def to_json(state = nil)
|
|
413
413
|
{
|
|
414
414
|
declaration: :global,
|
|
415
415
|
name: name,
|
|
@@ -445,7 +445,7 @@ module RBS
|
|
|
445
445
|
end
|
|
446
446
|
|
|
447
447
|
class ClassAlias < AliasDecl
|
|
448
|
-
def to_json(state =
|
|
448
|
+
def to_json(state = nil)
|
|
449
449
|
{
|
|
450
450
|
declaration: :class_alias,
|
|
451
451
|
new_name: new_name,
|
|
@@ -457,7 +457,7 @@ module RBS
|
|
|
457
457
|
end
|
|
458
458
|
|
|
459
459
|
class ModuleAlias < AliasDecl
|
|
460
|
-
def to_json(state =
|
|
460
|
+
def to_json(state = nil)
|
|
461
461
|
{
|
|
462
462
|
declaration: :module_alias,
|
|
463
463
|
new_name: new_name,
|
data/lib/rbs/ast/members.rb
CHANGED
|
@@ -35,7 +35,7 @@ module RBS
|
|
|
35
35
|
update(method_type: self.method_type.sub(subst))
|
|
36
36
|
end
|
|
37
37
|
|
|
38
|
-
def to_json(state =
|
|
38
|
+
def to_json(state = nil)
|
|
39
39
|
{
|
|
40
40
|
annotations: annotations,
|
|
41
41
|
method_type: method_type
|
|
@@ -103,7 +103,7 @@ module RBS
|
|
|
103
103
|
)
|
|
104
104
|
end
|
|
105
105
|
|
|
106
|
-
def to_json(state =
|
|
106
|
+
def to_json(state = nil)
|
|
107
107
|
{
|
|
108
108
|
member: :method_definition,
|
|
109
109
|
name: name,
|
|
@@ -145,7 +145,7 @@ module RBS
|
|
|
145
145
|
class InstanceVariable < Base
|
|
146
146
|
include Var
|
|
147
147
|
|
|
148
|
-
def to_json(state =
|
|
148
|
+
def to_json(state = nil)
|
|
149
149
|
{
|
|
150
150
|
member: :instance_variable,
|
|
151
151
|
name: name,
|
|
@@ -159,7 +159,7 @@ module RBS
|
|
|
159
159
|
class ClassInstanceVariable < Base
|
|
160
160
|
include Var
|
|
161
161
|
|
|
162
|
-
def to_json(state =
|
|
162
|
+
def to_json(state = nil)
|
|
163
163
|
{
|
|
164
164
|
member: :class_instance_variable,
|
|
165
165
|
name: name,
|
|
@@ -173,7 +173,7 @@ module RBS
|
|
|
173
173
|
class ClassVariable < Base
|
|
174
174
|
include Var
|
|
175
175
|
|
|
176
|
-
def to_json(state =
|
|
176
|
+
def to_json(state = nil)
|
|
177
177
|
{
|
|
178
178
|
member: :class_variable,
|
|
179
179
|
name: name,
|
|
@@ -215,7 +215,7 @@ module RBS
|
|
|
215
215
|
class Include < Base
|
|
216
216
|
include Mixin
|
|
217
217
|
|
|
218
|
-
def to_json(state =
|
|
218
|
+
def to_json(state = nil)
|
|
219
219
|
{
|
|
220
220
|
member: :include,
|
|
221
221
|
name: name,
|
|
@@ -230,7 +230,7 @@ module RBS
|
|
|
230
230
|
class Extend < Base
|
|
231
231
|
include Mixin
|
|
232
232
|
|
|
233
|
-
def to_json(state =
|
|
233
|
+
def to_json(state = nil)
|
|
234
234
|
{
|
|
235
235
|
member: :extend,
|
|
236
236
|
name: name,
|
|
@@ -245,7 +245,7 @@ module RBS
|
|
|
245
245
|
class Prepend < Base
|
|
246
246
|
include Mixin
|
|
247
247
|
|
|
248
|
-
def to_json(state =
|
|
248
|
+
def to_json(state = nil)
|
|
249
249
|
{
|
|
250
250
|
member: :prepend,
|
|
251
251
|
name: name,
|
|
@@ -311,7 +311,7 @@ module RBS
|
|
|
311
311
|
class AttrReader < Base
|
|
312
312
|
include Attribute
|
|
313
313
|
|
|
314
|
-
def to_json(state =
|
|
314
|
+
def to_json(state = nil)
|
|
315
315
|
{
|
|
316
316
|
member: :attr_reader,
|
|
317
317
|
name: name,
|
|
@@ -329,7 +329,7 @@ module RBS
|
|
|
329
329
|
class AttrAccessor < Base
|
|
330
330
|
include Attribute
|
|
331
331
|
|
|
332
|
-
def to_json(state =
|
|
332
|
+
def to_json(state = nil)
|
|
333
333
|
{
|
|
334
334
|
member: :attr_accessor,
|
|
335
335
|
name: name,
|
|
@@ -347,7 +347,7 @@ module RBS
|
|
|
347
347
|
class AttrWriter < Base
|
|
348
348
|
include Attribute
|
|
349
349
|
|
|
350
|
-
def to_json(state =
|
|
350
|
+
def to_json(state = nil)
|
|
351
351
|
{
|
|
352
352
|
member: :attr_writer,
|
|
353
353
|
name: name,
|
|
@@ -383,7 +383,7 @@ module RBS
|
|
|
383
383
|
class Public < Base
|
|
384
384
|
include LocationOnly
|
|
385
385
|
|
|
386
|
-
def to_json(state =
|
|
386
|
+
def to_json(state = nil)
|
|
387
387
|
{ member: :public, location: location }.to_json(state)
|
|
388
388
|
end
|
|
389
389
|
end
|
|
@@ -391,7 +391,7 @@ module RBS
|
|
|
391
391
|
class Private < Base
|
|
392
392
|
include LocationOnly
|
|
393
393
|
|
|
394
|
-
def to_json(state =
|
|
394
|
+
def to_json(state = nil)
|
|
395
395
|
{ member: :private, location: location }.to_json(state)
|
|
396
396
|
end
|
|
397
397
|
end
|
|
@@ -426,7 +426,7 @@ module RBS
|
|
|
426
426
|
new_name.hash ^ old_name.hash ^ kind.hash
|
|
427
427
|
end
|
|
428
428
|
|
|
429
|
-
def to_json(state =
|
|
429
|
+
def to_json(state = nil)
|
|
430
430
|
{
|
|
431
431
|
member: :alias,
|
|
432
432
|
new_name: new_name,
|
|
@@ -31,6 +31,52 @@ module RBS
|
|
|
31
31
|
type: type.map_type_name { yield _1 }
|
|
32
32
|
) #: self
|
|
33
33
|
end
|
|
34
|
+
|
|
35
|
+
def type_fingerprint
|
|
36
|
+
[
|
|
37
|
+
"annots/node_type_assertion",
|
|
38
|
+
type.to_s
|
|
39
|
+
]
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
class AliasAnnotation < Base
|
|
44
|
+
attr_reader :keyword_location, :type_name_location, :type_name
|
|
45
|
+
|
|
46
|
+
def initialize(location:, prefix_location:, keyword_location:, type_name:, type_name_location:)
|
|
47
|
+
super(location, prefix_location)
|
|
48
|
+
@keyword_location = keyword_location
|
|
49
|
+
@type_name = type_name
|
|
50
|
+
@type_name_location = type_name_location
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def map_type_name
|
|
54
|
+
self.class.new(
|
|
55
|
+
location:,
|
|
56
|
+
prefix_location:,
|
|
57
|
+
keyword_location:,
|
|
58
|
+
type_name: type_name ? yield(type_name) : nil,
|
|
59
|
+
type_name_location:
|
|
60
|
+
) #: self
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
class ClassAliasAnnotation < AliasAnnotation
|
|
65
|
+
def type_fingerprint
|
|
66
|
+
[
|
|
67
|
+
"annots/class-alias",
|
|
68
|
+
type_name&.to_s
|
|
69
|
+
]
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
class ModuleAliasAnnotation < AliasAnnotation
|
|
74
|
+
def type_fingerprint
|
|
75
|
+
[
|
|
76
|
+
"annots/module-alias",
|
|
77
|
+
type_name&.to_s
|
|
78
|
+
]
|
|
79
|
+
end
|
|
34
80
|
end
|
|
35
81
|
|
|
36
82
|
class ColonMethodTypeAnnotation < Base
|
|
@@ -50,6 +96,14 @@ module RBS
|
|
|
50
96
|
method_type: method_type.map_type {|type| type.map_type_name { yield _1 }}
|
|
51
97
|
) #: self
|
|
52
98
|
end
|
|
99
|
+
|
|
100
|
+
def type_fingerprint
|
|
101
|
+
[
|
|
102
|
+
"annots/colon_method_type",
|
|
103
|
+
annotations.map(&:to_s),
|
|
104
|
+
method_type.to_s
|
|
105
|
+
]
|
|
106
|
+
end
|
|
53
107
|
end
|
|
54
108
|
|
|
55
109
|
class MethodTypesAnnotation < Base
|
|
@@ -73,6 +127,13 @@ module RBS
|
|
|
73
127
|
|
|
74
128
|
self.class.new(location:, prefix_location:, overloads: ovs, vertical_bar_locations:) #: self
|
|
75
129
|
end
|
|
130
|
+
|
|
131
|
+
def type_fingerprint
|
|
132
|
+
[
|
|
133
|
+
"annots/method_types",
|
|
134
|
+
overloads.map { |o| [o.annotations.map(&:to_s), o.method_type.to_s] }
|
|
135
|
+
]
|
|
136
|
+
end
|
|
76
137
|
end
|
|
77
138
|
|
|
78
139
|
class SkipAnnotation < Base
|
|
@@ -83,6 +144,10 @@ module RBS
|
|
|
83
144
|
@skip_location = skip_location
|
|
84
145
|
@comment_location = comment_location
|
|
85
146
|
end
|
|
147
|
+
|
|
148
|
+
def type_fingerprint
|
|
149
|
+
"annots/skip"
|
|
150
|
+
end
|
|
86
151
|
end
|
|
87
152
|
|
|
88
153
|
class ReturnTypeAnnotation < Base
|
|
@@ -112,6 +177,78 @@ module RBS
|
|
|
112
177
|
comment_location: comment_location
|
|
113
178
|
) #: self
|
|
114
179
|
end
|
|
180
|
+
|
|
181
|
+
def type_fingerprint
|
|
182
|
+
[
|
|
183
|
+
"annots/return_type",
|
|
184
|
+
return_type.to_s,
|
|
185
|
+
comment_location&.source
|
|
186
|
+
]
|
|
187
|
+
end
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
class TypeApplicationAnnotation < Base
|
|
191
|
+
attr_reader :type_args, :close_bracket_location, :comma_locations
|
|
192
|
+
|
|
193
|
+
def initialize(location:, prefix_location:, type_args:, close_bracket_location:, comma_locations:)
|
|
194
|
+
super(location, prefix_location)
|
|
195
|
+
@type_args = type_args
|
|
196
|
+
@close_bracket_location = close_bracket_location
|
|
197
|
+
@comma_locations = comma_locations
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
def map_type_name(&block)
|
|
201
|
+
mapped_type_args = type_args.map { |type| type.map_type_name { yield _1 } }
|
|
202
|
+
|
|
203
|
+
self.class.new(
|
|
204
|
+
location:,
|
|
205
|
+
prefix_location:,
|
|
206
|
+
type_args: mapped_type_args,
|
|
207
|
+
close_bracket_location:,
|
|
208
|
+
comma_locations:
|
|
209
|
+
) #: self
|
|
210
|
+
end
|
|
211
|
+
|
|
212
|
+
def type_fingerprint
|
|
213
|
+
[
|
|
214
|
+
"annots/type_application",
|
|
215
|
+
type_args.map(&:to_s)
|
|
216
|
+
]
|
|
217
|
+
end
|
|
218
|
+
end
|
|
219
|
+
|
|
220
|
+
class InstanceVariableAnnotation < Base
|
|
221
|
+
attr_reader :ivar_name, :ivar_name_location, :colon_location, :type, :comment_location
|
|
222
|
+
|
|
223
|
+
def initialize(location:, prefix_location:, ivar_name:, ivar_name_location:, colon_location:, type:, comment_location:)
|
|
224
|
+
super(location, prefix_location)
|
|
225
|
+
@ivar_name = ivar_name
|
|
226
|
+
@ivar_name_location = ivar_name_location
|
|
227
|
+
@colon_location = colon_location
|
|
228
|
+
@type = type
|
|
229
|
+
@comment_location = comment_location
|
|
230
|
+
end
|
|
231
|
+
|
|
232
|
+
def map_type_name(&block)
|
|
233
|
+
self.class.new(
|
|
234
|
+
location:,
|
|
235
|
+
prefix_location:,
|
|
236
|
+
ivar_name:,
|
|
237
|
+
ivar_name_location:,
|
|
238
|
+
colon_location:,
|
|
239
|
+
type: type.map_type_name { yield _1 },
|
|
240
|
+
comment_location:
|
|
241
|
+
) #: self
|
|
242
|
+
end
|
|
243
|
+
|
|
244
|
+
def type_fingerprint
|
|
245
|
+
[
|
|
246
|
+
"annots/instance_variable",
|
|
247
|
+
ivar_name.to_s,
|
|
248
|
+
type.to_s,
|
|
249
|
+
comment_location&.source
|
|
250
|
+
]
|
|
251
|
+
end
|
|
115
252
|
end
|
|
116
253
|
end
|
|
117
254
|
end
|
|
@@ -177,6 +177,13 @@ module RBS
|
|
|
177
177
|
Location.new(comment_buffer, start_offset, end_offset)
|
|
178
178
|
end
|
|
179
179
|
|
|
180
|
+
def location()
|
|
181
|
+
first_comment = comments[0] or raise
|
|
182
|
+
last_comment = comments[-1] or raise
|
|
183
|
+
|
|
184
|
+
comment_buffer.rbs_location(first_comment.location.join last_comment.location)
|
|
185
|
+
end
|
|
186
|
+
|
|
180
187
|
def parse_annotation_lines(start_line, end_line, variables)
|
|
181
188
|
start_pos = comment_buffer.ranges[start_line].begin
|
|
182
189
|
end_pos = comment_buffer.ranges[end_line].end
|
|
@@ -215,6 +222,23 @@ module RBS
|
|
|
215
222
|
|
|
216
223
|
false
|
|
217
224
|
end
|
|
225
|
+
|
|
226
|
+
def as_comment
|
|
227
|
+
lines = [] #: Array[String]
|
|
228
|
+
|
|
229
|
+
each_paragraph([]) do |paragraph|
|
|
230
|
+
case paragraph
|
|
231
|
+
when Location
|
|
232
|
+
lines << paragraph.local_source
|
|
233
|
+
end
|
|
234
|
+
end
|
|
235
|
+
|
|
236
|
+
string = lines.join("\n")
|
|
237
|
+
|
|
238
|
+
unless string.strip.empty?
|
|
239
|
+
AST::Comment.new(string: string, location: location)
|
|
240
|
+
end
|
|
241
|
+
end
|
|
218
242
|
end
|
|
219
243
|
end
|
|
220
244
|
end
|