Ruby: prism/serialize.c Source File

Ruby 3.3.4p94 (2024-07-09 revision be1089c8ec5ba40e09b1553e36b3174bf4014d9d)

serialize.c
1/******************************************************************************/
2/* This file is generated by the templates/template.rb script and should not */
3/* be modified manually. See */
4/* templates/src/serialize.c.erb */
5/* if you are looking to modify the */
6/* template */
7/******************************************************************************/
8#include "prism.h"
9
10#include <stdio.h>
11
12static inline uint32_t
13pm_ptrdifft_to_u32(ptrdiff_t value) {
14 assert(value >= 0 && ((unsigned long) value) < UINT32_MAX);
15 return (uint32_t) value;
16}
17
18static inline uint32_t
19pm_sizet_to_u32(size_t value) {
20 assert(value < UINT32_MAX);
21 return (uint32_t) value;
22}
23
24static void
25pm_serialize_location(const pm_parser_t *parser, const pm_location_t *location, pm_buffer_t *buffer) {
26 assert(location->start);
27 assert(location->end);
28 assert(location->start <= location->end);
29
30 pm_buffer_append_varuint(buffer, pm_ptrdifft_to_u32(location->start - parser->start));
31 pm_buffer_append_varuint(buffer, pm_ptrdifft_to_u32(location->end - location->start));
32}
33
34static void
35pm_serialize_string(pm_parser_t *parser, pm_string_t *string, pm_buffer_t *buffer) {
36 switch (string->type) {
37 case PM_STRING_SHARED: {
38 pm_buffer_append_byte(buffer, 1);
39 pm_buffer_append_varuint(buffer, pm_ptrdifft_to_u32(pm_string_source(string) - parser->start));
40 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(pm_string_length(string)));
41 break;
42 }
43 case PM_STRING_OWNED:
44 case PM_STRING_CONSTANT: {
45 uint32_t length = pm_sizet_to_u32(pm_string_length(string));
46 pm_buffer_append_byte(buffer, 2);
47 pm_buffer_append_varuint(buffer, length);
48 pm_buffer_append_bytes(buffer, pm_string_source(string), length);
49 break;
50 }
51 case PM_STRING_MAPPED:
52 assert(false && "Cannot serialize mapped strings.");
53 break;
54 }
55}
56
57static void
58pm_serialize_node(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) {
59 pm_buffer_append_byte(buffer, (uint8_t) PM_NODE_TYPE(node));
60
61 size_t offset = buffer->length;
62
63 pm_serialize_location(parser, &node->location, buffer);
64
65 switch (PM_NODE_TYPE(node)) {
66 // We do not need to serialize a ScopeNode ever as
67 // it is not part of the AST
68 case PM_SCOPE_NODE:
69 return;
70 case PM_ALIAS_GLOBAL_VARIABLE_NODE: {
71 pm_serialize_node(parser, (pm_node_t *)((pm_alias_global_variable_node_t *)node)->new_name, buffer);
72 pm_serialize_node(parser, (pm_node_t *)((pm_alias_global_variable_node_t *)node)->old_name, buffer);
73 pm_serialize_location(parser, &((pm_alias_global_variable_node_t *)node)->keyword_loc, buffer);
74 break;
75 }
76 case PM_ALIAS_METHOD_NODE: {
77 pm_serialize_node(parser, (pm_node_t *)((pm_alias_method_node_t *)node)->new_name, buffer);
78 pm_serialize_node(parser, (pm_node_t *)((pm_alias_method_node_t *)node)->old_name, buffer);
79 pm_serialize_location(parser, &((pm_alias_method_node_t *)node)->keyword_loc, buffer);
80 break;
81 }
82 case PM_ALTERNATION_PATTERN_NODE: {
83 pm_serialize_node(parser, (pm_node_t *)((pm_alternation_pattern_node_t *)node)->left, buffer);
84 pm_serialize_node(parser, (pm_node_t *)((pm_alternation_pattern_node_t *)node)->right, buffer);
85 pm_serialize_location(parser, &((pm_alternation_pattern_node_t *)node)->operator_loc, buffer);
86 break;
87 }
88 case PM_AND_NODE: {
89 pm_serialize_node(parser, (pm_node_t *)((pm_and_node_t *)node)->left, buffer);
90 pm_serialize_node(parser, (pm_node_t *)((pm_and_node_t *)node)->right, buffer);
91 pm_serialize_location(parser, &((pm_and_node_t *)node)->operator_loc, buffer);
92 break;
93 }
94 case PM_ARGUMENTS_NODE: {
95 pm_buffer_append_varuint(buffer, (uint32_t)(node->flags & ~PM_NODE_FLAG_COMMON_MASK));
96 uint32_t arguments_size = pm_sizet_to_u32(((pm_arguments_node_t *)node)->arguments.size);
97 pm_buffer_append_varuint(buffer, arguments_size);
98 for (uint32_t index = 0; index < arguments_size; index++) {
99 pm_serialize_node(parser, (pm_node_t *) ((pm_arguments_node_t *)node)->arguments.nodes[index], buffer);
100 }
101 break;
102 }
103 case PM_ARRAY_NODE: {
104 pm_buffer_append_varuint(buffer, (uint32_t)(node->flags & ~PM_NODE_FLAG_COMMON_MASK));
105 uint32_t elements_size = pm_sizet_to_u32(((pm_array_node_t *)node)->elements.size);
106 pm_buffer_append_varuint(buffer, elements_size);
107 for (uint32_t index = 0; index < elements_size; index++) {
108 pm_serialize_node(parser, (pm_node_t *) ((pm_array_node_t *)node)->elements.nodes[index], buffer);
109 }
110 if (((pm_array_node_t *)node)->opening_loc.start == NULL) {
111 pm_buffer_append_byte(buffer, 0);
112 } else {
113 pm_buffer_append_byte(buffer, 1);
114 pm_serialize_location(parser, &((pm_array_node_t *)node)->opening_loc, buffer);
115 }
116 if (((pm_array_node_t *)node)->closing_loc.start == NULL) {
117 pm_buffer_append_byte(buffer, 0);
118 } else {
119 pm_buffer_append_byte(buffer, 1);
120 pm_serialize_location(parser, &((pm_array_node_t *)node)->closing_loc, buffer);
121 }
122 break;
123 }
124 case PM_ARRAY_PATTERN_NODE: {
125 if (((pm_array_pattern_node_t *)node)->constant == NULL) {
126 pm_buffer_append_byte(buffer, 0);
127 } else {
128 pm_serialize_node(parser, (pm_node_t *)((pm_array_pattern_node_t *)node)->constant, buffer);
129 }
130 uint32_t requireds_size = pm_sizet_to_u32(((pm_array_pattern_node_t *)node)->requireds.size);
131 pm_buffer_append_varuint(buffer, requireds_size);
132 for (uint32_t index = 0; index < requireds_size; index++) {
133 pm_serialize_node(parser, (pm_node_t *) ((pm_array_pattern_node_t *)node)->requireds.nodes[index], buffer);
134 }
135 if (((pm_array_pattern_node_t *)node)->rest == NULL) {
136 pm_buffer_append_byte(buffer, 0);
137 } else {
138 pm_serialize_node(parser, (pm_node_t *)((pm_array_pattern_node_t *)node)->rest, buffer);
139 }
140 uint32_t posts_size = pm_sizet_to_u32(((pm_array_pattern_node_t *)node)->posts.size);
141 pm_buffer_append_varuint(buffer, posts_size);
142 for (uint32_t index = 0; index < posts_size; index++) {
143 pm_serialize_node(parser, (pm_node_t *) ((pm_array_pattern_node_t *)node)->posts.nodes[index], buffer);
144 }
145 if (((pm_array_pattern_node_t *)node)->opening_loc.start == NULL) {
146 pm_buffer_append_byte(buffer, 0);
147 } else {
148 pm_buffer_append_byte(buffer, 1);
149 pm_serialize_location(parser, &((pm_array_pattern_node_t *)node)->opening_loc, buffer);
150 }
151 if (((pm_array_pattern_node_t *)node)->closing_loc.start == NULL) {
152 pm_buffer_append_byte(buffer, 0);
153 } else {
154 pm_buffer_append_byte(buffer, 1);
155 pm_serialize_location(parser, &((pm_array_pattern_node_t *)node)->closing_loc, buffer);
156 }
157 break;
158 }
159 case PM_ASSOC_NODE: {
160 pm_serialize_node(parser, (pm_node_t *)((pm_assoc_node_t *)node)->key, buffer);
161 if (((pm_assoc_node_t *)node)->value == NULL) {
162 pm_buffer_append_byte(buffer, 0);
163 } else {
164 pm_serialize_node(parser, (pm_node_t *)((pm_assoc_node_t *)node)->value, buffer);
165 }
166 if (((pm_assoc_node_t *)node)->operator_loc.start == NULL) {
167 pm_buffer_append_byte(buffer, 0);
168 } else {
169 pm_buffer_append_byte(buffer, 1);
170 pm_serialize_location(parser, &((pm_assoc_node_t *)node)->operator_loc, buffer);
171 }
172 break;
173 }
174 case PM_ASSOC_SPLAT_NODE: {
175 if (((pm_assoc_splat_node_t *)node)->value == NULL) {
176 pm_buffer_append_byte(buffer, 0);
177 } else {
178 pm_serialize_node(parser, (pm_node_t *)((pm_assoc_splat_node_t *)node)->value, buffer);
179 }
180 pm_serialize_location(parser, &((pm_assoc_splat_node_t *)node)->operator_loc, buffer);
181 break;
182 }
183 case PM_BACK_REFERENCE_READ_NODE: {
184 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_back_reference_read_node_t *)node)->name));
185 break;
186 }
187 case PM_BEGIN_NODE: {
188 if (((pm_begin_node_t *)node)->begin_keyword_loc.start == NULL) {
189 pm_buffer_append_byte(buffer, 0);
190 } else {
191 pm_buffer_append_byte(buffer, 1);
192 pm_serialize_location(parser, &((pm_begin_node_t *)node)->begin_keyword_loc, buffer);
193 }
194 if (((pm_begin_node_t *)node)->statements == NULL) {
195 pm_buffer_append_byte(buffer, 0);
196 } else {
197 pm_serialize_node(parser, (pm_node_t *)((pm_begin_node_t *)node)->statements, buffer);
198 }
199 if (((pm_begin_node_t *)node)->rescue_clause == NULL) {
200 pm_buffer_append_byte(buffer, 0);
201 } else {
202 pm_serialize_node(parser, (pm_node_t *)((pm_begin_node_t *)node)->rescue_clause, buffer);
203 }
204 if (((pm_begin_node_t *)node)->else_clause == NULL) {
205 pm_buffer_append_byte(buffer, 0);
206 } else {
207 pm_serialize_node(parser, (pm_node_t *)((pm_begin_node_t *)node)->else_clause, buffer);
208 }
209 if (((pm_begin_node_t *)node)->ensure_clause == NULL) {
210 pm_buffer_append_byte(buffer, 0);
211 } else {
212 pm_serialize_node(parser, (pm_node_t *)((pm_begin_node_t *)node)->ensure_clause, buffer);
213 }
214 if (((pm_begin_node_t *)node)->end_keyword_loc.start == NULL) {
215 pm_buffer_append_byte(buffer, 0);
216 } else {
217 pm_buffer_append_byte(buffer, 1);
218 pm_serialize_location(parser, &((pm_begin_node_t *)node)->end_keyword_loc, buffer);
219 }
220 break;
221 }
222 case PM_BLOCK_ARGUMENT_NODE: {
223 if (((pm_block_argument_node_t *)node)->expression == NULL) {
224 pm_buffer_append_byte(buffer, 0);
225 } else {
226 pm_serialize_node(parser, (pm_node_t *)((pm_block_argument_node_t *)node)->expression, buffer);
227 }
228 pm_serialize_location(parser, &((pm_block_argument_node_t *)node)->operator_loc, buffer);
229 break;
230 }
231 case PM_BLOCK_LOCAL_VARIABLE_NODE: {
232 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_block_local_variable_node_t *)node)->name));
233 break;
234 }
235 case PM_BLOCK_NODE: {
236 uint32_t locals_size = pm_sizet_to_u32(((pm_block_node_t *)node)->locals.size);
237 pm_buffer_append_varuint(buffer, locals_size);
238 for (uint32_t index = 0; index < locals_size; index++) {
239 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_block_node_t *)node)->locals.ids[index]));
240 }
241 pm_buffer_append_varuint(buffer, ((pm_block_node_t *)node)->locals_body_index);
242 if (((pm_block_node_t *)node)->parameters == NULL) {
243 pm_buffer_append_byte(buffer, 0);
244 } else {
245 pm_serialize_node(parser, (pm_node_t *)((pm_block_node_t *)node)->parameters, buffer);
246 }
247 if (((pm_block_node_t *)node)->body == NULL) {
248 pm_buffer_append_byte(buffer, 0);
249 } else {
250 pm_serialize_node(parser, (pm_node_t *)((pm_block_node_t *)node)->body, buffer);
251 }
252 pm_serialize_location(parser, &((pm_block_node_t *)node)->opening_loc, buffer);
253 pm_serialize_location(parser, &((pm_block_node_t *)node)->closing_loc, buffer);
254 break;
255 }
256 case PM_BLOCK_PARAMETER_NODE: {
257 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_block_parameter_node_t *)node)->name));
258 if (((pm_block_parameter_node_t *)node)->name_loc.start == NULL) {
259 pm_buffer_append_byte(buffer, 0);
260 } else {
261 pm_buffer_append_byte(buffer, 1);
262 pm_serialize_location(parser, &((pm_block_parameter_node_t *)node)->name_loc, buffer);
263 }
264 pm_serialize_location(parser, &((pm_block_parameter_node_t *)node)->operator_loc, buffer);
265 break;
266 }
267 case PM_BLOCK_PARAMETERS_NODE: {
268 if (((pm_block_parameters_node_t *)node)->parameters == NULL) {
269 pm_buffer_append_byte(buffer, 0);
270 } else {
271 pm_serialize_node(parser, (pm_node_t *)((pm_block_parameters_node_t *)node)->parameters, buffer);
272 }
273 uint32_t locals_size = pm_sizet_to_u32(((pm_block_parameters_node_t *)node)->locals.size);
274 pm_buffer_append_varuint(buffer, locals_size);
275 for (uint32_t index = 0; index < locals_size; index++) {
276 pm_serialize_node(parser, (pm_node_t *) ((pm_block_parameters_node_t *)node)->locals.nodes[index], buffer);
277 }
278 if (((pm_block_parameters_node_t *)node)->opening_loc.start == NULL) {
279 pm_buffer_append_byte(buffer, 0);
280 } else {
281 pm_buffer_append_byte(buffer, 1);
282 pm_serialize_location(parser, &((pm_block_parameters_node_t *)node)->opening_loc, buffer);
283 }
284 if (((pm_block_parameters_node_t *)node)->closing_loc.start == NULL) {
285 pm_buffer_append_byte(buffer, 0);
286 } else {
287 pm_buffer_append_byte(buffer, 1);
288 pm_serialize_location(parser, &((pm_block_parameters_node_t *)node)->closing_loc, buffer);
289 }
290 break;
291 }
292 case PM_BREAK_NODE: {
293 if (((pm_break_node_t *)node)->arguments == NULL) {
294 pm_buffer_append_byte(buffer, 0);
295 } else {
296 pm_serialize_node(parser, (pm_node_t *)((pm_break_node_t *)node)->arguments, buffer);
297 }
298 pm_serialize_location(parser, &((pm_break_node_t *)node)->keyword_loc, buffer);
299 break;
300 }
301 case PM_CALL_AND_WRITE_NODE: {
302 pm_buffer_append_varuint(buffer, (uint32_t)(node->flags & ~PM_NODE_FLAG_COMMON_MASK));
303 if (((pm_call_and_write_node_t *)node)->receiver == NULL) {
304 pm_buffer_append_byte(buffer, 0);
305 } else {
306 pm_serialize_node(parser, (pm_node_t *)((pm_call_and_write_node_t *)node)->receiver, buffer);
307 }
308 if (((pm_call_and_write_node_t *)node)->call_operator_loc.start == NULL) {
309 pm_buffer_append_byte(buffer, 0);
310 } else {
311 pm_buffer_append_byte(buffer, 1);
312 pm_serialize_location(parser, &((pm_call_and_write_node_t *)node)->call_operator_loc, buffer);
313 }
314 if (((pm_call_and_write_node_t *)node)->message_loc.start == NULL) {
315 pm_buffer_append_byte(buffer, 0);
316 } else {
317 pm_buffer_append_byte(buffer, 1);
318 pm_serialize_location(parser, &((pm_call_and_write_node_t *)node)->message_loc, buffer);
319 }
320 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_call_and_write_node_t *)node)->read_name));
321 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_call_and_write_node_t *)node)->write_name));
322 pm_serialize_location(parser, &((pm_call_and_write_node_t *)node)->operator_loc, buffer);
323 pm_serialize_node(parser, (pm_node_t *)((pm_call_and_write_node_t *)node)->value, buffer);
324 break;
325 }
326 case PM_CALL_NODE: {
327 pm_buffer_append_varuint(buffer, (uint32_t)(node->flags & ~PM_NODE_FLAG_COMMON_MASK));
328 if (((pm_call_node_t *)node)->receiver == NULL) {
329 pm_buffer_append_byte(buffer, 0);
330 } else {
331 pm_serialize_node(parser, (pm_node_t *)((pm_call_node_t *)node)->receiver, buffer);
332 }
333 if (((pm_call_node_t *)node)->call_operator_loc.start == NULL) {
334 pm_buffer_append_byte(buffer, 0);
335 } else {
336 pm_buffer_append_byte(buffer, 1);
337 pm_serialize_location(parser, &((pm_call_node_t *)node)->call_operator_loc, buffer);
338 }
339 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_call_node_t *)node)->name));
340 if (((pm_call_node_t *)node)->message_loc.start == NULL) {
341 pm_buffer_append_byte(buffer, 0);
342 } else {
343 pm_buffer_append_byte(buffer, 1);
344 pm_serialize_location(parser, &((pm_call_node_t *)node)->message_loc, buffer);
345 }
346 if (((pm_call_node_t *)node)->opening_loc.start == NULL) {
347 pm_buffer_append_byte(buffer, 0);
348 } else {
349 pm_buffer_append_byte(buffer, 1);
350 pm_serialize_location(parser, &((pm_call_node_t *)node)->opening_loc, buffer);
351 }
352 if (((pm_call_node_t *)node)->arguments == NULL) {
353 pm_buffer_append_byte(buffer, 0);
354 } else {
355 pm_serialize_node(parser, (pm_node_t *)((pm_call_node_t *)node)->arguments, buffer);
356 }
357 if (((pm_call_node_t *)node)->closing_loc.start == NULL) {
358 pm_buffer_append_byte(buffer, 0);
359 } else {
360 pm_buffer_append_byte(buffer, 1);
361 pm_serialize_location(parser, &((pm_call_node_t *)node)->closing_loc, buffer);
362 }
363 if (((pm_call_node_t *)node)->block == NULL) {
364 pm_buffer_append_byte(buffer, 0);
365 } else {
366 pm_serialize_node(parser, (pm_node_t *)((pm_call_node_t *)node)->block, buffer);
367 }
368 break;
369 }
370 case PM_CALL_OPERATOR_WRITE_NODE: {
371 pm_buffer_append_varuint(buffer, (uint32_t)(node->flags & ~PM_NODE_FLAG_COMMON_MASK));
372 if (((pm_call_operator_write_node_t *)node)->receiver == NULL) {
373 pm_buffer_append_byte(buffer, 0);
374 } else {
375 pm_serialize_node(parser, (pm_node_t *)((pm_call_operator_write_node_t *)node)->receiver, buffer);
376 }
377 if (((pm_call_operator_write_node_t *)node)->call_operator_loc.start == NULL) {
378 pm_buffer_append_byte(buffer, 0);
379 } else {
380 pm_buffer_append_byte(buffer, 1);
381 pm_serialize_location(parser, &((pm_call_operator_write_node_t *)node)->call_operator_loc, buffer);
382 }
383 if (((pm_call_operator_write_node_t *)node)->message_loc.start == NULL) {
384 pm_buffer_append_byte(buffer, 0);
385 } else {
386 pm_buffer_append_byte(buffer, 1);
387 pm_serialize_location(parser, &((pm_call_operator_write_node_t *)node)->message_loc, buffer);
388 }
389 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_call_operator_write_node_t *)node)->read_name));
390 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_call_operator_write_node_t *)node)->write_name));
391 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_call_operator_write_node_t *)node)->operator));
392 pm_serialize_location(parser, &((pm_call_operator_write_node_t *)node)->operator_loc, buffer);
393 pm_serialize_node(parser, (pm_node_t *)((pm_call_operator_write_node_t *)node)->value, buffer);
394 break;
395 }
396 case PM_CALL_OR_WRITE_NODE: {
397 pm_buffer_append_varuint(buffer, (uint32_t)(node->flags & ~PM_NODE_FLAG_COMMON_MASK));
398 if (((pm_call_or_write_node_t *)node)->receiver == NULL) {
399 pm_buffer_append_byte(buffer, 0);
400 } else {
401 pm_serialize_node(parser, (pm_node_t *)((pm_call_or_write_node_t *)node)->receiver, buffer);
402 }
403 if (((pm_call_or_write_node_t *)node)->call_operator_loc.start == NULL) {
404 pm_buffer_append_byte(buffer, 0);
405 } else {
406 pm_buffer_append_byte(buffer, 1);
407 pm_serialize_location(parser, &((pm_call_or_write_node_t *)node)->call_operator_loc, buffer);
408 }
409 if (((pm_call_or_write_node_t *)node)->message_loc.start == NULL) {
410 pm_buffer_append_byte(buffer, 0);
411 } else {
412 pm_buffer_append_byte(buffer, 1);
413 pm_serialize_location(parser, &((pm_call_or_write_node_t *)node)->message_loc, buffer);
414 }
415 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_call_or_write_node_t *)node)->read_name));
416 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_call_or_write_node_t *)node)->write_name));
417 pm_serialize_location(parser, &((pm_call_or_write_node_t *)node)->operator_loc, buffer);
418 pm_serialize_node(parser, (pm_node_t *)((pm_call_or_write_node_t *)node)->value, buffer);
419 break;
420 }
421 case PM_CALL_TARGET_NODE: {
422 pm_buffer_append_varuint(buffer, (uint32_t)(node->flags & ~PM_NODE_FLAG_COMMON_MASK));
423 pm_serialize_node(parser, (pm_node_t *)((pm_call_target_node_t *)node)->receiver, buffer);
424 pm_serialize_location(parser, &((pm_call_target_node_t *)node)->call_operator_loc, buffer);
425 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_call_target_node_t *)node)->name));
426 pm_serialize_location(parser, &((pm_call_target_node_t *)node)->message_loc, buffer);
427 break;
428 }
429 case PM_CAPTURE_PATTERN_NODE: {
430 pm_serialize_node(parser, (pm_node_t *)((pm_capture_pattern_node_t *)node)->value, buffer);
431 pm_serialize_node(parser, (pm_node_t *)((pm_capture_pattern_node_t *)node)->target, buffer);
432 pm_serialize_location(parser, &((pm_capture_pattern_node_t *)node)->operator_loc, buffer);
433 break;
434 }
435 case PM_CASE_MATCH_NODE: {
436 if (((pm_case_match_node_t *)node)->predicate == NULL) {
437 pm_buffer_append_byte(buffer, 0);
438 } else {
439 pm_serialize_node(parser, (pm_node_t *)((pm_case_match_node_t *)node)->predicate, buffer);
440 }
441 uint32_t conditions_size = pm_sizet_to_u32(((pm_case_match_node_t *)node)->conditions.size);
442 pm_buffer_append_varuint(buffer, conditions_size);
443 for (uint32_t index = 0; index < conditions_size; index++) {
444 pm_serialize_node(parser, (pm_node_t *) ((pm_case_match_node_t *)node)->conditions.nodes[index], buffer);
445 }
446 if (((pm_case_match_node_t *)node)->consequent == NULL) {
447 pm_buffer_append_byte(buffer, 0);
448 } else {
449 pm_serialize_node(parser, (pm_node_t *)((pm_case_match_node_t *)node)->consequent, buffer);
450 }
451 pm_serialize_location(parser, &((pm_case_match_node_t *)node)->case_keyword_loc, buffer);
452 pm_serialize_location(parser, &((pm_case_match_node_t *)node)->end_keyword_loc, buffer);
453 break;
454 }
455 case PM_CASE_NODE: {
456 if (((pm_case_node_t *)node)->predicate == NULL) {
457 pm_buffer_append_byte(buffer, 0);
458 } else {
459 pm_serialize_node(parser, (pm_node_t *)((pm_case_node_t *)node)->predicate, buffer);
460 }
461 uint32_t conditions_size = pm_sizet_to_u32(((pm_case_node_t *)node)->conditions.size);
462 pm_buffer_append_varuint(buffer, conditions_size);
463 for (uint32_t index = 0; index < conditions_size; index++) {
464 pm_serialize_node(parser, (pm_node_t *) ((pm_case_node_t *)node)->conditions.nodes[index], buffer);
465 }
466 if (((pm_case_node_t *)node)->consequent == NULL) {
467 pm_buffer_append_byte(buffer, 0);
468 } else {
469 pm_serialize_node(parser, (pm_node_t *)((pm_case_node_t *)node)->consequent, buffer);
470 }
471 pm_serialize_location(parser, &((pm_case_node_t *)node)->case_keyword_loc, buffer);
472 pm_serialize_location(parser, &((pm_case_node_t *)node)->end_keyword_loc, buffer);
473 break;
474 }
475 case PM_CLASS_NODE: {
476 uint32_t locals_size = pm_sizet_to_u32(((pm_class_node_t *)node)->locals.size);
477 pm_buffer_append_varuint(buffer, locals_size);
478 for (uint32_t index = 0; index < locals_size; index++) {
479 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_class_node_t *)node)->locals.ids[index]));
480 }
481 pm_serialize_location(parser, &((pm_class_node_t *)node)->class_keyword_loc, buffer);
482 pm_serialize_node(parser, (pm_node_t *)((pm_class_node_t *)node)->constant_path, buffer);
483 if (((pm_class_node_t *)node)->inheritance_operator_loc.start == NULL) {
484 pm_buffer_append_byte(buffer, 0);
485 } else {
486 pm_buffer_append_byte(buffer, 1);
487 pm_serialize_location(parser, &((pm_class_node_t *)node)->inheritance_operator_loc, buffer);
488 }
489 if (((pm_class_node_t *)node)->superclass == NULL) {
490 pm_buffer_append_byte(buffer, 0);
491 } else {
492 pm_serialize_node(parser, (pm_node_t *)((pm_class_node_t *)node)->superclass, buffer);
493 }
494 if (((pm_class_node_t *)node)->body == NULL) {
495 pm_buffer_append_byte(buffer, 0);
496 } else {
497 pm_serialize_node(parser, (pm_node_t *)((pm_class_node_t *)node)->body, buffer);
498 }
499 pm_serialize_location(parser, &((pm_class_node_t *)node)->end_keyword_loc, buffer);
500 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_class_node_t *)node)->name));
501 break;
502 }
503 case PM_CLASS_VARIABLE_AND_WRITE_NODE: {
504 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_class_variable_and_write_node_t *)node)->name));
505 pm_serialize_location(parser, &((pm_class_variable_and_write_node_t *)node)->name_loc, buffer);
506 pm_serialize_location(parser, &((pm_class_variable_and_write_node_t *)node)->operator_loc, buffer);
507 pm_serialize_node(parser, (pm_node_t *)((pm_class_variable_and_write_node_t *)node)->value, buffer);
508 break;
509 }
510 case PM_CLASS_VARIABLE_OPERATOR_WRITE_NODE: {
511 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_class_variable_operator_write_node_t *)node)->name));
512 pm_serialize_location(parser, &((pm_class_variable_operator_write_node_t *)node)->name_loc, buffer);
513 pm_serialize_location(parser, &((pm_class_variable_operator_write_node_t *)node)->operator_loc, buffer);
514 pm_serialize_node(parser, (pm_node_t *)((pm_class_variable_operator_write_node_t *)node)->value, buffer);
515 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_class_variable_operator_write_node_t *)node)->operator));
516 break;
517 }
518 case PM_CLASS_VARIABLE_OR_WRITE_NODE: {
519 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_class_variable_or_write_node_t *)node)->name));
520 pm_serialize_location(parser, &((pm_class_variable_or_write_node_t *)node)->name_loc, buffer);
521 pm_serialize_location(parser, &((pm_class_variable_or_write_node_t *)node)->operator_loc, buffer);
522 pm_serialize_node(parser, (pm_node_t *)((pm_class_variable_or_write_node_t *)node)->value, buffer);
523 break;
524 }
525 case PM_CLASS_VARIABLE_READ_NODE: {
526 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_class_variable_read_node_t *)node)->name));
527 break;
528 }
529 case PM_CLASS_VARIABLE_TARGET_NODE: {
530 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_class_variable_target_node_t *)node)->name));
531 break;
532 }
533 case PM_CLASS_VARIABLE_WRITE_NODE: {
534 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_class_variable_write_node_t *)node)->name));
535 pm_serialize_location(parser, &((pm_class_variable_write_node_t *)node)->name_loc, buffer);
536 pm_serialize_node(parser, (pm_node_t *)((pm_class_variable_write_node_t *)node)->value, buffer);
537 if (((pm_class_variable_write_node_t *)node)->operator_loc.start == NULL) {
538 pm_buffer_append_byte(buffer, 0);
539 } else {
540 pm_buffer_append_byte(buffer, 1);
541 pm_serialize_location(parser, &((pm_class_variable_write_node_t *)node)->operator_loc, buffer);
542 }
543 break;
544 }
545 case PM_CONSTANT_AND_WRITE_NODE: {
546 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_constant_and_write_node_t *)node)->name));
547 pm_serialize_location(parser, &((pm_constant_and_write_node_t *)node)->name_loc, buffer);
548 pm_serialize_location(parser, &((pm_constant_and_write_node_t *)node)->operator_loc, buffer);
549 pm_serialize_node(parser, (pm_node_t *)((pm_constant_and_write_node_t *)node)->value, buffer);
550 break;
551 }
552 case PM_CONSTANT_OPERATOR_WRITE_NODE: {
553 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_constant_operator_write_node_t *)node)->name));
554 pm_serialize_location(parser, &((pm_constant_operator_write_node_t *)node)->name_loc, buffer);
555 pm_serialize_location(parser, &((pm_constant_operator_write_node_t *)node)->operator_loc, buffer);
556 pm_serialize_node(parser, (pm_node_t *)((pm_constant_operator_write_node_t *)node)->value, buffer);
557 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_constant_operator_write_node_t *)node)->operator));
558 break;
559 }
560 case PM_CONSTANT_OR_WRITE_NODE: {
561 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_constant_or_write_node_t *)node)->name));
562 pm_serialize_location(parser, &((pm_constant_or_write_node_t *)node)->name_loc, buffer);
563 pm_serialize_location(parser, &((pm_constant_or_write_node_t *)node)->operator_loc, buffer);
564 pm_serialize_node(parser, (pm_node_t *)((pm_constant_or_write_node_t *)node)->value, buffer);
565 break;
566 }
567 case PM_CONSTANT_PATH_AND_WRITE_NODE: {
568 pm_serialize_node(parser, (pm_node_t *)((pm_constant_path_and_write_node_t *)node)->target, buffer);
569 pm_serialize_location(parser, &((pm_constant_path_and_write_node_t *)node)->operator_loc, buffer);
570 pm_serialize_node(parser, (pm_node_t *)((pm_constant_path_and_write_node_t *)node)->value, buffer);
571 break;
572 }
573 case PM_CONSTANT_PATH_NODE: {
574 if (((pm_constant_path_node_t *)node)->parent == NULL) {
575 pm_buffer_append_byte(buffer, 0);
576 } else {
577 pm_serialize_node(parser, (pm_node_t *)((pm_constant_path_node_t *)node)->parent, buffer);
578 }
579 pm_serialize_node(parser, (pm_node_t *)((pm_constant_path_node_t *)node)->child, buffer);
580 pm_serialize_location(parser, &((pm_constant_path_node_t *)node)->delimiter_loc, buffer);
581 break;
582 }
583 case PM_CONSTANT_PATH_OPERATOR_WRITE_NODE: {
584 pm_serialize_node(parser, (pm_node_t *)((pm_constant_path_operator_write_node_t *)node)->target, buffer);
585 pm_serialize_location(parser, &((pm_constant_path_operator_write_node_t *)node)->operator_loc, buffer);
586 pm_serialize_node(parser, (pm_node_t *)((pm_constant_path_operator_write_node_t *)node)->value, buffer);
587 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_constant_path_operator_write_node_t *)node)->operator));
588 break;
589 }
590 case PM_CONSTANT_PATH_OR_WRITE_NODE: {
591 pm_serialize_node(parser, (pm_node_t *)((pm_constant_path_or_write_node_t *)node)->target, buffer);
592 pm_serialize_location(parser, &((pm_constant_path_or_write_node_t *)node)->operator_loc, buffer);
593 pm_serialize_node(parser, (pm_node_t *)((pm_constant_path_or_write_node_t *)node)->value, buffer);
594 break;
595 }
596 case PM_CONSTANT_PATH_TARGET_NODE: {
597 if (((pm_constant_path_target_node_t *)node)->parent == NULL) {
598 pm_buffer_append_byte(buffer, 0);
599 } else {
600 pm_serialize_node(parser, (pm_node_t *)((pm_constant_path_target_node_t *)node)->parent, buffer);
601 }
602 pm_serialize_node(parser, (pm_node_t *)((pm_constant_path_target_node_t *)node)->child, buffer);
603 pm_serialize_location(parser, &((pm_constant_path_target_node_t *)node)->delimiter_loc, buffer);
604 break;
605 }
606 case PM_CONSTANT_PATH_WRITE_NODE: {
607 pm_serialize_node(parser, (pm_node_t *)((pm_constant_path_write_node_t *)node)->target, buffer);
608 pm_serialize_location(parser, &((pm_constant_path_write_node_t *)node)->operator_loc, buffer);
609 pm_serialize_node(parser, (pm_node_t *)((pm_constant_path_write_node_t *)node)->value, buffer);
610 break;
611 }
612 case PM_CONSTANT_READ_NODE: {
613 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_constant_read_node_t *)node)->name));
614 break;
615 }
616 case PM_CONSTANT_TARGET_NODE: {
617 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_constant_target_node_t *)node)->name));
618 break;
619 }
620 case PM_CONSTANT_WRITE_NODE: {
621 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_constant_write_node_t *)node)->name));
622 pm_serialize_location(parser, &((pm_constant_write_node_t *)node)->name_loc, buffer);
623 pm_serialize_node(parser, (pm_node_t *)((pm_constant_write_node_t *)node)->value, buffer);
624 pm_serialize_location(parser, &((pm_constant_write_node_t *)node)->operator_loc, buffer);
625 break;
626 }
627 case PM_DEF_NODE: {
628 // serialize length
629 // encoding of location u32s make us need to save this offset.
630 size_t length_offset = buffer->length;
631 pm_buffer_append_string(buffer, "\0\0\0\0", 4); /* consume 4 bytes, updated below */
632 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_def_node_t *)node)->name));
633 pm_serialize_location(parser, &((pm_def_node_t *)node)->name_loc, buffer);
634 if (((pm_def_node_t *)node)->receiver == NULL) {
635 pm_buffer_append_byte(buffer, 0);
636 } else {
637 pm_serialize_node(parser, (pm_node_t *)((pm_def_node_t *)node)->receiver, buffer);
638 }
639 if (((pm_def_node_t *)node)->parameters == NULL) {
640 pm_buffer_append_byte(buffer, 0);
641 } else {
642 pm_serialize_node(parser, (pm_node_t *)((pm_def_node_t *)node)->parameters, buffer);
643 }
644 if (((pm_def_node_t *)node)->body == NULL) {
645 pm_buffer_append_byte(buffer, 0);
646 } else {
647 pm_serialize_node(parser, (pm_node_t *)((pm_def_node_t *)node)->body, buffer);
648 }
649 uint32_t locals_size = pm_sizet_to_u32(((pm_def_node_t *)node)->locals.size);
650 pm_buffer_append_varuint(buffer, locals_size);
651 for (uint32_t index = 0; index < locals_size; index++) {
652 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_def_node_t *)node)->locals.ids[index]));
653 }
654 pm_buffer_append_varuint(buffer, ((pm_def_node_t *)node)->locals_body_index);
655 pm_serialize_location(parser, &((pm_def_node_t *)node)->def_keyword_loc, buffer);
656 if (((pm_def_node_t *)node)->operator_loc.start == NULL) {
657 pm_buffer_append_byte(buffer, 0);
658 } else {
659 pm_buffer_append_byte(buffer, 1);
660 pm_serialize_location(parser, &((pm_def_node_t *)node)->operator_loc, buffer);
661 }
662 if (((pm_def_node_t *)node)->lparen_loc.start == NULL) {
663 pm_buffer_append_byte(buffer, 0);
664 } else {
665 pm_buffer_append_byte(buffer, 1);
666 pm_serialize_location(parser, &((pm_def_node_t *)node)->lparen_loc, buffer);
667 }
668 if (((pm_def_node_t *)node)->rparen_loc.start == NULL) {
669 pm_buffer_append_byte(buffer, 0);
670 } else {
671 pm_buffer_append_byte(buffer, 1);
672 pm_serialize_location(parser, &((pm_def_node_t *)node)->rparen_loc, buffer);
673 }
674 if (((pm_def_node_t *)node)->equal_loc.start == NULL) {
675 pm_buffer_append_byte(buffer, 0);
676 } else {
677 pm_buffer_append_byte(buffer, 1);
678 pm_serialize_location(parser, &((pm_def_node_t *)node)->equal_loc, buffer);
679 }
680 if (((pm_def_node_t *)node)->end_keyword_loc.start == NULL) {
681 pm_buffer_append_byte(buffer, 0);
682 } else {
683 pm_buffer_append_byte(buffer, 1);
684 pm_serialize_location(parser, &((pm_def_node_t *)node)->end_keyword_loc, buffer);
685 }
686 // serialize length
687 uint32_t length = pm_sizet_to_u32(buffer->length - offset - sizeof(uint32_t));
688 memcpy(buffer->value + length_offset, &length, sizeof(uint32_t));
689 break;
690 }
691 case PM_DEFINED_NODE: {
692 if (((pm_defined_node_t *)node)->lparen_loc.start == NULL) {
693 pm_buffer_append_byte(buffer, 0);
694 } else {
695 pm_buffer_append_byte(buffer, 1);
696 pm_serialize_location(parser, &((pm_defined_node_t *)node)->lparen_loc, buffer);
697 }
698 pm_serialize_node(parser, (pm_node_t *)((pm_defined_node_t *)node)->value, buffer);
699 if (((pm_defined_node_t *)node)->rparen_loc.start == NULL) {
700 pm_buffer_append_byte(buffer, 0);
701 } else {
702 pm_buffer_append_byte(buffer, 1);
703 pm_serialize_location(parser, &((pm_defined_node_t *)node)->rparen_loc, buffer);
704 }
705 pm_serialize_location(parser, &((pm_defined_node_t *)node)->keyword_loc, buffer);
706 break;
707 }
708 case PM_ELSE_NODE: {
709 pm_serialize_location(parser, &((pm_else_node_t *)node)->else_keyword_loc, buffer);
710 if (((pm_else_node_t *)node)->statements == NULL) {
711 pm_buffer_append_byte(buffer, 0);
712 } else {
713 pm_serialize_node(parser, (pm_node_t *)((pm_else_node_t *)node)->statements, buffer);
714 }
715 if (((pm_else_node_t *)node)->end_keyword_loc.start == NULL) {
716 pm_buffer_append_byte(buffer, 0);
717 } else {
718 pm_buffer_append_byte(buffer, 1);
719 pm_serialize_location(parser, &((pm_else_node_t *)node)->end_keyword_loc, buffer);
720 }
721 break;
722 }
723 case PM_EMBEDDED_STATEMENTS_NODE: {
724 pm_serialize_location(parser, &((pm_embedded_statements_node_t *)node)->opening_loc, buffer);
725 if (((pm_embedded_statements_node_t *)node)->statements == NULL) {
726 pm_buffer_append_byte(buffer, 0);
727 } else {
728 pm_serialize_node(parser, (pm_node_t *)((pm_embedded_statements_node_t *)node)->statements, buffer);
729 }
730 pm_serialize_location(parser, &((pm_embedded_statements_node_t *)node)->closing_loc, buffer);
731 break;
732 }
733 case PM_EMBEDDED_VARIABLE_NODE: {
734 pm_serialize_location(parser, &((pm_embedded_variable_node_t *)node)->operator_loc, buffer);
735 pm_serialize_node(parser, (pm_node_t *)((pm_embedded_variable_node_t *)node)->variable, buffer);
736 break;
737 }
738 case PM_ENSURE_NODE: {
739 pm_serialize_location(parser, &((pm_ensure_node_t *)node)->ensure_keyword_loc, buffer);
740 if (((pm_ensure_node_t *)node)->statements == NULL) {
741 pm_buffer_append_byte(buffer, 0);
742 } else {
743 pm_serialize_node(parser, (pm_node_t *)((pm_ensure_node_t *)node)->statements, buffer);
744 }
745 pm_serialize_location(parser, &((pm_ensure_node_t *)node)->end_keyword_loc, buffer);
746 break;
747 }
748 case PM_FALSE_NODE: {
749 break;
750 }
751 case PM_FIND_PATTERN_NODE: {
752 if (((pm_find_pattern_node_t *)node)->constant == NULL) {
753 pm_buffer_append_byte(buffer, 0);
754 } else {
755 pm_serialize_node(parser, (pm_node_t *)((pm_find_pattern_node_t *)node)->constant, buffer);
756 }
757 pm_serialize_node(parser, (pm_node_t *)((pm_find_pattern_node_t *)node)->left, buffer);
758 uint32_t requireds_size = pm_sizet_to_u32(((pm_find_pattern_node_t *)node)->requireds.size);
759 pm_buffer_append_varuint(buffer, requireds_size);
760 for (uint32_t index = 0; index < requireds_size; index++) {
761 pm_serialize_node(parser, (pm_node_t *) ((pm_find_pattern_node_t *)node)->requireds.nodes[index], buffer);
762 }
763 pm_serialize_node(parser, (pm_node_t *)((pm_find_pattern_node_t *)node)->right, buffer);
764 if (((pm_find_pattern_node_t *)node)->opening_loc.start == NULL) {
765 pm_buffer_append_byte(buffer, 0);
766 } else {
767 pm_buffer_append_byte(buffer, 1);
768 pm_serialize_location(parser, &((pm_find_pattern_node_t *)node)->opening_loc, buffer);
769 }
770 if (((pm_find_pattern_node_t *)node)->closing_loc.start == NULL) {
771 pm_buffer_append_byte(buffer, 0);
772 } else {
773 pm_buffer_append_byte(buffer, 1);
774 pm_serialize_location(parser, &((pm_find_pattern_node_t *)node)->closing_loc, buffer);
775 }
776 break;
777 }
778 case PM_FLIP_FLOP_NODE: {
779 pm_buffer_append_varuint(buffer, (uint32_t)(node->flags & ~PM_NODE_FLAG_COMMON_MASK));
780 if (((pm_flip_flop_node_t *)node)->left == NULL) {
781 pm_buffer_append_byte(buffer, 0);
782 } else {
783 pm_serialize_node(parser, (pm_node_t *)((pm_flip_flop_node_t *)node)->left, buffer);
784 }
785 if (((pm_flip_flop_node_t *)node)->right == NULL) {
786 pm_buffer_append_byte(buffer, 0);
787 } else {
788 pm_serialize_node(parser, (pm_node_t *)((pm_flip_flop_node_t *)node)->right, buffer);
789 }
790 pm_serialize_location(parser, &((pm_flip_flop_node_t *)node)->operator_loc, buffer);
791 break;
792 }
793 case PM_FLOAT_NODE: {
794 break;
795 }
796 case PM_FOR_NODE: {
797 pm_serialize_node(parser, (pm_node_t *)((pm_for_node_t *)node)->index, buffer);
798 pm_serialize_node(parser, (pm_node_t *)((pm_for_node_t *)node)->collection, buffer);
799 if (((pm_for_node_t *)node)->statements == NULL) {
800 pm_buffer_append_byte(buffer, 0);
801 } else {
802 pm_serialize_node(parser, (pm_node_t *)((pm_for_node_t *)node)->statements, buffer);
803 }
804 pm_serialize_location(parser, &((pm_for_node_t *)node)->for_keyword_loc, buffer);
805 pm_serialize_location(parser, &((pm_for_node_t *)node)->in_keyword_loc, buffer);
806 if (((pm_for_node_t *)node)->do_keyword_loc.start == NULL) {
807 pm_buffer_append_byte(buffer, 0);
808 } else {
809 pm_buffer_append_byte(buffer, 1);
810 pm_serialize_location(parser, &((pm_for_node_t *)node)->do_keyword_loc, buffer);
811 }
812 pm_serialize_location(parser, &((pm_for_node_t *)node)->end_keyword_loc, buffer);
813 break;
814 }
815 case PM_FORWARDING_ARGUMENTS_NODE: {
816 break;
817 }
818 case PM_FORWARDING_PARAMETER_NODE: {
819 break;
820 }
821 case PM_FORWARDING_SUPER_NODE: {
822 if (((pm_forwarding_super_node_t *)node)->block == NULL) {
823 pm_buffer_append_byte(buffer, 0);
824 } else {
825 pm_serialize_node(parser, (pm_node_t *)((pm_forwarding_super_node_t *)node)->block, buffer);
826 }
827 break;
828 }
829 case PM_GLOBAL_VARIABLE_AND_WRITE_NODE: {
830 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_global_variable_and_write_node_t *)node)->name));
831 pm_serialize_location(parser, &((pm_global_variable_and_write_node_t *)node)->name_loc, buffer);
832 pm_serialize_location(parser, &((pm_global_variable_and_write_node_t *)node)->operator_loc, buffer);
833 pm_serialize_node(parser, (pm_node_t *)((pm_global_variable_and_write_node_t *)node)->value, buffer);
834 break;
835 }
836 case PM_GLOBAL_VARIABLE_OPERATOR_WRITE_NODE: {
837 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_global_variable_operator_write_node_t *)node)->name));
838 pm_serialize_location(parser, &((pm_global_variable_operator_write_node_t *)node)->name_loc, buffer);
839 pm_serialize_location(parser, &((pm_global_variable_operator_write_node_t *)node)->operator_loc, buffer);
840 pm_serialize_node(parser, (pm_node_t *)((pm_global_variable_operator_write_node_t *)node)->value, buffer);
841 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_global_variable_operator_write_node_t *)node)->operator));
842 break;
843 }
844 case PM_GLOBAL_VARIABLE_OR_WRITE_NODE: {
845 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_global_variable_or_write_node_t *)node)->name));
846 pm_serialize_location(parser, &((pm_global_variable_or_write_node_t *)node)->name_loc, buffer);
847 pm_serialize_location(parser, &((pm_global_variable_or_write_node_t *)node)->operator_loc, buffer);
848 pm_serialize_node(parser, (pm_node_t *)((pm_global_variable_or_write_node_t *)node)->value, buffer);
849 break;
850 }
851 case PM_GLOBAL_VARIABLE_READ_NODE: {
852 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_global_variable_read_node_t *)node)->name));
853 break;
854 }
855 case PM_GLOBAL_VARIABLE_TARGET_NODE: {
856 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_global_variable_target_node_t *)node)->name));
857 break;
858 }
859 case PM_GLOBAL_VARIABLE_WRITE_NODE: {
860 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_global_variable_write_node_t *)node)->name));
861 pm_serialize_location(parser, &((pm_global_variable_write_node_t *)node)->name_loc, buffer);
862 pm_serialize_node(parser, (pm_node_t *)((pm_global_variable_write_node_t *)node)->value, buffer);
863 pm_serialize_location(parser, &((pm_global_variable_write_node_t *)node)->operator_loc, buffer);
864 break;
865 }
866 case PM_HASH_NODE: {
867 pm_serialize_location(parser, &((pm_hash_node_t *)node)->opening_loc, buffer);
868 uint32_t elements_size = pm_sizet_to_u32(((pm_hash_node_t *)node)->elements.size);
869 pm_buffer_append_varuint(buffer, elements_size);
870 for (uint32_t index = 0; index < elements_size; index++) {
871 pm_serialize_node(parser, (pm_node_t *) ((pm_hash_node_t *)node)->elements.nodes[index], buffer);
872 }
873 pm_serialize_location(parser, &((pm_hash_node_t *)node)->closing_loc, buffer);
874 break;
875 }
876 case PM_HASH_PATTERN_NODE: {
877 if (((pm_hash_pattern_node_t *)node)->constant == NULL) {
878 pm_buffer_append_byte(buffer, 0);
879 } else {
880 pm_serialize_node(parser, (pm_node_t *)((pm_hash_pattern_node_t *)node)->constant, buffer);
881 }
882 uint32_t elements_size = pm_sizet_to_u32(((pm_hash_pattern_node_t *)node)->elements.size);
883 pm_buffer_append_varuint(buffer, elements_size);
884 for (uint32_t index = 0; index < elements_size; index++) {
885 pm_serialize_node(parser, (pm_node_t *) ((pm_hash_pattern_node_t *)node)->elements.nodes[index], buffer);
886 }
887 if (((pm_hash_pattern_node_t *)node)->rest == NULL) {
888 pm_buffer_append_byte(buffer, 0);
889 } else {
890 pm_serialize_node(parser, (pm_node_t *)((pm_hash_pattern_node_t *)node)->rest, buffer);
891 }
892 if (((pm_hash_pattern_node_t *)node)->opening_loc.start == NULL) {
893 pm_buffer_append_byte(buffer, 0);
894 } else {
895 pm_buffer_append_byte(buffer, 1);
896 pm_serialize_location(parser, &((pm_hash_pattern_node_t *)node)->opening_loc, buffer);
897 }
898 if (((pm_hash_pattern_node_t *)node)->closing_loc.start == NULL) {
899 pm_buffer_append_byte(buffer, 0);
900 } else {
901 pm_buffer_append_byte(buffer, 1);
902 pm_serialize_location(parser, &((pm_hash_pattern_node_t *)node)->closing_loc, buffer);
903 }
904 break;
905 }
906 case PM_IF_NODE: {
907 if (((pm_if_node_t *)node)->if_keyword_loc.start == NULL) {
908 pm_buffer_append_byte(buffer, 0);
909 } else {
910 pm_buffer_append_byte(buffer, 1);
911 pm_serialize_location(parser, &((pm_if_node_t *)node)->if_keyword_loc, buffer);
912 }
913 pm_serialize_node(parser, (pm_node_t *)((pm_if_node_t *)node)->predicate, buffer);
914 if (((pm_if_node_t *)node)->then_keyword_loc.start == NULL) {
915 pm_buffer_append_byte(buffer, 0);
916 } else {
917 pm_buffer_append_byte(buffer, 1);
918 pm_serialize_location(parser, &((pm_if_node_t *)node)->then_keyword_loc, buffer);
919 }
920 if (((pm_if_node_t *)node)->statements == NULL) {
921 pm_buffer_append_byte(buffer, 0);
922 } else {
923 pm_serialize_node(parser, (pm_node_t *)((pm_if_node_t *)node)->statements, buffer);
924 }
925 if (((pm_if_node_t *)node)->consequent == NULL) {
926 pm_buffer_append_byte(buffer, 0);
927 } else {
928 pm_serialize_node(parser, (pm_node_t *)((pm_if_node_t *)node)->consequent, buffer);
929 }
930 if (((pm_if_node_t *)node)->end_keyword_loc.start == NULL) {
931 pm_buffer_append_byte(buffer, 0);
932 } else {
933 pm_buffer_append_byte(buffer, 1);
934 pm_serialize_location(parser, &((pm_if_node_t *)node)->end_keyword_loc, buffer);
935 }
936 break;
937 }
938 case PM_IMAGINARY_NODE: {
939 pm_serialize_node(parser, (pm_node_t *)((pm_imaginary_node_t *)node)->numeric, buffer);
940 break;
941 }
942 case PM_IMPLICIT_NODE: {
943 pm_serialize_node(parser, (pm_node_t *)((pm_implicit_node_t *)node)->value, buffer);
944 break;
945 }
946 case PM_IMPLICIT_REST_NODE: {
947 break;
948 }
949 case PM_IN_NODE: {
950 pm_serialize_node(parser, (pm_node_t *)((pm_in_node_t *)node)->pattern, buffer);
951 if (((pm_in_node_t *)node)->statements == NULL) {
952 pm_buffer_append_byte(buffer, 0);
953 } else {
954 pm_serialize_node(parser, (pm_node_t *)((pm_in_node_t *)node)->statements, buffer);
955 }
956 pm_serialize_location(parser, &((pm_in_node_t *)node)->in_loc, buffer);
957 if (((pm_in_node_t *)node)->then_loc.start == NULL) {
958 pm_buffer_append_byte(buffer, 0);
959 } else {
960 pm_buffer_append_byte(buffer, 1);
961 pm_serialize_location(parser, &((pm_in_node_t *)node)->then_loc, buffer);
962 }
963 break;
964 }
965 case PM_INDEX_AND_WRITE_NODE: {
966 pm_buffer_append_varuint(buffer, (uint32_t)(node->flags & ~PM_NODE_FLAG_COMMON_MASK));
967 if (((pm_index_and_write_node_t *)node)->receiver == NULL) {
968 pm_buffer_append_byte(buffer, 0);
969 } else {
970 pm_serialize_node(parser, (pm_node_t *)((pm_index_and_write_node_t *)node)->receiver, buffer);
971 }
972 if (((pm_index_and_write_node_t *)node)->call_operator_loc.start == NULL) {
973 pm_buffer_append_byte(buffer, 0);
974 } else {
975 pm_buffer_append_byte(buffer, 1);
976 pm_serialize_location(parser, &((pm_index_and_write_node_t *)node)->call_operator_loc, buffer);
977 }
978 pm_serialize_location(parser, &((pm_index_and_write_node_t *)node)->opening_loc, buffer);
979 if (((pm_index_and_write_node_t *)node)->arguments == NULL) {
980 pm_buffer_append_byte(buffer, 0);
981 } else {
982 pm_serialize_node(parser, (pm_node_t *)((pm_index_and_write_node_t *)node)->arguments, buffer);
983 }
984 pm_serialize_location(parser, &((pm_index_and_write_node_t *)node)->closing_loc, buffer);
985 if (((pm_index_and_write_node_t *)node)->block == NULL) {
986 pm_buffer_append_byte(buffer, 0);
987 } else {
988 pm_serialize_node(parser, (pm_node_t *)((pm_index_and_write_node_t *)node)->block, buffer);
989 }
990 pm_serialize_location(parser, &((pm_index_and_write_node_t *)node)->operator_loc, buffer);
991 pm_serialize_node(parser, (pm_node_t *)((pm_index_and_write_node_t *)node)->value, buffer);
992 break;
993 }
994 case PM_INDEX_OPERATOR_WRITE_NODE: {
995 pm_buffer_append_varuint(buffer, (uint32_t)(node->flags & ~PM_NODE_FLAG_COMMON_MASK));
996 if (((pm_index_operator_write_node_t *)node)->receiver == NULL) {
997 pm_buffer_append_byte(buffer, 0);
998 } else {
999 pm_serialize_node(parser, (pm_node_t *)((pm_index_operator_write_node_t *)node)->receiver, buffer);
1000 }
1001 if (((pm_index_operator_write_node_t *)node)->call_operator_loc.start == NULL) {
1002 pm_buffer_append_byte(buffer, 0);
1003 } else {
1004 pm_buffer_append_byte(buffer, 1);
1005 pm_serialize_location(parser, &((pm_index_operator_write_node_t *)node)->call_operator_loc, buffer);
1006 }
1007 pm_serialize_location(parser, &((pm_index_operator_write_node_t *)node)->opening_loc, buffer);
1008 if (((pm_index_operator_write_node_t *)node)->arguments == NULL) {
1009 pm_buffer_append_byte(buffer, 0);
1010 } else {
1011 pm_serialize_node(parser, (pm_node_t *)((pm_index_operator_write_node_t *)node)->arguments, buffer);
1012 }
1013 pm_serialize_location(parser, &((pm_index_operator_write_node_t *)node)->closing_loc, buffer);
1014 if (((pm_index_operator_write_node_t *)node)->block == NULL) {
1015 pm_buffer_append_byte(buffer, 0);
1016 } else {
1017 pm_serialize_node(parser, (pm_node_t *)((pm_index_operator_write_node_t *)node)->block, buffer);
1018 }
1019 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_index_operator_write_node_t *)node)->operator));
1020 pm_serialize_location(parser, &((pm_index_operator_write_node_t *)node)->operator_loc, buffer);
1021 pm_serialize_node(parser, (pm_node_t *)((pm_index_operator_write_node_t *)node)->value, buffer);
1022 break;
1023 }
1024 case PM_INDEX_OR_WRITE_NODE: {
1025 pm_buffer_append_varuint(buffer, (uint32_t)(node->flags & ~PM_NODE_FLAG_COMMON_MASK));
1026 if (((pm_index_or_write_node_t *)node)->receiver == NULL) {
1027 pm_buffer_append_byte(buffer, 0);
1028 } else {
1029 pm_serialize_node(parser, (pm_node_t *)((pm_index_or_write_node_t *)node)->receiver, buffer);
1030 }
1031 if (((pm_index_or_write_node_t *)node)->call_operator_loc.start == NULL) {
1032 pm_buffer_append_byte(buffer, 0);
1033 } else {
1034 pm_buffer_append_byte(buffer, 1);
1035 pm_serialize_location(parser, &((pm_index_or_write_node_t *)node)->call_operator_loc, buffer);
1036 }
1037 pm_serialize_location(parser, &((pm_index_or_write_node_t *)node)->opening_loc, buffer);
1038 if (((pm_index_or_write_node_t *)node)->arguments == NULL) {
1039 pm_buffer_append_byte(buffer, 0);
1040 } else {
1041 pm_serialize_node(parser, (pm_node_t *)((pm_index_or_write_node_t *)node)->arguments, buffer);
1042 }
1043 pm_serialize_location(parser, &((pm_index_or_write_node_t *)node)->closing_loc, buffer);
1044 if (((pm_index_or_write_node_t *)node)->block == NULL) {
1045 pm_buffer_append_byte(buffer, 0);
1046 } else {
1047 pm_serialize_node(parser, (pm_node_t *)((pm_index_or_write_node_t *)node)->block, buffer);
1048 }
1049 pm_serialize_location(parser, &((pm_index_or_write_node_t *)node)->operator_loc, buffer);
1050 pm_serialize_node(parser, (pm_node_t *)((pm_index_or_write_node_t *)node)->value, buffer);
1051 break;
1052 }
1053 case PM_INDEX_TARGET_NODE: {
1054 pm_buffer_append_varuint(buffer, (uint32_t)(node->flags & ~PM_NODE_FLAG_COMMON_MASK));
1055 pm_serialize_node(parser, (pm_node_t *)((pm_index_target_node_t *)node)->receiver, buffer);
1056 pm_serialize_location(parser, &((pm_index_target_node_t *)node)->opening_loc, buffer);
1057 if (((pm_index_target_node_t *)node)->arguments == NULL) {
1058 pm_buffer_append_byte(buffer, 0);
1059 } else {
1060 pm_serialize_node(parser, (pm_node_t *)((pm_index_target_node_t *)node)->arguments, buffer);
1061 }
1062 pm_serialize_location(parser, &((pm_index_target_node_t *)node)->closing_loc, buffer);
1063 if (((pm_index_target_node_t *)node)->block == NULL) {
1064 pm_buffer_append_byte(buffer, 0);
1065 } else {
1066 pm_serialize_node(parser, (pm_node_t *)((pm_index_target_node_t *)node)->block, buffer);
1067 }
1068 break;
1069 }
1070 case PM_INSTANCE_VARIABLE_AND_WRITE_NODE: {
1071 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_instance_variable_and_write_node_t *)node)->name));
1072 pm_serialize_location(parser, &((pm_instance_variable_and_write_node_t *)node)->name_loc, buffer);
1073 pm_serialize_location(parser, &((pm_instance_variable_and_write_node_t *)node)->operator_loc, buffer);
1074 pm_serialize_node(parser, (pm_node_t *)((pm_instance_variable_and_write_node_t *)node)->value, buffer);
1075 break;
1076 }
1077 case PM_INSTANCE_VARIABLE_OPERATOR_WRITE_NODE: {
1078 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_instance_variable_operator_write_node_t *)node)->name));
1079 pm_serialize_location(parser, &((pm_instance_variable_operator_write_node_t *)node)->name_loc, buffer);
1080 pm_serialize_location(parser, &((pm_instance_variable_operator_write_node_t *)node)->operator_loc, buffer);
1081 pm_serialize_node(parser, (pm_node_t *)((pm_instance_variable_operator_write_node_t *)node)->value, buffer);
1082 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_instance_variable_operator_write_node_t *)node)->operator));
1083 break;
1084 }
1085 case PM_INSTANCE_VARIABLE_OR_WRITE_NODE: {
1086 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_instance_variable_or_write_node_t *)node)->name));
1087 pm_serialize_location(parser, &((pm_instance_variable_or_write_node_t *)node)->name_loc, buffer);
1088 pm_serialize_location(parser, &((pm_instance_variable_or_write_node_t *)node)->operator_loc, buffer);
1089 pm_serialize_node(parser, (pm_node_t *)((pm_instance_variable_or_write_node_t *)node)->value, buffer);
1090 break;
1091 }
1092 case PM_INSTANCE_VARIABLE_READ_NODE: {
1093 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_instance_variable_read_node_t *)node)->name));
1094 break;
1095 }
1096 case PM_INSTANCE_VARIABLE_TARGET_NODE: {
1097 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_instance_variable_target_node_t *)node)->name));
1098 break;
1099 }
1100 case PM_INSTANCE_VARIABLE_WRITE_NODE: {
1101 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_instance_variable_write_node_t *)node)->name));
1102 pm_serialize_location(parser, &((pm_instance_variable_write_node_t *)node)->name_loc, buffer);
1103 pm_serialize_node(parser, (pm_node_t *)((pm_instance_variable_write_node_t *)node)->value, buffer);
1104 pm_serialize_location(parser, &((pm_instance_variable_write_node_t *)node)->operator_loc, buffer);
1105 break;
1106 }
1107 case PM_INTEGER_NODE: {
1108 pm_buffer_append_varuint(buffer, (uint32_t)(node->flags & ~PM_NODE_FLAG_COMMON_MASK));
1109 break;
1110 }
1111 case PM_INTERPOLATED_MATCH_LAST_LINE_NODE: {
1112 pm_buffer_append_varuint(buffer, (uint32_t)(node->flags & ~PM_NODE_FLAG_COMMON_MASK));
1113 pm_serialize_location(parser, &((pm_interpolated_match_last_line_node_t *)node)->opening_loc, buffer);
1114 uint32_t parts_size = pm_sizet_to_u32(((pm_interpolated_match_last_line_node_t *)node)->parts.size);
1115 pm_buffer_append_varuint(buffer, parts_size);
1116 for (uint32_t index = 0; index < parts_size; index++) {
1117 pm_serialize_node(parser, (pm_node_t *) ((pm_interpolated_match_last_line_node_t *)node)->parts.nodes[index], buffer);
1118 }
1119 pm_serialize_location(parser, &((pm_interpolated_match_last_line_node_t *)node)->closing_loc, buffer);
1120 break;
1121 }
1122 case PM_INTERPOLATED_REGULAR_EXPRESSION_NODE: {
1123 pm_buffer_append_varuint(buffer, (uint32_t)(node->flags & ~PM_NODE_FLAG_COMMON_MASK));
1124 pm_serialize_location(parser, &((pm_interpolated_regular_expression_node_t *)node)->opening_loc, buffer);
1125 uint32_t parts_size = pm_sizet_to_u32(((pm_interpolated_regular_expression_node_t *)node)->parts.size);
1126 pm_buffer_append_varuint(buffer, parts_size);
1127 for (uint32_t index = 0; index < parts_size; index++) {
1128 pm_serialize_node(parser, (pm_node_t *) ((pm_interpolated_regular_expression_node_t *)node)->parts.nodes[index], buffer);
1129 }
1130 pm_serialize_location(parser, &((pm_interpolated_regular_expression_node_t *)node)->closing_loc, buffer);
1131 break;
1132 }
1133 case PM_INTERPOLATED_STRING_NODE: {
1134 if (((pm_interpolated_string_node_t *)node)->opening_loc.start == NULL) {
1135 pm_buffer_append_byte(buffer, 0);
1136 } else {
1137 pm_buffer_append_byte(buffer, 1);
1138 pm_serialize_location(parser, &((pm_interpolated_string_node_t *)node)->opening_loc, buffer);
1139 }
1140 uint32_t parts_size = pm_sizet_to_u32(((pm_interpolated_string_node_t *)node)->parts.size);
1141 pm_buffer_append_varuint(buffer, parts_size);
1142 for (uint32_t index = 0; index < parts_size; index++) {
1143 pm_serialize_node(parser, (pm_node_t *) ((pm_interpolated_string_node_t *)node)->parts.nodes[index], buffer);
1144 }
1145 if (((pm_interpolated_string_node_t *)node)->closing_loc.start == NULL) {
1146 pm_buffer_append_byte(buffer, 0);
1147 } else {
1148 pm_buffer_append_byte(buffer, 1);
1149 pm_serialize_location(parser, &((pm_interpolated_string_node_t *)node)->closing_loc, buffer);
1150 }
1151 break;
1152 }
1153 case PM_INTERPOLATED_SYMBOL_NODE: {
1154 if (((pm_interpolated_symbol_node_t *)node)->opening_loc.start == NULL) {
1155 pm_buffer_append_byte(buffer, 0);
1156 } else {
1157 pm_buffer_append_byte(buffer, 1);
1158 pm_serialize_location(parser, &((pm_interpolated_symbol_node_t *)node)->opening_loc, buffer);
1159 }
1160 uint32_t parts_size = pm_sizet_to_u32(((pm_interpolated_symbol_node_t *)node)->parts.size);
1161 pm_buffer_append_varuint(buffer, parts_size);
1162 for (uint32_t index = 0; index < parts_size; index++) {
1163 pm_serialize_node(parser, (pm_node_t *) ((pm_interpolated_symbol_node_t *)node)->parts.nodes[index], buffer);
1164 }
1165 if (((pm_interpolated_symbol_node_t *)node)->closing_loc.start == NULL) {
1166 pm_buffer_append_byte(buffer, 0);
1167 } else {
1168 pm_buffer_append_byte(buffer, 1);
1169 pm_serialize_location(parser, &((pm_interpolated_symbol_node_t *)node)->closing_loc, buffer);
1170 }
1171 break;
1172 }
1173 case PM_INTERPOLATED_X_STRING_NODE: {
1174 pm_serialize_location(parser, &((pm_interpolated_x_string_node_t *)node)->opening_loc, buffer);
1175 uint32_t parts_size = pm_sizet_to_u32(((pm_interpolated_x_string_node_t *)node)->parts.size);
1176 pm_buffer_append_varuint(buffer, parts_size);
1177 for (uint32_t index = 0; index < parts_size; index++) {
1178 pm_serialize_node(parser, (pm_node_t *) ((pm_interpolated_x_string_node_t *)node)->parts.nodes[index], buffer);
1179 }
1180 pm_serialize_location(parser, &((pm_interpolated_x_string_node_t *)node)->closing_loc, buffer);
1181 break;
1182 }
1183 case PM_KEYWORD_HASH_NODE: {
1184 pm_buffer_append_varuint(buffer, (uint32_t)(node->flags & ~PM_NODE_FLAG_COMMON_MASK));
1185 uint32_t elements_size = pm_sizet_to_u32(((pm_keyword_hash_node_t *)node)->elements.size);
1186 pm_buffer_append_varuint(buffer, elements_size);
1187 for (uint32_t index = 0; index < elements_size; index++) {
1188 pm_serialize_node(parser, (pm_node_t *) ((pm_keyword_hash_node_t *)node)->elements.nodes[index], buffer);
1189 }
1190 break;
1191 }
1192 case PM_KEYWORD_REST_PARAMETER_NODE: {
1193 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_keyword_rest_parameter_node_t *)node)->name));
1194 if (((pm_keyword_rest_parameter_node_t *)node)->name_loc.start == NULL) {
1195 pm_buffer_append_byte(buffer, 0);
1196 } else {
1197 pm_buffer_append_byte(buffer, 1);
1198 pm_serialize_location(parser, &((pm_keyword_rest_parameter_node_t *)node)->name_loc, buffer);
1199 }
1200 pm_serialize_location(parser, &((pm_keyword_rest_parameter_node_t *)node)->operator_loc, buffer);
1201 break;
1202 }
1203 case PM_LAMBDA_NODE: {
1204 uint32_t locals_size = pm_sizet_to_u32(((pm_lambda_node_t *)node)->locals.size);
1205 pm_buffer_append_varuint(buffer, locals_size);
1206 for (uint32_t index = 0; index < locals_size; index++) {
1207 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_lambda_node_t *)node)->locals.ids[index]));
1208 }
1209 pm_buffer_append_varuint(buffer, ((pm_lambda_node_t *)node)->locals_body_index);
1210 pm_serialize_location(parser, &((pm_lambda_node_t *)node)->operator_loc, buffer);
1211 pm_serialize_location(parser, &((pm_lambda_node_t *)node)->opening_loc, buffer);
1212 pm_serialize_location(parser, &((pm_lambda_node_t *)node)->closing_loc, buffer);
1213 if (((pm_lambda_node_t *)node)->parameters == NULL) {
1214 pm_buffer_append_byte(buffer, 0);
1215 } else {
1216 pm_serialize_node(parser, (pm_node_t *)((pm_lambda_node_t *)node)->parameters, buffer);
1217 }
1218 if (((pm_lambda_node_t *)node)->body == NULL) {
1219 pm_buffer_append_byte(buffer, 0);
1220 } else {
1221 pm_serialize_node(parser, (pm_node_t *)((pm_lambda_node_t *)node)->body, buffer);
1222 }
1223 break;
1224 }
1225 case PM_LOCAL_VARIABLE_AND_WRITE_NODE: {
1226 pm_serialize_location(parser, &((pm_local_variable_and_write_node_t *)node)->name_loc, buffer);
1227 pm_serialize_location(parser, &((pm_local_variable_and_write_node_t *)node)->operator_loc, buffer);
1228 pm_serialize_node(parser, (pm_node_t *)((pm_local_variable_and_write_node_t *)node)->value, buffer);
1229 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_local_variable_and_write_node_t *)node)->name));
1230 pm_buffer_append_varuint(buffer, ((pm_local_variable_and_write_node_t *)node)->depth);
1231 break;
1232 }
1233 case PM_LOCAL_VARIABLE_OPERATOR_WRITE_NODE: {
1234 pm_serialize_location(parser, &((pm_local_variable_operator_write_node_t *)node)->name_loc, buffer);
1235 pm_serialize_location(parser, &((pm_local_variable_operator_write_node_t *)node)->operator_loc, buffer);
1236 pm_serialize_node(parser, (pm_node_t *)((pm_local_variable_operator_write_node_t *)node)->value, buffer);
1237 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_local_variable_operator_write_node_t *)node)->name));
1238 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_local_variable_operator_write_node_t *)node)->operator));
1239 pm_buffer_append_varuint(buffer, ((pm_local_variable_operator_write_node_t *)node)->depth);
1240 break;
1241 }
1242 case PM_LOCAL_VARIABLE_OR_WRITE_NODE: {
1243 pm_serialize_location(parser, &((pm_local_variable_or_write_node_t *)node)->name_loc, buffer);
1244 pm_serialize_location(parser, &((pm_local_variable_or_write_node_t *)node)->operator_loc, buffer);
1245 pm_serialize_node(parser, (pm_node_t *)((pm_local_variable_or_write_node_t *)node)->value, buffer);
1246 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_local_variable_or_write_node_t *)node)->name));
1247 pm_buffer_append_varuint(buffer, ((pm_local_variable_or_write_node_t *)node)->depth);
1248 break;
1249 }
1250 case PM_LOCAL_VARIABLE_READ_NODE: {
1251 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_local_variable_read_node_t *)node)->name));
1252 pm_buffer_append_varuint(buffer, ((pm_local_variable_read_node_t *)node)->depth);
1253 break;
1254 }
1255 case PM_LOCAL_VARIABLE_TARGET_NODE: {
1256 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_local_variable_target_node_t *)node)->name));
1257 pm_buffer_append_varuint(buffer, ((pm_local_variable_target_node_t *)node)->depth);
1258 break;
1259 }
1260 case PM_LOCAL_VARIABLE_WRITE_NODE: {
1261 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_local_variable_write_node_t *)node)->name));
1262 pm_buffer_append_varuint(buffer, ((pm_local_variable_write_node_t *)node)->depth);
1263 pm_serialize_location(parser, &((pm_local_variable_write_node_t *)node)->name_loc, buffer);
1264 pm_serialize_node(parser, (pm_node_t *)((pm_local_variable_write_node_t *)node)->value, buffer);
1265 pm_serialize_location(parser, &((pm_local_variable_write_node_t *)node)->operator_loc, buffer);
1266 break;
1267 }
1268 case PM_MATCH_LAST_LINE_NODE: {
1269 pm_buffer_append_varuint(buffer, (uint32_t)(node->flags & ~PM_NODE_FLAG_COMMON_MASK));
1270 pm_serialize_location(parser, &((pm_match_last_line_node_t *)node)->opening_loc, buffer);
1271 pm_serialize_location(parser, &((pm_match_last_line_node_t *)node)->content_loc, buffer);
1272 pm_serialize_location(parser, &((pm_match_last_line_node_t *)node)->closing_loc, buffer);
1273 pm_serialize_string(parser, &((pm_match_last_line_node_t *)node)->unescaped, buffer);
1274 break;
1275 }
1276 case PM_MATCH_PREDICATE_NODE: {
1277 pm_serialize_node(parser, (pm_node_t *)((pm_match_predicate_node_t *)node)->value, buffer);
1278 pm_serialize_node(parser, (pm_node_t *)((pm_match_predicate_node_t *)node)->pattern, buffer);
1279 pm_serialize_location(parser, &((pm_match_predicate_node_t *)node)->operator_loc, buffer);
1280 break;
1281 }
1282 case PM_MATCH_REQUIRED_NODE: {
1283 pm_serialize_node(parser, (pm_node_t *)((pm_match_required_node_t *)node)->value, buffer);
1284 pm_serialize_node(parser, (pm_node_t *)((pm_match_required_node_t *)node)->pattern, buffer);
1285 pm_serialize_location(parser, &((pm_match_required_node_t *)node)->operator_loc, buffer);
1286 break;
1287 }
1288 case PM_MATCH_WRITE_NODE: {
1289 pm_serialize_node(parser, (pm_node_t *)((pm_match_write_node_t *)node)->call, buffer);
1290 uint32_t targets_size = pm_sizet_to_u32(((pm_match_write_node_t *)node)->targets.size);
1291 pm_buffer_append_varuint(buffer, targets_size);
1292 for (uint32_t index = 0; index < targets_size; index++) {
1293 pm_serialize_node(parser, (pm_node_t *) ((pm_match_write_node_t *)node)->targets.nodes[index], buffer);
1294 }
1295 break;
1296 }
1297 case PM_MISSING_NODE: {
1298 break;
1299 }
1300 case PM_MODULE_NODE: {
1301 uint32_t locals_size = pm_sizet_to_u32(((pm_module_node_t *)node)->locals.size);
1302 pm_buffer_append_varuint(buffer, locals_size);
1303 for (uint32_t index = 0; index < locals_size; index++) {
1304 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_module_node_t *)node)->locals.ids[index]));
1305 }
1306 pm_serialize_location(parser, &((pm_module_node_t *)node)->module_keyword_loc, buffer);
1307 pm_serialize_node(parser, (pm_node_t *)((pm_module_node_t *)node)->constant_path, buffer);
1308 if (((pm_module_node_t *)node)->body == NULL) {
1309 pm_buffer_append_byte(buffer, 0);
1310 } else {
1311 pm_serialize_node(parser, (pm_node_t *)((pm_module_node_t *)node)->body, buffer);
1312 }
1313 pm_serialize_location(parser, &((pm_module_node_t *)node)->end_keyword_loc, buffer);
1314 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_module_node_t *)node)->name));
1315 break;
1316 }
1317 case PM_MULTI_TARGET_NODE: {
1318 uint32_t lefts_size = pm_sizet_to_u32(((pm_multi_target_node_t *)node)->lefts.size);
1319 pm_buffer_append_varuint(buffer, lefts_size);
1320 for (uint32_t index = 0; index < lefts_size; index++) {
1321 pm_serialize_node(parser, (pm_node_t *) ((pm_multi_target_node_t *)node)->lefts.nodes[index], buffer);
1322 }
1323 if (((pm_multi_target_node_t *)node)->rest == NULL) {
1324 pm_buffer_append_byte(buffer, 0);
1325 } else {
1326 pm_serialize_node(parser, (pm_node_t *)((pm_multi_target_node_t *)node)->rest, buffer);
1327 }
1328 uint32_t rights_size = pm_sizet_to_u32(((pm_multi_target_node_t *)node)->rights.size);
1329 pm_buffer_append_varuint(buffer, rights_size);
1330 for (uint32_t index = 0; index < rights_size; index++) {
1331 pm_serialize_node(parser, (pm_node_t *) ((pm_multi_target_node_t *)node)->rights.nodes[index], buffer);
1332 }
1333 if (((pm_multi_target_node_t *)node)->lparen_loc.start == NULL) {
1334 pm_buffer_append_byte(buffer, 0);
1335 } else {
1336 pm_buffer_append_byte(buffer, 1);
1337 pm_serialize_location(parser, &((pm_multi_target_node_t *)node)->lparen_loc, buffer);
1338 }
1339 if (((pm_multi_target_node_t *)node)->rparen_loc.start == NULL) {
1340 pm_buffer_append_byte(buffer, 0);
1341 } else {
1342 pm_buffer_append_byte(buffer, 1);
1343 pm_serialize_location(parser, &((pm_multi_target_node_t *)node)->rparen_loc, buffer);
1344 }
1345 break;
1346 }
1347 case PM_MULTI_WRITE_NODE: {
1348 uint32_t lefts_size = pm_sizet_to_u32(((pm_multi_write_node_t *)node)->lefts.size);
1349 pm_buffer_append_varuint(buffer, lefts_size);
1350 for (uint32_t index = 0; index < lefts_size; index++) {
1351 pm_serialize_node(parser, (pm_node_t *) ((pm_multi_write_node_t *)node)->lefts.nodes[index], buffer);
1352 }
1353 if (((pm_multi_write_node_t *)node)->rest == NULL) {
1354 pm_buffer_append_byte(buffer, 0);
1355 } else {
1356 pm_serialize_node(parser, (pm_node_t *)((pm_multi_write_node_t *)node)->rest, buffer);
1357 }
1358 uint32_t rights_size = pm_sizet_to_u32(((pm_multi_write_node_t *)node)->rights.size);
1359 pm_buffer_append_varuint(buffer, rights_size);
1360 for (uint32_t index = 0; index < rights_size; index++) {
1361 pm_serialize_node(parser, (pm_node_t *) ((pm_multi_write_node_t *)node)->rights.nodes[index], buffer);
1362 }
1363 if (((pm_multi_write_node_t *)node)->lparen_loc.start == NULL) {
1364 pm_buffer_append_byte(buffer, 0);
1365 } else {
1366 pm_buffer_append_byte(buffer, 1);
1367 pm_serialize_location(parser, &((pm_multi_write_node_t *)node)->lparen_loc, buffer);
1368 }
1369 if (((pm_multi_write_node_t *)node)->rparen_loc.start == NULL) {
1370 pm_buffer_append_byte(buffer, 0);
1371 } else {
1372 pm_buffer_append_byte(buffer, 1);
1373 pm_serialize_location(parser, &((pm_multi_write_node_t *)node)->rparen_loc, buffer);
1374 }
1375 pm_serialize_location(parser, &((pm_multi_write_node_t *)node)->operator_loc, buffer);
1376 pm_serialize_node(parser, (pm_node_t *)((pm_multi_write_node_t *)node)->value, buffer);
1377 break;
1378 }
1379 case PM_NEXT_NODE: {
1380 if (((pm_next_node_t *)node)->arguments == NULL) {
1381 pm_buffer_append_byte(buffer, 0);
1382 } else {
1383 pm_serialize_node(parser, (pm_node_t *)((pm_next_node_t *)node)->arguments, buffer);
1384 }
1385 pm_serialize_location(parser, &((pm_next_node_t *)node)->keyword_loc, buffer);
1386 break;
1387 }
1388 case PM_NIL_NODE: {
1389 break;
1390 }
1391 case PM_NO_KEYWORDS_PARAMETER_NODE: {
1392 pm_serialize_location(parser, &((pm_no_keywords_parameter_node_t *)node)->operator_loc, buffer);
1393 pm_serialize_location(parser, &((pm_no_keywords_parameter_node_t *)node)->keyword_loc, buffer);
1394 break;
1395 }
1396 case PM_NUMBERED_PARAMETERS_NODE: {
1397 pm_buffer_append_byte(buffer, ((pm_numbered_parameters_node_t *)node)->maximum);
1398 break;
1399 }
1400 case PM_NUMBERED_REFERENCE_READ_NODE: {
1401 pm_buffer_append_varuint(buffer, ((pm_numbered_reference_read_node_t *)node)->number);
1402 break;
1403 }
1404 case PM_OPTIONAL_KEYWORD_PARAMETER_NODE: {
1405 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_optional_keyword_parameter_node_t *)node)->name));
1406 pm_serialize_location(parser, &((pm_optional_keyword_parameter_node_t *)node)->name_loc, buffer);
1407 pm_serialize_node(parser, (pm_node_t *)((pm_optional_keyword_parameter_node_t *)node)->value, buffer);
1408 break;
1409 }
1410 case PM_OPTIONAL_PARAMETER_NODE: {
1411 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_optional_parameter_node_t *)node)->name));
1412 pm_serialize_location(parser, &((pm_optional_parameter_node_t *)node)->name_loc, buffer);
1413 pm_serialize_location(parser, &((pm_optional_parameter_node_t *)node)->operator_loc, buffer);
1414 pm_serialize_node(parser, (pm_node_t *)((pm_optional_parameter_node_t *)node)->value, buffer);
1415 break;
1416 }
1417 case PM_OR_NODE: {
1418 pm_serialize_node(parser, (pm_node_t *)((pm_or_node_t *)node)->left, buffer);
1419 pm_serialize_node(parser, (pm_node_t *)((pm_or_node_t *)node)->right, buffer);
1420 pm_serialize_location(parser, &((pm_or_node_t *)node)->operator_loc, buffer);
1421 break;
1422 }
1423 case PM_PARAMETERS_NODE: {
1424 uint32_t requireds_size = pm_sizet_to_u32(((pm_parameters_node_t *)node)->requireds.size);
1425 pm_buffer_append_varuint(buffer, requireds_size);
1426 for (uint32_t index = 0; index < requireds_size; index++) {
1427 pm_serialize_node(parser, (pm_node_t *) ((pm_parameters_node_t *)node)->requireds.nodes[index], buffer);
1428 }
1429 uint32_t optionals_size = pm_sizet_to_u32(((pm_parameters_node_t *)node)->optionals.size);
1430 pm_buffer_append_varuint(buffer, optionals_size);
1431 for (uint32_t index = 0; index < optionals_size; index++) {
1432 pm_serialize_node(parser, (pm_node_t *) ((pm_parameters_node_t *)node)->optionals.nodes[index], buffer);
1433 }
1434 if (((pm_parameters_node_t *)node)->rest == NULL) {
1435 pm_buffer_append_byte(buffer, 0);
1436 } else {
1437 pm_serialize_node(parser, (pm_node_t *)((pm_parameters_node_t *)node)->rest, buffer);
1438 }
1439 uint32_t posts_size = pm_sizet_to_u32(((pm_parameters_node_t *)node)->posts.size);
1440 pm_buffer_append_varuint(buffer, posts_size);
1441 for (uint32_t index = 0; index < posts_size; index++) {
1442 pm_serialize_node(parser, (pm_node_t *) ((pm_parameters_node_t *)node)->posts.nodes[index], buffer);
1443 }
1444 uint32_t keywords_size = pm_sizet_to_u32(((pm_parameters_node_t *)node)->keywords.size);
1445 pm_buffer_append_varuint(buffer, keywords_size);
1446 for (uint32_t index = 0; index < keywords_size; index++) {
1447 pm_serialize_node(parser, (pm_node_t *) ((pm_parameters_node_t *)node)->keywords.nodes[index], buffer);
1448 }
1449 if (((pm_parameters_node_t *)node)->keyword_rest == NULL) {
1450 pm_buffer_append_byte(buffer, 0);
1451 } else {
1452 pm_serialize_node(parser, (pm_node_t *)((pm_parameters_node_t *)node)->keyword_rest, buffer);
1453 }
1454 if (((pm_parameters_node_t *)node)->block == NULL) {
1455 pm_buffer_append_byte(buffer, 0);
1456 } else {
1457 pm_serialize_node(parser, (pm_node_t *)((pm_parameters_node_t *)node)->block, buffer);
1458 }
1459 break;
1460 }
1461 case PM_PARENTHESES_NODE: {
1462 if (((pm_parentheses_node_t *)node)->body == NULL) {
1463 pm_buffer_append_byte(buffer, 0);
1464 } else {
1465 pm_serialize_node(parser, (pm_node_t *)((pm_parentheses_node_t *)node)->body, buffer);
1466 }
1467 pm_serialize_location(parser, &((pm_parentheses_node_t *)node)->opening_loc, buffer);
1468 pm_serialize_location(parser, &((pm_parentheses_node_t *)node)->closing_loc, buffer);
1469 break;
1470 }
1471 case PM_PINNED_EXPRESSION_NODE: {
1472 pm_serialize_node(parser, (pm_node_t *)((pm_pinned_expression_node_t *)node)->expression, buffer);
1473 pm_serialize_location(parser, &((pm_pinned_expression_node_t *)node)->operator_loc, buffer);
1474 pm_serialize_location(parser, &((pm_pinned_expression_node_t *)node)->lparen_loc, buffer);
1475 pm_serialize_location(parser, &((pm_pinned_expression_node_t *)node)->rparen_loc, buffer);
1476 break;
1477 }
1478 case PM_PINNED_VARIABLE_NODE: {
1479 pm_serialize_node(parser, (pm_node_t *)((pm_pinned_variable_node_t *)node)->variable, buffer);
1480 pm_serialize_location(parser, &((pm_pinned_variable_node_t *)node)->operator_loc, buffer);
1481 break;
1482 }
1483 case PM_POST_EXECUTION_NODE: {
1484 if (((pm_post_execution_node_t *)node)->statements == NULL) {
1485 pm_buffer_append_byte(buffer, 0);
1486 } else {
1487 pm_serialize_node(parser, (pm_node_t *)((pm_post_execution_node_t *)node)->statements, buffer);
1488 }
1489 pm_serialize_location(parser, &((pm_post_execution_node_t *)node)->keyword_loc, buffer);
1490 pm_serialize_location(parser, &((pm_post_execution_node_t *)node)->opening_loc, buffer);
1491 pm_serialize_location(parser, &((pm_post_execution_node_t *)node)->closing_loc, buffer);
1492 break;
1493 }
1494 case PM_PRE_EXECUTION_NODE: {
1495 if (((pm_pre_execution_node_t *)node)->statements == NULL) {
1496 pm_buffer_append_byte(buffer, 0);
1497 } else {
1498 pm_serialize_node(parser, (pm_node_t *)((pm_pre_execution_node_t *)node)->statements, buffer);
1499 }
1500 pm_serialize_location(parser, &((pm_pre_execution_node_t *)node)->keyword_loc, buffer);
1501 pm_serialize_location(parser, &((pm_pre_execution_node_t *)node)->opening_loc, buffer);
1502 pm_serialize_location(parser, &((pm_pre_execution_node_t *)node)->closing_loc, buffer);
1503 break;
1504 }
1505 case PM_PROGRAM_NODE: {
1506 uint32_t locals_size = pm_sizet_to_u32(((pm_program_node_t *)node)->locals.size);
1507 pm_buffer_append_varuint(buffer, locals_size);
1508 for (uint32_t index = 0; index < locals_size; index++) {
1509 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_program_node_t *)node)->locals.ids[index]));
1510 }
1511 pm_serialize_node(parser, (pm_node_t *)((pm_program_node_t *)node)->statements, buffer);
1512 break;
1513 }
1514 case PM_RANGE_NODE: {
1515 pm_buffer_append_varuint(buffer, (uint32_t)(node->flags & ~PM_NODE_FLAG_COMMON_MASK));
1516 if (((pm_range_node_t *)node)->left == NULL) {
1517 pm_buffer_append_byte(buffer, 0);
1518 } else {
1519 pm_serialize_node(parser, (pm_node_t *)((pm_range_node_t *)node)->left, buffer);
1520 }
1521 if (((pm_range_node_t *)node)->right == NULL) {
1522 pm_buffer_append_byte(buffer, 0);
1523 } else {
1524 pm_serialize_node(parser, (pm_node_t *)((pm_range_node_t *)node)->right, buffer);
1525 }
1526 pm_serialize_location(parser, &((pm_range_node_t *)node)->operator_loc, buffer);
1527 break;
1528 }
1529 case PM_RATIONAL_NODE: {
1530 pm_serialize_node(parser, (pm_node_t *)((pm_rational_node_t *)node)->numeric, buffer);
1531 break;
1532 }
1533 case PM_REDO_NODE: {
1534 break;
1535 }
1536 case PM_REGULAR_EXPRESSION_NODE: {
1537 pm_buffer_append_varuint(buffer, (uint32_t)(node->flags & ~PM_NODE_FLAG_COMMON_MASK));
1538 pm_serialize_location(parser, &((pm_regular_expression_node_t *)node)->opening_loc, buffer);
1539 pm_serialize_location(parser, &((pm_regular_expression_node_t *)node)->content_loc, buffer);
1540 pm_serialize_location(parser, &((pm_regular_expression_node_t *)node)->closing_loc, buffer);
1541 pm_serialize_string(parser, &((pm_regular_expression_node_t *)node)->unescaped, buffer);
1542 break;
1543 }
1544 case PM_REQUIRED_KEYWORD_PARAMETER_NODE: {
1545 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_required_keyword_parameter_node_t *)node)->name));
1546 pm_serialize_location(parser, &((pm_required_keyword_parameter_node_t *)node)->name_loc, buffer);
1547 break;
1548 }
1549 case PM_REQUIRED_PARAMETER_NODE: {
1550 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_required_parameter_node_t *)node)->name));
1551 break;
1552 }
1553 case PM_RESCUE_MODIFIER_NODE: {
1554 pm_serialize_node(parser, (pm_node_t *)((pm_rescue_modifier_node_t *)node)->expression, buffer);
1555 pm_serialize_location(parser, &((pm_rescue_modifier_node_t *)node)->keyword_loc, buffer);
1556 pm_serialize_node(parser, (pm_node_t *)((pm_rescue_modifier_node_t *)node)->rescue_expression, buffer);
1557 break;
1558 }
1559 case PM_RESCUE_NODE: {
1560 pm_serialize_location(parser, &((pm_rescue_node_t *)node)->keyword_loc, buffer);
1561 uint32_t exceptions_size = pm_sizet_to_u32(((pm_rescue_node_t *)node)->exceptions.size);
1562 pm_buffer_append_varuint(buffer, exceptions_size);
1563 for (uint32_t index = 0; index < exceptions_size; index++) {
1564 pm_serialize_node(parser, (pm_node_t *) ((pm_rescue_node_t *)node)->exceptions.nodes[index], buffer);
1565 }
1566 if (((pm_rescue_node_t *)node)->operator_loc.start == NULL) {
1567 pm_buffer_append_byte(buffer, 0);
1568 } else {
1569 pm_buffer_append_byte(buffer, 1);
1570 pm_serialize_location(parser, &((pm_rescue_node_t *)node)->operator_loc, buffer);
1571 }
1572 if (((pm_rescue_node_t *)node)->reference == NULL) {
1573 pm_buffer_append_byte(buffer, 0);
1574 } else {
1575 pm_serialize_node(parser, (pm_node_t *)((pm_rescue_node_t *)node)->reference, buffer);
1576 }
1577 if (((pm_rescue_node_t *)node)->statements == NULL) {
1578 pm_buffer_append_byte(buffer, 0);
1579 } else {
1580 pm_serialize_node(parser, (pm_node_t *)((pm_rescue_node_t *)node)->statements, buffer);
1581 }
1582 if (((pm_rescue_node_t *)node)->consequent == NULL) {
1583 pm_buffer_append_byte(buffer, 0);
1584 } else {
1585 pm_serialize_node(parser, (pm_node_t *)((pm_rescue_node_t *)node)->consequent, buffer);
1586 }
1587 break;
1588 }
1589 case PM_REST_PARAMETER_NODE: {
1590 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_rest_parameter_node_t *)node)->name));
1591 if (((pm_rest_parameter_node_t *)node)->name_loc.start == NULL) {
1592 pm_buffer_append_byte(buffer, 0);
1593 } else {
1594 pm_buffer_append_byte(buffer, 1);
1595 pm_serialize_location(parser, &((pm_rest_parameter_node_t *)node)->name_loc, buffer);
1596 }
1597 pm_serialize_location(parser, &((pm_rest_parameter_node_t *)node)->operator_loc, buffer);
1598 break;
1599 }
1600 case PM_RETRY_NODE: {
1601 break;
1602 }
1603 case PM_RETURN_NODE: {
1604 pm_serialize_location(parser, &((pm_return_node_t *)node)->keyword_loc, buffer);
1605 if (((pm_return_node_t *)node)->arguments == NULL) {
1606 pm_buffer_append_byte(buffer, 0);
1607 } else {
1608 pm_serialize_node(parser, (pm_node_t *)((pm_return_node_t *)node)->arguments, buffer);
1609 }
1610 break;
1611 }
1612 case PM_SELF_NODE: {
1613 break;
1614 }
1615 case PM_SINGLETON_CLASS_NODE: {
1616 uint32_t locals_size = pm_sizet_to_u32(((pm_singleton_class_node_t *)node)->locals.size);
1617 pm_buffer_append_varuint(buffer, locals_size);
1618 for (uint32_t index = 0; index < locals_size; index++) {
1619 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_singleton_class_node_t *)node)->locals.ids[index]));
1620 }
1621 pm_serialize_location(parser, &((pm_singleton_class_node_t *)node)->class_keyword_loc, buffer);
1622 pm_serialize_location(parser, &((pm_singleton_class_node_t *)node)->operator_loc, buffer);
1623 pm_serialize_node(parser, (pm_node_t *)((pm_singleton_class_node_t *)node)->expression, buffer);
1624 if (((pm_singleton_class_node_t *)node)->body == NULL) {
1625 pm_buffer_append_byte(buffer, 0);
1626 } else {
1627 pm_serialize_node(parser, (pm_node_t *)((pm_singleton_class_node_t *)node)->body, buffer);
1628 }
1629 pm_serialize_location(parser, &((pm_singleton_class_node_t *)node)->end_keyword_loc, buffer);
1630 break;
1631 }
1632 case PM_SOURCE_ENCODING_NODE: {
1633 break;
1634 }
1635 case PM_SOURCE_FILE_NODE: {
1636 pm_serialize_string(parser, &((pm_source_file_node_t *)node)->filepath, buffer);
1637 break;
1638 }
1639 case PM_SOURCE_LINE_NODE: {
1640 break;
1641 }
1642 case PM_SPLAT_NODE: {
1643 pm_serialize_location(parser, &((pm_splat_node_t *)node)->operator_loc, buffer);
1644 if (((pm_splat_node_t *)node)->expression == NULL) {
1645 pm_buffer_append_byte(buffer, 0);
1646 } else {
1647 pm_serialize_node(parser, (pm_node_t *)((pm_splat_node_t *)node)->expression, buffer);
1648 }
1649 break;
1650 }
1651 case PM_STATEMENTS_NODE: {
1652 uint32_t body_size = pm_sizet_to_u32(((pm_statements_node_t *)node)->body.size);
1653 pm_buffer_append_varuint(buffer, body_size);
1654 for (uint32_t index = 0; index < body_size; index++) {
1655 pm_serialize_node(parser, (pm_node_t *) ((pm_statements_node_t *)node)->body.nodes[index], buffer);
1656 }
1657 break;
1658 }
1659 case PM_STRING_NODE: {
1660 pm_buffer_append_varuint(buffer, (uint32_t)(node->flags & ~PM_NODE_FLAG_COMMON_MASK));
1661 if (((pm_string_node_t *)node)->opening_loc.start == NULL) {
1662 pm_buffer_append_byte(buffer, 0);
1663 } else {
1664 pm_buffer_append_byte(buffer, 1);
1665 pm_serialize_location(parser, &((pm_string_node_t *)node)->opening_loc, buffer);
1666 }
1667 pm_serialize_location(parser, &((pm_string_node_t *)node)->content_loc, buffer);
1668 if (((pm_string_node_t *)node)->closing_loc.start == NULL) {
1669 pm_buffer_append_byte(buffer, 0);
1670 } else {
1671 pm_buffer_append_byte(buffer, 1);
1672 pm_serialize_location(parser, &((pm_string_node_t *)node)->closing_loc, buffer);
1673 }
1674 pm_serialize_string(parser, &((pm_string_node_t *)node)->unescaped, buffer);
1675 break;
1676 }
1677 case PM_SUPER_NODE: {
1678 pm_serialize_location(parser, &((pm_super_node_t *)node)->keyword_loc, buffer);
1679 if (((pm_super_node_t *)node)->lparen_loc.start == NULL) {
1680 pm_buffer_append_byte(buffer, 0);
1681 } else {
1682 pm_buffer_append_byte(buffer, 1);
1683 pm_serialize_location(parser, &((pm_super_node_t *)node)->lparen_loc, buffer);
1684 }
1685 if (((pm_super_node_t *)node)->arguments == NULL) {
1686 pm_buffer_append_byte(buffer, 0);
1687 } else {
1688 pm_serialize_node(parser, (pm_node_t *)((pm_super_node_t *)node)->arguments, buffer);
1689 }
1690 if (((pm_super_node_t *)node)->rparen_loc.start == NULL) {
1691 pm_buffer_append_byte(buffer, 0);
1692 } else {
1693 pm_buffer_append_byte(buffer, 1);
1694 pm_serialize_location(parser, &((pm_super_node_t *)node)->rparen_loc, buffer);
1695 }
1696 if (((pm_super_node_t *)node)->block == NULL) {
1697 pm_buffer_append_byte(buffer, 0);
1698 } else {
1699 pm_serialize_node(parser, (pm_node_t *)((pm_super_node_t *)node)->block, buffer);
1700 }
1701 break;
1702 }
1703 case PM_SYMBOL_NODE: {
1704 pm_buffer_append_varuint(buffer, (uint32_t)(node->flags & ~PM_NODE_FLAG_COMMON_MASK));
1705 if (((pm_symbol_node_t *)node)->opening_loc.start == NULL) {
1706 pm_buffer_append_byte(buffer, 0);
1707 } else {
1708 pm_buffer_append_byte(buffer, 1);
1709 pm_serialize_location(parser, &((pm_symbol_node_t *)node)->opening_loc, buffer);
1710 }
1711 if (((pm_symbol_node_t *)node)->value_loc.start == NULL) {
1712 pm_buffer_append_byte(buffer, 0);
1713 } else {
1714 pm_buffer_append_byte(buffer, 1);
1715 pm_serialize_location(parser, &((pm_symbol_node_t *)node)->value_loc, buffer);
1716 }
1717 if (((pm_symbol_node_t *)node)->closing_loc.start == NULL) {
1718 pm_buffer_append_byte(buffer, 0);
1719 } else {
1720 pm_buffer_append_byte(buffer, 1);
1721 pm_serialize_location(parser, &((pm_symbol_node_t *)node)->closing_loc, buffer);
1722 }
1723 pm_serialize_string(parser, &((pm_symbol_node_t *)node)->unescaped, buffer);
1724 break;
1725 }
1726 case PM_TRUE_NODE: {
1727 break;
1728 }
1729 case PM_UNDEF_NODE: {
1730 uint32_t names_size = pm_sizet_to_u32(((pm_undef_node_t *)node)->names.size);
1731 pm_buffer_append_varuint(buffer, names_size);
1732 for (uint32_t index = 0; index < names_size; index++) {
1733 pm_serialize_node(parser, (pm_node_t *) ((pm_undef_node_t *)node)->names.nodes[index], buffer);
1734 }
1735 pm_serialize_location(parser, &((pm_undef_node_t *)node)->keyword_loc, buffer);
1736 break;
1737 }
1738 case PM_UNLESS_NODE: {
1739 pm_serialize_location(parser, &((pm_unless_node_t *)node)->keyword_loc, buffer);
1740 pm_serialize_node(parser, (pm_node_t *)((pm_unless_node_t *)node)->predicate, buffer);
1741 if (((pm_unless_node_t *)node)->then_keyword_loc.start == NULL) {
1742 pm_buffer_append_byte(buffer, 0);
1743 } else {
1744 pm_buffer_append_byte(buffer, 1);
1745 pm_serialize_location(parser, &((pm_unless_node_t *)node)->then_keyword_loc, buffer);
1746 }
1747 if (((pm_unless_node_t *)node)->statements == NULL) {
1748 pm_buffer_append_byte(buffer, 0);
1749 } else {
1750 pm_serialize_node(parser, (pm_node_t *)((pm_unless_node_t *)node)->statements, buffer);
1751 }
1752 if (((pm_unless_node_t *)node)->consequent == NULL) {
1753 pm_buffer_append_byte(buffer, 0);
1754 } else {
1755 pm_serialize_node(parser, (pm_node_t *)((pm_unless_node_t *)node)->consequent, buffer);
1756 }
1757 if (((pm_unless_node_t *)node)->end_keyword_loc.start == NULL) {
1758 pm_buffer_append_byte(buffer, 0);
1759 } else {
1760 pm_buffer_append_byte(buffer, 1);
1761 pm_serialize_location(parser, &((pm_unless_node_t *)node)->end_keyword_loc, buffer);
1762 }
1763 break;
1764 }
1765 case PM_UNTIL_NODE: {
1766 pm_buffer_append_varuint(buffer, (uint32_t)(node->flags & ~PM_NODE_FLAG_COMMON_MASK));
1767 pm_serialize_location(parser, &((pm_until_node_t *)node)->keyword_loc, buffer);
1768 if (((pm_until_node_t *)node)->closing_loc.start == NULL) {
1769 pm_buffer_append_byte(buffer, 0);
1770 } else {
1771 pm_buffer_append_byte(buffer, 1);
1772 pm_serialize_location(parser, &((pm_until_node_t *)node)->closing_loc, buffer);
1773 }
1774 pm_serialize_node(parser, (pm_node_t *)((pm_until_node_t *)node)->predicate, buffer);
1775 if (((pm_until_node_t *)node)->statements == NULL) {
1776 pm_buffer_append_byte(buffer, 0);
1777 } else {
1778 pm_serialize_node(parser, (pm_node_t *)((pm_until_node_t *)node)->statements, buffer);
1779 }
1780 break;
1781 }
1782 case PM_WHEN_NODE: {
1783 pm_serialize_location(parser, &((pm_when_node_t *)node)->keyword_loc, buffer);
1784 uint32_t conditions_size = pm_sizet_to_u32(((pm_when_node_t *)node)->conditions.size);
1785 pm_buffer_append_varuint(buffer, conditions_size);
1786 for (uint32_t index = 0; index < conditions_size; index++) {
1787 pm_serialize_node(parser, (pm_node_t *) ((pm_when_node_t *)node)->conditions.nodes[index], buffer);
1788 }
1789 if (((pm_when_node_t *)node)->statements == NULL) {
1790 pm_buffer_append_byte(buffer, 0);
1791 } else {
1792 pm_serialize_node(parser, (pm_node_t *)((pm_when_node_t *)node)->statements, buffer);
1793 }
1794 break;
1795 }
1796 case PM_WHILE_NODE: {
1797 pm_buffer_append_varuint(buffer, (uint32_t)(node->flags & ~PM_NODE_FLAG_COMMON_MASK));
1798 pm_serialize_location(parser, &((pm_while_node_t *)node)->keyword_loc, buffer);
1799 if (((pm_while_node_t *)node)->closing_loc.start == NULL) {
1800 pm_buffer_append_byte(buffer, 0);
1801 } else {
1802 pm_buffer_append_byte(buffer, 1);
1803 pm_serialize_location(parser, &((pm_while_node_t *)node)->closing_loc, buffer);
1804 }
1805 pm_serialize_node(parser, (pm_node_t *)((pm_while_node_t *)node)->predicate, buffer);
1806 if (((pm_while_node_t *)node)->statements == NULL) {
1807 pm_buffer_append_byte(buffer, 0);
1808 } else {
1809 pm_serialize_node(parser, (pm_node_t *)((pm_while_node_t *)node)->statements, buffer);
1810 }
1811 break;
1812 }
1813 case PM_X_STRING_NODE: {
1814 pm_buffer_append_varuint(buffer, (uint32_t)(node->flags & ~PM_NODE_FLAG_COMMON_MASK));
1815 pm_serialize_location(parser, &((pm_x_string_node_t *)node)->opening_loc, buffer);
1816 pm_serialize_location(parser, &((pm_x_string_node_t *)node)->content_loc, buffer);
1817 pm_serialize_location(parser, &((pm_x_string_node_t *)node)->closing_loc, buffer);
1818 pm_serialize_string(parser, &((pm_x_string_node_t *)node)->unescaped, buffer);
1819 break;
1820 }
1821 case PM_YIELD_NODE: {
1822 pm_serialize_location(parser, &((pm_yield_node_t *)node)->keyword_loc, buffer);
1823 if (((pm_yield_node_t *)node)->lparen_loc.start == NULL) {
1824 pm_buffer_append_byte(buffer, 0);
1825 } else {
1826 pm_buffer_append_byte(buffer, 1);
1827 pm_serialize_location(parser, &((pm_yield_node_t *)node)->lparen_loc, buffer);
1828 }
1829 if (((pm_yield_node_t *)node)->arguments == NULL) {
1830 pm_buffer_append_byte(buffer, 0);
1831 } else {
1832 pm_serialize_node(parser, (pm_node_t *)((pm_yield_node_t *)node)->arguments, buffer);
1833 }
1834 if (((pm_yield_node_t *)node)->rparen_loc.start == NULL) {
1835 pm_buffer_append_byte(buffer, 0);
1836 } else {
1837 pm_buffer_append_byte(buffer, 1);
1838 pm_serialize_location(parser, &((pm_yield_node_t *)node)->rparen_loc, buffer);
1839 }
1840 break;
1841 }
1842 }
1843}
1844
1845static void
1846pm_serialize_comment(pm_parser_t *parser, pm_comment_t *comment, pm_buffer_t *buffer) {
1847 // serialize type
1848 pm_buffer_append_byte(buffer, (uint8_t) comment->type);
1849
1850 // serialize location
1851 pm_serialize_location(parser, &comment->location, buffer);
1852}
1853
1857void
1858pm_serialize_comment_list(pm_parser_t *parser, pm_list_t *list, pm_buffer_t *buffer) {
1859 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(pm_list_size(list)));
1860
1861 pm_comment_t *comment;
1862 for (comment = (pm_comment_t *) list->head; comment != NULL; comment = (pm_comment_t *) comment->node.next) {
1863 pm_serialize_comment(parser, comment, buffer);
1864 }
1865}
1866
1867static void
1868pm_serialize_magic_comment(pm_parser_t *parser, pm_magic_comment_t *magic_comment, pm_buffer_t *buffer) {
1869 // serialize key location
1870 pm_buffer_append_varuint(buffer, pm_ptrdifft_to_u32(magic_comment->key_start - parser->start));
1871 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(magic_comment->key_length));
1872
1873 // serialize value location
1874 pm_buffer_append_varuint(buffer, pm_ptrdifft_to_u32(magic_comment->value_start - parser->start));
1875 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(magic_comment->value_length));
1876}
1877
1878static void
1879pm_serialize_magic_comment_list(pm_parser_t *parser, pm_list_t *list, pm_buffer_t *buffer) {
1880 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(pm_list_size(list)));
1881
1882 pm_magic_comment_t *magic_comment;
1883 for (magic_comment = (pm_magic_comment_t *) list->head; magic_comment != NULL; magic_comment = (pm_magic_comment_t *) magic_comment->node.next) {
1884 pm_serialize_magic_comment(parser, magic_comment, buffer);
1885 }
1886}
1887
1888static void
1889pm_serialize_data_loc(const pm_parser_t *parser, pm_buffer_t *buffer) {
1890 if (parser->data_loc.end == NULL) {
1891 pm_buffer_append_byte(buffer, 0);
1892 } else {
1893 pm_buffer_append_byte(buffer, 1);
1894 pm_serialize_location(parser, &parser->data_loc, buffer);
1895 }
1896}
1897
1898static void
1899pm_serialize_diagnostic(pm_parser_t *parser, pm_diagnostic_t *diagnostic, pm_buffer_t *buffer) {
1900 // serialize message
1901 size_t message_length = strlen(diagnostic->message);
1902 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(message_length));
1903 pm_buffer_append_string(buffer, diagnostic->message, message_length);
1904
1905 // serialize location
1906 pm_serialize_location(parser, &diagnostic->location, buffer);
1907}
1908
1909static void
1910pm_serialize_diagnostic_list(pm_parser_t *parser, pm_list_t *list, pm_buffer_t *buffer) {
1911 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(pm_list_size(list)));
1912
1913 pm_diagnostic_t *diagnostic;
1914 for (diagnostic = (pm_diagnostic_t *) list->head; diagnostic != NULL; diagnostic = (pm_diagnostic_t *) diagnostic->node.next) {
1915 pm_serialize_diagnostic(parser, diagnostic, buffer);
1916 }
1917}
1918
1922void
1923pm_serialize_encoding(const pm_encoding_t *encoding, pm_buffer_t *buffer) {
1924 size_t encoding_length = strlen(encoding->name);
1925 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(encoding_length));
1926 pm_buffer_append_string(buffer, encoding->name, encoding_length);
1927}
1928
1929#line 216 "serialize.c.erb"
1933void
1934pm_serialize_content(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) {
1935 pm_serialize_encoding(parser->encoding, buffer);
1936 pm_buffer_append_varsint(buffer, parser->start_line);
1937 pm_serialize_comment_list(parser, &parser->comment_list, buffer);
1938 pm_serialize_magic_comment_list(parser, &parser->magic_comment_list, buffer);
1939 pm_serialize_data_loc(parser, buffer);
1940 pm_serialize_diagnostic_list(parser, &parser->error_list, buffer);
1941 pm_serialize_diagnostic_list(parser, &parser->warning_list, buffer);
1942
1943 // Here we're going to leave space for the offset of the constant pool in
1944 // the buffer.
1945 size_t offset = buffer->length;
1946 pm_buffer_append_zeroes(buffer, 4);
1947
1948 // Next, encode the length of the constant pool.
1949 pm_buffer_append_varuint(buffer, parser->constant_pool.size);
1950
1951 // Now we're going to serialize the content of the node.
1952 pm_serialize_node(parser, node, buffer);
1953
1954 // Now we're going to serialize the offset of the constant pool back where
1955 // we left space for it.
1956 uint32_t length = pm_sizet_to_u32(buffer->length);
1957 memcpy(buffer->value + offset, &length, sizeof(uint32_t));
1958
1959 // Now we're going to serialize the constant pool.
1960 offset = buffer->length;
1961 pm_buffer_append_zeroes(buffer, parser->constant_pool.size * 8);
1962
1963 for (uint32_t index = 0; index < parser->constant_pool.capacity; index++) {
1964 pm_constant_pool_bucket_t *bucket = &parser->constant_pool.buckets[index];
1965
1966 // If we find a constant at this index, serialize it at the correct
1967 // index in the buffer.
1968 if (bucket->id != 0) {
1969 pm_constant_t *constant = &parser->constant_pool.constants[bucket->id - 1];
1970 size_t buffer_offset = offset + ((((size_t)bucket->id) - 1) * 8);
1971
1972 if (bucket->type == PM_CONSTANT_POOL_BUCKET_OWNED || bucket->type == PM_CONSTANT_POOL_BUCKET_CONSTANT) {
1973 // Since this is an owned or constant constant, we are going to
1974 // write its contents into the buffer after the constant pool.
1975 // So effectively in place of the source offset, we have a
1976 // buffer offset. We will add a leading 1 to indicate that this
1977 // is a buffer offset.
1978 uint32_t content_offset = pm_sizet_to_u32(buffer->length);
1979 uint32_t owned_mask = (uint32_t) (1 << 31);
1980
1981 assert(content_offset < owned_mask);
1982 content_offset |= owned_mask;
1983
1984 memcpy(buffer->value + buffer_offset, &content_offset, 4);
1985 pm_buffer_append_bytes(buffer, constant->start, constant->length);
1986 } else {
1987 // Since this is a shared constant, we are going to write its
1988 // source offset directly into the buffer.
1989 uint32_t source_offset = pm_ptrdifft_to_u32(constant->start - parser->start);
1990 memcpy(buffer->value + buffer_offset, &source_offset, 4);
1991 }
1992
1993 // Now we can write the length of the constant into the buffer.
1994 uint32_t constant_length = pm_sizet_to_u32(constant->length);
1995 memcpy(buffer->value + buffer_offset + 4, &constant_length, 4);
1996 }
1997 }
1998}
1999
2000static void
2001serialize_token(void *data, pm_parser_t *parser, pm_token_t *token) {
2002 pm_buffer_t *buffer = (pm_buffer_t *) data;
2003
2004 pm_buffer_append_varuint(buffer, token->type);
2005 pm_buffer_append_varuint(buffer, pm_ptrdifft_to_u32(token->start - parser->start));
2006 pm_buffer_append_varuint(buffer, pm_ptrdifft_to_u32(token->end - token->start));
2007 pm_buffer_append_varuint(buffer, parser->lex_state);
2008}
2009
2013 PRISM_EXPORTED_FUNCTION void
2014pm_serialize_lex(pm_buffer_t *buffer, const uint8_t *source, size_t size, const char *data) {
2015 pm_options_t options = { 0 };
2016 pm_options_read(&options, data);
2017
2018 pm_parser_t parser;
2019 pm_parser_init(&parser, source, size, &options);
2020
2021 pm_lex_callback_t lex_callback = (pm_lex_callback_t) {
2022 .data = (void *) buffer,
2023 .callback = serialize_token,
2024 };
2025
2026 parser.lex_callback = &lex_callback;
2027 pm_node_t *node = pm_parse(&parser);
2028
2029 // Append 0 to mark end of tokens.
2030 pm_buffer_append_byte(buffer, 0);
2031
2032 pm_serialize_encoding(parser.encoding, buffer);
2033 pm_buffer_append_varsint(buffer, parser.start_line);
2034 pm_serialize_comment_list(&parser, &parser.comment_list, buffer);
2035 pm_serialize_magic_comment_list(&parser, &parser.magic_comment_list, buffer);
2036 pm_serialize_data_loc(&parser, buffer);
2037 pm_serialize_diagnostic_list(&parser, &parser.error_list, buffer);
2038 pm_serialize_diagnostic_list(&parser, &parser.warning_list, buffer);
2039
2040 pm_node_destroy(&parser, node);
2041 pm_parser_free(&parser);
2042 pm_options_free(&options);
2043}
2044
2049 PRISM_EXPORTED_FUNCTION void
2050pm_serialize_parse_lex(pm_buffer_t *buffer, const uint8_t *source, size_t size, const char *data) {
2051 pm_options_t options = { 0 };
2052 pm_options_read(&options, data);
2053
2054 pm_parser_t parser;
2055 pm_parser_init(&parser, source, size, &options);
2056
2057 pm_lex_callback_t lex_callback = (pm_lex_callback_t) {
2058 .data = (void *) buffer,
2059 .callback = serialize_token,
2060 };
2061
2062 parser.lex_callback = &lex_callback;
2063 pm_node_t *node = pm_parse(&parser);
2064
2065 pm_buffer_append_byte(buffer, 0);
2066 pm_serialize(&parser, node, buffer);
2067
2068 pm_node_destroy(&parser, node);
2069 pm_parser_free(&parser);
2070 pm_options_free(&options);
2071}
2072
2076 PRISM_EXPORTED_FUNCTION bool
2077pm_parse_success_p(const uint8_t *source, size_t size, const char *data) {
2078 pm_options_t options = { 0 };
2079 pm_options_read(&options, data);
2080
2081 pm_parser_t parser;
2082 pm_parser_init(&parser, source, size, &options);
2083
2084 pm_node_t *node = pm_parse(&parser);
2085 pm_node_destroy(&parser, node);
2086
2087 bool result = parser.error_list.size == 0 && parser.warning_list.size == 0;
2088 pm_parser_free(&parser);
2089 pm_options_free(&options);
2090
2091 return result;
2092}
PM_DEFINED_NODE
@ PM_DEFINED_NODE
DefinedNode.
Definition ast.h:707
PM_PRE_EXECUTION_NODE
@ PM_PRE_EXECUTION_NODE
PreExecutionNode.
Definition ast.h:923
PM_RETRY_NODE
@ PM_RETRY_NODE
RetryNode.
Definition ast.h:956
PM_REDO_NODE
@ PM_REDO_NODE
RedoNode.
Definition ast.h:935
PM_CONSTANT_PATH_WRITE_NODE
@ PM_CONSTANT_PATH_WRITE_NODE
ConstantPathWriteNode.
Definition ast.h:692
PM_INDEX_AND_WRITE_NODE
@ PM_INDEX_AND_WRITE_NODE
IndexAndWriteNode.
Definition ast.h:785
PM_SOURCE_LINE_NODE
@ PM_SOURCE_LINE_NODE
SourceLineNode.
Definition ast.h:974
PM_UNLESS_NODE
@ PM_UNLESS_NODE
UnlessNode.
Definition ast.h:998
PM_EMBEDDED_VARIABLE_NODE
@ PM_EMBEDDED_VARIABLE_NODE
EmbeddedVariableNode.
Definition ast.h:716
PM_GLOBAL_VARIABLE_OPERATOR_WRITE_NODE
@ PM_GLOBAL_VARIABLE_OPERATOR_WRITE_NODE
GlobalVariableOperatorWriteNode.
Definition ast.h:749
PM_CALL_NODE
@ PM_CALL_NODE
CallNode.
Definition ast.h:626
PM_NIL_NODE
@ PM_NIL_NODE
NilNode.
Definition ast.h:887
PM_GLOBAL_VARIABLE_READ_NODE
@ PM_GLOBAL_VARIABLE_READ_NODE
GlobalVariableReadNode.
Definition ast.h:755
PM_RATIONAL_NODE
@ PM_RATIONAL_NODE
RationalNode.
Definition ast.h:932
PM_YIELD_NODE
@ PM_YIELD_NODE
YieldNode.
Definition ast.h:1013
PM_LOCAL_VARIABLE_AND_WRITE_NODE
@ PM_LOCAL_VARIABLE_AND_WRITE_NODE
LocalVariableAndWriteNode.
Definition ast.h:842
PM_CONSTANT_AND_WRITE_NODE
@ PM_CONSTANT_AND_WRITE_NODE
ConstantAndWriteNode.
Definition ast.h:668
PM_CLASS_NODE
@ PM_CLASS_NODE
ClassNode.
Definition ast.h:647
PM_FIND_PATTERN_NODE
@ PM_FIND_PATTERN_NODE
FindPatternNode.
Definition ast.h:725
PM_CALL_OPERATOR_WRITE_NODE
@ PM_CALL_OPERATOR_WRITE_NODE
CallOperatorWriteNode.
Definition ast.h:629
PM_MATCH_WRITE_NODE
@ PM_MATCH_WRITE_NODE
MatchWriteNode.
Definition ast.h:869
PM_ARRAY_NODE
@ PM_ARRAY_NODE
ArrayNode.
Definition ast.h:587
PM_CONSTANT_PATH_TARGET_NODE
@ PM_CONSTANT_PATH_TARGET_NODE
ConstantPathTargetNode.
Definition ast.h:689
PM_PROGRAM_NODE
@ PM_PROGRAM_NODE
ProgramNode.
Definition ast.h:926
PM_OR_NODE
@ PM_OR_NODE
OrNode.
Definition ast.h:905
PM_MULTI_WRITE_NODE
@ PM_MULTI_WRITE_NODE
MultiWriteNode.
Definition ast.h:881
PM_IF_NODE
@ PM_IF_NODE
IfNode.
Definition ast.h:770
PM_IMPLICIT_NODE
@ PM_IMPLICIT_NODE
ImplicitNode.
Definition ast.h:776
PM_ARGUMENTS_NODE
@ PM_ARGUMENTS_NODE
ArgumentsNode.
Definition ast.h:584
PM_FORWARDING_SUPER_NODE
@ PM_FORWARDING_SUPER_NODE
ForwardingSuperNode.
Definition ast.h:743
PM_WHILE_NODE
@ PM_WHILE_NODE
WhileNode.
Definition ast.h:1007
PM_INTERPOLATED_STRING_NODE
@ PM_INTERPOLATED_STRING_NODE
InterpolatedStringNode.
Definition ast.h:824
PM_FALSE_NODE
@ PM_FALSE_NODE
FalseNode.
Definition ast.h:722
PM_FORWARDING_PARAMETER_NODE
@ PM_FORWARDING_PARAMETER_NODE
ForwardingParameterNode.
Definition ast.h:740
PM_BLOCK_LOCAL_VARIABLE_NODE
@ PM_BLOCK_LOCAL_VARIABLE_NODE
BlockLocalVariableNode.
Definition ast.h:608
PM_HASH_NODE
@ PM_HASH_NODE
HashNode.
Definition ast.h:764
PM_UNTIL_NODE
@ PM_UNTIL_NODE
UntilNode.
Definition ast.h:1001
PM_MATCH_PREDICATE_NODE
@ PM_MATCH_PREDICATE_NODE
MatchPredicateNode.
Definition ast.h:863
PM_X_STRING_NODE
@ PM_X_STRING_NODE
XStringNode.
Definition ast.h:1010
PM_LOCAL_VARIABLE_OPERATOR_WRITE_NODE
@ PM_LOCAL_VARIABLE_OPERATOR_WRITE_NODE
LocalVariableOperatorWriteNode.
Definition ast.h:845
PM_LOCAL_VARIABLE_OR_WRITE_NODE
@ PM_LOCAL_VARIABLE_OR_WRITE_NODE
LocalVariableOrWriteNode.
Definition ast.h:848
PM_INSTANCE_VARIABLE_AND_WRITE_NODE
@ PM_INSTANCE_VARIABLE_AND_WRITE_NODE
InstanceVariableAndWriteNode.
Definition ast.h:797
PM_GLOBAL_VARIABLE_TARGET_NODE
@ PM_GLOBAL_VARIABLE_TARGET_NODE
GlobalVariableTargetNode.
Definition ast.h:758
PM_AND_NODE
@ PM_AND_NODE
AndNode.
Definition ast.h:581
PM_CONSTANT_TARGET_NODE
@ PM_CONSTANT_TARGET_NODE
ConstantTargetNode.
Definition ast.h:698
PM_CONSTANT_PATH_AND_WRITE_NODE
@ PM_CONSTANT_PATH_AND_WRITE_NODE
ConstantPathAndWriteNode.
Definition ast.h:677
PM_IN_NODE
@ PM_IN_NODE
InNode.
Definition ast.h:782
PM_BLOCK_PARAMETER_NODE
@ PM_BLOCK_PARAMETER_NODE
BlockParameterNode.
Definition ast.h:614
PM_CAPTURE_PATTERN_NODE
@ PM_CAPTURE_PATTERN_NODE
CapturePatternNode.
Definition ast.h:638
PM_SOURCE_FILE_NODE
@ PM_SOURCE_FILE_NODE
SourceFileNode.
Definition ast.h:971
PM_NO_KEYWORDS_PARAMETER_NODE
@ PM_NO_KEYWORDS_PARAMETER_NODE
NoKeywordsParameterNode.
Definition ast.h:890
PM_CONSTANT_PATH_OPERATOR_WRITE_NODE
@ PM_CONSTANT_PATH_OPERATOR_WRITE_NODE
ConstantPathOperatorWriteNode.
Definition ast.h:683
PM_MULTI_TARGET_NODE
@ PM_MULTI_TARGET_NODE
MultiTargetNode.
Definition ast.h:878
PM_SPLAT_NODE
@ PM_SPLAT_NODE
SplatNode.
Definition ast.h:977
PM_LAMBDA_NODE
@ PM_LAMBDA_NODE
LambdaNode.
Definition ast.h:839
PM_CLASS_VARIABLE_READ_NODE
@ PM_CLASS_VARIABLE_READ_NODE
ClassVariableReadNode.
Definition ast.h:659
PM_REQUIRED_KEYWORD_PARAMETER_NODE
@ PM_REQUIRED_KEYWORD_PARAMETER_NODE
RequiredKeywordParameterNode.
Definition ast.h:941
PM_CALL_TARGET_NODE
@ PM_CALL_TARGET_NODE
CallTargetNode.
Definition ast.h:635
PM_ELSE_NODE
@ PM_ELSE_NODE
ElseNode.
Definition ast.h:710
PM_INTERPOLATED_MATCH_LAST_LINE_NODE
@ PM_INTERPOLATED_MATCH_LAST_LINE_NODE
InterpolatedMatchLastLineNode.
Definition ast.h:818
PM_WHEN_NODE
@ PM_WHEN_NODE
WhenNode.
Definition ast.h:1004
PM_NUMBERED_PARAMETERS_NODE
@ PM_NUMBERED_PARAMETERS_NODE
NumberedParametersNode.
Definition ast.h:893
PM_SYMBOL_NODE
@ PM_SYMBOL_NODE
SymbolNode.
Definition ast.h:989
PM_RESCUE_MODIFIER_NODE
@ PM_RESCUE_MODIFIER_NODE
RescueModifierNode.
Definition ast.h:947
PM_ALIAS_METHOD_NODE
@ PM_ALIAS_METHOD_NODE
AliasMethodNode.
Definition ast.h:575
PM_MATCH_REQUIRED_NODE
@ PM_MATCH_REQUIRED_NODE
MatchRequiredNode.
Definition ast.h:866
PM_FORWARDING_ARGUMENTS_NODE
@ PM_FORWARDING_ARGUMENTS_NODE
ForwardingArgumentsNode.
Definition ast.h:737
PM_BACK_REFERENCE_READ_NODE
@ PM_BACK_REFERENCE_READ_NODE
BackReferenceReadNode.
Definition ast.h:599
PM_SCOPE_NODE
@ PM_SCOPE_NODE
A special kind of node used for compilation.
Definition ast.h:1016
PM_BLOCK_ARGUMENT_NODE
@ PM_BLOCK_ARGUMENT_NODE
BlockArgumentNode.
Definition ast.h:605
PM_MISSING_NODE
@ PM_MISSING_NODE
MissingNode.
Definition ast.h:872
PM_SELF_NODE
@ PM_SELF_NODE
SelfNode.
Definition ast.h:962
PM_IMPLICIT_REST_NODE
@ PM_IMPLICIT_REST_NODE
ImplicitRestNode.
Definition ast.h:779
PM_TRUE_NODE
@ PM_TRUE_NODE
TrueNode.
Definition ast.h:992
PM_ASSOC_SPLAT_NODE
@ PM_ASSOC_SPLAT_NODE
AssocSplatNode.
Definition ast.h:596
PM_CLASS_VARIABLE_AND_WRITE_NODE
@ PM_CLASS_VARIABLE_AND_WRITE_NODE
ClassVariableAndWriteNode.
Definition ast.h:650
PM_RANGE_NODE
@ PM_RANGE_NODE
RangeNode.
Definition ast.h:929
PM_INSTANCE_VARIABLE_OPERATOR_WRITE_NODE
@ PM_INSTANCE_VARIABLE_OPERATOR_WRITE_NODE
InstanceVariableOperatorWriteNode.
Definition ast.h:800
PM_LOCAL_VARIABLE_READ_NODE
@ PM_LOCAL_VARIABLE_READ_NODE
LocalVariableReadNode.
Definition ast.h:851
PM_NEXT_NODE
@ PM_NEXT_NODE
NextNode.
Definition ast.h:884
PM_INSTANCE_VARIABLE_OR_WRITE_NODE
@ PM_INSTANCE_VARIABLE_OR_WRITE_NODE
InstanceVariableOrWriteNode.
Definition ast.h:803
PM_REGULAR_EXPRESSION_NODE
@ PM_REGULAR_EXPRESSION_NODE
RegularExpressionNode.
Definition ast.h:938
PM_CLASS_VARIABLE_OR_WRITE_NODE
@ PM_CLASS_VARIABLE_OR_WRITE_NODE
ClassVariableOrWriteNode.
Definition ast.h:656
PM_BLOCK_PARAMETERS_NODE
@ PM_BLOCK_PARAMETERS_NODE
BlockParametersNode.
Definition ast.h:617
PM_CONSTANT_WRITE_NODE
@ PM_CONSTANT_WRITE_NODE
ConstantWriteNode.
Definition ast.h:701
PM_HASH_PATTERN_NODE
@ PM_HASH_PATTERN_NODE
HashPatternNode.
Definition ast.h:767
PM_INDEX_OPERATOR_WRITE_NODE
@ PM_INDEX_OPERATOR_WRITE_NODE
IndexOperatorWriteNode.
Definition ast.h:788
PM_UNDEF_NODE
@ PM_UNDEF_NODE
UndefNode.
Definition ast.h:995
PM_ALTERNATION_PATTERN_NODE
@ PM_ALTERNATION_PATTERN_NODE
AlternationPatternNode.
Definition ast.h:578
PM_ENSURE_NODE
@ PM_ENSURE_NODE
EnsureNode.
Definition ast.h:719
PM_LOCAL_VARIABLE_WRITE_NODE
@ PM_LOCAL_VARIABLE_WRITE_NODE
LocalVariableWriteNode.
Definition ast.h:857
PM_SINGLETON_CLASS_NODE
@ PM_SINGLETON_CLASS_NODE
SingletonClassNode.
Definition ast.h:965
PM_KEYWORD_HASH_NODE
@ PM_KEYWORD_HASH_NODE
KeywordHashNode.
Definition ast.h:833
PM_PARENTHESES_NODE
@ PM_PARENTHESES_NODE
ParenthesesNode.
Definition ast.h:911
PM_FOR_NODE
@ PM_FOR_NODE
ForNode.
Definition ast.h:734
PM_CLASS_VARIABLE_WRITE_NODE
@ PM_CLASS_VARIABLE_WRITE_NODE
ClassVariableWriteNode.
Definition ast.h:665
PM_POST_EXECUTION_NODE
@ PM_POST_EXECUTION_NODE
PostExecutionNode.
Definition ast.h:920
PM_CONSTANT_OPERATOR_WRITE_NODE
@ PM_CONSTANT_OPERATOR_WRITE_NODE
ConstantOperatorWriteNode.
Definition ast.h:671
PM_RETURN_NODE
@ PM_RETURN_NODE
ReturnNode.
Definition ast.h:959
PM_MODULE_NODE
@ PM_MODULE_NODE
ModuleNode.
Definition ast.h:875
PM_ARRAY_PATTERN_NODE
@ PM_ARRAY_PATTERN_NODE
ArrayPatternNode.
Definition ast.h:590
PM_SUPER_NODE
@ PM_SUPER_NODE
SuperNode.
Definition ast.h:986
PM_MATCH_LAST_LINE_NODE
@ PM_MATCH_LAST_LINE_NODE
MatchLastLineNode.
Definition ast.h:860
PM_CONSTANT_PATH_NODE
@ PM_CONSTANT_PATH_NODE
ConstantPathNode.
Definition ast.h:680
PM_INTERPOLATED_SYMBOL_NODE
@ PM_INTERPOLATED_SYMBOL_NODE
InterpolatedSymbolNode.
Definition ast.h:827
PM_CALL_AND_WRITE_NODE
@ PM_CALL_AND_WRITE_NODE
CallAndWriteNode.
Definition ast.h:623
PM_OPTIONAL_KEYWORD_PARAMETER_NODE
@ PM_OPTIONAL_KEYWORD_PARAMETER_NODE
OptionalKeywordParameterNode.
Definition ast.h:899
PM_CLASS_VARIABLE_TARGET_NODE
@ PM_CLASS_VARIABLE_TARGET_NODE
ClassVariableTargetNode.
Definition ast.h:662
PM_CASE_MATCH_NODE
@ PM_CASE_MATCH_NODE
CaseMatchNode.
Definition ast.h:641
PM_BREAK_NODE
@ PM_BREAK_NODE
BreakNode.
Definition ast.h:620
PM_CALL_OR_WRITE_NODE
@ PM_CALL_OR_WRITE_NODE
CallOrWriteNode.
Definition ast.h:632
PM_IMAGINARY_NODE
@ PM_IMAGINARY_NODE
ImaginaryNode.
Definition ast.h:773
PM_DEF_NODE
@ PM_DEF_NODE
DefNode.
Definition ast.h:704
PM_CONSTANT_READ_NODE
@ PM_CONSTANT_READ_NODE
ConstantReadNode.
Definition ast.h:695
PM_GLOBAL_VARIABLE_WRITE_NODE
@ PM_GLOBAL_VARIABLE_WRITE_NODE
GlobalVariableWriteNode.
Definition ast.h:761
PM_SOURCE_ENCODING_NODE
@ PM_SOURCE_ENCODING_NODE
SourceEncodingNode.
Definition ast.h:968
PM_BEGIN_NODE
@ PM_BEGIN_NODE
BeginNode.
Definition ast.h:602
PM_INTERPOLATED_X_STRING_NODE
@ PM_INTERPOLATED_X_STRING_NODE
InterpolatedXStringNode.
Definition ast.h:830
PM_INSTANCE_VARIABLE_READ_NODE
@ PM_INSTANCE_VARIABLE_READ_NODE
InstanceVariableReadNode.
Definition ast.h:806
PM_FLIP_FLOP_NODE
@ PM_FLIP_FLOP_NODE
FlipFlopNode.
Definition ast.h:728
PM_PINNED_VARIABLE_NODE
@ PM_PINNED_VARIABLE_NODE
PinnedVariableNode.
Definition ast.h:917
PM_REQUIRED_PARAMETER_NODE
@ PM_REQUIRED_PARAMETER_NODE
RequiredParameterNode.
Definition ast.h:944
PM_INSTANCE_VARIABLE_WRITE_NODE
@ PM_INSTANCE_VARIABLE_WRITE_NODE
InstanceVariableWriteNode.
Definition ast.h:812
PM_INSTANCE_VARIABLE_TARGET_NODE
@ PM_INSTANCE_VARIABLE_TARGET_NODE
InstanceVariableTargetNode.
Definition ast.h:809
PM_GLOBAL_VARIABLE_AND_WRITE_NODE
@ PM_GLOBAL_VARIABLE_AND_WRITE_NODE
GlobalVariableAndWriteNode.
Definition ast.h:746
PM_CASE_NODE
@ PM_CASE_NODE
CaseNode.
Definition ast.h:644
PM_RESCUE_NODE
@ PM_RESCUE_NODE
RescueNode.
Definition ast.h:950
PM_FLOAT_NODE
@ PM_FLOAT_NODE
FloatNode.
Definition ast.h:731
PM_ASSOC_NODE
@ PM_ASSOC_NODE
AssocNode.
Definition ast.h:593
PM_INTEGER_NODE
@ PM_INTEGER_NODE
IntegerNode.
Definition ast.h:815
PM_LOCAL_VARIABLE_TARGET_NODE
@ PM_LOCAL_VARIABLE_TARGET_NODE
LocalVariableTargetNode.
Definition ast.h:854
PM_STRING_NODE
@ PM_STRING_NODE
StringNode.
Definition ast.h:983
PM_INDEX_OR_WRITE_NODE
@ PM_INDEX_OR_WRITE_NODE
IndexOrWriteNode.
Definition ast.h:791
PM_ALIAS_GLOBAL_VARIABLE_NODE
@ PM_ALIAS_GLOBAL_VARIABLE_NODE
AliasGlobalVariableNode.
Definition ast.h:572
PM_PARAMETERS_NODE
@ PM_PARAMETERS_NODE
ParametersNode.
Definition ast.h:908
PM_NUMBERED_REFERENCE_READ_NODE
@ PM_NUMBERED_REFERENCE_READ_NODE
NumberedReferenceReadNode.
Definition ast.h:896
PM_CONSTANT_PATH_OR_WRITE_NODE
@ PM_CONSTANT_PATH_OR_WRITE_NODE
ConstantPathOrWriteNode.
Definition ast.h:686
PM_GLOBAL_VARIABLE_OR_WRITE_NODE
@ PM_GLOBAL_VARIABLE_OR_WRITE_NODE
GlobalVariableOrWriteNode.
Definition ast.h:752
PM_CONSTANT_OR_WRITE_NODE
@ PM_CONSTANT_OR_WRITE_NODE
ConstantOrWriteNode.
Definition ast.h:674
PM_STATEMENTS_NODE
@ PM_STATEMENTS_NODE
StatementsNode.
Definition ast.h:980
PM_OPTIONAL_PARAMETER_NODE
@ PM_OPTIONAL_PARAMETER_NODE
OptionalParameterNode.
Definition ast.h:902
PM_PINNED_EXPRESSION_NODE
@ PM_PINNED_EXPRESSION_NODE
PinnedExpressionNode.
Definition ast.h:914
PM_BLOCK_NODE
@ PM_BLOCK_NODE
BlockNode.
Definition ast.h:611
PM_CLASS_VARIABLE_OPERATOR_WRITE_NODE
@ PM_CLASS_VARIABLE_OPERATOR_WRITE_NODE
ClassVariableOperatorWriteNode.
Definition ast.h:653
PM_REST_PARAMETER_NODE
@ PM_REST_PARAMETER_NODE
RestParameterNode.
Definition ast.h:953
PM_EMBEDDED_STATEMENTS_NODE
@ PM_EMBEDDED_STATEMENTS_NODE
EmbeddedStatementsNode.
Definition ast.h:713
PM_INTERPOLATED_REGULAR_EXPRESSION_NODE
@ PM_INTERPOLATED_REGULAR_EXPRESSION_NODE
InterpolatedRegularExpressionNode.
Definition ast.h:821
PM_INDEX_TARGET_NODE
@ PM_INDEX_TARGET_NODE
IndexTargetNode.
Definition ast.h:794
PM_KEYWORD_REST_PARAMETER_NODE
@ PM_KEYWORD_REST_PARAMETER_NODE
KeywordRestParameterNode.
Definition ast.h:836
PM_NODE_TYPE
#define PM_NODE_TYPE(node)
Cast the type to an enum to allow the compiler to provide exhaustiveness checking.
Definition ast.h:1045
PM_CONSTANT_POOL_BUCKET_OWNED
static const pm_constant_pool_bucket_type_t PM_CONSTANT_POOL_BUCKET_OWNED
An owned constant is one for which memory has been allocated.
Definition pm_constant_pool.h:91
PM_CONSTANT_POOL_BUCKET_CONSTANT
static const pm_constant_pool_bucket_type_t PM_CONSTANT_POOL_BUCKET_CONSTANT
A constant constant is known at compile time.
Definition pm_constant_pool.h:94
PRISM_EXPORTED_FUNCTION
#define PRISM_EXPORTED_FUNCTION
By default, we compile with -fvisibility=hidden.
Definition defines.h:32
prism.h
The main header file for the prism parser.
pm_serialize_lex
PRISM_EXPORTED_FUNCTION void pm_serialize_lex(pm_buffer_t *buffer, const uint8_t *source, size_t size, const char *data)
Lex the given source and serialize to the given buffer.
Definition serialize.c:2014
pm_serialize_content
void pm_serialize_content(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer)
Serialize the encoding, metadata, nodes, and constant pool.
Definition serialize.c:1934
pm_serialize_parse_lex
PRISM_EXPORTED_FUNCTION void pm_serialize_parse_lex(pm_buffer_t *buffer, const uint8_t *source, size_t size, const char *data)
Parse and serialize both the AST and the tokens represented by the given source to the given buffer.
Definition serialize.c:2050
pm_serialize_encoding
void pm_serialize_encoding(const pm_encoding_t *encoding, pm_buffer_t *buffer)
Serialize the name of the encoding to the buffer.
Definition serialize.c:1923
pm_parse_success_p
PRISM_EXPORTED_FUNCTION bool pm_parse_success_p(const uint8_t *source, size_t size, const char *data)
Parse the source and return true if it parses without errors or warnings.
Definition serialize.c:2077
pm_serialize_comment_list
void pm_serialize_comment_list(pm_parser_t *parser, pm_list_t *list, pm_buffer_t *buffer)
Serialize the given list of comments to the given buffer.
Definition serialize.c:1858
magic_comment
Definition parse.c:19461
pm_alias_global_variable_node
AliasGlobalVariableNode.
Definition ast.h:1088
pm_alias_method_node
AliasMethodNode.
Definition ast.h:1109
pm_alternation_pattern_node
AlternationPatternNode.
Definition ast.h:1130
pm_and_node
AndNode.
Definition ast.h:1151
pm_arguments_node
ArgumentsNode.
Definition ast.h:1174
pm_array_node
ArrayNode.
Definition ast.h:1191
pm_array_pattern_node
ArrayPatternNode.
Definition ast.h:1212
pm_assoc_node
AssocNode.
Definition ast.h:1242
pm_assoc_splat_node
AssocSplatNode.
Definition ast.h:1263
pm_back_reference_read_node
BackReferenceReadNode.
Definition ast.h:1281
pm_begin_node
BeginNode.
Definition ast.h:1296
pm_block_argument_node
BlockArgumentNode.
Definition ast.h:1326
pm_block_local_variable_node
BlockLocalVariableNode.
Definition ast.h:1344
pm_block_node
BlockNode.
Definition ast.h:1359
pm_block_parameter_node
BlockParameterNode.
Definition ast.h:1389
pm_block_parameters_node
BlockParametersNode.
Definition ast.h:1410
pm_break_node
BreakNode.
Definition ast.h:1434
pm_buffer_t
A pm_buffer_t is a simple memory buffer that stores data in a contiguous block of memory.
Definition pm_buffer.h:21
pm_buffer_t::length
size_t length
The length of the buffer in bytes.
Definition pm_buffer.h:23
pm_buffer_t::value
char * value
A pointer to the start of the buffer.
Definition pm_buffer.h:29
pm_call_and_write_node
CallAndWriteNode.
Definition ast.h:1456
pm_call_node
CallNode.
Definition ast.h:1493
pm_call_operator_write_node
CallOperatorWriteNode.
Definition ast.h:1533
pm_call_or_write_node
CallOrWriteNode.
Definition ast.h:1573
pm_call_target_node
CallTargetNode.
Definition ast.h:1610
pm_capture_pattern_node
CapturePatternNode.
Definition ast.h:1634
pm_case_match_node
CaseMatchNode.
Definition ast.h:1655
pm_case_node
CaseNode.
Definition ast.h:1682
pm_class_node
ClassNode.
Definition ast.h:1709
pm_class_variable_and_write_node
ClassVariableAndWriteNode.
Definition ast.h:1745
pm_class_variable_operator_write_node
ClassVariableOperatorWriteNode.
Definition ast.h:1769
pm_class_variable_or_write_node
ClassVariableOrWriteNode.
Definition ast.h:1796
pm_class_variable_read_node
ClassVariableReadNode.
Definition ast.h:1820
pm_class_variable_target_node
ClassVariableTargetNode.
Definition ast.h:1835
pm_class_variable_write_node
ClassVariableWriteNode.
Definition ast.h:1850
pm_comment
This is a node in the linked list of comments that we've found while parsing.
Definition parser.h:387
pm_comment::node
pm_list_node_t node
The embedded base node.
Definition parser.h:389
pm_comment::type
pm_comment_type_t type
The type of comment that we've found.
Definition parser.h:395
pm_comment::location
pm_location_t location
The location of the comment in the source.
Definition parser.h:392
pm_constant_and_write_node
ConstantAndWriteNode.
Definition ast.h:1874
pm_constant_operator_write_node
ConstantOperatorWriteNode.
Definition ast.h:1898
pm_constant_or_write_node
ConstantOrWriteNode.
Definition ast.h:1925
pm_constant_path_and_write_node
ConstantPathAndWriteNode.
Definition ast.h:1949
pm_constant_path_node
ConstantPathNode.
Definition ast.h:1970
pm_constant_path_operator_write_node
ConstantPathOperatorWriteNode.
Definition ast.h:1991
pm_constant_path_or_write_node
ConstantPathOrWriteNode.
Definition ast.h:2015
pm_constant_path_target_node
ConstantPathTargetNode.
Definition ast.h:2036
pm_constant_path_write_node
ConstantPathWriteNode.
Definition ast.h:2057
pm_constant_pool_bucket_t
A bucket in the hash map.
Definition pm_constant_pool.h:97
pm_constant_pool_bucket_t::id
unsigned int id
The incremental ID used for indexing back into the pool.
Definition pm_constant_pool.h:99
pm_constant_pool_bucket_t::type
pm_constant_pool_bucket_type_t type
The type of the bucket, which determines how to free it.
Definition pm_constant_pool.h:102
pm_constant_pool_t::capacity
uint32_t capacity
The number of buckets that have been allocated in the hash map.
Definition pm_constant_pool.h:129
pm_constant_pool_t::buckets
pm_constant_pool_bucket_t * buckets
The buckets in the hash map.
Definition pm_constant_pool.h:120
pm_constant_pool_t::size
uint32_t size
The number of buckets in the hash map.
Definition pm_constant_pool.h:126
pm_constant_pool_t::constants
pm_constant_t * constants
The constants that are stored in the buckets.
Definition pm_constant_pool.h:123
pm_constant_read_node
ConstantReadNode.
Definition ast.h:2078
pm_constant_t
A constant in the pool which effectively stores a string.
Definition pm_constant_pool.h:109
pm_constant_t::length
size_t length
The length of the string.
Definition pm_constant_pool.h:114
pm_constant_t::start
const uint8_t * start
A pointer to the start of the string.
Definition pm_constant_pool.h:111
pm_constant_target_node
ConstantTargetNode.
Definition ast.h:2093
pm_constant_write_node
ConstantWriteNode.
Definition ast.h:2108
pm_def_node
DefNode.
Definition ast.h:2132
pm_defined_node
DefinedNode.
Definition ast.h:2183
pm_diagnostic_t
This struct represents a diagnostic generated during parsing.
Definition diagnostic.h:22
pm_diagnostic_t::location
pm_location_t location
The location of the diagnostic in the source.
Definition diagnostic.h:27
pm_diagnostic_t::message
const char * message
The message associated with the diagnostic.
Definition diagnostic.h:30
pm_diagnostic_t::node
pm_list_node_t node
The embedded base node.
Definition diagnostic.h:24
pm_else_node
ElseNode.
Definition ast.h:2207
pm_embedded_statements_node
EmbeddedStatementsNode.
Definition ast.h:2228
pm_embedded_variable_node
EmbeddedVariableNode.
Definition ast.h:2249
pm_encoding_t
This struct defines the functions necessary to implement the encoding interface so we can determine h...
Definition encoding.h:23
pm_encoding_t::name
const char * name
The name of the encoding.
Definition encoding.h:56
pm_ensure_node
EnsureNode.
Definition ast.h:2267
pm_find_pattern_node
FindPatternNode.
Definition ast.h:2300
pm_flip_flop_node
FlipFlopNode.
Definition ast.h:2332
pm_for_node
ForNode.
Definition ast.h:2365
pm_forwarding_super_node
ForwardingSuperNode.
Definition ast.h:2422
pm_global_variable_and_write_node
GlobalVariableAndWriteNode.
Definition ast.h:2437
pm_global_variable_operator_write_node
GlobalVariableOperatorWriteNode.
Definition ast.h:2461
pm_global_variable_or_write_node
GlobalVariableOrWriteNode.
Definition ast.h:2488
pm_global_variable_read_node
GlobalVariableReadNode.
Definition ast.h:2512
pm_global_variable_target_node
GlobalVariableTargetNode.
Definition ast.h:2527
pm_global_variable_write_node
GlobalVariableWriteNode.
Definition ast.h:2542
pm_hash_node
HashNode.
Definition ast.h:2566
pm_hash_pattern_node
HashPatternNode.
Definition ast.h:2587
pm_if_node
IfNode.
Definition ast.h:2614
pm_imaginary_node
ImaginaryNode.
Definition ast.h:2644
pm_implicit_node
ImplicitNode.
Definition ast.h:2659
pm_in_node
InNode.
Definition ast.h:2686
pm_index_and_write_node
IndexAndWriteNode.
Definition ast.h:2714
pm_index_operator_write_node
IndexOperatorWriteNode.
Definition ast.h:2754
pm_index_or_write_node
IndexOrWriteNode.
Definition ast.h:2797
pm_index_target_node
IndexTargetNode.
Definition ast.h:2837
pm_instance_variable_and_write_node
InstanceVariableAndWriteNode.
Definition ast.h:2864
pm_instance_variable_operator_write_node
InstanceVariableOperatorWriteNode.
Definition ast.h:2888
pm_instance_variable_or_write_node
InstanceVariableOrWriteNode.
Definition ast.h:2915
pm_instance_variable_read_node
InstanceVariableReadNode.
Definition ast.h:2939
pm_instance_variable_target_node
InstanceVariableTargetNode.
Definition ast.h:2954
pm_instance_variable_write_node
InstanceVariableWriteNode.
Definition ast.h:2969
pm_interpolated_match_last_line_node
InterpolatedMatchLastLineNode.
Definition ast.h:3022
pm_interpolated_regular_expression_node
InterpolatedRegularExpressionNode.
Definition ast.h:3055
pm_interpolated_string_node
InterpolatedStringNode.
Definition ast.h:3076
pm_interpolated_symbol_node
InterpolatedSymbolNode.
Definition ast.h:3097
pm_interpolated_x_string_node
InterpolatedXStringNode.
Definition ast.h:3118
pm_keyword_hash_node
KeywordHashNode.
Definition ast.h:3141
pm_keyword_rest_parameter_node
KeywordRestParameterNode.
Definition ast.h:3156
pm_lambda_node
LambdaNode.
Definition ast.h:3177
pm_lex_callback_t
When you are lexing through a file, the lexer needs all of the information that the parser additional...
Definition parser.h:435
pm_lex_callback_t::data
void * data
This opaque pointer is used to provide whatever information the user deemed necessary to the callback...
Definition parser.h:441
pm_list_node::next
struct pm_list_node * next
A pointer to the next node in the list.
Definition pm_list.h:48
pm_list_t
This represents the overall linked list.
Definition pm_list.h:55
pm_list_t::head
pm_list_node_t * head
A pointer to the head of the list.
Definition pm_list.h:60
pm_list_t::size
size_t size
The size of the list.
Definition pm_list.h:57
pm_local_variable_and_write_node
LocalVariableAndWriteNode.
Definition ast.h:3210
pm_local_variable_operator_write_node
LocalVariableOperatorWriteNode.
Definition ast.h:3237
pm_local_variable_or_write_node
LocalVariableOrWriteNode.
Definition ast.h:3267
pm_local_variable_read_node
LocalVariableReadNode.
Definition ast.h:3294
pm_local_variable_target_node
LocalVariableTargetNode.
Definition ast.h:3312
pm_local_variable_write_node
LocalVariableWriteNode.
Definition ast.h:3330
pm_location_t
This represents a range of bytes in the source string to which a node or token corresponds.
Definition ast.h:543
pm_location_t::start
const uint8_t * start
A pointer to the start location of the range in the source.
Definition ast.h:545
pm_location_t::end
const uint8_t * end
A pointer to the end location of the range in the source.
Definition ast.h:548
pm_magic_comment_t
This is a node in the linked list of magic comments that we've found while parsing.
Definition parser.h:404
pm_match_last_line_node
MatchLastLineNode.
Definition ast.h:3369
pm_match_predicate_node
MatchPredicateNode.
Definition ast.h:3393
pm_match_required_node
MatchRequiredNode.
Definition ast.h:3414
pm_match_write_node
MatchWriteNode.
Definition ast.h:3435
pm_module_node
ModuleNode.
Definition ast.h:3465
pm_multi_target_node
MultiTargetNode.
Definition ast.h:3495
pm_multi_write_node
MultiWriteNode.
Definition ast.h:3522
pm_next_node
NextNode.
Definition ast.h:3555
pm_no_keywords_parameter_node
NoKeywordsParameterNode.
Definition ast.h:3585
pm_node
This is the base structure that represents a node in the syntax tree.
Definition ast.h:1061
pm_node::flags
pm_node_flags_t flags
This represents any flags on the node.
Definition ast.h:1072
pm_node::location
pm_location_t location
This is the location of the node in the source.
Definition ast.h:1078
pm_numbered_parameters_node
NumberedParametersNode.
Definition ast.h:3603
pm_numbered_reference_read_node
NumberedReferenceReadNode.
Definition ast.h:3618
pm_optional_keyword_parameter_node
OptionalKeywordParameterNode.
Definition ast.h:3633
pm_optional_parameter_node
OptionalParameterNode.
Definition ast.h:3654
pm_options_t
The options that can be passed to the parser.
Definition options.h:30
pm_or_node
OrNode.
Definition ast.h:3678
pm_parameters_node
ParametersNode.
Definition ast.h:3699
pm_parentheses_node
ParenthesesNode.
Definition ast.h:3732
pm_parser
This struct represents the overall parser.
Definition parser.h:489
pm_parser::lex_state
pm_lex_state_t lex_state
The current state of the lexer.
Definition parser.h:491
pm_parser::encoding
const pm_encoding_t * encoding
The encoding functions for the current file is attached to the parser as it's parsing so that it can ...
Definition parser.h:584
pm_parser::constant_pool
pm_constant_pool_t constant_pool
This constant pool keeps all of the constants defined throughout the file so that we can reference th...
Definition parser.h:615
pm_parser::magic_comment_list
pm_list_t magic_comment_list
The list of magic comments that have been found while parsing.
Definition parser.h:563
pm_parser::lex_callback
pm_lex_callback_t * lex_callback
This is an optional callback that can be attached to the parser that will be called whenever a new to...
Definition parser.h:603
pm_parser::data_loc
pm_location_t data_loc
The optional location of the END keyword and its contents.
Definition parser.h:566
pm_parser::start
const uint8_t * start
The pointer to the start of the source.
Definition parser.h:533
pm_parser::error_list
pm_list_t error_list
The list of errors that have been found while parsing.
Definition parser.h:572
pm_parser::warning_list
pm_list_t warning_list
The list of warnings that have been found while parsing.
Definition parser.h:569
pm_parser::start_line
int32_t start_line
The line number at the start of the parse.
Definition parser.h:638
pm_parser::comment_list
pm_list_t comment_list
The list of comments that have been found while parsing.
Definition parser.h:560
pm_pinned_expression_node
PinnedExpressionNode.
Definition ast.h:3753
pm_pinned_variable_node
PinnedVariableNode.
Definition ast.h:3777
pm_post_execution_node
PostExecutionNode.
Definition ast.h:3795
pm_pre_execution_node
PreExecutionNode.
Definition ast.h:3819
pm_program_node
ProgramNode.
Definition ast.h:3843
pm_range_node
RangeNode.
Definition ast.h:3863
pm_rational_node
RationalNode.
Definition ast.h:3884
pm_regular_expression_node
RegularExpressionNode.
Definition ast.h:3923
pm_required_keyword_parameter_node
RequiredKeywordParameterNode.
Definition ast.h:3947
pm_required_parameter_node
RequiredParameterNode.
Definition ast.h:3965
pm_rescue_modifier_node
RescueModifierNode.
Definition ast.h:3980
pm_rescue_node
RescueNode.
Definition ast.h:4001
pm_rest_parameter_node
RestParameterNode.
Definition ast.h:4031
pm_return_node
ReturnNode.
Definition ast.h:4064
pm_singleton_class_node
SingletonClassNode.
Definition ast.h:4094
pm_source_file_node
SourceFileNode.
Definition ast.h:4136
pm_splat_node
SplatNode.
Definition ast.h:4163
pm_statements_node
StatementsNode.
Definition ast.h:4181
pm_string_node
StringNode.
Definition ast.h:4200
pm_string_t
A generic string type that can have various ownership semantics.
Definition pm_string.h:30
pm_string_t::type
enum pm_string_t::@97 type
The type of the string.
pm_super_node
SuperNode.
Definition ast.h:4224
pm_symbol_node
SymbolNode.
Definition ast.h:4255
pm_token_t
This struct represents a token in the Ruby source.
Definition ast.h:528
pm_undef_node
UndefNode.
Definition ast.h:4291
pm_unless_node
UnlessNode.
Definition ast.h:4309
pm_until_node
UntilNode.
Definition ast.h:4341
pm_when_node
WhenNode.
Definition ast.h:4365
pm_while_node
WhileNode.
Definition ast.h:4388
pm_x_string_node
XStringNode.
Definition ast.h:4415
pm_yield_node
YieldNode.
Definition ast.h:4439