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
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
#ifndef RBS__RBS_STRING_BRIDGING_H
|
|
2
2
|
#define RBS__RBS_STRING_BRIDGING_H
|
|
3
3
|
|
|
4
|
-
#include "compat.h"
|
|
5
|
-
|
|
6
|
-
SUPPRESS_RUBY_HEADER_DIAGNOSTICS_BEGIN
|
|
7
4
|
#include "ruby.h"
|
|
8
5
|
#include "ruby/encoding.h"
|
|
9
|
-
SUPPRESS_RUBY_HEADER_DIAGNOSTICS_END
|
|
10
6
|
|
|
11
7
|
#include "rbs/string.h"
|
|
12
8
|
|
data/include/rbs/ast.h
CHANGED
|
@@ -45,38 +45,43 @@ enum rbs_node_type {
|
|
|
45
45
|
RBS_AST_MEMBERS_PREPEND = 29,
|
|
46
46
|
RBS_AST_MEMBERS_PRIVATE = 30,
|
|
47
47
|
RBS_AST_MEMBERS_PUBLIC = 31,
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
48
|
+
RBS_AST_RUBY_ANNOTATIONS_COLON_METHOD_TYPE_ANNOTATION = 32,
|
|
49
|
+
RBS_AST_RUBY_ANNOTATIONS_METHOD_TYPES_ANNOTATION = 33,
|
|
50
|
+
RBS_AST_RUBY_ANNOTATIONS_NODE_TYPE_ASSERTION = 34,
|
|
51
|
+
RBS_AST_RUBY_ANNOTATIONS_RETURN_TYPE_ANNOTATION = 35,
|
|
52
|
+
RBS_AST_RUBY_ANNOTATIONS_SKIP_ANNOTATION = 36,
|
|
53
|
+
RBS_AST_STRING = 37,
|
|
54
|
+
RBS_AST_TYPE_PARAM = 38,
|
|
55
|
+
RBS_METHOD_TYPE = 39,
|
|
56
|
+
RBS_NAMESPACE = 40,
|
|
57
|
+
RBS_SIGNATURE = 41,
|
|
58
|
+
RBS_TYPE_NAME = 42,
|
|
59
|
+
RBS_TYPES_ALIAS = 43,
|
|
60
|
+
RBS_TYPES_BASES_ANY = 44,
|
|
61
|
+
RBS_TYPES_BASES_BOOL = 45,
|
|
62
|
+
RBS_TYPES_BASES_BOTTOM = 46,
|
|
63
|
+
RBS_TYPES_BASES_CLASS = 47,
|
|
64
|
+
RBS_TYPES_BASES_INSTANCE = 48,
|
|
65
|
+
RBS_TYPES_BASES_NIL = 49,
|
|
66
|
+
RBS_TYPES_BASES_SELF = 50,
|
|
67
|
+
RBS_TYPES_BASES_TOP = 51,
|
|
68
|
+
RBS_TYPES_BASES_VOID = 52,
|
|
69
|
+
RBS_TYPES_BLOCK = 53,
|
|
70
|
+
RBS_TYPES_CLASS_INSTANCE = 54,
|
|
71
|
+
RBS_TYPES_CLASS_SINGLETON = 55,
|
|
72
|
+
RBS_TYPES_FUNCTION = 56,
|
|
73
|
+
RBS_TYPES_FUNCTION_PARAM = 57,
|
|
74
|
+
RBS_TYPES_INTERFACE = 58,
|
|
75
|
+
RBS_TYPES_INTERSECTION = 59,
|
|
76
|
+
RBS_TYPES_LITERAL = 60,
|
|
77
|
+
RBS_TYPES_OPTIONAL = 61,
|
|
78
|
+
RBS_TYPES_PROC = 62,
|
|
79
|
+
RBS_TYPES_RECORD = 63,
|
|
80
|
+
RBS_TYPES_RECORD_FIELD_TYPE = 64,
|
|
81
|
+
RBS_TYPES_TUPLE = 65,
|
|
82
|
+
RBS_TYPES_UNION = 66,
|
|
83
|
+
RBS_TYPES_UNTYPED_FUNCTION = 67,
|
|
84
|
+
RBS_TYPES_VARIABLE = 68,
|
|
80
85
|
RBS_KEYWORD,
|
|
81
86
|
RBS_AST_SYMBOL,
|
|
82
87
|
};
|
|
@@ -86,7 +91,7 @@ typedef struct rbs_node {
|
|
|
86
91
|
rbs_location_t *location;
|
|
87
92
|
} rbs_node_t;
|
|
88
93
|
|
|
89
|
-
const char
|
|
94
|
+
const char* rbs_node_type_name(rbs_node_t *node);
|
|
90
95
|
|
|
91
96
|
/* rbs_node_list_node */
|
|
92
97
|
|
|
@@ -102,7 +107,7 @@ typedef struct rbs_node_list {
|
|
|
102
107
|
size_t length;
|
|
103
108
|
} rbs_node_list_t;
|
|
104
109
|
|
|
105
|
-
rbs_node_list_t
|
|
110
|
+
rbs_node_list_t* rbs_node_list_new(rbs_allocator_t *);
|
|
106
111
|
|
|
107
112
|
void rbs_node_list_append(rbs_node_list_t *list, rbs_node_t *node);
|
|
108
113
|
|
|
@@ -121,13 +126,13 @@ typedef struct rbs_hash {
|
|
|
121
126
|
size_t length;
|
|
122
127
|
} rbs_hash_t;
|
|
123
128
|
|
|
124
|
-
rbs_hash_t
|
|
129
|
+
rbs_hash_t* rbs_hash_new(rbs_allocator_t *);
|
|
125
130
|
|
|
126
131
|
void rbs_hash_set(rbs_hash_t *hash, rbs_node_t *key, rbs_node_t *value);
|
|
127
132
|
|
|
128
|
-
rbs_hash_node_t
|
|
133
|
+
rbs_hash_node_t* rbs_hash_find(rbs_hash_t *hash, rbs_node_t *key);
|
|
129
134
|
|
|
130
|
-
rbs_node_t
|
|
135
|
+
rbs_node_t* rbs_hash_get(rbs_hash_t *hash, rbs_node_t *key);
|
|
131
136
|
|
|
132
137
|
/* rbs_ast_node */
|
|
133
138
|
|
|
@@ -392,6 +397,47 @@ typedef struct rbs_ast_members_public {
|
|
|
392
397
|
|
|
393
398
|
} rbs_ast_members_public_t;
|
|
394
399
|
|
|
400
|
+
typedef struct rbs_ast_ruby_annotations_colon_method_type_annotation {
|
|
401
|
+
rbs_node_t base;
|
|
402
|
+
|
|
403
|
+
struct rbs_location *prefix_location;
|
|
404
|
+
struct rbs_node_list *annotations;
|
|
405
|
+
struct rbs_node *method_type;
|
|
406
|
+
} rbs_ast_ruby_annotations_colon_method_type_annotation_t;
|
|
407
|
+
|
|
408
|
+
typedef struct rbs_ast_ruby_annotations_method_types_annotation {
|
|
409
|
+
rbs_node_t base;
|
|
410
|
+
|
|
411
|
+
struct rbs_location *prefix_location;
|
|
412
|
+
struct rbs_node_list *overloads;
|
|
413
|
+
struct rbs_location_list *vertical_bar_locations;
|
|
414
|
+
} rbs_ast_ruby_annotations_method_types_annotation_t;
|
|
415
|
+
|
|
416
|
+
typedef struct rbs_ast_ruby_annotations_node_type_assertion {
|
|
417
|
+
rbs_node_t base;
|
|
418
|
+
|
|
419
|
+
struct rbs_location *prefix_location;
|
|
420
|
+
struct rbs_node *type;
|
|
421
|
+
} rbs_ast_ruby_annotations_node_type_assertion_t;
|
|
422
|
+
|
|
423
|
+
typedef struct rbs_ast_ruby_annotations_return_type_annotation {
|
|
424
|
+
rbs_node_t base;
|
|
425
|
+
|
|
426
|
+
struct rbs_location *prefix_location;
|
|
427
|
+
struct rbs_location *return_location;
|
|
428
|
+
struct rbs_location *colon_location;
|
|
429
|
+
struct rbs_node *return_type;
|
|
430
|
+
struct rbs_location *comment_location;
|
|
431
|
+
} rbs_ast_ruby_annotations_return_type_annotation_t;
|
|
432
|
+
|
|
433
|
+
typedef struct rbs_ast_ruby_annotations_skip_annotation {
|
|
434
|
+
rbs_node_t base;
|
|
435
|
+
|
|
436
|
+
struct rbs_location *prefix_location;
|
|
437
|
+
struct rbs_location *skip_location;
|
|
438
|
+
struct rbs_location *comment_location;
|
|
439
|
+
} rbs_ast_ruby_annotations_skip_annotation_t;
|
|
440
|
+
|
|
395
441
|
typedef struct rbs_ast_string {
|
|
396
442
|
rbs_node_t base;
|
|
397
443
|
|
|
@@ -601,6 +647,16 @@ typedef struct rbs_types_variable {
|
|
|
601
647
|
struct rbs_ast_symbol *name;
|
|
602
648
|
} rbs_types_variable_t;
|
|
603
649
|
|
|
650
|
+
|
|
651
|
+
typedef union rbs_ast_ruby_annotations {
|
|
652
|
+
rbs_node_t base;
|
|
653
|
+
rbs_ast_ruby_annotations_colon_method_type_annotation_t colon_method_type_annotation;
|
|
654
|
+
rbs_ast_ruby_annotations_method_types_annotation_t method_types_annotation;
|
|
655
|
+
rbs_ast_ruby_annotations_node_type_assertion_t node_type_assertion;
|
|
656
|
+
rbs_ast_ruby_annotations_return_type_annotation_t return_type_annotation;
|
|
657
|
+
rbs_ast_ruby_annotations_skip_annotation_t skip_annotation;
|
|
658
|
+
} rbs_ast_ruby_annotations_t;
|
|
659
|
+
|
|
604
660
|
/// `rbs_keyword_t` models RBS keywords like "private", "instance", "covariant", etc.
|
|
605
661
|
/// These are stored in the global constant pool, and get surfaced to Ruby as `Symbol`s,
|
|
606
662
|
/// just like `rbs_ast_symbol_t`s.
|
|
@@ -651,6 +707,11 @@ rbs_ast_members_method_definition_overload_t *rbs_ast_members_method_definition_
|
|
|
651
707
|
rbs_ast_members_prepend_t *rbs_ast_members_prepend_new(rbs_allocator_t *allocator, rbs_location_t *location, rbs_type_name_t *name, rbs_node_list_t *args, rbs_node_list_t *annotations, rbs_ast_comment_t *comment);
|
|
652
708
|
rbs_ast_members_private_t *rbs_ast_members_private_new(rbs_allocator_t *allocator, rbs_location_t *location);
|
|
653
709
|
rbs_ast_members_public_t *rbs_ast_members_public_new(rbs_allocator_t *allocator, rbs_location_t *location);
|
|
710
|
+
rbs_ast_ruby_annotations_colon_method_type_annotation_t *rbs_ast_ruby_annotations_colon_method_type_annotation_new(rbs_allocator_t *allocator, rbs_location_t *location, rbs_location_t *prefix_location, rbs_node_list_t *annotations, rbs_node_t *method_type);
|
|
711
|
+
rbs_ast_ruby_annotations_method_types_annotation_t *rbs_ast_ruby_annotations_method_types_annotation_new(rbs_allocator_t *allocator, rbs_location_t *location, rbs_location_t *prefix_location, rbs_node_list_t *overloads, rbs_location_list_t *vertical_bar_locations);
|
|
712
|
+
rbs_ast_ruby_annotations_node_type_assertion_t *rbs_ast_ruby_annotations_node_type_assertion_new(rbs_allocator_t *allocator, rbs_location_t *location, rbs_location_t *prefix_location, rbs_node_t *type);
|
|
713
|
+
rbs_ast_ruby_annotations_return_type_annotation_t *rbs_ast_ruby_annotations_return_type_annotation_new(rbs_allocator_t *allocator, rbs_location_t *location, rbs_location_t *prefix_location, rbs_location_t *return_location, rbs_location_t *colon_location, rbs_node_t *return_type, rbs_location_t *comment_location);
|
|
714
|
+
rbs_ast_ruby_annotations_skip_annotation_t *rbs_ast_ruby_annotations_skip_annotation_new(rbs_allocator_t *allocator, rbs_location_t *location, rbs_location_t *prefix_location, rbs_location_t *skip_location, rbs_location_t *comment_location);
|
|
654
715
|
rbs_ast_string_t *rbs_ast_string_new(rbs_allocator_t *allocator, rbs_location_t *location, rbs_string_t string);
|
|
655
716
|
rbs_ast_type_param_t *rbs_ast_type_param_new(rbs_allocator_t *allocator, rbs_location_t *location, rbs_ast_symbol_t *name, rbs_keyword_t *variance, rbs_node_t *upper_bound, rbs_node_t *default_type, bool unchecked);
|
|
656
717
|
rbs_method_type_t *rbs_method_type_new(rbs_allocator_t *allocator, rbs_location_t *location, rbs_node_list_t *type_params, rbs_node_t *type, rbs_types_block_t *block);
|
data/include/rbs/defines.h
CHANGED
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
#ifndef RBS_DEFINES_H
|
|
11
11
|
#define RBS_DEFINES_H
|
|
12
12
|
|
|
13
|
+
|
|
13
14
|
/***********************************************************************************************************************
|
|
14
15
|
* Copied+modified subset of Prism's `include/prism/defines.h` *
|
|
15
16
|
**********************************************************************************************************************/
|
|
@@ -21,33 +22,15 @@
|
|
|
21
22
|
* compiler-agnostic way.
|
|
22
23
|
*/
|
|
23
24
|
#if defined(__GNUC__)
|
|
24
|
-
#if defined(__MINGW_PRINTF_FORMAT)
|
|
25
|
-
#define RBS_ATTRIBUTE_FORMAT(string_index, argument_index) __attribute__((format(__MINGW_PRINTF_FORMAT, string_index, argument_index)))
|
|
26
|
-
#else
|
|
27
|
-
#define RBS_ATTRIBUTE_FORMAT(string_index, argument_index) __attribute__((format(printf, string_index, argument_index)))
|
|
28
|
-
#endif
|
|
25
|
+
# if defined(__MINGW_PRINTF_FORMAT)
|
|
26
|
+
# define RBS_ATTRIBUTE_FORMAT(string_index, argument_index) __attribute__((format(__MINGW_PRINTF_FORMAT, string_index, argument_index)))
|
|
27
|
+
# else
|
|
28
|
+
# define RBS_ATTRIBUTE_FORMAT(string_index, argument_index) __attribute__((format(printf, string_index, argument_index)))
|
|
29
|
+
# endif
|
|
29
30
|
#elif defined(__clang__)
|
|
30
|
-
#define RBS_ATTRIBUTE_FORMAT(string_index, argument_index) __attribute__((__format__(__printf__, string_index, argument_index)))
|
|
31
|
+
# define RBS_ATTRIBUTE_FORMAT(string_index, argument_index) __attribute__((__format__(__printf__, string_index, argument_index)))
|
|
31
32
|
#else
|
|
32
|
-
#define RBS_ATTRIBUTE_FORMAT(string_index, argument_index)
|
|
33
|
-
#endif
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Support RBS_LIKELY and RBS_UNLIKELY to help the compiler optimize its
|
|
37
|
-
* branch predication.
|
|
38
|
-
*/
|
|
39
|
-
#if defined(__GNUC__) || defined(__clang__)
|
|
40
|
-
/** The compiler should predicate that this branch will be taken. */
|
|
41
|
-
#define RBS_LIKELY(x) __builtin_expect(!!(x), 1)
|
|
42
|
-
|
|
43
|
-
/** The compiler should predicate that this branch will not be taken. */
|
|
44
|
-
#define RBS_UNLIKELY(x) __builtin_expect(!!(x), 0)
|
|
45
|
-
#else
|
|
46
|
-
/** Void because this platform does not support branch prediction hints. */
|
|
47
|
-
#define RBS_LIKELY(x) (x)
|
|
48
|
-
|
|
49
|
-
/** Void because this platform does not support branch prediction hints. */
|
|
50
|
-
#define RBS_UNLIKELY(x) (x)
|
|
33
|
+
# define RBS_ATTRIBUTE_FORMAT(string_index, argument_index)
|
|
51
34
|
#endif
|
|
52
35
|
|
|
53
36
|
/**
|
|
@@ -55,13 +38,13 @@
|
|
|
55
38
|
* Use RBS_FALLTHROUGH to explicitly annotate cases where the fallthrough is intentional.
|
|
56
39
|
*/
|
|
57
40
|
#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L // C23 or later
|
|
58
|
-
#define RBS_FALLTHROUGH [[fallthrough]];
|
|
41
|
+
#define RBS_FALLTHROUGH [[fallthrough]];
|
|
59
42
|
#elif defined(__GNUC__) || defined(__clang__)
|
|
60
|
-
#define RBS_FALLTHROUGH __attribute__((fallthrough));
|
|
43
|
+
#define RBS_FALLTHROUGH __attribute__((fallthrough));
|
|
61
44
|
#elif defined(_MSC_VER)
|
|
62
|
-
#define RBS_FALLTHROUGH __fallthrough;
|
|
45
|
+
#define RBS_FALLTHROUGH __fallthrough;
|
|
63
46
|
#else
|
|
64
|
-
#define RBS_FALLTHROUGH
|
|
47
|
+
#define RBS_FALLTHROUGH
|
|
65
48
|
#endif
|
|
66
49
|
|
|
67
50
|
/***********************************************************************************************************************
|
|
@@ -74,13 +57,4 @@
|
|
|
74
57
|
#define NODISCARD __attribute__((warn_unused_result))
|
|
75
58
|
#endif
|
|
76
59
|
|
|
77
|
-
/**
|
|
78
|
-
* Mark a function or variable as potentially unused to suppress compiler warnings.
|
|
79
|
-
*/
|
|
80
|
-
#if defined(__GNUC__) || defined(__clang__)
|
|
81
|
-
#define RBS_ATTRIBUTE_UNUSED __attribute__((unused))
|
|
82
|
-
#else
|
|
83
|
-
#define RBS_ATTRIBUTE_UNUSED
|
|
84
|
-
#endif
|
|
85
|
-
|
|
86
60
|
#endif
|
data/include/rbs/lexer.h
CHANGED
|
@@ -5,91 +5,95 @@
|
|
|
5
5
|
#include "util/rbs_encoding.h"
|
|
6
6
|
|
|
7
7
|
enum RBSTokenType {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
8
|
+
NullType, /* (Nothing) */
|
|
9
|
+
pEOF, /* EOF */
|
|
10
|
+
ErrorToken, /* Error */
|
|
11
|
+
|
|
12
|
+
pLPAREN, /* ( */
|
|
13
|
+
pRPAREN, /* ) */
|
|
14
|
+
pCOLON, /* : */
|
|
15
|
+
pCOLON2, /* :: */
|
|
16
|
+
pLBRACKET, /* [ */
|
|
17
|
+
pRBRACKET, /* ] */
|
|
18
|
+
pLBRACE, /* { */
|
|
19
|
+
pRBRACE, /* } */
|
|
20
|
+
pHAT, /* ^ */
|
|
21
|
+
pARROW, /* -> */
|
|
22
|
+
pFATARROW, /* => */
|
|
23
|
+
pCOMMA, /* , */
|
|
24
|
+
pBAR, /* | */
|
|
25
|
+
pAMP, /* & */
|
|
26
|
+
pSTAR, /* * */
|
|
27
|
+
pSTAR2, /* ** */
|
|
28
|
+
pDOT, /* . */
|
|
29
|
+
pDOT3, /* ... */
|
|
30
|
+
pBANG, /* ! */
|
|
31
|
+
pQUESTION, /* ? */
|
|
32
|
+
pLT, /* < */
|
|
33
|
+
pEQ, /* = */
|
|
34
|
+
|
|
35
|
+
kALIAS, /* alias */
|
|
36
|
+
kATTRACCESSOR, /* attr_accessor */
|
|
37
|
+
kATTRREADER, /* attr_reader */
|
|
38
|
+
kATTRWRITER, /* attr_writer */
|
|
39
|
+
kBOOL, /* bool */
|
|
40
|
+
kBOT, /* bot */
|
|
41
|
+
kCLASS, /* class */
|
|
42
|
+
kDEF, /* def */
|
|
43
|
+
kEND, /* end */
|
|
44
|
+
kEXTEND, /* extend */
|
|
45
|
+
kFALSE, /* false */
|
|
46
|
+
kIN, /* in */
|
|
47
|
+
kINCLUDE, /* include */
|
|
48
|
+
kINSTANCE, /* instance */
|
|
49
|
+
kINTERFACE, /* interface */
|
|
50
|
+
kMODULE, /* module */
|
|
51
|
+
kNIL, /* nil */
|
|
52
|
+
kOUT, /* out */
|
|
53
|
+
kPREPEND, /* prepend */
|
|
54
|
+
kPRIVATE, /* private */
|
|
55
|
+
kPUBLIC, /* public */
|
|
56
|
+
kSELF, /* self */
|
|
57
|
+
kSINGLETON, /* singleton */
|
|
58
|
+
kTOP, /* top */
|
|
59
|
+
kTRUE, /* true */
|
|
60
|
+
kTYPE, /* type */
|
|
61
|
+
kUNCHECKED, /* unchecked */
|
|
62
|
+
kUNTYPED, /* untyped */
|
|
63
|
+
kVOID, /* void */
|
|
64
|
+
kUSE, /* use */
|
|
65
|
+
kAS, /* as */
|
|
66
|
+
k__TODO__, /* __todo__ */
|
|
67
|
+
kATRBS, /* @rbs */
|
|
68
|
+
kSKIP, /* skip */
|
|
69
|
+
kRETURN, /* return */
|
|
70
|
+
|
|
71
|
+
tLIDENT, /* Identifiers starting with lower case */
|
|
72
|
+
tUIDENT, /* Identifiers starting with upper case */
|
|
73
|
+
tULIDENT, /* Identifiers starting with `_` followed by upper case */
|
|
74
|
+
tULLIDENT, /* Identifiers starting with `_` followed by lower case */
|
|
75
|
+
tGIDENT, /* Identifiers starting with `$` */
|
|
76
|
+
tAIDENT, /* Identifiers starting with `@` */
|
|
77
|
+
tA2IDENT, /* Identifiers starting with `@@` */
|
|
78
|
+
tBANGIDENT, /* Identifiers ending with `!` */
|
|
79
|
+
tEQIDENT, /* Identifiers ending with `=` */
|
|
80
|
+
tQIDENT, /* Quoted identifier */
|
|
81
|
+
pAREF_OPR, /* [] */
|
|
82
|
+
tOPERATOR, /* Operator identifier */
|
|
83
|
+
|
|
84
|
+
tCOMMENT, /* Comment */
|
|
85
|
+
tLINECOMMENT, /* Comment of all line */
|
|
86
|
+
tINLINECOMMENT, /* Comment in inline decl starting with -- */
|
|
87
|
+
|
|
88
|
+
tTRIVIA, /* Trivia tokens -- space and new line */
|
|
89
|
+
|
|
90
|
+
tDQSTRING, /* Double quoted string */
|
|
91
|
+
tSQSTRING, /* Single quoted string */
|
|
92
|
+
tINTEGER, /* Integer */
|
|
93
|
+
tSYMBOL, /* Symbol */
|
|
94
|
+
tDQSYMBOL, /* Double quoted symbol */
|
|
95
|
+
tSQSYMBOL, /* Single quoted symbol */
|
|
96
|
+
tANNOTATION, /* Annotation */
|
|
93
97
|
};
|
|
94
98
|
|
|
95
99
|
/**
|
|
@@ -99,52 +103,46 @@ enum RBSTokenType {
|
|
|
99
103
|
* They can be computed from `byte_pos` (or `char_pos`), but it needs full scan from the beginning of the string (depending on the encoding).
|
|
100
104
|
* */
|
|
101
105
|
typedef struct {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
+
int byte_pos;
|
|
107
|
+
int char_pos;
|
|
108
|
+
int line;
|
|
109
|
+
int column;
|
|
106
110
|
} rbs_position_t;
|
|
107
111
|
|
|
108
112
|
typedef struct {
|
|
109
|
-
|
|
110
|
-
|
|
113
|
+
rbs_position_t start;
|
|
114
|
+
rbs_position_t end;
|
|
111
115
|
} rbs_range_t;
|
|
112
116
|
|
|
113
117
|
typedef struct {
|
|
114
|
-
|
|
115
|
-
|
|
118
|
+
enum RBSTokenType type;
|
|
119
|
+
rbs_range_t range;
|
|
116
120
|
} rbs_token_t;
|
|
117
121
|
|
|
118
122
|
/**
|
|
119
123
|
* The lexer state is the curren token.
|
|
120
124
|
*
|
|
121
125
|
* ```
|
|
122
|
-
|
|
123
|
-
*
|
|
124
|
-
*
|
|
125
|
-
*
|
|
126
|
-
* ^ current character ('i', bytes = 1)
|
|
127
|
-
* ~~~~~~~~~~~ Token => "a str
|
|
126
|
+
* ... "a string token"
|
|
127
|
+
* ^ start position
|
|
128
|
+
* ^ current position
|
|
129
|
+
* ~~~~~~ Token => "a str
|
|
128
130
|
* ```
|
|
129
131
|
* */
|
|
130
132
|
typedef struct {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
bool first_token_of_line; /* This flag is used for tLINECOMMENT */
|
|
141
|
-
|
|
142
|
-
const rbs_encoding_t *encoding;
|
|
133
|
+
rbs_string_t string;
|
|
134
|
+
int start_pos; /* The character position that defines the start of the input */
|
|
135
|
+
int end_pos; /* The character position that defines the end of the input */
|
|
136
|
+
rbs_position_t current; /* The current position */
|
|
137
|
+
rbs_position_t start; /* The start position of the current token */
|
|
138
|
+
bool first_token_of_line; /* This flag is used for tLINECOMMENT */
|
|
139
|
+
unsigned int last_char; /* Last peeked character */
|
|
140
|
+
const rbs_encoding_t *encoding;
|
|
143
141
|
} rbs_lexer_t;
|
|
144
142
|
|
|
145
|
-
extern
|
|
146
|
-
extern
|
|
147
|
-
extern
|
|
143
|
+
extern rbs_token_t NullToken;
|
|
144
|
+
extern rbs_position_t NullPosition;
|
|
145
|
+
extern rbs_range_t NULL_RANGE;
|
|
148
146
|
|
|
149
147
|
char *rbs_peek_token(rbs_lexer_t *lexer, rbs_token_t tok);
|
|
150
148
|
int rbs_token_chars(rbs_token_t tok);
|
|
@@ -158,23 +156,15 @@ int rbs_token_bytes(rbs_token_t tok);
|
|
|
158
156
|
const char *rbs_token_type_str(enum RBSTokenType type);
|
|
159
157
|
|
|
160
158
|
/**
|
|
161
|
-
*
|
|
159
|
+
* Read next character.
|
|
162
160
|
* */
|
|
163
161
|
unsigned int rbs_peek(rbs_lexer_t *lexer);
|
|
164
162
|
|
|
165
163
|
/**
|
|
166
|
-
*
|
|
164
|
+
* Skip one character.
|
|
167
165
|
* */
|
|
168
166
|
void rbs_skip(rbs_lexer_t *lexer);
|
|
169
167
|
|
|
170
|
-
/**
|
|
171
|
-
* Read next character and store the codepoint and byte length to the given pointers.
|
|
172
|
-
*
|
|
173
|
-
* This doesn't update the lexer state.
|
|
174
|
-
* Returns `true` if succeeded, or `false` if reached to EOF.
|
|
175
|
-
* */
|
|
176
|
-
bool rbs_next_char(rbs_lexer_t *lexer, unsigned int *codepoint, size_t *bytes);
|
|
177
|
-
|
|
178
168
|
/**
|
|
179
169
|
* Skip n characters.
|
|
180
170
|
* */
|
|
@@ -194,6 +184,4 @@ rbs_token_t rbs_lexer_next_token(rbs_lexer_t *lexer);
|
|
|
194
184
|
|
|
195
185
|
void rbs_print_token(rbs_token_t tok);
|
|
196
186
|
|
|
197
|
-
void rbs_print_lexer(rbs_lexer_t *lexer);
|
|
198
|
-
|
|
199
187
|
#endif
|
data/include/rbs/location.h
CHANGED
|
@@ -7,13 +7,13 @@
|
|
|
7
7
|
#include "rbs/util/rbs_allocator.h"
|
|
8
8
|
|
|
9
9
|
typedef struct {
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
int start;
|
|
11
|
+
int end;
|
|
12
12
|
} rbs_loc_range;
|
|
13
13
|
|
|
14
14
|
typedef struct {
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
rbs_constant_id_t name;
|
|
16
|
+
rbs_loc_range rg;
|
|
17
17
|
} rbs_loc_entry;
|
|
18
18
|
|
|
19
19
|
typedef unsigned int rbs_loc_entry_bitmap;
|
|
@@ -21,10 +21,10 @@ typedef unsigned int rbs_loc_entry_bitmap;
|
|
|
21
21
|
// The flexible array always allocates, but it's okay.
|
|
22
22
|
// This struct is not allocated when the `rbs_loc` doesn't have children.
|
|
23
23
|
typedef struct {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
unsigned short len;
|
|
25
|
+
unsigned short cap;
|
|
26
|
+
rbs_loc_entry_bitmap required_p;
|
|
27
|
+
rbs_loc_entry entries[1];
|
|
28
28
|
} rbs_loc_children;
|
|
29
29
|
|
|
30
30
|
typedef struct rbs_location {
|
|
@@ -33,15 +33,15 @@ typedef struct rbs_location {
|
|
|
33
33
|
} rbs_location_t;
|
|
34
34
|
|
|
35
35
|
typedef struct rbs_location_list_node {
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
rbs_location_t *loc;
|
|
37
|
+
struct rbs_location_list_node *next;
|
|
38
38
|
} rbs_location_list_node_t;
|
|
39
39
|
|
|
40
40
|
typedef struct rbs_location_list {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
41
|
+
rbs_allocator_t *allocator;
|
|
42
|
+
rbs_location_list_node_t *head;
|
|
43
|
+
rbs_location_list_node_t *tail;
|
|
44
|
+
size_t length;
|
|
45
45
|
} rbs_location_list_t;
|
|
46
46
|
|
|
47
47
|
void rbs_loc_alloc_children(rbs_allocator_t *, rbs_location_t *loc, size_t capacity);
|