rbs 4.0.0.dev.1 → 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.
- checksums.yaml +4 -4
- data/.clang-format +74 -0
- data/.clangd +2 -0
- data/.github/workflows/c-check.yml +51 -0
- data/.github/workflows/dependabot.yml +1 -1
- data/.github/workflows/ruby.yml +28 -17
- data/.github/workflows/typecheck.yml +0 -2
- data/.gitignore +4 -0
- data/.rubocop.yml +1 -1
- data/.vscode/extensions.json +5 -0
- data/.vscode/settings.json +19 -0
- data/README.md +37 -0
- data/Rakefile +90 -0
- data/config.yml +1 -1
- data/core/enumerable.rbs +9 -0
- data/core/io.rbs +4 -4
- data/core/thread.rbs +0 -7
- data/ext/rbs_extension/ast_translation.c +1010 -1074
- data/ext/rbs_extension/ast_translation.h +4 -0
- data/ext/rbs_extension/class_constants.c +78 -74
- data/ext/rbs_extension/class_constants.h +4 -0
- data/ext/rbs_extension/compat.h +10 -0
- data/ext/rbs_extension/extconf.rb +15 -1
- data/ext/rbs_extension/legacy_location.c +173 -172
- data/ext/rbs_extension/legacy_location.h +8 -3
- data/ext/rbs_extension/main.c +315 -273
- data/ext/rbs_extension/rbs_extension.h +3 -0
- data/ext/rbs_extension/rbs_string_bridging.h +4 -0
- data/include/rbs/ast.h +11 -12
- data/include/rbs/defines.h +11 -12
- data/include/rbs/lexer.h +108 -108
- data/include/rbs/location.h +14 -14
- data/include/rbs/parser.h +21 -19
- data/include/rbs/string.h +3 -3
- data/include/rbs/util/rbs_allocator.h +14 -14
- data/include/rbs/util/rbs_constant_pool.h +3 -3
- data/include/rbs/util/rbs_encoding.h +1 -1
- data/lib/rbs/environment.rb +4 -0
- data/lib/rbs/namespace.rb +0 -7
- data/lib/rbs/parser_aux.rb +5 -0
- data/lib/rbs/type_name.rb +0 -7
- data/lib/rbs/types.rb +3 -1
- data/lib/rbs/unit_test/convertibles.rb +1 -0
- data/lib/rbs/version.rb +1 -1
- data/sig/environment.rbs +3 -0
- data/sig/namespace.rbs +0 -5
- data/sig/parser.rbs +20 -0
- data/sig/typename.rbs +0 -5
- data/sig/types.rbs +4 -1
- data/src/ast.c +216 -214
- data/src/lexer.c +2923 -2675
- data/src/lexstate.c +157 -157
- data/src/location.c +40 -40
- data/src/parser.c +2591 -2586
- data/src/string.c +2 -2
- data/src/util/rbs_allocator.c +7 -9
- data/src/util/rbs_assert.c +9 -9
- data/src/util/rbs_constant_pool.c +5 -7
- data/src/util/rbs_encoding.c +20095 -4056
- data/src/util/rbs_unescape.c +33 -32
- data/stdlib/json/0/json.rbs +9 -43
- data/stdlib/ripper/0/ripper.rbs +3 -0
- data/stdlib/socket/0/addrinfo.rbs +2 -2
- metadata +8 -2
@@ -1,8 +1,12 @@
|
|
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
|
4
7
|
#include "ruby.h"
|
5
8
|
#include "ruby/encoding.h"
|
9
|
+
SUPPRESS_RUBY_HEADER_DIAGNOSTICS_END
|
6
10
|
|
7
11
|
#include "rbs/string.h"
|
8
12
|
|
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*
|
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*
|
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*
|
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*
|
133
|
+
rbs_hash_node_t *rbs_hash_find(rbs_hash_t *hash, rbs_node_t *key);
|
134
134
|
|
135
|
-
rbs_node_t*
|
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
|
-
|
653
|
-
|
654
|
-
|
655
|
-
|
656
|
-
|
657
|
-
|
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.
|
data/include/rbs/defines.h
CHANGED
@@ -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
|
-
#
|
26
|
-
#
|
27
|
-
#
|
28
|
-
#
|
29
|
-
#
|
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
|
-
#
|
30
|
+
#define RBS_ATTRIBUTE_FORMAT(string_index, argument_index) __attribute__((__format__(__printf__, string_index, argument_index)))
|
32
31
|
#else
|
33
|
-
#
|
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
|
-
|
40
|
+
#define RBS_FALLTHROUGH [[fallthrough]];
|
42
41
|
#elif defined(__GNUC__) || defined(__clang__)
|
43
|
-
|
42
|
+
#define RBS_FALLTHROUGH __attribute__((fallthrough));
|
44
43
|
#elif defined(_MSC_VER)
|
45
|
-
|
44
|
+
#define RBS_FALLTHROUGH __fallthrough;
|
46
45
|
#else
|
47
|
-
|
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
|
-
|
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
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
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
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
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
|
-
|
114
|
-
|
113
|
+
rbs_position_t start;
|
114
|
+
rbs_position_t end;
|
115
115
|
} rbs_range_t;
|
116
116
|
|
117
117
|
typedef struct {
|
118
|
-
|
119
|
-
|
118
|
+
enum RBSTokenType type;
|
119
|
+
rbs_range_t range;
|
120
120
|
} rbs_token_t;
|
121
121
|
|
122
122
|
/**
|
@@ -130,19 +130,19 @@ typedef struct {
|
|
130
130
|
* ```
|
131
131
|
* */
|
132
132
|
typedef struct {
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
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
|
-
extern rbs_token_t NullToken;
|
144
|
-
extern rbs_position_t NullPosition;
|
145
|
-
extern rbs_range_t NULL_RANGE;
|
143
|
+
extern const rbs_token_t NullToken;
|
144
|
+
extern const rbs_position_t NullPosition;
|
145
|
+
extern const rbs_range_t NULL_RANGE;
|
146
146
|
|
147
147
|
char *rbs_peek_token(rbs_lexer_t *lexer, rbs_token_t tok);
|
148
148
|
int rbs_token_chars(rbs_token_t tok);
|
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);
|
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
|
-
|
28
|
-
|
27
|
+
rbs_position_t start;
|
28
|
+
rbs_position_t end;
|
29
29
|
|
30
|
-
|
31
|
-
|
32
|
-
|
30
|
+
size_t line_size;
|
31
|
+
size_t line_count;
|
32
|
+
rbs_token_t *tokens;
|
33
33
|
|
34
|
-
|
34
|
+
struct rbs_comment_t *next_comment;
|
35
35
|
} rbs_comment_t;
|
36
36
|
|
37
37
|
typedef struct rbs_error_t {
|
38
|
-
|
39
|
-
|
40
|
-
|
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
|
-
|
47
|
+
rbs_lexer_t *rbs_lexer_t;
|
48
48
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
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
|
-
|
55
|
-
|
54
|
+
struct id_table *vars; /* Known type variables */
|
55
|
+
rbs_comment_t *last_comment; /* Last read comment */
|
56
56
|
|
57
|
-
|
58
|
-
|
59
|
-
|
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
|
-
|
10
|
-
|
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
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
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
|
23
|
-
void *rbs_allocator_malloc_many_impl
|
24
|
-
void *rbs_allocator_calloc_impl
|
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
|
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)
|
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)
|
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 *
|
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 *
|
278
|
+
const rbs_encoding_t *rbs_encoding_find(const uint8_t *start, const uint8_t *end);
|
279
279
|
|
280
280
|
#endif
|
data/lib/rbs/environment.rb
CHANGED
data/lib/rbs/namespace.rb
CHANGED
data/lib/rbs/parser_aux.rb
CHANGED
@@ -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