Ruby: prism/serialize.c Source File

Ruby 4.0.6p0 (2026-07-14 revision 03b6d3f8898a28604fe6cb00eae3226b821168f4)

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