rbs 4.0.0.dev.2 → 4.0.0.dev.3

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 (60) hide show
  1. checksums.yaml +4 -4
  2. data/.clang-format +74 -0
  3. data/.clangd +2 -0
  4. data/.github/workflows/c-check.yml +51 -0
  5. data/.github/workflows/dependabot.yml +1 -1
  6. data/.github/workflows/ruby.yml +0 -17
  7. data/.github/workflows/typecheck.yml +0 -2
  8. data/.gitignore +4 -0
  9. data/.rubocop.yml +1 -1
  10. data/.vscode/extensions.json +5 -0
  11. data/.vscode/settings.json +19 -0
  12. data/README.md +37 -0
  13. data/Rakefile +82 -0
  14. data/config.yml +1 -1
  15. data/core/enumerable.rbs +9 -0
  16. data/core/io.rbs +4 -4
  17. data/core/thread.rbs +0 -7
  18. data/ext/rbs_extension/ast_translation.c +1008 -1074
  19. data/ext/rbs_extension/class_constants.c +78 -74
  20. data/ext/rbs_extension/compat.h +3 -3
  21. data/ext/rbs_extension/extconf.rb +11 -1
  22. data/ext/rbs_extension/legacy_location.c +173 -172
  23. data/ext/rbs_extension/legacy_location.h +3 -3
  24. data/ext/rbs_extension/main.c +315 -273
  25. data/include/rbs/ast.h +11 -12
  26. data/include/rbs/defines.h +11 -12
  27. data/include/rbs/lexer.h +105 -105
  28. data/include/rbs/location.h +14 -14
  29. data/include/rbs/parser.h +21 -19
  30. data/include/rbs/string.h +3 -3
  31. data/include/rbs/util/rbs_allocator.h +14 -14
  32. data/include/rbs/util/rbs_constant_pool.h +3 -3
  33. data/include/rbs/util/rbs_encoding.h +1 -1
  34. data/lib/rbs/environment.rb +4 -0
  35. data/lib/rbs/namespace.rb +0 -7
  36. data/lib/rbs/parser_aux.rb +5 -0
  37. data/lib/rbs/type_name.rb +0 -7
  38. data/lib/rbs/types.rb +3 -1
  39. data/lib/rbs/unit_test/convertibles.rb +1 -0
  40. data/lib/rbs/version.rb +1 -1
  41. data/sig/environment.rbs +3 -0
  42. data/sig/namespace.rbs +0 -5
  43. data/sig/parser.rbs +20 -0
  44. data/sig/typename.rbs +0 -5
  45. data/sig/types.rbs +4 -1
  46. data/src/ast.c +216 -214
  47. data/src/lexer.c +2923 -2675
  48. data/src/lexstate.c +155 -155
  49. data/src/location.c +40 -40
  50. data/src/parser.c +2591 -2586
  51. data/src/string.c +2 -2
  52. data/src/util/rbs_allocator.c +7 -9
  53. data/src/util/rbs_assert.c +9 -9
  54. data/src/util/rbs_constant_pool.c +5 -7
  55. data/src/util/rbs_encoding.c +20095 -4056
  56. data/src/util/rbs_unescape.c +33 -32
  57. data/stdlib/json/0/json.rbs +9 -43
  58. data/stdlib/ripper/0/ripper.rbs +3 -0
  59. data/stdlib/socket/0/addrinfo.rbs +2 -2
  60. metadata +7 -2
data/include/rbs/ast.h CHANGED
@@ -91,7 +91,7 @@ typedef struct rbs_node {
91
91
  rbs_location_t *location;
92
92
  } rbs_node_t;
93
93
 
94
- const char* rbs_node_type_name(rbs_node_t *node);
94
+ const char *rbs_node_type_name(rbs_node_t *node);
95
95
 
96
96
  /* rbs_node_list_node */
97
97
 
@@ -107,7 +107,7 @@ typedef struct rbs_node_list {
107
107
  size_t length;
108
108
  } rbs_node_list_t;
109
109
 
110
- rbs_node_list_t* rbs_node_list_new(rbs_allocator_t *);
110
+ rbs_node_list_t *rbs_node_list_new(rbs_allocator_t *);
111
111
 
112
112
  void rbs_node_list_append(rbs_node_list_t *list, rbs_node_t *node);
113
113
 
@@ -126,13 +126,13 @@ typedef struct rbs_hash {
126
126
  size_t length;
127
127
  } rbs_hash_t;
128
128
 
129
- rbs_hash_t* rbs_hash_new(rbs_allocator_t *);
129
+ rbs_hash_t *rbs_hash_new(rbs_allocator_t *);
130
130
 
131
131
  void rbs_hash_set(rbs_hash_t *hash, rbs_node_t *key, rbs_node_t *value);
132
132
 
133
- 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);
134
134
 
135
- 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);
136
136
 
137
137
  /* rbs_ast_node */
138
138
 
@@ -647,14 +647,13 @@ typedef struct rbs_types_variable {
647
647
  struct rbs_ast_symbol *name;
648
648
  } rbs_types_variable_t;
649
649
 
650
-
651
650
  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;
651
+ rbs_node_t base;
652
+ rbs_ast_ruby_annotations_colon_method_type_annotation_t colon_method_type_annotation;
653
+ rbs_ast_ruby_annotations_method_types_annotation_t method_types_annotation;
654
+ rbs_ast_ruby_annotations_node_type_assertion_t node_type_assertion;
655
+ rbs_ast_ruby_annotations_return_type_annotation_t return_type_annotation;
656
+ rbs_ast_ruby_annotations_skip_annotation_t skip_annotation;
658
657
  } rbs_ast_ruby_annotations_t;
659
658
 
660
659
  /// `rbs_keyword_t` models RBS keywords like "private", "instance", "covariant", etc.
@@ -10,7 +10,6 @@
10
10
  #ifndef RBS_DEFINES_H
11
11
  #define RBS_DEFINES_H
12
12
 
13
-
14
13
  /***********************************************************************************************************************
15
14
  * Copied+modified subset of Prism's `include/prism/defines.h` *
16
15
  **********************************************************************************************************************/
@@ -22,15 +21,15 @@
22
21
  * compiler-agnostic way.
23
22
  */
24
23
  #if defined(__GNUC__)
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
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
30
29
  #elif defined(__clang__)
31
- # define RBS_ATTRIBUTE_FORMAT(string_index, argument_index) __attribute__((__format__(__printf__, string_index, argument_index)))
30
+ #define RBS_ATTRIBUTE_FORMAT(string_index, argument_index) __attribute__((__format__(__printf__, string_index, argument_index)))
32
31
  #else
33
- # define RBS_ATTRIBUTE_FORMAT(string_index, argument_index)
32
+ #define RBS_ATTRIBUTE_FORMAT(string_index, argument_index)
34
33
  #endif
35
34
 
36
35
  /**
@@ -38,13 +37,13 @@
38
37
  * Use RBS_FALLTHROUGH to explicitly annotate cases where the fallthrough is intentional.
39
38
  */
40
39
  #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L // C23 or later
41
- #define RBS_FALLTHROUGH [[fallthrough]];
40
+ #define RBS_FALLTHROUGH [[fallthrough]];
42
41
  #elif defined(__GNUC__) || defined(__clang__)
43
- #define RBS_FALLTHROUGH __attribute__((fallthrough));
42
+ #define RBS_FALLTHROUGH __attribute__((fallthrough));
44
43
  #elif defined(_MSC_VER)
45
- #define RBS_FALLTHROUGH __fallthrough;
44
+ #define RBS_FALLTHROUGH __fallthrough;
46
45
  #else
47
- #define RBS_FALLTHROUGH
46
+ #define RBS_FALLTHROUGH
48
47
  #endif
49
48
 
50
49
  /***********************************************************************************************************************
data/include/rbs/lexer.h CHANGED
@@ -5,95 +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
- 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 */
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 */
97
97
  };
98
98
 
99
99
  /**
@@ -103,20 +103,20 @@ enum RBSTokenType {
103
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).
104
104
  * */
105
105
  typedef struct {
106
- int byte_pos;
107
- int char_pos;
108
- int line;
109
- int column;
106
+ int byte_pos;
107
+ int char_pos;
108
+ int line;
109
+ int column;
110
110
  } rbs_position_t;
111
111
 
112
112
  typedef struct {
113
- rbs_position_t start;
114
- rbs_position_t end;
113
+ rbs_position_t start;
114
+ rbs_position_t end;
115
115
  } rbs_range_t;
116
116
 
117
117
  typedef struct {
118
- enum RBSTokenType type;
119
- rbs_range_t range;
118
+ enum RBSTokenType type;
119
+ rbs_range_t range;
120
120
  } rbs_token_t;
121
121
 
122
122
  /**
@@ -130,14 +130,14 @@ typedef struct {
130
130
  * ```
131
131
  * */
132
132
  typedef struct {
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;
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;
141
141
  } rbs_lexer_t;
142
142
 
143
143
  extern const rbs_token_t NullToken;
@@ -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);
data/include/rbs/parser.h CHANGED
@@ -24,39 +24,39 @@
24
24
  * A comment object represents the six lines of comments.
25
25
  * */
26
26
  typedef struct rbs_comment_t {
27
- rbs_position_t start;
28
- rbs_position_t end;
27
+ rbs_position_t start;
28
+ rbs_position_t end;
29
29
 
30
- size_t line_size;
31
- size_t line_count;
32
- rbs_token_t *tokens;
30
+ size_t line_size;
31
+ size_t line_count;
32
+ rbs_token_t *tokens;
33
33
 
34
- struct rbs_comment_t *next_comment;
34
+ struct rbs_comment_t *next_comment;
35
35
  } rbs_comment_t;
36
36
 
37
37
  typedef struct rbs_error_t {
38
- char *message;
39
- rbs_token_t token;
40
- bool syntax_error;
38
+ char *message;
39
+ rbs_token_t token;
40
+ bool syntax_error;
41
41
  } rbs_error_t;
42
42
 
43
43
  /**
44
44
  * An RBS parser is a LL(3) parser.
45
45
  * */
46
46
  typedef struct {
47
- rbs_lexer_t *rbs_lexer_t;
47
+ rbs_lexer_t *rbs_lexer_t;
48
48
 
49
- rbs_token_t current_token;
50
- rbs_token_t next_token; /* The first lookahead token */
51
- rbs_token_t next_token2; /* The second lookahead token */
52
- rbs_token_t next_token3; /* The third lookahead token */
49
+ rbs_token_t current_token;
50
+ rbs_token_t next_token; /* The first lookahead token */
51
+ rbs_token_t next_token2; /* The second lookahead token */
52
+ rbs_token_t next_token3; /* The third lookahead token */
53
53
 
54
- struct id_table *vars; /* Known type variables */
55
- rbs_comment_t *last_comment; /* Last read comment */
54
+ struct id_table *vars; /* Known type variables */
55
+ rbs_comment_t *last_comment; /* Last read comment */
56
56
 
57
- rbs_constant_pool_t constant_pool;
58
- rbs_allocator_t *allocator;
59
- rbs_error_t *error;
57
+ rbs_constant_pool_t constant_pool;
58
+ rbs_allocator_t *allocator;
59
+ rbs_error_t *error;
60
60
  } rbs_parser_t;
61
61
 
62
62
  /**
@@ -130,6 +130,8 @@ bool rbs_parse_type(rbs_parser_t *parser, rbs_node_t **type);
130
130
  bool rbs_parse_method_type(rbs_parser_t *parser, rbs_method_type_t **method_type);
131
131
  bool rbs_parse_signature(rbs_parser_t *parser, rbs_signature_t **signature);
132
132
 
133
+ bool rbs_parse_type_params(rbs_parser_t *parser, bool module_type_params, rbs_node_list_t **params);
134
+
133
135
  /**
134
136
  * Parse an inline leading annotation from a string.
135
137
  *
data/include/rbs/string.h CHANGED
@@ -6,14 +6,14 @@
6
6
  #include "rbs/util/rbs_allocator.h"
7
7
 
8
8
  typedef struct {
9
- const char *start;
10
- const char *end;
9
+ const char *start;
10
+ const char *end;
11
11
  } rbs_string_t;
12
12
 
13
13
  #define RBS_STRING_NULL ((rbs_string_t) { \
14
14
  .start = NULL, \
15
15
  .end = NULL, \
16
- })
16
+ })
17
17
 
18
18
  /**
19
19
  * Returns a new `rbs_string_t` struct
@@ -4,14 +4,14 @@
4
4
  #include <stddef.h>
5
5
 
6
6
  #ifndef alignof
7
- #if defined(__GNUC__) || defined(__clang__)
8
- #define alignof(type) __alignof__(type)
9
- #elif defined(_MSC_VER)
10
- #define alignof(type) __alignof(type)
11
- #else
12
- // Fallback using offset trick
13
- #define alignof(type) offsetof(struct { char c; type member; }, member)
14
- #endif
7
+ #if defined(__GNUC__) || defined(__clang__)
8
+ #define alignof(type) __alignof__(type)
9
+ #elif defined(_MSC_VER)
10
+ #define alignof(type) __alignof(type)
11
+ #else
12
+ // Fallback using offset trick
13
+ #define alignof(type) offsetof(struct { char c; type member; }, member)
14
+ #endif
15
15
  #endif
16
16
 
17
17
  struct rbs_allocator;
@@ -19,20 +19,20 @@ typedef struct rbs_allocator rbs_allocator_t;
19
19
 
20
20
  rbs_allocator_t *rbs_allocator_init(void);
21
21
  void rbs_allocator_free(rbs_allocator_t *);
22
- void *rbs_allocator_malloc_impl (rbs_allocator_t *, /* 1 */ size_t size, size_t alignment);
23
- void *rbs_allocator_malloc_many_impl (rbs_allocator_t *, size_t count, size_t size, size_t alignment);
24
- void *rbs_allocator_calloc_impl (rbs_allocator_t *, size_t count, size_t size, size_t alignment);
22
+ void *rbs_allocator_malloc_impl(rbs_allocator_t *, /* 1 */ size_t size, size_t alignment);
23
+ void *rbs_allocator_malloc_many_impl(rbs_allocator_t *, size_t count, size_t size, size_t alignment);
24
+ void *rbs_allocator_calloc_impl(rbs_allocator_t *, size_t count, size_t size, size_t alignment);
25
25
 
26
- void *rbs_allocator_realloc_impl (rbs_allocator_t *, void *ptr, size_t old_size, size_t new_size, size_t alignment);
26
+ void *rbs_allocator_realloc_impl(rbs_allocator_t *, void *ptr, size_t old_size, size_t new_size, size_t alignment);
27
27
 
28
28
  // 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), alignof(type)))
29
+ #define rbs_allocator_alloc(allocator, type) ((type *) rbs_allocator_malloc_impl((allocator), sizeof(type), alignof(type)))
30
30
  // Use this when allocating memory that will be immediately written to in full.
31
31
  // Such as allocating strings
32
32
  #define rbs_allocator_alloc_many(allocator, count, type) ((type *) rbs_allocator_malloc_many_impl((allocator), (count), sizeof(type), alignof(type)))
33
33
  // Use this when allocating memory that will NOT be immediately written to in full.
34
34
  // Such as allocating buffers
35
- #define rbs_allocator_calloc(allocator, count, type) ((type *) rbs_allocator_calloc_impl((allocator), (count), sizeof(type), alignof(type)))
35
+ #define rbs_allocator_calloc(allocator, count, type) ((type *) rbs_allocator_calloc_impl((allocator), (count), sizeof(type), alignof(type)))
36
36
  #define rbs_allocator_realloc(allocator, ptr, old_size, new_size, type) ((type *) rbs_allocator_realloc_impl((allocator), (ptr), (old_size), (new_size), alignof(type)))
37
37
 
38
38
  #endif
@@ -48,10 +48,10 @@ static const rbs_constant_pool_bucket_type_t RBS_CONSTANT_POOL_BUCKET_CONSTANT =
48
48
  /** A bucket in the hash map. */
49
49
  typedef struct {
50
50
  /** The incremental ID used for indexing back into the pool. */
51
- unsigned int id: 30;
51
+ unsigned int id : 30;
52
52
 
53
53
  /** The type of the bucket, which determines how to free it. */
54
- rbs_constant_pool_bucket_type_t type: 2;
54
+ rbs_constant_pool_bucket_type_t type : 2;
55
55
 
56
56
  /** The hash of the bucket. */
57
57
  uint32_t hash;
@@ -100,7 +100,7 @@ bool rbs_constant_pool_init(rbs_constant_pool_t *pool, uint32_t capacity);
100
100
  * @param constant_id The id of the constant to get.
101
101
  * @return A pointer to the constant.
102
102
  */
103
- rbs_constant_t * rbs_constant_pool_id_to_constant(const rbs_constant_pool_t *pool, rbs_constant_id_t constant_id);
103
+ rbs_constant_t *rbs_constant_pool_id_to_constant(const rbs_constant_pool_t *pool, rbs_constant_id_t constant_id);
104
104
 
105
105
  /**
106
106
  * Find a constant in a constant pool. Returns the id of the constant, or 0 if
@@ -275,6 +275,6 @@ extern const rbs_encoding_t rbs_encodings[RBS_ENCODING_MAXIMUM];
275
275
  * @param end A pointer to the last byte of the name.
276
276
  * @returns A pointer to the encoding struct if one is found, otherwise NULL.
277
277
  */
278
- const rbs_encoding_t * rbs_encoding_find(const uint8_t *start, const uint8_t *end);
278
+ const rbs_encoding_t *rbs_encoding_find(const uint8_t *start, const uint8_t *end);
279
279
 
280
280
  #endif
@@ -11,6 +11,10 @@ module RBS
11
11
 
12
12
  attr_reader :sources
13
13
 
14
+ def declarations
15
+ sources.flat_map(&:declarations)
16
+ end
17
+
14
18
  class SingleEntry
15
19
  attr_reader :name
16
20
  attr_reader :context
data/lib/rbs/namespace.rb CHANGED
@@ -116,10 +116,3 @@ module RBS
116
116
  end
117
117
  end
118
118
  end
119
-
120
- module Kernel
121
- def Namespace(name)
122
- warn "Kernel#Namespace() is deprecated. Use RBS::Namespace.parse instead.", category: :deprecated
123
- RBS::Namespace.parse(name)
124
- end
125
- end
@@ -35,6 +35,11 @@ module RBS
35
35
  [buf, dirs, decls]
36
36
  end
37
37
 
38
+ def self.parse_type_params(source, module_type_params: true)
39
+ buf = buffer(source)
40
+ _parse_type_params(buf, 0, buf.last_position, module_type_params)
41
+ end
42
+
38
43
  def self.magic_comment(buf)
39
44
  start_pos = 0
40
45
 
data/lib/rbs/type_name.rb CHANGED
@@ -100,10 +100,3 @@ module RBS
100
100
  end
101
101
  end
102
102
  end
103
-
104
- module Kernel
105
- def TypeName(string)
106
- warn "Kernel#TypeName() is deprecated. Use RBS::TypeName.parse instead.", category: :deprecated
107
- RBS::TypeName.parse(string)
108
- end
109
- end
data/lib/rbs/types.rb CHANGED
@@ -1339,8 +1339,10 @@ module RBS
1339
1339
  attr_reader :type
1340
1340
  attr_reader :required
1341
1341
  attr_reader :self_type
1342
+ attr_reader :location
1342
1343
 
1343
- def initialize(type:, required:, self_type: nil)
1344
+ def initialize(location: nil, type:, required:, self_type: nil)
1345
+ @location = location
1344
1346
  @type = type
1345
1347
  @required = required ? true : false
1346
1348
  @self_type = self_type
@@ -5,6 +5,7 @@ module RBS
5
5
  module Convertibles
6
6
  class BlankSlate < BasicObject
7
7
  instance_methods.each do |im|
8
+ next if im == :__id__
8
9
  next if im == :__send__
9
10
  undef_method im
10
11
  end
data/lib/rbs/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RBS
4
- VERSION = "4.0.0.dev.2"
4
+ VERSION = "4.0.0.dev.3"
5
5
  end