Ruby: prism/serialize.c Source File

Ruby 3.4.5p51 (2025-07-16 revision 20cda200d3ce092571d0b5d342dadca69636cb0f)

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