prism 2.0.0-arm-linux-musl

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 (233) hide show
  1. checksums.yaml +7 -0
  2. data/BSDmakefile +58 -0
  3. data/CHANGELOG.md +881 -0
  4. data/CODE_OF_CONDUCT.md +76 -0
  5. data/CONTRIBUTING.md +58 -0
  6. data/LICENSE.md +7 -0
  7. data/Makefile +145 -0
  8. data/README.md +81 -0
  9. data/config.yml +4752 -0
  10. data/docs/build_system.md +119 -0
  11. data/docs/configuration.md +69 -0
  12. data/docs/cruby_compilation.md +27 -0
  13. data/docs/design.md +53 -0
  14. data/docs/encoding.md +121 -0
  15. data/docs/fuzzing.md +81 -0
  16. data/docs/heredocs.md +36 -0
  17. data/docs/javascript.md +133 -0
  18. data/docs/local_variable_depth.md +229 -0
  19. data/docs/mapping.md +117 -0
  20. data/docs/parser_translation.md +24 -0
  21. data/docs/parsing_rules.md +22 -0
  22. data/docs/releasing.md +147 -0
  23. data/docs/relocation.md +32 -0
  24. data/docs/ripper_translation.md +63 -0
  25. data/docs/ruby_api.md +45 -0
  26. data/docs/ruby_parser_translation.md +19 -0
  27. data/docs/serialization.md +244 -0
  28. data/docs/testing.md +72 -0
  29. data/ext/prism/api_node.c +7005 -0
  30. data/ext/prism/extconf.rb +126 -0
  31. data/ext/prism/extension.c +1768 -0
  32. data/ext/prism/extension.h +19 -0
  33. data/include/prism/arena.h +45 -0
  34. data/include/prism/arena.hpp +42 -0
  35. data/include/prism/ast.h +10381 -0
  36. data/include/prism/ast.hpp +641 -0
  37. data/include/prism/buffer.h +60 -0
  38. data/include/prism/buffer.hpp +55 -0
  39. data/include/prism/comments.h +72 -0
  40. data/include/prism/compiler/accel.h +26 -0
  41. data/include/prism/compiler/align.h +36 -0
  42. data/include/prism/compiler/assume.h +25 -0
  43. data/include/prism/compiler/branch.h +26 -0
  44. data/include/prism/compiler/bswap.h +46 -0
  45. data/include/prism/compiler/cplusplus.hpp +16 -0
  46. data/include/prism/compiler/endianness.h +34 -0
  47. data/include/prism/compiler/exceptions.hpp +17 -0
  48. data/include/prism/compiler/exported.h +24 -0
  49. data/include/prism/compiler/fallthrough.h +22 -0
  50. data/include/prism/compiler/filesystem.h +32 -0
  51. data/include/prism/compiler/flex_array.h +19 -0
  52. data/include/prism/compiler/force_inline.h +21 -0
  53. data/include/prism/compiler/format.h +27 -0
  54. data/include/prism/compiler/inline.h +17 -0
  55. data/include/prism/compiler/lifetimebound.hpp +25 -0
  56. data/include/prism/compiler/nodiscard.h +22 -0
  57. data/include/prism/compiler/nonnull.h +18 -0
  58. data/include/prism/compiler/unused.h +18 -0
  59. data/include/prism/constant_pool.h +106 -0
  60. data/include/prism/diagnostic.h +111 -0
  61. data/include/prism/errors_format.h +61 -0
  62. data/include/prism/excludes.h +29 -0
  63. data/include/prism/integer.h +41 -0
  64. data/include/prism/internal/allocator.h +68 -0
  65. data/include/prism/internal/allocator_debug.h +88 -0
  66. data/include/prism/internal/arena.h +108 -0
  67. data/include/prism/internal/bit.h +42 -0
  68. data/include/prism/internal/buffer.h +94 -0
  69. data/include/prism/internal/char.h +145 -0
  70. data/include/prism/internal/comments.h +53 -0
  71. data/include/prism/internal/constant_pool.h +152 -0
  72. data/include/prism/internal/diagnostic.h +389 -0
  73. data/include/prism/internal/encoding.h +242 -0
  74. data/include/prism/internal/integer.h +68 -0
  75. data/include/prism/internal/isinf.h +16 -0
  76. data/include/prism/internal/line_offset_list.h +34 -0
  77. data/include/prism/internal/list.h +62 -0
  78. data/include/prism/internal/magic_comments.h +23 -0
  79. data/include/prism/internal/memchr.h +15 -0
  80. data/include/prism/internal/node.h +42 -0
  81. data/include/prism/internal/options.h +232 -0
  82. data/include/prism/internal/parser.h +1004 -0
  83. data/include/prism/internal/regexp.h +26 -0
  84. data/include/prism/internal/serialize.h +39 -0
  85. data/include/prism/internal/source.h +72 -0
  86. data/include/prism/internal/static_literals.h +100 -0
  87. data/include/prism/internal/stringy.h +30 -0
  88. data/include/prism/internal/strncasecmp.h +18 -0
  89. data/include/prism/internal/strpbrk.h +33 -0
  90. data/include/prism/internal/tokens.h +11 -0
  91. data/include/prism/internal/xxh3.h +16 -0
  92. data/include/prism/json.h +40 -0
  93. data/include/prism/line_offset_list.h +69 -0
  94. data/include/prism/magic_comments.h +53 -0
  95. data/include/prism/node.h +139 -0
  96. data/include/prism/node.hpp +272 -0
  97. data/include/prism/node_type.hpp +38 -0
  98. data/include/prism/options.h +363 -0
  99. data/include/prism/options.hpp +43 -0
  100. data/include/prism/parser.h +433 -0
  101. data/include/prism/parser.hpp +274 -0
  102. data/include/prism/prettyprint.h +39 -0
  103. data/include/prism/serialize.h +123 -0
  104. data/include/prism/source.h +163 -0
  105. data/include/prism/stream.h +36 -0
  106. data/include/prism/string_query.h +82 -0
  107. data/include/prism/stringy.h +61 -0
  108. data/include/prism/stringy.hpp +31 -0
  109. data/include/prism/version.h +46 -0
  110. data/include/prism.h +123 -0
  111. data/include/prism.hpp +24 -0
  112. data/lib/prism/3.3/prism.so +0 -0
  113. data/lib/prism/3.4/prism.so +0 -0
  114. data/lib/prism/4.0/prism.so +0 -0
  115. data/lib/prism/compiler.rb +815 -0
  116. data/lib/prism/desugar_compiler.rb +463 -0
  117. data/lib/prism/dispatcher.rb +2383 -0
  118. data/lib/prism/dot_visitor.rb +4848 -0
  119. data/lib/prism/dsl.rb +1369 -0
  120. data/lib/prism/ffi.rb +746 -0
  121. data/lib/prism/inspect_visitor.rb +2425 -0
  122. data/lib/prism/lex_compat.rb +953 -0
  123. data/lib/prism/mutation_compiler.rb +780 -0
  124. data/lib/prism/node.rb +33940 -0
  125. data/lib/prism/node_ext.rb +504 -0
  126. data/lib/prism/node_find.rb +215 -0
  127. data/lib/prism/parse_result/errors.rb +72 -0
  128. data/lib/prism/parse_result/newlines.rb +423 -0
  129. data/lib/prism/parse_result.rb +1236 -0
  130. data/lib/prism/pattern.rb +314 -0
  131. data/lib/prism/polyfill/append_as_bytes.rb +15 -0
  132. data/lib/prism/polyfill/byteindex.rb +13 -0
  133. data/lib/prism/polyfill/scan_byte.rb +14 -0
  134. data/lib/prism/polyfill/unpack1.rb +14 -0
  135. data/lib/prism/polyfill/warn.rb +36 -0
  136. data/lib/prism/reflection.rb +427 -0
  137. data/lib/prism/relocation.rb +567 -0
  138. data/lib/prism/serialize.rb +4589 -0
  139. data/lib/prism/string_query.rb +54 -0
  140. data/lib/prism/translation/parser/builder.rb +70 -0
  141. data/lib/prism/translation/parser/compiler.rb +2226 -0
  142. data/lib/prism/translation/parser/lexer.rb +769 -0
  143. data/lib/prism/translation/parser.rb +376 -0
  144. data/lib/prism/translation/parser_current.rb +26 -0
  145. data/lib/prism/translation/parser_versions.rb +36 -0
  146. data/lib/prism/translation/ripper/filter.rb +53 -0
  147. data/lib/prism/translation/ripper/lexer.rb +133 -0
  148. data/lib/prism/translation/ripper/sexp.rb +118 -0
  149. data/lib/prism/translation/ripper/shim.rb +7 -0
  150. data/lib/prism/translation/ripper.rb +4278 -0
  151. data/lib/prism/translation/ruby_parser.rb +1721 -0
  152. data/lib/prism/translation.rb +20 -0
  153. data/lib/prism/visitor.rb +1440 -0
  154. data/lib/prism.rb +168 -0
  155. data/prism.gemspec +251 -0
  156. data/rbi/generated/prism/compiler.rbi +489 -0
  157. data/rbi/generated/prism/desugar_compiler.rbi +306 -0
  158. data/rbi/generated/prism/dispatcher.rbi +1138 -0
  159. data/rbi/generated/prism/dot_visitor.rbi +618 -0
  160. data/rbi/generated/prism/dsl.rbi +751 -0
  161. data/rbi/generated/prism/inspect_visitor.rbi +503 -0
  162. data/rbi/generated/prism/lex_compat.rbi +162 -0
  163. data/rbi/generated/prism/mutation_compiler.rbi +464 -0
  164. data/rbi/generated/prism/node.rbi +15143 -0
  165. data/rbi/generated/prism/node_ext.rbi +259 -0
  166. data/rbi/generated/prism/node_find.rbi +79 -0
  167. data/rbi/generated/prism/parse_result/errors.rbi +21 -0
  168. data/rbi/generated/prism/parse_result/newlines.rbi +208 -0
  169. data/rbi/generated/prism/parse_result.rbi +776 -0
  170. data/rbi/generated/prism/pattern.rbi +134 -0
  171. data/rbi/generated/prism/reflection.rbi +89 -0
  172. data/rbi/generated/prism/relocation.rbi +329 -0
  173. data/rbi/generated/prism/serialize.rbi +185 -0
  174. data/rbi/generated/prism/string_query.rbi +43 -0
  175. data/rbi/generated/prism/translation.rbi +7 -0
  176. data/rbi/generated/prism/visitor.rbi +650 -0
  177. data/rbi/generated/prism.rbi +86 -0
  178. data/rbi/prism/translation/parser.rbi +11 -0
  179. data/rbi/prism/translation/parser_versions.rbi +28 -0
  180. data/rbi/prism/translation/ripper.rbi +15 -0
  181. data/rbi/rubyvm/node_find.rbi +14 -0
  182. data/sig/generated/prism/compiler.rbs +492 -0
  183. data/sig/generated/prism/desugar_compiler.rbs +305 -0
  184. data/sig/generated/prism/dispatcher.rbs +1292 -0
  185. data/sig/generated/prism/dot_visitor.rbs +635 -0
  186. data/sig/generated/prism/dsl.rbs +928 -0
  187. data/sig/generated/prism/inspect_visitor.rbs +509 -0
  188. data/sig/generated/prism/lex_compat.rbs +166 -0
  189. data/sig/generated/prism/mutation_compiler.rbs +464 -0
  190. data/sig/generated/prism/node.rbs +21632 -0
  191. data/sig/generated/prism/node_ext.rbs +290 -0
  192. data/sig/generated/prism/node_find.rbs +90 -0
  193. data/sig/generated/prism/parse_result/errors.rbs +22 -0
  194. data/sig/generated/prism/parse_result/newlines.rbs +223 -0
  195. data/sig/generated/prism/parse_result.rbs +871 -0
  196. data/sig/generated/prism/pattern.rbs +156 -0
  197. data/sig/generated/prism/reflection.rbs +101 -0
  198. data/sig/generated/prism/relocation.rbs +428 -0
  199. data/sig/generated/prism/serialize.rbs +200 -0
  200. data/sig/generated/prism/string_query.rbs +43 -0
  201. data/sig/generated/prism/translation.rbs +8 -0
  202. data/sig/generated/prism/visitor.rbs +1111 -0
  203. data/sig/generated/prism.rbs +84 -0
  204. data/sig/manifest.yaml +2 -0
  205. data/src/arena.c +117 -0
  206. data/src/buffer.c +389 -0
  207. data/src/char.c +289 -0
  208. data/src/comments.c +454 -0
  209. data/src/constant_pool.c +406 -0
  210. data/src/diagnostic.c +894 -0
  211. data/src/encoding.c +5345 -0
  212. data/src/errors_format.c +519 -0
  213. data/src/integer.c +681 -0
  214. data/src/json.c +5733 -0
  215. data/src/line_offset_list.c +100 -0
  216. data/src/list.c +24 -0
  217. data/src/memchr.c +37 -0
  218. data/src/node.c +4363 -0
  219. data/src/options.c +445 -0
  220. data/src/parser.c +371 -0
  221. data/src/prettyprint.c +9024 -0
  222. data/src/prism.c +23901 -0
  223. data/src/regexp.c +1705 -0
  224. data/src/serialize.c +2660 -0
  225. data/src/source.c +524 -0
  226. data/src/static_literals.c +685 -0
  227. data/src/string_query.c +180 -0
  228. data/src/stringy.c +61 -0
  229. data/src/strncasecmp.c +37 -0
  230. data/src/strpbrk.c +447 -0
  231. data/src/tokens.c +724 -0
  232. data/src/xxh3.c +292 -0
  233. metadata +276 -0
data/src/parser.c ADDED
@@ -0,0 +1,371 @@
1
+ #include "prism/internal/parser.h"
2
+
3
+ #include "prism/internal/allocator.h"
4
+ #include "prism/internal/comments.h"
5
+ #include "prism/internal/diagnostic.h"
6
+ #include "prism/internal/encoding.h"
7
+ #include "prism/internal/magic_comments.h"
8
+ #include "prism/internal/xxh3.h"
9
+
10
+ #include <assert.h>
11
+ #include <stdlib.h>
12
+ #include <string.h>
13
+
14
+ /**
15
+ * Register a callback that will be called whenever prism changes the encoding
16
+ * it is using to parse based on the magic comment.
17
+ */
18
+ void
19
+ pm_parser_encoding_changed_callback_set(pm_parser_t *parser, pm_encoding_changed_callback_t callback) {
20
+ parser->encoding_changed_callback = callback;
21
+ }
22
+
23
+ /**
24
+ * Register a callback that will be called whenever a token is lexed.
25
+ */
26
+ void
27
+ pm_parser_lex_callback_set(pm_parser_t *parser, pm_lex_callback_t callback, void *data) {
28
+ parser->lex_callback.callback = callback;
29
+ parser->lex_callback.data = data;
30
+ }
31
+
32
+ /**
33
+ * Returns the opaque data that is passed to the lex callback when it is called.
34
+ */
35
+ void *
36
+ pm_parser_lex_callback_data(const pm_parser_t *parser) {
37
+ return parser->lex_callback.data;
38
+ }
39
+
40
+ /**
41
+ * Returns the raw pointer to the start of the source that is being parsed.
42
+ */
43
+ const uint8_t *
44
+ pm_parser_start(const pm_parser_t *parser) {
45
+ return parser->start;
46
+ }
47
+
48
+ /**
49
+ * Returns the raw pointer to the end of the source that is being parsed.
50
+ */
51
+ const uint8_t *
52
+ pm_parser_end(const pm_parser_t *parser) {
53
+ return parser->end;
54
+ }
55
+
56
+ /**
57
+ * Returns the line that the parser was considered to have started on.
58
+ *
59
+ * @param parser the parser whose start line we want to get
60
+ * @return the line that the parser was considered to have started on
61
+ */
62
+ int32_t
63
+ pm_parser_start_line(const pm_parser_t *parser) {
64
+ return parser->start_line;
65
+ }
66
+
67
+ /**
68
+ * Returns the name of the encoding that is being used to parse the source.
69
+ */
70
+ const char *
71
+ pm_parser_encoding_name(const pm_parser_t *parser) {
72
+ return parser->encoding->name;
73
+ }
74
+
75
+ /**
76
+ * Returns the width of the character at the given pointer in the encoding that
77
+ * is being used to parse the source.
78
+ */
79
+ size_t
80
+ pm_parser_encoding_char_width(const pm_parser_t *parser, const uint8_t *start, ptrdiff_t remaining) {
81
+ return parser->encoding->char_width(start, remaining);
82
+ }
83
+
84
+ /**
85
+ * Returns whether or not the parser is using the US-ASCII encoding.
86
+ */
87
+ bool
88
+ pm_parser_encoding_us_ascii(const pm_parser_t *parser) {
89
+ return parser->encoding == PM_ENCODING_US_ASCII_ENTRY;
90
+ }
91
+
92
+ /**
93
+ * Returns the filepath that is being used to parse the source.
94
+ */
95
+ const pm_string_t *
96
+ pm_parser_filepath(const pm_parser_t *parser) {
97
+ return &parser->filepath;
98
+ }
99
+
100
+ /**
101
+ * Find a constant in the parser's constant pool. Returns the id of the
102
+ * constant, or 0 if the constant is not found.
103
+ */
104
+ pm_constant_id_t
105
+ pm_parser_constant_find(const pm_parser_t *parser, const uint8_t *start, size_t length) {
106
+ return pm_constant_pool_find(&parser->constant_pool, start, length);
107
+ }
108
+
109
+ /**
110
+ * Add a constant to the parser's constant pool, copying its bytes into the
111
+ * parser's arena only if the constant is not already there.
112
+ */
113
+ pm_constant_id_t
114
+ pm_parser_constant_insert(pm_parser_t *parser, const uint8_t *start, size_t length) {
115
+ pm_constant_id_t id = pm_constant_pool_find(&parser->constant_pool, start, length);
116
+ if (id != PM_CONSTANT_ID_UNSET) return id;
117
+
118
+ const uint8_t *copy = (const uint8_t *) pm_arena_memdup(&parser->metadata_arena, start, length, PRISM_ALIGNOF(uint8_t));
119
+ return pm_constant_pool_insert_constant(&parser->metadata_arena, &parser->constant_pool, copy, length);
120
+ }
121
+
122
+ /**
123
+ * Returns the frozen string literal value of the parser.
124
+ */
125
+ int8_t
126
+ pm_parser_frozen_string_literal(const pm_parser_t *parser) {
127
+ return parser->frozen_string_literal;
128
+ }
129
+
130
+ /**
131
+ * Returns the line offsets that are associated with the given parser.
132
+ *
133
+ * @param parser the parser whose line offsets we want to get
134
+ * @return the line offsets that are associated with the given parser
135
+ */
136
+ const pm_line_offset_list_t *
137
+ pm_parser_line_offsets(const pm_parser_t *parser) {
138
+ return &parser->line_offsets;
139
+ }
140
+
141
+ /**
142
+ * Returns the location of the __DATA__ section that is associated with the
143
+ * given parser, if it exists.
144
+ */
145
+ const pm_location_t *
146
+ pm_parser_data_loc(const pm_parser_t *parser) {
147
+ return &parser->data_loc;
148
+ }
149
+
150
+ /**
151
+ * Returns the checksum of the source code that was parsed.
152
+ */
153
+ uint64_t
154
+ pm_parser_checksum(const pm_parser_t *parser) {
155
+ const uint8_t *end = parser->end;
156
+
157
+ if (parser->data_loc.length != 0) {
158
+ const uint8_t *cursor = parser->start + parser->data_loc.start;
159
+ const uint8_t *newline = memchr(cursor, '\n', (size_t) (end - cursor));
160
+ if (newline != NULL) end = newline + 1;
161
+ }
162
+
163
+ return pm_xxh3(parser->start, (size_t) (end - parser->start));
164
+ }
165
+
166
+ /**
167
+ * Returns whether the given parser is continuable, meaning that it could become
168
+ * valid if more input were appended, as opposed to being definitively invalid.
169
+ */
170
+ bool
171
+ pm_parser_continuable(const pm_parser_t *parser) {
172
+ return parser->continuable;
173
+ }
174
+
175
+ /**
176
+ * Returns the lex state of the parser. Note that this is an internal detail,
177
+ * and we are purposefully not returning an instance of the internal enum that
178
+ * we use to track this. This is only exposed because we need it for some very
179
+ * niche use cases. Most consumers should avoid this function.
180
+ */
181
+ int
182
+ pm_parser_lex_state(const pm_parser_t *parser) {
183
+ return (int) parser->lex_state;
184
+ }
185
+
186
+ /**
187
+ * Returns the location associated with the given comment.
188
+ */
189
+ pm_location_t
190
+ pm_comment_location(const pm_comment_t *comment) {
191
+ return comment->location;
192
+ }
193
+
194
+ /**
195
+ * Returns the type associated with the given comment.
196
+ */
197
+ pm_comment_type_t
198
+ pm_comment_type(const pm_comment_t *comment) {
199
+ return comment->type;
200
+ }
201
+
202
+ /**
203
+ * Returns the comment that follows the given comment.
204
+ */
205
+ const pm_comment_t *
206
+ pm_comment_next(const pm_comment_t *comment) {
207
+ return (const pm_comment_t *) comment->node.next;
208
+ }
209
+
210
+ /**
211
+ * Returns the number of comments associated with the given parser.
212
+ */
213
+ size_t
214
+ pm_parser_comments_size(const pm_parser_t *parser) {
215
+ return parser->comment_list.size;
216
+ }
217
+
218
+ /**
219
+ * Returns the first comment associated with the given parser.
220
+ */
221
+ const pm_comment_t *
222
+ pm_parser_comments_first(const pm_parser_t *parser) {
223
+ return (const pm_comment_t *) parser->comment_list.head;
224
+ }
225
+
226
+ /**
227
+ * Returns the number of comments owned by the given node.
228
+ */
229
+ uint32_t
230
+ pm_node_comments_size(const pm_parser_t *parser, const pm_node_t *node) {
231
+ return pm_parser_comment_range(parser, node->node_id).length;
232
+ }
233
+
234
+ /**
235
+ * Returns the comment at the given index among the comments owned by the given
236
+ * node.
237
+ */
238
+ const pm_comment_t *
239
+ pm_node_comment(const pm_parser_t *parser, const pm_node_t *node, uint32_t index) {
240
+ pm_comment_range_t range = pm_parser_comment_range(parser, node->node_id);
241
+ if (index >= range.length) return NULL;
242
+
243
+ return parser->comment_attachments.comments[parser->comment_attachments.attachments[range.index + index]];
244
+ }
245
+
246
+ /**
247
+ * Returns the index, among the comments associated with the given parser, of
248
+ * the comment at the given index among the comment attachments.
249
+ */
250
+ uint32_t
251
+ pm_parser_comment_attachment(const pm_parser_t *parser, uint32_t index) {
252
+ if (parser->comment_attachments.attachments == NULL || index >= parser->comment_list.size) return UINT32_MAX;
253
+ return parser->comment_attachments.attachments[index];
254
+ }
255
+
256
+ /**
257
+ * Returns the number of node ids that have a comment range.
258
+ */
259
+ uint32_t
260
+ pm_parser_comment_ranges_size(const pm_parser_t *parser) {
261
+ return parser->comment_attachments.ranges_size;
262
+ }
263
+
264
+ /**
265
+ * Returns the range of comment attachments owned by the node with the given id.
266
+ */
267
+ pm_comment_range_t
268
+ pm_parser_comment_range(const pm_parser_t *parser, uint32_t node_id) {
269
+ if (node_id >= parser->comment_attachments.ranges_size) return (pm_comment_range_t) { .index = 0, .length = 0 };
270
+ return parser->comment_attachments.ranges[node_id];
271
+ }
272
+
273
+ /**
274
+ * Returns the location associated with the given magic comment key.
275
+ */
276
+ pm_location_t
277
+ pm_magic_comment_key(const pm_magic_comment_t *magic_comment) {
278
+ return magic_comment->key;
279
+ }
280
+
281
+ /**
282
+ * Returns the location associated with the given magic comment value.
283
+ */
284
+ pm_location_t
285
+ pm_magic_comment_value(const pm_magic_comment_t *magic_comment) {
286
+ return magic_comment->value;
287
+ }
288
+
289
+ /**
290
+ * Returns the magic comment that follows the given magic comment.
291
+ */
292
+ const pm_magic_comment_t *
293
+ pm_magic_comment_next(const pm_magic_comment_t *magic_comment) {
294
+ return (const pm_magic_comment_t *) magic_comment->node.next;
295
+ }
296
+
297
+ /**
298
+ * Returns the number of magic comments associated with the given parser.
299
+ */
300
+ size_t
301
+ pm_parser_magic_comments_size(const pm_parser_t *parser) {
302
+ return parser->magic_comment_list.size;
303
+ }
304
+
305
+ /**
306
+ * Returns the first magic comment associated with the given parser.
307
+ */
308
+ const pm_magic_comment_t *
309
+ pm_parser_magic_comments_first(const pm_parser_t *parser) {
310
+ return (const pm_magic_comment_t *) parser->magic_comment_list.head;
311
+ }
312
+
313
+ /**
314
+ * Returns the number of errors associated with the given parser.
315
+ */
316
+ size_t
317
+ pm_parser_errors_size(const pm_parser_t *parser) {
318
+ return parser->error_list.size;
319
+ }
320
+
321
+ /**
322
+ * Returns the number of warnings associated with the given parser.
323
+ */
324
+ size_t
325
+ pm_parser_warnings_size(const pm_parser_t *parser) {
326
+ return parser->warning_list.size;
327
+ }
328
+
329
+ /**
330
+ * Returns the first error associated with the given parser.
331
+ */
332
+ const pm_diagnostic_t *
333
+ pm_parser_errors_first(const pm_parser_t *parser) {
334
+ return (const pm_diagnostic_t *) parser->error_list.head;
335
+ }
336
+
337
+ /**
338
+ * Returns the first warning associated with the given parser.
339
+ */
340
+ const pm_diagnostic_t *
341
+ pm_parser_warnings_first(const pm_parser_t *parser) {
342
+ return (const pm_diagnostic_t *) parser->warning_list.head;
343
+ }
344
+
345
+ /**
346
+ * Returns the number of constants in the constant pool associated with the
347
+ * given parser.
348
+ */
349
+ size_t
350
+ pm_parser_constants_size(const pm_parser_t *parser) {
351
+ return parser->constant_pool.size;
352
+ }
353
+
354
+ /**
355
+ * Returns the constant at the given index in the constant pool associated with
356
+ * the given parser.
357
+ */
358
+ const pm_constant_t *
359
+ pm_parser_constant_at(const pm_parser_t *parser, size_t index) {
360
+ assert(index < parser->constant_pool.size);
361
+ return &parser->constant_pool.constants[index];
362
+ }
363
+
364
+ /**
365
+ * Returns a pointer to the constant at the given id in the constant pool
366
+ * associated with the given parser.
367
+ */
368
+ const pm_constant_t *
369
+ pm_parser_constant(const pm_parser_t *parser, pm_constant_id_t constant_id) {
370
+ return pm_constant_pool_id_to_constant(&parser->constant_pool, constant_id);
371
+ }