rbs 3.10.0 → 4.0.0.dev.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (202) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/comments.yml +3 -3
  3. data/.github/workflows/ruby.yml +24 -35
  4. data/.github/workflows/typecheck.yml +3 -1
  5. data/.github/workflows/windows.yml +2 -2
  6. data/.gitignore +0 -4
  7. data/CHANGELOG.md +0 -88
  8. data/README.md +1 -38
  9. data/Rakefile +20 -142
  10. data/Steepfile +1 -0
  11. data/config.yml +43 -1
  12. data/core/array.rbs +46 -100
  13. data/core/complex.rbs +21 -32
  14. data/core/dir.rbs +2 -2
  15. data/core/encoding.rbs +9 -6
  16. data/core/enumerable.rbs +3 -90
  17. data/core/enumerator.rbs +1 -18
  18. data/core/errno.rbs +0 -8
  19. data/core/errors.rbs +1 -28
  20. data/core/exception.rbs +2 -2
  21. data/core/fiber.rbs +4 -5
  22. data/core/file.rbs +12 -27
  23. data/core/file_test.rbs +1 -1
  24. data/core/float.rbs +22 -209
  25. data/core/gc.rbs +281 -417
  26. data/core/hash.rbs +727 -1024
  27. data/core/integer.rbs +38 -78
  28. data/core/io/buffer.rbs +7 -18
  29. data/core/io/wait.rbs +33 -11
  30. data/core/io.rbs +12 -14
  31. data/core/kernel.rbs +51 -57
  32. data/core/marshal.rbs +1 -1
  33. data/core/match_data.rbs +1 -1
  34. data/core/math.rbs +3 -42
  35. data/core/method.rbs +6 -14
  36. data/core/module.rbs +17 -88
  37. data/core/nil_class.rbs +3 -3
  38. data/core/numeric.rbs +16 -16
  39. data/core/object.rbs +3 -3
  40. data/core/object_space.rbs +15 -21
  41. data/core/proc.rbs +8 -15
  42. data/core/process.rbs +2 -2
  43. data/core/ractor.rbs +437 -278
  44. data/core/range.rbs +8 -7
  45. data/core/rational.rbs +24 -37
  46. data/core/rbs/unnamed/argf.rbs +2 -2
  47. data/core/rbs/unnamed/env_class.rbs +1 -1
  48. data/core/rbs/unnamed/random.rbs +2 -4
  49. data/core/regexp.rbs +20 -25
  50. data/core/ruby_vm.rbs +4 -6
  51. data/core/rubygems/errors.rbs +70 -3
  52. data/core/rubygems/rubygems.rbs +79 -11
  53. data/core/rubygems/version.rbs +3 -2
  54. data/core/set.rbs +359 -488
  55. data/core/string.rbs +1228 -3153
  56. data/core/struct.rbs +1 -1
  57. data/core/symbol.rbs +4 -4
  58. data/core/thread.rbs +29 -92
  59. data/core/time.rbs +9 -35
  60. data/core/trace_point.rbs +4 -7
  61. data/core/unbound_method.rbs +6 -14
  62. data/docs/collection.md +2 -2
  63. data/docs/gem.md +1 -0
  64. data/docs/sigs.md +3 -3
  65. data/ext/rbs_extension/ast_translation.c +1077 -944
  66. data/ext/rbs_extension/ast_translation.h +0 -7
  67. data/ext/rbs_extension/class_constants.c +83 -71
  68. data/ext/rbs_extension/class_constants.h +7 -4
  69. data/ext/rbs_extension/extconf.rb +2 -24
  70. data/ext/rbs_extension/legacy_location.c +172 -173
  71. data/ext/rbs_extension/legacy_location.h +3 -8
  72. data/ext/rbs_extension/main.c +289 -239
  73. data/ext/rbs_extension/rbs_extension.h +0 -3
  74. data/ext/rbs_extension/rbs_string_bridging.h +0 -4
  75. data/include/rbs/ast.h +98 -37
  76. data/include/rbs/defines.h +12 -38
  77. data/include/rbs/lexer.h +114 -126
  78. data/include/rbs/location.h +14 -14
  79. data/include/rbs/parser.h +37 -21
  80. data/include/rbs/string.h +5 -3
  81. data/include/rbs/util/rbs_allocator.h +19 -40
  82. data/include/rbs/util/rbs_assert.h +1 -12
  83. data/include/rbs/util/rbs_constant_pool.h +3 -3
  84. data/include/rbs/util/rbs_encoding.h +1 -3
  85. data/include/rbs/util/rbs_unescape.h +1 -2
  86. data/lib/rbs/ast/ruby/annotations.rb +119 -0
  87. data/lib/rbs/ast/ruby/comment_block.rb +221 -0
  88. data/lib/rbs/ast/ruby/declarations.rb +86 -0
  89. data/lib/rbs/ast/ruby/helpers/constant_helper.rb +24 -0
  90. data/lib/rbs/ast/ruby/helpers/location_helper.rb +15 -0
  91. data/lib/rbs/ast/ruby/members.rb +213 -0
  92. data/lib/rbs/buffer.rb +104 -24
  93. data/lib/rbs/cli/validate.rb +40 -35
  94. data/lib/rbs/cli.rb +5 -6
  95. data/lib/rbs/collection/config/lockfile_generator.rb +0 -1
  96. data/lib/rbs/collection.rb +0 -1
  97. data/lib/rbs/definition.rb +6 -1
  98. data/lib/rbs/definition_builder/ancestor_builder.rb +65 -62
  99. data/lib/rbs/definition_builder/method_builder.rb +45 -30
  100. data/lib/rbs/definition_builder.rb +44 -9
  101. data/lib/rbs/environment/class_entry.rb +69 -0
  102. data/lib/rbs/environment/module_entry.rb +66 -0
  103. data/lib/rbs/environment.rb +244 -218
  104. data/lib/rbs/environment_loader.rb +3 -3
  105. data/lib/rbs/errors.rb +5 -4
  106. data/lib/rbs/inline_parser/comment_association.rb +117 -0
  107. data/lib/rbs/inline_parser.rb +206 -0
  108. data/lib/rbs/location_aux.rb +35 -3
  109. data/lib/rbs/parser_aux.rb +11 -6
  110. data/lib/rbs/prototype/runtime.rb +2 -2
  111. data/lib/rbs/resolver/constant_resolver.rb +2 -2
  112. data/lib/rbs/resolver/type_name_resolver.rb +38 -124
  113. data/lib/rbs/source.rb +99 -0
  114. data/lib/rbs/subtractor.rb +4 -3
  115. data/lib/rbs/test/type_check.rb +0 -14
  116. data/lib/rbs/types.rb +1 -3
  117. data/lib/rbs/version.rb +1 -1
  118. data/lib/rbs.rb +13 -1
  119. data/lib/rdoc/discover.rb +1 -1
  120. data/lib/rdoc_plugin/parser.rb +1 -1
  121. data/rbs.gemspec +1 -0
  122. data/sig/ancestor_builder.rbs +1 -1
  123. data/sig/ast/ruby/annotations.rbs +110 -0
  124. data/sig/ast/ruby/comment_block.rbs +119 -0
  125. data/sig/ast/ruby/declarations.rbs +60 -0
  126. data/sig/ast/ruby/helpers/constant_helper.rbs +11 -0
  127. data/sig/ast/ruby/helpers/location_helper.rbs +15 -0
  128. data/sig/ast/ruby/members.rbs +72 -0
  129. data/sig/buffer.rbs +63 -5
  130. data/sig/definition.rbs +1 -0
  131. data/sig/definition_builder.rbs +1 -1
  132. data/sig/environment/class_entry.rbs +50 -0
  133. data/sig/environment/module_entry.rbs +50 -0
  134. data/sig/environment.rbs +28 -133
  135. data/sig/errors.rbs +13 -6
  136. data/sig/inline_parser/comment_association.rbs +71 -0
  137. data/sig/inline_parser.rbs +87 -0
  138. data/sig/location.rbs +32 -7
  139. data/sig/manifest.yaml +1 -0
  140. data/sig/method_builder.rbs +7 -4
  141. data/sig/parser.rbs +16 -20
  142. data/sig/resolver/type_name_resolver.rbs +7 -38
  143. data/sig/source.rbs +48 -0
  144. data/sig/types.rbs +1 -4
  145. data/src/ast.c +290 -201
  146. data/src/lexer.c +2813 -2902
  147. data/src/lexer.re +4 -0
  148. data/src/lexstate.c +155 -169
  149. data/src/location.c +40 -40
  150. data/src/parser.c +2665 -2433
  151. data/src/string.c +48 -0
  152. data/src/util/rbs_allocator.c +77 -80
  153. data/src/util/rbs_assert.c +10 -10
  154. data/src/util/rbs_buffer.c +2 -2
  155. data/src/util/rbs_constant_pool.c +15 -13
  156. data/src/util/rbs_encoding.c +4062 -20097
  157. data/src/util/rbs_unescape.c +48 -85
  158. data/stdlib/bigdecimal/0/big_decimal.rbs +82 -100
  159. data/stdlib/bigdecimal-math/0/big_math.rbs +8 -169
  160. data/stdlib/cgi/0/core.rbs +396 -2
  161. data/stdlib/cgi/0/manifest.yaml +0 -1
  162. data/stdlib/coverage/0/coverage.rbs +1 -3
  163. data/stdlib/date/0/date.rbs +59 -67
  164. data/stdlib/date/0/date_time.rbs +1 -1
  165. data/stdlib/delegate/0/delegator.rbs +7 -10
  166. data/stdlib/erb/0/erb.rbs +347 -737
  167. data/stdlib/fileutils/0/fileutils.rbs +13 -18
  168. data/stdlib/forwardable/0/forwardable.rbs +0 -3
  169. data/stdlib/json/0/json.rbs +48 -68
  170. data/stdlib/net-http/0/net-http.rbs +0 -3
  171. data/stdlib/objspace/0/objspace.rbs +4 -9
  172. data/stdlib/open-uri/0/open-uri.rbs +0 -40
  173. data/stdlib/openssl/0/openssl.rbs +228 -331
  174. data/stdlib/optparse/0/optparse.rbs +3 -3
  175. data/{core → stdlib/pathname/0}/pathname.rbs +355 -255
  176. data/stdlib/psych/0/psych.rbs +3 -3
  177. data/stdlib/rdoc/0/rdoc.rbs +1 -1
  178. data/stdlib/resolv/0/resolv.rbs +68 -25
  179. data/stdlib/ripper/0/ripper.rbs +2 -5
  180. data/stdlib/singleton/0/singleton.rbs +0 -3
  181. data/stdlib/socket/0/socket.rbs +1 -13
  182. data/stdlib/socket/0/tcp_socket.rbs +2 -10
  183. data/stdlib/stringio/0/stringio.rbs +85 -1176
  184. data/stdlib/strscan/0/string_scanner.rbs +31 -31
  185. data/stdlib/tempfile/0/tempfile.rbs +3 -3
  186. data/stdlib/time/0/time.rbs +1 -1
  187. data/stdlib/timeout/0/timeout.rbs +7 -63
  188. data/stdlib/tsort/0/cyclic.rbs +0 -3
  189. data/stdlib/uri/0/common.rbs +2 -11
  190. data/stdlib/uri/0/file.rbs +1 -1
  191. data/stdlib/uri/0/generic.rbs +16 -17
  192. data/stdlib/uri/0/rfc2396_parser.rbs +7 -6
  193. data/stdlib/zlib/0/zstream.rbs +0 -1
  194. metadata +40 -12
  195. data/.clang-format +0 -74
  196. data/.clangd +0 -2
  197. data/.github/workflows/c-check.yml +0 -54
  198. data/core/ruby.rbs +0 -53
  199. data/docs/aliases.md +0 -79
  200. data/docs/encoding.md +0 -56
  201. data/ext/rbs_extension/compat.h +0 -10
  202. data/stdlib/cgi-escape/0/escape.rbs +0 -153
@@ -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
- RBS_AST_STRING = 32,
49
- RBS_AST_TYPE_PARAM = 33,
50
- RBS_METHOD_TYPE = 34,
51
- RBS_NAMESPACE = 35,
52
- RBS_SIGNATURE = 36,
53
- RBS_TYPE_NAME = 37,
54
- RBS_TYPES_ALIAS = 38,
55
- RBS_TYPES_BASES_ANY = 39,
56
- RBS_TYPES_BASES_BOOL = 40,
57
- RBS_TYPES_BASES_BOTTOM = 41,
58
- RBS_TYPES_BASES_CLASS = 42,
59
- RBS_TYPES_BASES_INSTANCE = 43,
60
- RBS_TYPES_BASES_NIL = 44,
61
- RBS_TYPES_BASES_SELF = 45,
62
- RBS_TYPES_BASES_TOP = 46,
63
- RBS_TYPES_BASES_VOID = 47,
64
- RBS_TYPES_BLOCK = 48,
65
- RBS_TYPES_CLASS_INSTANCE = 49,
66
- RBS_TYPES_CLASS_SINGLETON = 50,
67
- RBS_TYPES_FUNCTION = 51,
68
- RBS_TYPES_FUNCTION_PARAM = 52,
69
- RBS_TYPES_INTERFACE = 53,
70
- RBS_TYPES_INTERSECTION = 54,
71
- RBS_TYPES_LITERAL = 55,
72
- RBS_TYPES_OPTIONAL = 56,
73
- RBS_TYPES_PROC = 57,
74
- RBS_TYPES_RECORD = 58,
75
- RBS_TYPES_RECORD_FIELD_TYPE = 59,
76
- RBS_TYPES_TUPLE = 60,
77
- RBS_TYPES_UNION = 61,
78
- RBS_TYPES_UNTYPED_FUNCTION = 62,
79
- RBS_TYPES_VARIABLE = 63,
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 *rbs_node_type_name(rbs_node_t *node);
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 *rbs_node_list_new(rbs_allocator_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 *rbs_hash_new(rbs_allocator_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 *rbs_hash_find(rbs_hash_t *hash, rbs_node_t *key);
133
+ rbs_hash_node_t* rbs_hash_find(rbs_hash_t *hash, rbs_node_t *key);
129
134
 
130
- rbs_node_t *rbs_hash_get(rbs_hash_t *hash, rbs_node_t *key);
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);
@@ -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
- 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
-
68
- tLIDENT, /* Identifiers starting with lower case */
69
- tUIDENT, /* Identifiers starting with upper case */
70
- tULIDENT, /* Identifiers starting with `_` followed by upper case */
71
- tULLIDENT, /* Identifiers starting with `_` followed by lower case */
72
- tGIDENT, /* Identifiers starting with `$` */
73
- tAIDENT, /* Identifiers starting with `@` */
74
- tA2IDENT, /* Identifiers starting with `@@` */
75
- tBANGIDENT, /* Identifiers ending with `!` */
76
- tEQIDENT, /* Identifiers ending with `=` */
77
- tQIDENT, /* Quoted identifier */
78
- pAREF_OPR, /* [] */
79
- tOPERATOR, /* Operator identifier */
80
-
81
- tCOMMENT, /* Comment */
82
- tLINECOMMENT, /* Comment of all line */
83
-
84
- tTRIVIA, /* Trivia tokens -- space and new line */
85
-
86
- tDQSTRING, /* Double quoted string */
87
- tSQSTRING, /* Single quoted string */
88
- tINTEGER, /* Integer */
89
- tSYMBOL, /* Symbol */
90
- tDQSYMBOL, /* Double quoted symbol */
91
- tSQSYMBOL, /* Single quoted symbol */
92
- tANNOTATION, /* Annotation */
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
- int byte_pos;
103
- int char_pos;
104
- int line;
105
- int column;
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
- rbs_position_t start;
110
- rbs_position_t end;
113
+ rbs_position_t start;
114
+ rbs_position_t end;
111
115
  } rbs_range_t;
112
116
 
113
117
  typedef struct {
114
- enum RBSTokenType type;
115
- rbs_range_t range;
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
- #. 0.1.2.3.4.5.6.7.8.9.0.1.2.3.4.5.6
123
- * ... " a s t r i n g t o k e n "
124
- * ^ start position (0)
125
- * ^ current position (6)
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
- rbs_string_t string;
132
- int start_pos; /* The character position that defines the start of the input */
133
- int end_pos; /* The character position that defines the end of the input */
134
- rbs_position_t current; /* The current position: just before the current_character */
135
- rbs_position_t start; /* The start position of the current token */
136
-
137
- unsigned int current_code_point; /* Current character code point */
138
- size_t current_character_bytes; /* Current character byte length (0 or 1~4) */
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 const rbs_token_t NullToken;
146
- extern const rbs_position_t NullPosition;
147
- extern const rbs_range_t NULL_RANGE;
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
- * Returns the next character.
159
+ * Read next character.
162
160
  * */
163
161
  unsigned int rbs_peek(rbs_lexer_t *lexer);
164
162
 
165
163
  /**
166
- * Advances the current position by one character.
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
@@ -7,13 +7,13 @@
7
7
  #include "rbs/util/rbs_allocator.h"
8
8
 
9
9
  typedef struct {
10
- int start;
11
- int end;
10
+ int start;
11
+ int end;
12
12
  } rbs_loc_range;
13
13
 
14
14
  typedef struct {
15
- rbs_constant_id_t name;
16
- rbs_loc_range rg;
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
- unsigned short len;
25
- unsigned short cap;
26
- rbs_loc_entry_bitmap required_p;
27
- rbs_loc_entry entries[1];
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
- rbs_location_t *loc;
37
- struct rbs_location_list_node *next;
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
- rbs_allocator_t *allocator;
42
- rbs_location_list_node_t *head;
43
- rbs_location_list_node_t *tail;
44
- size_t length;
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);