Ruby: prism/serialize.c Source File

Ruby 3.4.8p72 (2025-12-17 revision 995b59f66677d44767ce9faac6957e5543617ff9)

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)->block == NULL) {
399 pm_buffer_append_byte(buffer, 0);
400 } else {
401 pm_serialize_node(parser, (pm_node_t *)((pm_call_node_t *)node)->block, buffer);
402 }
403 break;
404 }
405 case PM_CALL_OPERATOR_WRITE_NODE: {
406 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
407 if (((pm_call_operator_write_node_t *)node)->receiver == NULL) {
408 pm_buffer_append_byte(buffer, 0);
409 } else {
410 pm_serialize_node(parser, (pm_node_t *)((pm_call_operator_write_node_t *)node)->receiver, buffer);
411 }
412 if (((pm_call_operator_write_node_t *)node)->call_operator_loc.start == NULL) {
413 pm_buffer_append_byte(buffer, 0);
414 } else {
415 pm_buffer_append_byte(buffer, 1);
416 pm_serialize_location(parser, &((pm_call_operator_write_node_t *)node)->call_operator_loc, buffer);
417 }
418 if (((pm_call_operator_write_node_t *)node)->message_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)->message_loc, buffer);
423 }
424 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_call_operator_write_node_t *)node)->read_name));
425 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_call_operator_write_node_t *)node)->write_name));
426 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_call_operator_write_node_t *)node)->binary_operator));
427 pm_serialize_location(parser, &((pm_call_operator_write_node_t *)node)->binary_operator_loc, buffer);
428 pm_serialize_node(parser, (pm_node_t *)((pm_call_operator_write_node_t *)node)->value, buffer);
429 break;
430 }
431 case PM_CALL_OR_WRITE_NODE: {
432 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
433 if (((pm_call_or_write_node_t *)node)->receiver == NULL) {
434 pm_buffer_append_byte(buffer, 0);
435 } else {
436 pm_serialize_node(parser, (pm_node_t *)((pm_call_or_write_node_t *)node)->receiver, buffer);
437 }
438 if (((pm_call_or_write_node_t *)node)->call_operator_loc.start == NULL) {
439 pm_buffer_append_byte(buffer, 0);
440 } else {
441 pm_buffer_append_byte(buffer, 1);
442 pm_serialize_location(parser, &((pm_call_or_write_node_t *)node)->call_operator_loc, buffer);
443 }
444 if (((pm_call_or_write_node_t *)node)->message_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)->message_loc, buffer);
449 }
450 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_call_or_write_node_t *)node)->read_name));
451 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_call_or_write_node_t *)node)->write_name));
452 pm_serialize_location(parser, &((pm_call_or_write_node_t *)node)->operator_loc, buffer);
453 pm_serialize_node(parser, (pm_node_t *)((pm_call_or_write_node_t *)node)->value, buffer);
454 break;
455 }
456 case PM_CALL_TARGET_NODE: {
457 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
458 pm_serialize_node(parser, (pm_node_t *)((pm_call_target_node_t *)node)->receiver, buffer);
459 pm_serialize_location(parser, &((pm_call_target_node_t *)node)->call_operator_loc, buffer);
460 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_call_target_node_t *)node)->name));
461 pm_serialize_location(parser, &((pm_call_target_node_t *)node)->message_loc, buffer);
462 break;
463 }
464 case PM_CAPTURE_PATTERN_NODE: {
465 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
466 pm_serialize_node(parser, (pm_node_t *)((pm_capture_pattern_node_t *)node)->value, buffer);
467 pm_serialize_node(parser, (pm_node_t *)((pm_capture_pattern_node_t *)node)->target, buffer);
468 pm_serialize_location(parser, &((pm_capture_pattern_node_t *)node)->operator_loc, buffer);
469 break;
470 }
471 case PM_CASE_MATCH_NODE: {
472 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
473 if (((pm_case_match_node_t *)node)->predicate == NULL) {
474 pm_buffer_append_byte(buffer, 0);
475 } else {
476 pm_serialize_node(parser, (pm_node_t *)((pm_case_match_node_t *)node)->predicate, buffer);
477 }
478 uint32_t conditions_size = pm_sizet_to_u32(((pm_case_match_node_t *)node)->conditions.size);
479 pm_buffer_append_varuint(buffer, conditions_size);
480 for (uint32_t index = 0; index < conditions_size; index++) {
481 pm_serialize_node(parser, (pm_node_t *) ((pm_case_match_node_t *)node)->conditions.nodes[index], buffer);
482 }
483 if (((pm_case_match_node_t *)node)->else_clause == NULL) {
484 pm_buffer_append_byte(buffer, 0);
485 } else {
486 pm_serialize_node(parser, (pm_node_t *)((pm_case_match_node_t *)node)->else_clause, buffer);
487 }
488 pm_serialize_location(parser, &((pm_case_match_node_t *)node)->case_keyword_loc, buffer);
489 pm_serialize_location(parser, &((pm_case_match_node_t *)node)->end_keyword_loc, buffer);
490 break;
491 }
492 case PM_CASE_NODE: {
493 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
494 if (((pm_case_node_t *)node)->predicate == NULL) {
495 pm_buffer_append_byte(buffer, 0);
496 } else {
497 pm_serialize_node(parser, (pm_node_t *)((pm_case_node_t *)node)->predicate, buffer);
498 }
499 uint32_t conditions_size = pm_sizet_to_u32(((pm_case_node_t *)node)->conditions.size);
500 pm_buffer_append_varuint(buffer, conditions_size);
501 for (uint32_t index = 0; index < conditions_size; index++) {
502 pm_serialize_node(parser, (pm_node_t *) ((pm_case_node_t *)node)->conditions.nodes[index], buffer);
503 }
504 if (((pm_case_node_t *)node)->else_clause == NULL) {
505 pm_buffer_append_byte(buffer, 0);
506 } else {
507 pm_serialize_node(parser, (pm_node_t *)((pm_case_node_t *)node)->else_clause, buffer);
508 }
509 pm_serialize_location(parser, &((pm_case_node_t *)node)->case_keyword_loc, buffer);
510 pm_serialize_location(parser, &((pm_case_node_t *)node)->end_keyword_loc, buffer);
511 break;
512 }
513 case PM_CLASS_NODE: {
514 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
515 uint32_t locals_size = pm_sizet_to_u32(((pm_class_node_t *)node)->locals.size);
516 pm_buffer_append_varuint(buffer, locals_size);
517 for (uint32_t index = 0; index < locals_size; index++) {
518 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_class_node_t *)node)->locals.ids[index]));
519 }
520 pm_serialize_location(parser, &((pm_class_node_t *)node)->class_keyword_loc, buffer);
521 pm_serialize_node(parser, (pm_node_t *)((pm_class_node_t *)node)->constant_path, buffer);
522 if (((pm_class_node_t *)node)->inheritance_operator_loc.start == NULL) {
523 pm_buffer_append_byte(buffer, 0);
524 } else {
525 pm_buffer_append_byte(buffer, 1);
526 pm_serialize_location(parser, &((pm_class_node_t *)node)->inheritance_operator_loc, buffer);
527 }
528 if (((pm_class_node_t *)node)->superclass == NULL) {
529 pm_buffer_append_byte(buffer, 0);
530 } else {
531 pm_serialize_node(parser, (pm_node_t *)((pm_class_node_t *)node)->superclass, buffer);
532 }
533 if (((pm_class_node_t *)node)->body == NULL) {
534 pm_buffer_append_byte(buffer, 0);
535 } else {
536 pm_serialize_node(parser, (pm_node_t *)((pm_class_node_t *)node)->body, buffer);
537 }
538 pm_serialize_location(parser, &((pm_class_node_t *)node)->end_keyword_loc, buffer);
539 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_class_node_t *)node)->name));
540 break;
541 }
542 case PM_CLASS_VARIABLE_AND_WRITE_NODE: {
543 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
544 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_class_variable_and_write_node_t *)node)->name));
545 pm_serialize_location(parser, &((pm_class_variable_and_write_node_t *)node)->name_loc, buffer);
546 pm_serialize_location(parser, &((pm_class_variable_and_write_node_t *)node)->operator_loc, buffer);
547 pm_serialize_node(parser, (pm_node_t *)((pm_class_variable_and_write_node_t *)node)->value, buffer);
548 break;
549 }
550 case PM_CLASS_VARIABLE_OPERATOR_WRITE_NODE: {
551 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
552 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_class_variable_operator_write_node_t *)node)->name));
553 pm_serialize_location(parser, &((pm_class_variable_operator_write_node_t *)node)->name_loc, buffer);
554 pm_serialize_location(parser, &((pm_class_variable_operator_write_node_t *)node)->binary_operator_loc, buffer);
555 pm_serialize_node(parser, (pm_node_t *)((pm_class_variable_operator_write_node_t *)node)->value, buffer);
556 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_class_variable_operator_write_node_t *)node)->binary_operator));
557 break;
558 }
559 case PM_CLASS_VARIABLE_OR_WRITE_NODE: {
560 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
561 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_class_variable_or_write_node_t *)node)->name));
562 pm_serialize_location(parser, &((pm_class_variable_or_write_node_t *)node)->name_loc, buffer);
563 pm_serialize_location(parser, &((pm_class_variable_or_write_node_t *)node)->operator_loc, buffer);
564 pm_serialize_node(parser, (pm_node_t *)((pm_class_variable_or_write_node_t *)node)->value, buffer);
565 break;
566 }
567 case PM_CLASS_VARIABLE_READ_NODE: {
568 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
569 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_class_variable_read_node_t *)node)->name));
570 break;
571 }
572 case PM_CLASS_VARIABLE_TARGET_NODE: {
573 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
574 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_class_variable_target_node_t *)node)->name));
575 break;
576 }
577 case PM_CLASS_VARIABLE_WRITE_NODE: {
578 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
579 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_class_variable_write_node_t *)node)->name));
580 pm_serialize_location(parser, &((pm_class_variable_write_node_t *)node)->name_loc, buffer);
581 pm_serialize_node(parser, (pm_node_t *)((pm_class_variable_write_node_t *)node)->value, buffer);
582 pm_serialize_location(parser, &((pm_class_variable_write_node_t *)node)->operator_loc, buffer);
583 break;
584 }
585 case PM_CONSTANT_AND_WRITE_NODE: {
586 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
587 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_constant_and_write_node_t *)node)->name));
588 pm_serialize_location(parser, &((pm_constant_and_write_node_t *)node)->name_loc, buffer);
589 pm_serialize_location(parser, &((pm_constant_and_write_node_t *)node)->operator_loc, buffer);
590 pm_serialize_node(parser, (pm_node_t *)((pm_constant_and_write_node_t *)node)->value, buffer);
591 break;
592 }
593 case PM_CONSTANT_OPERATOR_WRITE_NODE: {
594 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
595 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_constant_operator_write_node_t *)node)->name));
596 pm_serialize_location(parser, &((pm_constant_operator_write_node_t *)node)->name_loc, buffer);
597 pm_serialize_location(parser, &((pm_constant_operator_write_node_t *)node)->binary_operator_loc, buffer);
598 pm_serialize_node(parser, (pm_node_t *)((pm_constant_operator_write_node_t *)node)->value, buffer);
599 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_constant_operator_write_node_t *)node)->binary_operator));
600 break;
601 }
602 case PM_CONSTANT_OR_WRITE_NODE: {
603 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
604 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_constant_or_write_node_t *)node)->name));
605 pm_serialize_location(parser, &((pm_constant_or_write_node_t *)node)->name_loc, buffer);
606 pm_serialize_location(parser, &((pm_constant_or_write_node_t *)node)->operator_loc, buffer);
607 pm_serialize_node(parser, (pm_node_t *)((pm_constant_or_write_node_t *)node)->value, buffer);
608 break;
609 }
610 case PM_CONSTANT_PATH_AND_WRITE_NODE: {
611 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
612 pm_serialize_node(parser, (pm_node_t *)((pm_constant_path_and_write_node_t *)node)->target, buffer);
613 pm_serialize_location(parser, &((pm_constant_path_and_write_node_t *)node)->operator_loc, buffer);
614 pm_serialize_node(parser, (pm_node_t *)((pm_constant_path_and_write_node_t *)node)->value, buffer);
615 break;
616 }
617 case PM_CONSTANT_PATH_NODE: {
618 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
619 if (((pm_constant_path_node_t *)node)->parent == NULL) {
620 pm_buffer_append_byte(buffer, 0);
621 } else {
622 pm_serialize_node(parser, (pm_node_t *)((pm_constant_path_node_t *)node)->parent, buffer);
623 }
624 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_constant_path_node_t *)node)->name));
625 pm_serialize_location(parser, &((pm_constant_path_node_t *)node)->delimiter_loc, buffer);
626 pm_serialize_location(parser, &((pm_constant_path_node_t *)node)->name_loc, buffer);
627 break;
628 }
629 case PM_CONSTANT_PATH_OPERATOR_WRITE_NODE: {
630 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
631 pm_serialize_node(parser, (pm_node_t *)((pm_constant_path_operator_write_node_t *)node)->target, buffer);
632 pm_serialize_location(parser, &((pm_constant_path_operator_write_node_t *)node)->binary_operator_loc, buffer);
633 pm_serialize_node(parser, (pm_node_t *)((pm_constant_path_operator_write_node_t *)node)->value, buffer);
634 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_constant_path_operator_write_node_t *)node)->binary_operator));
635 break;
636 }
637 case PM_CONSTANT_PATH_OR_WRITE_NODE: {
638 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
639 pm_serialize_node(parser, (pm_node_t *)((pm_constant_path_or_write_node_t *)node)->target, buffer);
640 pm_serialize_location(parser, &((pm_constant_path_or_write_node_t *)node)->operator_loc, buffer);
641 pm_serialize_node(parser, (pm_node_t *)((pm_constant_path_or_write_node_t *)node)->value, buffer);
642 break;
643 }
644 case PM_CONSTANT_PATH_TARGET_NODE: {
645 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
646 if (((pm_constant_path_target_node_t *)node)->parent == NULL) {
647 pm_buffer_append_byte(buffer, 0);
648 } else {
649 pm_serialize_node(parser, (pm_node_t *)((pm_constant_path_target_node_t *)node)->parent, buffer);
650 }
651 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_constant_path_target_node_t *)node)->name));
652 pm_serialize_location(parser, &((pm_constant_path_target_node_t *)node)->delimiter_loc, buffer);
653 pm_serialize_location(parser, &((pm_constant_path_target_node_t *)node)->name_loc, buffer);
654 break;
655 }
656 case PM_CONSTANT_PATH_WRITE_NODE: {
657 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
658 pm_serialize_node(parser, (pm_node_t *)((pm_constant_path_write_node_t *)node)->target, buffer);
659 pm_serialize_location(parser, &((pm_constant_path_write_node_t *)node)->operator_loc, buffer);
660 pm_serialize_node(parser, (pm_node_t *)((pm_constant_path_write_node_t *)node)->value, buffer);
661 break;
662 }
663 case PM_CONSTANT_READ_NODE: {
664 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
665 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_constant_read_node_t *)node)->name));
666 break;
667 }
668 case PM_CONSTANT_TARGET_NODE: {
669 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
670 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_constant_target_node_t *)node)->name));
671 break;
672 }
673 case PM_CONSTANT_WRITE_NODE: {
674 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
675 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_constant_write_node_t *)node)->name));
676 pm_serialize_location(parser, &((pm_constant_write_node_t *)node)->name_loc, buffer);
677 pm_serialize_node(parser, (pm_node_t *)((pm_constant_write_node_t *)node)->value, buffer);
678 pm_serialize_location(parser, &((pm_constant_write_node_t *)node)->operator_loc, buffer);
679 break;
680 }
681 case PM_DEF_NODE: {
682 // serialize length
683 // encoding of location u32s make us need to save this offset.
684 size_t length_offset = buffer->length;
685 pm_buffer_append_string(buffer, "\0\0\0\0", 4); /* consume 4 bytes, updated below */
686 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
687 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_def_node_t *)node)->name));
688 pm_serialize_location(parser, &((pm_def_node_t *)node)->name_loc, buffer);
689 if (((pm_def_node_t *)node)->receiver == NULL) {
690 pm_buffer_append_byte(buffer, 0);
691 } else {
692 pm_serialize_node(parser, (pm_node_t *)((pm_def_node_t *)node)->receiver, buffer);
693 }
694 if (((pm_def_node_t *)node)->parameters == NULL) {
695 pm_buffer_append_byte(buffer, 0);
696 } else {
697 pm_serialize_node(parser, (pm_node_t *)((pm_def_node_t *)node)->parameters, buffer);
698 }
699 if (((pm_def_node_t *)node)->body == NULL) {
700 pm_buffer_append_byte(buffer, 0);
701 } else {
702 pm_serialize_node(parser, (pm_node_t *)((pm_def_node_t *)node)->body, buffer);
703 }
704 uint32_t locals_size = pm_sizet_to_u32(((pm_def_node_t *)node)->locals.size);
705 pm_buffer_append_varuint(buffer, locals_size);
706 for (uint32_t index = 0; index < locals_size; index++) {
707 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_def_node_t *)node)->locals.ids[index]));
708 }
709 pm_serialize_location(parser, &((pm_def_node_t *)node)->def_keyword_loc, buffer);
710 if (((pm_def_node_t *)node)->operator_loc.start == NULL) {
711 pm_buffer_append_byte(buffer, 0);
712 } else {
713 pm_buffer_append_byte(buffer, 1);
714 pm_serialize_location(parser, &((pm_def_node_t *)node)->operator_loc, buffer);
715 }
716 if (((pm_def_node_t *)node)->lparen_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)->lparen_loc, buffer);
721 }
722 if (((pm_def_node_t *)node)->rparen_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)->rparen_loc, buffer);
727 }
728 if (((pm_def_node_t *)node)->equal_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)->equal_loc, buffer);
733 }
734 if (((pm_def_node_t *)node)->end_keyword_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)->end_keyword_loc, buffer);
739 }
740 // serialize length
741 uint32_t length = pm_sizet_to_u32(buffer->length - offset - sizeof(uint32_t));
742 memcpy(buffer->value + length_offset, &length, sizeof(uint32_t));
743 break;
744 }
745 case PM_DEFINED_NODE: {
746 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
747 if (((pm_defined_node_t *)node)->lparen_loc.start == NULL) {
748 pm_buffer_append_byte(buffer, 0);
749 } else {
750 pm_buffer_append_byte(buffer, 1);
751 pm_serialize_location(parser, &((pm_defined_node_t *)node)->lparen_loc, buffer);
752 }
753 pm_serialize_node(parser, (pm_node_t *)((pm_defined_node_t *)node)->value, buffer);
754 if (((pm_defined_node_t *)node)->rparen_loc.start == NULL) {
755 pm_buffer_append_byte(buffer, 0);
756 } else {
757 pm_buffer_append_byte(buffer, 1);
758 pm_serialize_location(parser, &((pm_defined_node_t *)node)->rparen_loc, buffer);
759 }
760 pm_serialize_location(parser, &((pm_defined_node_t *)node)->keyword_loc, buffer);
761 break;
762 }
763 case PM_ELSE_NODE: {
764 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
765 pm_serialize_location(parser, &((pm_else_node_t *)node)->else_keyword_loc, buffer);
766 if (((pm_else_node_t *)node)->statements == NULL) {
767 pm_buffer_append_byte(buffer, 0);
768 } else {
769 pm_serialize_node(parser, (pm_node_t *)((pm_else_node_t *)node)->statements, buffer);
770 }
771 if (((pm_else_node_t *)node)->end_keyword_loc.start == NULL) {
772 pm_buffer_append_byte(buffer, 0);
773 } else {
774 pm_buffer_append_byte(buffer, 1);
775 pm_serialize_location(parser, &((pm_else_node_t *)node)->end_keyword_loc, buffer);
776 }
777 break;
778 }
779 case PM_EMBEDDED_STATEMENTS_NODE: {
780 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
781 pm_serialize_location(parser, &((pm_embedded_statements_node_t *)node)->opening_loc, buffer);
782 if (((pm_embedded_statements_node_t *)node)->statements == NULL) {
783 pm_buffer_append_byte(buffer, 0);
784 } else {
785 pm_serialize_node(parser, (pm_node_t *)((pm_embedded_statements_node_t *)node)->statements, buffer);
786 }
787 pm_serialize_location(parser, &((pm_embedded_statements_node_t *)node)->closing_loc, buffer);
788 break;
789 }
790 case PM_EMBEDDED_VARIABLE_NODE: {
791 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
792 pm_serialize_location(parser, &((pm_embedded_variable_node_t *)node)->operator_loc, buffer);
793 pm_serialize_node(parser, (pm_node_t *)((pm_embedded_variable_node_t *)node)->variable, buffer);
794 break;
795 }
796 case PM_ENSURE_NODE: {
797 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
798 pm_serialize_location(parser, &((pm_ensure_node_t *)node)->ensure_keyword_loc, buffer);
799 if (((pm_ensure_node_t *)node)->statements == NULL) {
800 pm_buffer_append_byte(buffer, 0);
801 } else {
802 pm_serialize_node(parser, (pm_node_t *)((pm_ensure_node_t *)node)->statements, buffer);
803 }
804 pm_serialize_location(parser, &((pm_ensure_node_t *)node)->end_keyword_loc, buffer);
805 break;
806 }
807 case PM_FALSE_NODE: {
808 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
809 break;
810 }
811 case PM_FIND_PATTERN_NODE: {
812 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
813 if (((pm_find_pattern_node_t *)node)->constant == NULL) {
814 pm_buffer_append_byte(buffer, 0);
815 } else {
816 pm_serialize_node(parser, (pm_node_t *)((pm_find_pattern_node_t *)node)->constant, buffer);
817 }
818 pm_serialize_node(parser, (pm_node_t *)((pm_find_pattern_node_t *)node)->left, buffer);
819 uint32_t requireds_size = pm_sizet_to_u32(((pm_find_pattern_node_t *)node)->requireds.size);
820 pm_buffer_append_varuint(buffer, requireds_size);
821 for (uint32_t index = 0; index < requireds_size; index++) {
822 pm_serialize_node(parser, (pm_node_t *) ((pm_find_pattern_node_t *)node)->requireds.nodes[index], buffer);
823 }
824 pm_serialize_node(parser, (pm_node_t *)((pm_find_pattern_node_t *)node)->right, buffer);
825 if (((pm_find_pattern_node_t *)node)->opening_loc.start == NULL) {
826 pm_buffer_append_byte(buffer, 0);
827 } else {
828 pm_buffer_append_byte(buffer, 1);
829 pm_serialize_location(parser, &((pm_find_pattern_node_t *)node)->opening_loc, buffer);
830 }
831 if (((pm_find_pattern_node_t *)node)->closing_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)->closing_loc, buffer);
836 }
837 break;
838 }
839 case PM_FLIP_FLOP_NODE: {
840 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
841 if (((pm_flip_flop_node_t *)node)->left == NULL) {
842 pm_buffer_append_byte(buffer, 0);
843 } else {
844 pm_serialize_node(parser, (pm_node_t *)((pm_flip_flop_node_t *)node)->left, buffer);
845 }
846 if (((pm_flip_flop_node_t *)node)->right == NULL) {
847 pm_buffer_append_byte(buffer, 0);
848 } else {
849 pm_serialize_node(parser, (pm_node_t *)((pm_flip_flop_node_t *)node)->right, buffer);
850 }
851 pm_serialize_location(parser, &((pm_flip_flop_node_t *)node)->operator_loc, buffer);
852 break;
853 }
854 case PM_FLOAT_NODE: {
855 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
856 pm_buffer_append_double(buffer, ((pm_float_node_t *)node)->value);
857 break;
858 }
859 case PM_FOR_NODE: {
860 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
861 pm_serialize_node(parser, (pm_node_t *)((pm_for_node_t *)node)->index, buffer);
862 pm_serialize_node(parser, (pm_node_t *)((pm_for_node_t *)node)->collection, buffer);
863 if (((pm_for_node_t *)node)->statements == NULL) {
864 pm_buffer_append_byte(buffer, 0);
865 } else {
866 pm_serialize_node(parser, (pm_node_t *)((pm_for_node_t *)node)->statements, buffer);
867 }
868 pm_serialize_location(parser, &((pm_for_node_t *)node)->for_keyword_loc, buffer);
869 pm_serialize_location(parser, &((pm_for_node_t *)node)->in_keyword_loc, buffer);
870 if (((pm_for_node_t *)node)->do_keyword_loc.start == NULL) {
871 pm_buffer_append_byte(buffer, 0);
872 } else {
873 pm_buffer_append_byte(buffer, 1);
874 pm_serialize_location(parser, &((pm_for_node_t *)node)->do_keyword_loc, buffer);
875 }
876 pm_serialize_location(parser, &((pm_for_node_t *)node)->end_keyword_loc, buffer);
877 break;
878 }
879 case PM_FORWARDING_ARGUMENTS_NODE: {
880 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
881 break;
882 }
883 case PM_FORWARDING_PARAMETER_NODE: {
884 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
885 break;
886 }
887 case PM_FORWARDING_SUPER_NODE: {
888 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
889 if (((pm_forwarding_super_node_t *)node)->block == NULL) {
890 pm_buffer_append_byte(buffer, 0);
891 } else {
892 pm_serialize_node(parser, (pm_node_t *)((pm_forwarding_super_node_t *)node)->block, buffer);
893 }
894 break;
895 }
896 case PM_GLOBAL_VARIABLE_AND_WRITE_NODE: {
897 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
898 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_global_variable_and_write_node_t *)node)->name));
899 pm_serialize_location(parser, &((pm_global_variable_and_write_node_t *)node)->name_loc, buffer);
900 pm_serialize_location(parser, &((pm_global_variable_and_write_node_t *)node)->operator_loc, buffer);
901 pm_serialize_node(parser, (pm_node_t *)((pm_global_variable_and_write_node_t *)node)->value, buffer);
902 break;
903 }
904 case PM_GLOBAL_VARIABLE_OPERATOR_WRITE_NODE: {
905 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
906 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_global_variable_operator_write_node_t *)node)->name));
907 pm_serialize_location(parser, &((pm_global_variable_operator_write_node_t *)node)->name_loc, buffer);
908 pm_serialize_location(parser, &((pm_global_variable_operator_write_node_t *)node)->binary_operator_loc, buffer);
909 pm_serialize_node(parser, (pm_node_t *)((pm_global_variable_operator_write_node_t *)node)->value, buffer);
910 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_global_variable_operator_write_node_t *)node)->binary_operator));
911 break;
912 }
913 case PM_GLOBAL_VARIABLE_OR_WRITE_NODE: {
914 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
915 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_global_variable_or_write_node_t *)node)->name));
916 pm_serialize_location(parser, &((pm_global_variable_or_write_node_t *)node)->name_loc, buffer);
917 pm_serialize_location(parser, &((pm_global_variable_or_write_node_t *)node)->operator_loc, buffer);
918 pm_serialize_node(parser, (pm_node_t *)((pm_global_variable_or_write_node_t *)node)->value, buffer);
919 break;
920 }
921 case PM_GLOBAL_VARIABLE_READ_NODE: {
922 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
923 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_global_variable_read_node_t *)node)->name));
924 break;
925 }
926 case PM_GLOBAL_VARIABLE_TARGET_NODE: {
927 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
928 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_global_variable_target_node_t *)node)->name));
929 break;
930 }
931 case PM_GLOBAL_VARIABLE_WRITE_NODE: {
932 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
933 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_global_variable_write_node_t *)node)->name));
934 pm_serialize_location(parser, &((pm_global_variable_write_node_t *)node)->name_loc, buffer);
935 pm_serialize_node(parser, (pm_node_t *)((pm_global_variable_write_node_t *)node)->value, buffer);
936 pm_serialize_location(parser, &((pm_global_variable_write_node_t *)node)->operator_loc, buffer);
937 break;
938 }
939 case PM_HASH_NODE: {
940 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
941 pm_serialize_location(parser, &((pm_hash_node_t *)node)->opening_loc, buffer);
942 uint32_t elements_size = pm_sizet_to_u32(((pm_hash_node_t *)node)->elements.size);
943 pm_buffer_append_varuint(buffer, elements_size);
944 for (uint32_t index = 0; index < elements_size; index++) {
945 pm_serialize_node(parser, (pm_node_t *) ((pm_hash_node_t *)node)->elements.nodes[index], buffer);
946 }
947 pm_serialize_location(parser, &((pm_hash_node_t *)node)->closing_loc, buffer);
948 break;
949 }
950 case PM_HASH_PATTERN_NODE: {
951 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
952 if (((pm_hash_pattern_node_t *)node)->constant == NULL) {
953 pm_buffer_append_byte(buffer, 0);
954 } else {
955 pm_serialize_node(parser, (pm_node_t *)((pm_hash_pattern_node_t *)node)->constant, buffer);
956 }
957 uint32_t elements_size = pm_sizet_to_u32(((pm_hash_pattern_node_t *)node)->elements.size);
958 pm_buffer_append_varuint(buffer, elements_size);
959 for (uint32_t index = 0; index < elements_size; index++) {
960 pm_serialize_node(parser, (pm_node_t *) ((pm_hash_pattern_node_t *)node)->elements.nodes[index], buffer);
961 }
962 if (((pm_hash_pattern_node_t *)node)->rest == NULL) {
963 pm_buffer_append_byte(buffer, 0);
964 } else {
965 pm_serialize_node(parser, (pm_node_t *)((pm_hash_pattern_node_t *)node)->rest, buffer);
966 }
967 if (((pm_hash_pattern_node_t *)node)->opening_loc.start == NULL) {
968 pm_buffer_append_byte(buffer, 0);
969 } else {
970 pm_buffer_append_byte(buffer, 1);
971 pm_serialize_location(parser, &((pm_hash_pattern_node_t *)node)->opening_loc, buffer);
972 }
973 if (((pm_hash_pattern_node_t *)node)->closing_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)->closing_loc, buffer);
978 }
979 break;
980 }
981 case PM_IF_NODE: {
982 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
983 if (((pm_if_node_t *)node)->if_keyword_loc.start == NULL) {
984 pm_buffer_append_byte(buffer, 0);
985 } else {
986 pm_buffer_append_byte(buffer, 1);
987 pm_serialize_location(parser, &((pm_if_node_t *)node)->if_keyword_loc, buffer);
988 }
989 pm_serialize_node(parser, (pm_node_t *)((pm_if_node_t *)node)->predicate, buffer);
990 if (((pm_if_node_t *)node)->then_keyword_loc.start == NULL) {
991 pm_buffer_append_byte(buffer, 0);
992 } else {
993 pm_buffer_append_byte(buffer, 1);
994 pm_serialize_location(parser, &((pm_if_node_t *)node)->then_keyword_loc, buffer);
995 }
996 if (((pm_if_node_t *)node)->statements == NULL) {
997 pm_buffer_append_byte(buffer, 0);
998 } else {
999 pm_serialize_node(parser, (pm_node_t *)((pm_if_node_t *)node)->statements, buffer);
1000 }
1001 if (((pm_if_node_t *)node)->subsequent == NULL) {
1002 pm_buffer_append_byte(buffer, 0);
1003 } else {
1004 pm_serialize_node(parser, (pm_node_t *)((pm_if_node_t *)node)->subsequent, buffer);
1005 }
1006 if (((pm_if_node_t *)node)->end_keyword_loc.start == NULL) {
1007 pm_buffer_append_byte(buffer, 0);
1008 } else {
1009 pm_buffer_append_byte(buffer, 1);
1010 pm_serialize_location(parser, &((pm_if_node_t *)node)->end_keyword_loc, buffer);
1011 }
1012 break;
1013 }
1014 case PM_IMAGINARY_NODE: {
1015 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
1016 pm_serialize_node(parser, (pm_node_t *)((pm_imaginary_node_t *)node)->numeric, buffer);
1017 break;
1018 }
1019 case PM_IMPLICIT_NODE: {
1020 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
1021 pm_serialize_node(parser, (pm_node_t *)((pm_implicit_node_t *)node)->value, buffer);
1022 break;
1023 }
1024 case PM_IMPLICIT_REST_NODE: {
1025 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
1026 break;
1027 }
1028 case PM_IN_NODE: {
1029 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
1030 pm_serialize_node(parser, (pm_node_t *)((pm_in_node_t *)node)->pattern, buffer);
1031 if (((pm_in_node_t *)node)->statements == NULL) {
1032 pm_buffer_append_byte(buffer, 0);
1033 } else {
1034 pm_serialize_node(parser, (pm_node_t *)((pm_in_node_t *)node)->statements, buffer);
1035 }
1036 pm_serialize_location(parser, &((pm_in_node_t *)node)->in_loc, buffer);
1037 if (((pm_in_node_t *)node)->then_loc.start == NULL) {
1038 pm_buffer_append_byte(buffer, 0);
1039 } else {
1040 pm_buffer_append_byte(buffer, 1);
1041 pm_serialize_location(parser, &((pm_in_node_t *)node)->then_loc, buffer);
1042 }
1043 break;
1044 }
1045 case PM_INDEX_AND_WRITE_NODE: {
1046 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
1047 if (((pm_index_and_write_node_t *)node)->receiver == NULL) {
1048 pm_buffer_append_byte(buffer, 0);
1049 } else {
1050 pm_serialize_node(parser, (pm_node_t *)((pm_index_and_write_node_t *)node)->receiver, buffer);
1051 }
1052 if (((pm_index_and_write_node_t *)node)->call_operator_loc.start == NULL) {
1053 pm_buffer_append_byte(buffer, 0);
1054 } else {
1055 pm_buffer_append_byte(buffer, 1);
1056 pm_serialize_location(parser, &((pm_index_and_write_node_t *)node)->call_operator_loc, buffer);
1057 }
1058 pm_serialize_location(parser, &((pm_index_and_write_node_t *)node)->opening_loc, buffer);
1059 if (((pm_index_and_write_node_t *)node)->arguments == NULL) {
1060 pm_buffer_append_byte(buffer, 0);
1061 } else {
1062 pm_serialize_node(parser, (pm_node_t *)((pm_index_and_write_node_t *)node)->arguments, buffer);
1063 }
1064 pm_serialize_location(parser, &((pm_index_and_write_node_t *)node)->closing_loc, buffer);
1065 if (((pm_index_and_write_node_t *)node)->block == 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)->block, buffer);
1069 }
1070 pm_serialize_location(parser, &((pm_index_and_write_node_t *)node)->operator_loc, buffer);
1071 pm_serialize_node(parser, (pm_node_t *)((pm_index_and_write_node_t *)node)->value, buffer);
1072 break;
1073 }
1074 case PM_INDEX_OPERATOR_WRITE_NODE: {
1075 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
1076 if (((pm_index_operator_write_node_t *)node)->receiver == NULL) {
1077 pm_buffer_append_byte(buffer, 0);
1078 } else {
1079 pm_serialize_node(parser, (pm_node_t *)((pm_index_operator_write_node_t *)node)->receiver, buffer);
1080 }
1081 if (((pm_index_operator_write_node_t *)node)->call_operator_loc.start == NULL) {
1082 pm_buffer_append_byte(buffer, 0);
1083 } else {
1084 pm_buffer_append_byte(buffer, 1);
1085 pm_serialize_location(parser, &((pm_index_operator_write_node_t *)node)->call_operator_loc, buffer);
1086 }
1087 pm_serialize_location(parser, &((pm_index_operator_write_node_t *)node)->opening_loc, buffer);
1088 if (((pm_index_operator_write_node_t *)node)->arguments == NULL) {
1089 pm_buffer_append_byte(buffer, 0);
1090 } else {
1091 pm_serialize_node(parser, (pm_node_t *)((pm_index_operator_write_node_t *)node)->arguments, buffer);
1092 }
1093 pm_serialize_location(parser, &((pm_index_operator_write_node_t *)node)->closing_loc, buffer);
1094 if (((pm_index_operator_write_node_t *)node)->block == 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)->block, buffer);
1098 }
1099 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_index_operator_write_node_t *)node)->binary_operator));
1100 pm_serialize_location(parser, &((pm_index_operator_write_node_t *)node)->binary_operator_loc, buffer);
1101 pm_serialize_node(parser, (pm_node_t *)((pm_index_operator_write_node_t *)node)->value, buffer);
1102 break;
1103 }
1104 case PM_INDEX_OR_WRITE_NODE: {
1105 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
1106 if (((pm_index_or_write_node_t *)node)->receiver == NULL) {
1107 pm_buffer_append_byte(buffer, 0);
1108 } else {
1109 pm_serialize_node(parser, (pm_node_t *)((pm_index_or_write_node_t *)node)->receiver, buffer);
1110 }
1111 if (((pm_index_or_write_node_t *)node)->call_operator_loc.start == NULL) {
1112 pm_buffer_append_byte(buffer, 0);
1113 } else {
1114 pm_buffer_append_byte(buffer, 1);
1115 pm_serialize_location(parser, &((pm_index_or_write_node_t *)node)->call_operator_loc, buffer);
1116 }
1117 pm_serialize_location(parser, &((pm_index_or_write_node_t *)node)->opening_loc, buffer);
1118 if (((pm_index_or_write_node_t *)node)->arguments == NULL) {
1119 pm_buffer_append_byte(buffer, 0);
1120 } else {
1121 pm_serialize_node(parser, (pm_node_t *)((pm_index_or_write_node_t *)node)->arguments, buffer);
1122 }
1123 pm_serialize_location(parser, &((pm_index_or_write_node_t *)node)->closing_loc, buffer);
1124 if (((pm_index_or_write_node_t *)node)->block == 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)->block, buffer);
1128 }
1129 pm_serialize_location(parser, &((pm_index_or_write_node_t *)node)->operator_loc, buffer);
1130 pm_serialize_node(parser, (pm_node_t *)((pm_index_or_write_node_t *)node)->value, buffer);
1131 break;
1132 }
1133 case PM_INDEX_TARGET_NODE: {
1134 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
1135 pm_serialize_node(parser, (pm_node_t *)((pm_index_target_node_t *)node)->receiver, buffer);
1136 pm_serialize_location(parser, &((pm_index_target_node_t *)node)->opening_loc, buffer);
1137 if (((pm_index_target_node_t *)node)->arguments == NULL) {
1138 pm_buffer_append_byte(buffer, 0);
1139 } else {
1140 pm_serialize_node(parser, (pm_node_t *)((pm_index_target_node_t *)node)->arguments, buffer);
1141 }
1142 pm_serialize_location(parser, &((pm_index_target_node_t *)node)->closing_loc, buffer);
1143 if (((pm_index_target_node_t *)node)->block == NULL) {
1144 pm_buffer_append_byte(buffer, 0);
1145 } else {
1146 pm_serialize_node(parser, (pm_node_t *)((pm_index_target_node_t *)node)->block, buffer);
1147 }
1148 break;
1149 }
1150 case PM_INSTANCE_VARIABLE_AND_WRITE_NODE: {
1151 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
1152 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_instance_variable_and_write_node_t *)node)->name));
1153 pm_serialize_location(parser, &((pm_instance_variable_and_write_node_t *)node)->name_loc, buffer);
1154 pm_serialize_location(parser, &((pm_instance_variable_and_write_node_t *)node)->operator_loc, buffer);
1155 pm_serialize_node(parser, (pm_node_t *)((pm_instance_variable_and_write_node_t *)node)->value, buffer);
1156 break;
1157 }
1158 case PM_INSTANCE_VARIABLE_OPERATOR_WRITE_NODE: {
1159 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
1160 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_instance_variable_operator_write_node_t *)node)->name));
1161 pm_serialize_location(parser, &((pm_instance_variable_operator_write_node_t *)node)->name_loc, buffer);
1162 pm_serialize_location(parser, &((pm_instance_variable_operator_write_node_t *)node)->binary_operator_loc, buffer);
1163 pm_serialize_node(parser, (pm_node_t *)((pm_instance_variable_operator_write_node_t *)node)->value, buffer);
1164 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_instance_variable_operator_write_node_t *)node)->binary_operator));
1165 break;
1166 }
1167 case PM_INSTANCE_VARIABLE_OR_WRITE_NODE: {
1168 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
1169 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_instance_variable_or_write_node_t *)node)->name));
1170 pm_serialize_location(parser, &((pm_instance_variable_or_write_node_t *)node)->name_loc, buffer);
1171 pm_serialize_location(parser, &((pm_instance_variable_or_write_node_t *)node)->operator_loc, buffer);
1172 pm_serialize_node(parser, (pm_node_t *)((pm_instance_variable_or_write_node_t *)node)->value, buffer);
1173 break;
1174 }
1175 case PM_INSTANCE_VARIABLE_READ_NODE: {
1176 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
1177 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_instance_variable_read_node_t *)node)->name));
1178 break;
1179 }
1180 case PM_INSTANCE_VARIABLE_TARGET_NODE: {
1181 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
1182 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_instance_variable_target_node_t *)node)->name));
1183 break;
1184 }
1185 case PM_INSTANCE_VARIABLE_WRITE_NODE: {
1186 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
1187 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_instance_variable_write_node_t *)node)->name));
1188 pm_serialize_location(parser, &((pm_instance_variable_write_node_t *)node)->name_loc, buffer);
1189 pm_serialize_node(parser, (pm_node_t *)((pm_instance_variable_write_node_t *)node)->value, buffer);
1190 pm_serialize_location(parser, &((pm_instance_variable_write_node_t *)node)->operator_loc, buffer);
1191 break;
1192 }
1193 case PM_INTEGER_NODE: {
1194 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
1195 pm_serialize_integer(&((pm_integer_node_t *)node)->value, buffer);
1196 break;
1197 }
1198 case PM_INTERPOLATED_MATCH_LAST_LINE_NODE: {
1199 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
1200 pm_serialize_location(parser, &((pm_interpolated_match_last_line_node_t *)node)->opening_loc, buffer);
1201 uint32_t parts_size = pm_sizet_to_u32(((pm_interpolated_match_last_line_node_t *)node)->parts.size);
1202 pm_buffer_append_varuint(buffer, parts_size);
1203 for (uint32_t index = 0; index < parts_size; index++) {
1204 pm_serialize_node(parser, (pm_node_t *) ((pm_interpolated_match_last_line_node_t *)node)->parts.nodes[index], buffer);
1205 }
1206 pm_serialize_location(parser, &((pm_interpolated_match_last_line_node_t *)node)->closing_loc, buffer);
1207 break;
1208 }
1209 case PM_INTERPOLATED_REGULAR_EXPRESSION_NODE: {
1210 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
1211 pm_serialize_location(parser, &((pm_interpolated_regular_expression_node_t *)node)->opening_loc, buffer);
1212 uint32_t parts_size = pm_sizet_to_u32(((pm_interpolated_regular_expression_node_t *)node)->parts.size);
1213 pm_buffer_append_varuint(buffer, parts_size);
1214 for (uint32_t index = 0; index < parts_size; index++) {
1215 pm_serialize_node(parser, (pm_node_t *) ((pm_interpolated_regular_expression_node_t *)node)->parts.nodes[index], buffer);
1216 }
1217 pm_serialize_location(parser, &((pm_interpolated_regular_expression_node_t *)node)->closing_loc, buffer);
1218 break;
1219 }
1220 case PM_INTERPOLATED_STRING_NODE: {
1221 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
1222 if (((pm_interpolated_string_node_t *)node)->opening_loc.start == NULL) {
1223 pm_buffer_append_byte(buffer, 0);
1224 } else {
1225 pm_buffer_append_byte(buffer, 1);
1226 pm_serialize_location(parser, &((pm_interpolated_string_node_t *)node)->opening_loc, buffer);
1227 }
1228 uint32_t parts_size = pm_sizet_to_u32(((pm_interpolated_string_node_t *)node)->parts.size);
1229 pm_buffer_append_varuint(buffer, parts_size);
1230 for (uint32_t index = 0; index < parts_size; index++) {
1231 pm_serialize_node(parser, (pm_node_t *) ((pm_interpolated_string_node_t *)node)->parts.nodes[index], buffer);
1232 }
1233 if (((pm_interpolated_string_node_t *)node)->closing_loc.start == NULL) {
1234 pm_buffer_append_byte(buffer, 0);
1235 } else {
1236 pm_buffer_append_byte(buffer, 1);
1237 pm_serialize_location(parser, &((pm_interpolated_string_node_t *)node)->closing_loc, buffer);
1238 }
1239 break;
1240 }
1241 case PM_INTERPOLATED_SYMBOL_NODE: {
1242 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
1243 if (((pm_interpolated_symbol_node_t *)node)->opening_loc.start == NULL) {
1244 pm_buffer_append_byte(buffer, 0);
1245 } else {
1246 pm_buffer_append_byte(buffer, 1);
1247 pm_serialize_location(parser, &((pm_interpolated_symbol_node_t *)node)->opening_loc, buffer);
1248 }
1249 uint32_t parts_size = pm_sizet_to_u32(((pm_interpolated_symbol_node_t *)node)->parts.size);
1250 pm_buffer_append_varuint(buffer, parts_size);
1251 for (uint32_t index = 0; index < parts_size; index++) {
1252 pm_serialize_node(parser, (pm_node_t *) ((pm_interpolated_symbol_node_t *)node)->parts.nodes[index], buffer);
1253 }
1254 if (((pm_interpolated_symbol_node_t *)node)->closing_loc.start == NULL) {
1255 pm_buffer_append_byte(buffer, 0);
1256 } else {
1257 pm_buffer_append_byte(buffer, 1);
1258 pm_serialize_location(parser, &((pm_interpolated_symbol_node_t *)node)->closing_loc, buffer);
1259 }
1260 break;
1261 }
1262 case PM_INTERPOLATED_X_STRING_NODE: {
1263 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
1264 pm_serialize_location(parser, &((pm_interpolated_x_string_node_t *)node)->opening_loc, buffer);
1265 uint32_t parts_size = pm_sizet_to_u32(((pm_interpolated_x_string_node_t *)node)->parts.size);
1266 pm_buffer_append_varuint(buffer, parts_size);
1267 for (uint32_t index = 0; index < parts_size; index++) {
1268 pm_serialize_node(parser, (pm_node_t *) ((pm_interpolated_x_string_node_t *)node)->parts.nodes[index], buffer);
1269 }
1270 pm_serialize_location(parser, &((pm_interpolated_x_string_node_t *)node)->closing_loc, buffer);
1271 break;
1272 }
1273 case PM_IT_LOCAL_VARIABLE_READ_NODE: {
1274 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
1275 break;
1276 }
1277 case PM_IT_PARAMETERS_NODE: {
1278 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
1279 break;
1280 }
1281 case PM_KEYWORD_HASH_NODE: {
1282 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
1283 uint32_t elements_size = pm_sizet_to_u32(((pm_keyword_hash_node_t *)node)->elements.size);
1284 pm_buffer_append_varuint(buffer, elements_size);
1285 for (uint32_t index = 0; index < elements_size; index++) {
1286 pm_serialize_node(parser, (pm_node_t *) ((pm_keyword_hash_node_t *)node)->elements.nodes[index], buffer);
1287 }
1288 break;
1289 }
1290 case PM_KEYWORD_REST_PARAMETER_NODE: {
1291 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
1292 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_keyword_rest_parameter_node_t *)node)->name));
1293 if (((pm_keyword_rest_parameter_node_t *)node)->name_loc.start == NULL) {
1294 pm_buffer_append_byte(buffer, 0);
1295 } else {
1296 pm_buffer_append_byte(buffer, 1);
1297 pm_serialize_location(parser, &((pm_keyword_rest_parameter_node_t *)node)->name_loc, buffer);
1298 }
1299 pm_serialize_location(parser, &((pm_keyword_rest_parameter_node_t *)node)->operator_loc, buffer);
1300 break;
1301 }
1302 case PM_LAMBDA_NODE: {
1303 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
1304 uint32_t locals_size = pm_sizet_to_u32(((pm_lambda_node_t *)node)->locals.size);
1305 pm_buffer_append_varuint(buffer, locals_size);
1306 for (uint32_t index = 0; index < locals_size; index++) {
1307 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_lambda_node_t *)node)->locals.ids[index]));
1308 }
1309 pm_serialize_location(parser, &((pm_lambda_node_t *)node)->operator_loc, buffer);
1310 pm_serialize_location(parser, &((pm_lambda_node_t *)node)->opening_loc, buffer);
1311 pm_serialize_location(parser, &((pm_lambda_node_t *)node)->closing_loc, buffer);
1312 if (((pm_lambda_node_t *)node)->parameters == NULL) {
1313 pm_buffer_append_byte(buffer, 0);
1314 } else {
1315 pm_serialize_node(parser, (pm_node_t *)((pm_lambda_node_t *)node)->parameters, buffer);
1316 }
1317 if (((pm_lambda_node_t *)node)->body == NULL) {
1318 pm_buffer_append_byte(buffer, 0);
1319 } else {
1320 pm_serialize_node(parser, (pm_node_t *)((pm_lambda_node_t *)node)->body, buffer);
1321 }
1322 break;
1323 }
1324 case PM_LOCAL_VARIABLE_AND_WRITE_NODE: {
1325 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
1326 pm_serialize_location(parser, &((pm_local_variable_and_write_node_t *)node)->name_loc, buffer);
1327 pm_serialize_location(parser, &((pm_local_variable_and_write_node_t *)node)->operator_loc, buffer);
1328 pm_serialize_node(parser, (pm_node_t *)((pm_local_variable_and_write_node_t *)node)->value, buffer);
1329 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_local_variable_and_write_node_t *)node)->name));
1330 pm_buffer_append_varuint(buffer, ((pm_local_variable_and_write_node_t *)node)->depth);
1331 break;
1332 }
1333 case PM_LOCAL_VARIABLE_OPERATOR_WRITE_NODE: {
1334 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
1335 pm_serialize_location(parser, &((pm_local_variable_operator_write_node_t *)node)->name_loc, buffer);
1336 pm_serialize_location(parser, &((pm_local_variable_operator_write_node_t *)node)->binary_operator_loc, buffer);
1337 pm_serialize_node(parser, (pm_node_t *)((pm_local_variable_operator_write_node_t *)node)->value, buffer);
1338 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_local_variable_operator_write_node_t *)node)->name));
1339 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_local_variable_operator_write_node_t *)node)->binary_operator));
1340 pm_buffer_append_varuint(buffer, ((pm_local_variable_operator_write_node_t *)node)->depth);
1341 break;
1342 }
1343 case PM_LOCAL_VARIABLE_OR_WRITE_NODE: {
1344 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
1345 pm_serialize_location(parser, &((pm_local_variable_or_write_node_t *)node)->name_loc, buffer);
1346 pm_serialize_location(parser, &((pm_local_variable_or_write_node_t *)node)->operator_loc, buffer);
1347 pm_serialize_node(parser, (pm_node_t *)((pm_local_variable_or_write_node_t *)node)->value, buffer);
1348 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_local_variable_or_write_node_t *)node)->name));
1349 pm_buffer_append_varuint(buffer, ((pm_local_variable_or_write_node_t *)node)->depth);
1350 break;
1351 }
1352 case PM_LOCAL_VARIABLE_READ_NODE: {
1353 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
1354 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_local_variable_read_node_t *)node)->name));
1355 pm_buffer_append_varuint(buffer, ((pm_local_variable_read_node_t *)node)->depth);
1356 break;
1357 }
1358 case PM_LOCAL_VARIABLE_TARGET_NODE: {
1359 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
1360 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_local_variable_target_node_t *)node)->name));
1361 pm_buffer_append_varuint(buffer, ((pm_local_variable_target_node_t *)node)->depth);
1362 break;
1363 }
1364 case PM_LOCAL_VARIABLE_WRITE_NODE: {
1365 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
1366 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_local_variable_write_node_t *)node)->name));
1367 pm_buffer_append_varuint(buffer, ((pm_local_variable_write_node_t *)node)->depth);
1368 pm_serialize_location(parser, &((pm_local_variable_write_node_t *)node)->name_loc, buffer);
1369 pm_serialize_node(parser, (pm_node_t *)((pm_local_variable_write_node_t *)node)->value, buffer);
1370 pm_serialize_location(parser, &((pm_local_variable_write_node_t *)node)->operator_loc, buffer);
1371 break;
1372 }
1373 case PM_MATCH_LAST_LINE_NODE: {
1374 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
1375 pm_serialize_location(parser, &((pm_match_last_line_node_t *)node)->opening_loc, buffer);
1376 pm_serialize_location(parser, &((pm_match_last_line_node_t *)node)->content_loc, buffer);
1377 pm_serialize_location(parser, &((pm_match_last_line_node_t *)node)->closing_loc, buffer);
1378 pm_serialize_string(parser, &((pm_match_last_line_node_t *)node)->unescaped, buffer);
1379 break;
1380 }
1381 case PM_MATCH_PREDICATE_NODE: {
1382 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
1383 pm_serialize_node(parser, (pm_node_t *)((pm_match_predicate_node_t *)node)->value, buffer);
1384 pm_serialize_node(parser, (pm_node_t *)((pm_match_predicate_node_t *)node)->pattern, buffer);
1385 pm_serialize_location(parser, &((pm_match_predicate_node_t *)node)->operator_loc, buffer);
1386 break;
1387 }
1388 case PM_MATCH_REQUIRED_NODE: {
1389 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
1390 pm_serialize_node(parser, (pm_node_t *)((pm_match_required_node_t *)node)->value, buffer);
1391 pm_serialize_node(parser, (pm_node_t *)((pm_match_required_node_t *)node)->pattern, buffer);
1392 pm_serialize_location(parser, &((pm_match_required_node_t *)node)->operator_loc, buffer);
1393 break;
1394 }
1395 case PM_MATCH_WRITE_NODE: {
1396 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
1397 pm_serialize_node(parser, (pm_node_t *)((pm_match_write_node_t *)node)->call, buffer);
1398 uint32_t targets_size = pm_sizet_to_u32(((pm_match_write_node_t *)node)->targets.size);
1399 pm_buffer_append_varuint(buffer, targets_size);
1400 for (uint32_t index = 0; index < targets_size; index++) {
1401 pm_serialize_node(parser, (pm_node_t *) ((pm_match_write_node_t *)node)->targets.nodes[index], buffer);
1402 }
1403 break;
1404 }
1405 case PM_MISSING_NODE: {
1406 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
1407 break;
1408 }
1409 case PM_MODULE_NODE: {
1410 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
1411 uint32_t locals_size = pm_sizet_to_u32(((pm_module_node_t *)node)->locals.size);
1412 pm_buffer_append_varuint(buffer, locals_size);
1413 for (uint32_t index = 0; index < locals_size; index++) {
1414 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_module_node_t *)node)->locals.ids[index]));
1415 }
1416 pm_serialize_location(parser, &((pm_module_node_t *)node)->module_keyword_loc, buffer);
1417 pm_serialize_node(parser, (pm_node_t *)((pm_module_node_t *)node)->constant_path, buffer);
1418 if (((pm_module_node_t *)node)->body == NULL) {
1419 pm_buffer_append_byte(buffer, 0);
1420 } else {
1421 pm_serialize_node(parser, (pm_node_t *)((pm_module_node_t *)node)->body, buffer);
1422 }
1423 pm_serialize_location(parser, &((pm_module_node_t *)node)->end_keyword_loc, buffer);
1424 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_module_node_t *)node)->name));
1425 break;
1426 }
1427 case PM_MULTI_TARGET_NODE: {
1428 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
1429 uint32_t lefts_size = pm_sizet_to_u32(((pm_multi_target_node_t *)node)->lefts.size);
1430 pm_buffer_append_varuint(buffer, lefts_size);
1431 for (uint32_t index = 0; index < lefts_size; index++) {
1432 pm_serialize_node(parser, (pm_node_t *) ((pm_multi_target_node_t *)node)->lefts.nodes[index], buffer);
1433 }
1434 if (((pm_multi_target_node_t *)node)->rest == NULL) {
1435 pm_buffer_append_byte(buffer, 0);
1436 } else {
1437 pm_serialize_node(parser, (pm_node_t *)((pm_multi_target_node_t *)node)->rest, buffer);
1438 }
1439 uint32_t rights_size = pm_sizet_to_u32(((pm_multi_target_node_t *)node)->rights.size);
1440 pm_buffer_append_varuint(buffer, rights_size);
1441 for (uint32_t index = 0; index < rights_size; index++) {
1442 pm_serialize_node(parser, (pm_node_t *) ((pm_multi_target_node_t *)node)->rights.nodes[index], buffer);
1443 }
1444 if (((pm_multi_target_node_t *)node)->lparen_loc.start == NULL) {
1445 pm_buffer_append_byte(buffer, 0);
1446 } else {
1447 pm_buffer_append_byte(buffer, 1);
1448 pm_serialize_location(parser, &((pm_multi_target_node_t *)node)->lparen_loc, buffer);
1449 }
1450 if (((pm_multi_target_node_t *)node)->rparen_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)->rparen_loc, buffer);
1455 }
1456 break;
1457 }
1458 case PM_MULTI_WRITE_NODE: {
1459 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
1460 uint32_t lefts_size = pm_sizet_to_u32(((pm_multi_write_node_t *)node)->lefts.size);
1461 pm_buffer_append_varuint(buffer, lefts_size);
1462 for (uint32_t index = 0; index < lefts_size; index++) {
1463 pm_serialize_node(parser, (pm_node_t *) ((pm_multi_write_node_t *)node)->lefts.nodes[index], buffer);
1464 }
1465 if (((pm_multi_write_node_t *)node)->rest == NULL) {
1466 pm_buffer_append_byte(buffer, 0);
1467 } else {
1468 pm_serialize_node(parser, (pm_node_t *)((pm_multi_write_node_t *)node)->rest, buffer);
1469 }
1470 uint32_t rights_size = pm_sizet_to_u32(((pm_multi_write_node_t *)node)->rights.size);
1471 pm_buffer_append_varuint(buffer, rights_size);
1472 for (uint32_t index = 0; index < rights_size; index++) {
1473 pm_serialize_node(parser, (pm_node_t *) ((pm_multi_write_node_t *)node)->rights.nodes[index], buffer);
1474 }
1475 if (((pm_multi_write_node_t *)node)->lparen_loc.start == NULL) {
1476 pm_buffer_append_byte(buffer, 0);
1477 } else {
1478 pm_buffer_append_byte(buffer, 1);
1479 pm_serialize_location(parser, &((pm_multi_write_node_t *)node)->lparen_loc, buffer);
1480 }
1481 if (((pm_multi_write_node_t *)node)->rparen_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)->rparen_loc, buffer);
1486 }
1487 pm_serialize_location(parser, &((pm_multi_write_node_t *)node)->operator_loc, buffer);
1488 pm_serialize_node(parser, (pm_node_t *)((pm_multi_write_node_t *)node)->value, buffer);
1489 break;
1490 }
1491 case PM_NEXT_NODE: {
1492 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
1493 if (((pm_next_node_t *)node)->arguments == NULL) {
1494 pm_buffer_append_byte(buffer, 0);
1495 } else {
1496 pm_serialize_node(parser, (pm_node_t *)((pm_next_node_t *)node)->arguments, buffer);
1497 }
1498 pm_serialize_location(parser, &((pm_next_node_t *)node)->keyword_loc, buffer);
1499 break;
1500 }
1501 case PM_NIL_NODE: {
1502 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
1503 break;
1504 }
1505 case PM_NO_KEYWORDS_PARAMETER_NODE: {
1506 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
1507 pm_serialize_location(parser, &((pm_no_keywords_parameter_node_t *)node)->operator_loc, buffer);
1508 pm_serialize_location(parser, &((pm_no_keywords_parameter_node_t *)node)->keyword_loc, buffer);
1509 break;
1510 }
1511 case PM_NUMBERED_PARAMETERS_NODE: {
1512 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
1513 pm_buffer_append_byte(buffer, ((pm_numbered_parameters_node_t *)node)->maximum);
1514 break;
1515 }
1516 case PM_NUMBERED_REFERENCE_READ_NODE: {
1517 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
1518 pm_buffer_append_varuint(buffer, ((pm_numbered_reference_read_node_t *)node)->number);
1519 break;
1520 }
1521 case PM_OPTIONAL_KEYWORD_PARAMETER_NODE: {
1522 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
1523 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_optional_keyword_parameter_node_t *)node)->name));
1524 pm_serialize_location(parser, &((pm_optional_keyword_parameter_node_t *)node)->name_loc, buffer);
1525 pm_serialize_node(parser, (pm_node_t *)((pm_optional_keyword_parameter_node_t *)node)->value, buffer);
1526 break;
1527 }
1528 case PM_OPTIONAL_PARAMETER_NODE: {
1529 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
1530 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_optional_parameter_node_t *)node)->name));
1531 pm_serialize_location(parser, &((pm_optional_parameter_node_t *)node)->name_loc, buffer);
1532 pm_serialize_location(parser, &((pm_optional_parameter_node_t *)node)->operator_loc, buffer);
1533 pm_serialize_node(parser, (pm_node_t *)((pm_optional_parameter_node_t *)node)->value, buffer);
1534 break;
1535 }
1536 case PM_OR_NODE: {
1537 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
1538 pm_serialize_node(parser, (pm_node_t *)((pm_or_node_t *)node)->left, buffer);
1539 pm_serialize_node(parser, (pm_node_t *)((pm_or_node_t *)node)->right, buffer);
1540 pm_serialize_location(parser, &((pm_or_node_t *)node)->operator_loc, buffer);
1541 break;
1542 }
1543 case PM_PARAMETERS_NODE: {
1544 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
1545 uint32_t requireds_size = pm_sizet_to_u32(((pm_parameters_node_t *)node)->requireds.size);
1546 pm_buffer_append_varuint(buffer, requireds_size);
1547 for (uint32_t index = 0; index < requireds_size; index++) {
1548 pm_serialize_node(parser, (pm_node_t *) ((pm_parameters_node_t *)node)->requireds.nodes[index], buffer);
1549 }
1550 uint32_t optionals_size = pm_sizet_to_u32(((pm_parameters_node_t *)node)->optionals.size);
1551 pm_buffer_append_varuint(buffer, optionals_size);
1552 for (uint32_t index = 0; index < optionals_size; index++) {
1553 pm_serialize_node(parser, (pm_node_t *) ((pm_parameters_node_t *)node)->optionals.nodes[index], buffer);
1554 }
1555 if (((pm_parameters_node_t *)node)->rest == NULL) {
1556 pm_buffer_append_byte(buffer, 0);
1557 } else {
1558 pm_serialize_node(parser, (pm_node_t *)((pm_parameters_node_t *)node)->rest, buffer);
1559 }
1560 uint32_t posts_size = pm_sizet_to_u32(((pm_parameters_node_t *)node)->posts.size);
1561 pm_buffer_append_varuint(buffer, posts_size);
1562 for (uint32_t index = 0; index < posts_size; index++) {
1563 pm_serialize_node(parser, (pm_node_t *) ((pm_parameters_node_t *)node)->posts.nodes[index], buffer);
1564 }
1565 uint32_t keywords_size = pm_sizet_to_u32(((pm_parameters_node_t *)node)->keywords.size);
1566 pm_buffer_append_varuint(buffer, keywords_size);
1567 for (uint32_t index = 0; index < keywords_size; index++) {
1568 pm_serialize_node(parser, (pm_node_t *) ((pm_parameters_node_t *)node)->keywords.nodes[index], buffer);
1569 }
1570 if (((pm_parameters_node_t *)node)->keyword_rest == NULL) {
1571 pm_buffer_append_byte(buffer, 0);
1572 } else {
1573 pm_serialize_node(parser, (pm_node_t *)((pm_parameters_node_t *)node)->keyword_rest, buffer);
1574 }
1575 if (((pm_parameters_node_t *)node)->block == NULL) {
1576 pm_buffer_append_byte(buffer, 0);
1577 } else {
1578 pm_serialize_node(parser, (pm_node_t *)((pm_parameters_node_t *)node)->block, buffer);
1579 }
1580 break;
1581 }
1582 case PM_PARENTHESES_NODE: {
1583 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
1584 if (((pm_parentheses_node_t *)node)->body == NULL) {
1585 pm_buffer_append_byte(buffer, 0);
1586 } else {
1587 pm_serialize_node(parser, (pm_node_t *)((pm_parentheses_node_t *)node)->body, buffer);
1588 }
1589 pm_serialize_location(parser, &((pm_parentheses_node_t *)node)->opening_loc, buffer);
1590 pm_serialize_location(parser, &((pm_parentheses_node_t *)node)->closing_loc, buffer);
1591 break;
1592 }
1593 case PM_PINNED_EXPRESSION_NODE: {
1594 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
1595 pm_serialize_node(parser, (pm_node_t *)((pm_pinned_expression_node_t *)node)->expression, buffer);
1596 pm_serialize_location(parser, &((pm_pinned_expression_node_t *)node)->operator_loc, buffer);
1597 pm_serialize_location(parser, &((pm_pinned_expression_node_t *)node)->lparen_loc, buffer);
1598 pm_serialize_location(parser, &((pm_pinned_expression_node_t *)node)->rparen_loc, buffer);
1599 break;
1600 }
1601 case PM_PINNED_VARIABLE_NODE: {
1602 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
1603 pm_serialize_node(parser, (pm_node_t *)((pm_pinned_variable_node_t *)node)->variable, buffer);
1604 pm_serialize_location(parser, &((pm_pinned_variable_node_t *)node)->operator_loc, buffer);
1605 break;
1606 }
1607 case PM_POST_EXECUTION_NODE: {
1608 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
1609 if (((pm_post_execution_node_t *)node)->statements == NULL) {
1610 pm_buffer_append_byte(buffer, 0);
1611 } else {
1612 pm_serialize_node(parser, (pm_node_t *)((pm_post_execution_node_t *)node)->statements, buffer);
1613 }
1614 pm_serialize_location(parser, &((pm_post_execution_node_t *)node)->keyword_loc, buffer);
1615 pm_serialize_location(parser, &((pm_post_execution_node_t *)node)->opening_loc, buffer);
1616 pm_serialize_location(parser, &((pm_post_execution_node_t *)node)->closing_loc, buffer);
1617 break;
1618 }
1619 case PM_PRE_EXECUTION_NODE: {
1620 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
1621 if (((pm_pre_execution_node_t *)node)->statements == NULL) {
1622 pm_buffer_append_byte(buffer, 0);
1623 } else {
1624 pm_serialize_node(parser, (pm_node_t *)((pm_pre_execution_node_t *)node)->statements, buffer);
1625 }
1626 pm_serialize_location(parser, &((pm_pre_execution_node_t *)node)->keyword_loc, buffer);
1627 pm_serialize_location(parser, &((pm_pre_execution_node_t *)node)->opening_loc, buffer);
1628 pm_serialize_location(parser, &((pm_pre_execution_node_t *)node)->closing_loc, buffer);
1629 break;
1630 }
1631 case PM_PROGRAM_NODE: {
1632 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
1633 uint32_t locals_size = pm_sizet_to_u32(((pm_program_node_t *)node)->locals.size);
1634 pm_buffer_append_varuint(buffer, locals_size);
1635 for (uint32_t index = 0; index < locals_size; index++) {
1636 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_program_node_t *)node)->locals.ids[index]));
1637 }
1638 pm_serialize_node(parser, (pm_node_t *)((pm_program_node_t *)node)->statements, buffer);
1639 break;
1640 }
1641 case PM_RANGE_NODE: {
1642 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
1643 if (((pm_range_node_t *)node)->left == NULL) {
1644 pm_buffer_append_byte(buffer, 0);
1645 } else {
1646 pm_serialize_node(parser, (pm_node_t *)((pm_range_node_t *)node)->left, buffer);
1647 }
1648 if (((pm_range_node_t *)node)->right == NULL) {
1649 pm_buffer_append_byte(buffer, 0);
1650 } else {
1651 pm_serialize_node(parser, (pm_node_t *)((pm_range_node_t *)node)->right, buffer);
1652 }
1653 pm_serialize_location(parser, &((pm_range_node_t *)node)->operator_loc, buffer);
1654 break;
1655 }
1656 case PM_RATIONAL_NODE: {
1657 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
1658 pm_serialize_integer(&((pm_rational_node_t *)node)->numerator, buffer);
1659 pm_serialize_integer(&((pm_rational_node_t *)node)->denominator, buffer);
1660 break;
1661 }
1662 case PM_REDO_NODE: {
1663 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
1664 break;
1665 }
1666 case PM_REGULAR_EXPRESSION_NODE: {
1667 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
1668 pm_serialize_location(parser, &((pm_regular_expression_node_t *)node)->opening_loc, buffer);
1669 pm_serialize_location(parser, &((pm_regular_expression_node_t *)node)->content_loc, buffer);
1670 pm_serialize_location(parser, &((pm_regular_expression_node_t *)node)->closing_loc, buffer);
1671 pm_serialize_string(parser, &((pm_regular_expression_node_t *)node)->unescaped, buffer);
1672 break;
1673 }
1674 case PM_REQUIRED_KEYWORD_PARAMETER_NODE: {
1675 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
1676 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_required_keyword_parameter_node_t *)node)->name));
1677 pm_serialize_location(parser, &((pm_required_keyword_parameter_node_t *)node)->name_loc, buffer);
1678 break;
1679 }
1680 case PM_REQUIRED_PARAMETER_NODE: {
1681 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
1682 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_required_parameter_node_t *)node)->name));
1683 break;
1684 }
1685 case PM_RESCUE_MODIFIER_NODE: {
1686 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
1687 pm_serialize_node(parser, (pm_node_t *)((pm_rescue_modifier_node_t *)node)->expression, buffer);
1688 pm_serialize_location(parser, &((pm_rescue_modifier_node_t *)node)->keyword_loc, buffer);
1689 pm_serialize_node(parser, (pm_node_t *)((pm_rescue_modifier_node_t *)node)->rescue_expression, buffer);
1690 break;
1691 }
1692 case PM_RESCUE_NODE: {
1693 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
1694 pm_serialize_location(parser, &((pm_rescue_node_t *)node)->keyword_loc, buffer);
1695 uint32_t exceptions_size = pm_sizet_to_u32(((pm_rescue_node_t *)node)->exceptions.size);
1696 pm_buffer_append_varuint(buffer, exceptions_size);
1697 for (uint32_t index = 0; index < exceptions_size; index++) {
1698 pm_serialize_node(parser, (pm_node_t *) ((pm_rescue_node_t *)node)->exceptions.nodes[index], buffer);
1699 }
1700 if (((pm_rescue_node_t *)node)->operator_loc.start == NULL) {
1701 pm_buffer_append_byte(buffer, 0);
1702 } else {
1703 pm_buffer_append_byte(buffer, 1);
1704 pm_serialize_location(parser, &((pm_rescue_node_t *)node)->operator_loc, buffer);
1705 }
1706 if (((pm_rescue_node_t *)node)->reference == NULL) {
1707 pm_buffer_append_byte(buffer, 0);
1708 } else {
1709 pm_serialize_node(parser, (pm_node_t *)((pm_rescue_node_t *)node)->reference, buffer);
1710 }
1711 if (((pm_rescue_node_t *)node)->then_keyword_loc.start == NULL) {
1712 pm_buffer_append_byte(buffer, 0);
1713 } else {
1714 pm_buffer_append_byte(buffer, 1);
1715 pm_serialize_location(parser, &((pm_rescue_node_t *)node)->then_keyword_loc, buffer);
1716 }
1717 if (((pm_rescue_node_t *)node)->statements == NULL) {
1718 pm_buffer_append_byte(buffer, 0);
1719 } else {
1720 pm_serialize_node(parser, (pm_node_t *)((pm_rescue_node_t *)node)->statements, buffer);
1721 }
1722 if (((pm_rescue_node_t *)node)->subsequent == NULL) {
1723 pm_buffer_append_byte(buffer, 0);
1724 } else {
1725 pm_serialize_node(parser, (pm_node_t *)((pm_rescue_node_t *)node)->subsequent, buffer);
1726 }
1727 break;
1728 }
1729 case PM_REST_PARAMETER_NODE: {
1730 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
1731 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_rest_parameter_node_t *)node)->name));
1732 if (((pm_rest_parameter_node_t *)node)->name_loc.start == NULL) {
1733 pm_buffer_append_byte(buffer, 0);
1734 } else {
1735 pm_buffer_append_byte(buffer, 1);
1736 pm_serialize_location(parser, &((pm_rest_parameter_node_t *)node)->name_loc, buffer);
1737 }
1738 pm_serialize_location(parser, &((pm_rest_parameter_node_t *)node)->operator_loc, buffer);
1739 break;
1740 }
1741 case PM_RETRY_NODE: {
1742 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
1743 break;
1744 }
1745 case PM_RETURN_NODE: {
1746 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
1747 pm_serialize_location(parser, &((pm_return_node_t *)node)->keyword_loc, buffer);
1748 if (((pm_return_node_t *)node)->arguments == NULL) {
1749 pm_buffer_append_byte(buffer, 0);
1750 } else {
1751 pm_serialize_node(parser, (pm_node_t *)((pm_return_node_t *)node)->arguments, buffer);
1752 }
1753 break;
1754 }
1755 case PM_SELF_NODE: {
1756 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
1757 break;
1758 }
1759 case PM_SHAREABLE_CONSTANT_NODE: {
1760 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
1761 pm_serialize_node(parser, (pm_node_t *)((pm_shareable_constant_node_t *)node)->write, buffer);
1762 break;
1763 }
1764 case PM_SINGLETON_CLASS_NODE: {
1765 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
1766 uint32_t locals_size = pm_sizet_to_u32(((pm_singleton_class_node_t *)node)->locals.size);
1767 pm_buffer_append_varuint(buffer, locals_size);
1768 for (uint32_t index = 0; index < locals_size; index++) {
1769 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(((pm_singleton_class_node_t *)node)->locals.ids[index]));
1770 }
1771 pm_serialize_location(parser, &((pm_singleton_class_node_t *)node)->class_keyword_loc, buffer);
1772 pm_serialize_location(parser, &((pm_singleton_class_node_t *)node)->operator_loc, buffer);
1773 pm_serialize_node(parser, (pm_node_t *)((pm_singleton_class_node_t *)node)->expression, buffer);
1774 if (((pm_singleton_class_node_t *)node)->body == NULL) {
1775 pm_buffer_append_byte(buffer, 0);
1776 } else {
1777 pm_serialize_node(parser, (pm_node_t *)((pm_singleton_class_node_t *)node)->body, buffer);
1778 }
1779 pm_serialize_location(parser, &((pm_singleton_class_node_t *)node)->end_keyword_loc, buffer);
1780 break;
1781 }
1782 case PM_SOURCE_ENCODING_NODE: {
1783 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
1784 break;
1785 }
1786 case PM_SOURCE_FILE_NODE: {
1787 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
1788 pm_serialize_string(parser, &((pm_source_file_node_t *)node)->filepath, buffer);
1789 break;
1790 }
1791 case PM_SOURCE_LINE_NODE: {
1792 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
1793 break;
1794 }
1795 case PM_SPLAT_NODE: {
1796 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
1797 pm_serialize_location(parser, &((pm_splat_node_t *)node)->operator_loc, buffer);
1798 if (((pm_splat_node_t *)node)->expression == NULL) {
1799 pm_buffer_append_byte(buffer, 0);
1800 } else {
1801 pm_serialize_node(parser, (pm_node_t *)((pm_splat_node_t *)node)->expression, buffer);
1802 }
1803 break;
1804 }
1805 case PM_STATEMENTS_NODE: {
1806 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
1807 uint32_t body_size = pm_sizet_to_u32(((pm_statements_node_t *)node)->body.size);
1808 pm_buffer_append_varuint(buffer, body_size);
1809 for (uint32_t index = 0; index < body_size; index++) {
1810 pm_serialize_node(parser, (pm_node_t *) ((pm_statements_node_t *)node)->body.nodes[index], buffer);
1811 }
1812 break;
1813 }
1814 case PM_STRING_NODE: {
1815 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
1816 if (((pm_string_node_t *)node)->opening_loc.start == NULL) {
1817 pm_buffer_append_byte(buffer, 0);
1818 } else {
1819 pm_buffer_append_byte(buffer, 1);
1820 pm_serialize_location(parser, &((pm_string_node_t *)node)->opening_loc, buffer);
1821 }
1822 pm_serialize_location(parser, &((pm_string_node_t *)node)->content_loc, buffer);
1823 if (((pm_string_node_t *)node)->closing_loc.start == NULL) {
1824 pm_buffer_append_byte(buffer, 0);
1825 } else {
1826 pm_buffer_append_byte(buffer, 1);
1827 pm_serialize_location(parser, &((pm_string_node_t *)node)->closing_loc, buffer);
1828 }
1829 pm_serialize_string(parser, &((pm_string_node_t *)node)->unescaped, buffer);
1830 break;
1831 }
1832 case PM_SUPER_NODE: {
1833 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
1834 pm_serialize_location(parser, &((pm_super_node_t *)node)->keyword_loc, buffer);
1835 if (((pm_super_node_t *)node)->lparen_loc.start == NULL) {
1836 pm_buffer_append_byte(buffer, 0);
1837 } else {
1838 pm_buffer_append_byte(buffer, 1);
1839 pm_serialize_location(parser, &((pm_super_node_t *)node)->lparen_loc, buffer);
1840 }
1841 if (((pm_super_node_t *)node)->arguments == NULL) {
1842 pm_buffer_append_byte(buffer, 0);
1843 } else {
1844 pm_serialize_node(parser, (pm_node_t *)((pm_super_node_t *)node)->arguments, buffer);
1845 }
1846 if (((pm_super_node_t *)node)->rparen_loc.start == NULL) {
1847 pm_buffer_append_byte(buffer, 0);
1848 } else {
1849 pm_buffer_append_byte(buffer, 1);
1850 pm_serialize_location(parser, &((pm_super_node_t *)node)->rparen_loc, buffer);
1851 }
1852 if (((pm_super_node_t *)node)->block == NULL) {
1853 pm_buffer_append_byte(buffer, 0);
1854 } else {
1855 pm_serialize_node(parser, (pm_node_t *)((pm_super_node_t *)node)->block, buffer);
1856 }
1857 break;
1858 }
1859 case PM_SYMBOL_NODE: {
1860 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
1861 if (((pm_symbol_node_t *)node)->opening_loc.start == NULL) {
1862 pm_buffer_append_byte(buffer, 0);
1863 } else {
1864 pm_buffer_append_byte(buffer, 1);
1865 pm_serialize_location(parser, &((pm_symbol_node_t *)node)->opening_loc, buffer);
1866 }
1867 if (((pm_symbol_node_t *)node)->value_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)->value_loc, buffer);
1872 }
1873 if (((pm_symbol_node_t *)node)->closing_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)->closing_loc, buffer);
1878 }
1879 pm_serialize_string(parser, &((pm_symbol_node_t *)node)->unescaped, buffer);
1880 break;
1881 }
1882 case PM_TRUE_NODE: {
1883 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
1884 break;
1885 }
1886 case PM_UNDEF_NODE: {
1887 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
1888 uint32_t names_size = pm_sizet_to_u32(((pm_undef_node_t *)node)->names.size);
1889 pm_buffer_append_varuint(buffer, names_size);
1890 for (uint32_t index = 0; index < names_size; index++) {
1891 pm_serialize_node(parser, (pm_node_t *) ((pm_undef_node_t *)node)->names.nodes[index], buffer);
1892 }
1893 pm_serialize_location(parser, &((pm_undef_node_t *)node)->keyword_loc, buffer);
1894 break;
1895 }
1896 case PM_UNLESS_NODE: {
1897 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
1898 pm_serialize_location(parser, &((pm_unless_node_t *)node)->keyword_loc, buffer);
1899 pm_serialize_node(parser, (pm_node_t *)((pm_unless_node_t *)node)->predicate, buffer);
1900 if (((pm_unless_node_t *)node)->then_keyword_loc.start == NULL) {
1901 pm_buffer_append_byte(buffer, 0);
1902 } else {
1903 pm_buffer_append_byte(buffer, 1);
1904 pm_serialize_location(parser, &((pm_unless_node_t *)node)->then_keyword_loc, buffer);
1905 }
1906 if (((pm_unless_node_t *)node)->statements == NULL) {
1907 pm_buffer_append_byte(buffer, 0);
1908 } else {
1909 pm_serialize_node(parser, (pm_node_t *)((pm_unless_node_t *)node)->statements, buffer);
1910 }
1911 if (((pm_unless_node_t *)node)->else_clause == NULL) {
1912 pm_buffer_append_byte(buffer, 0);
1913 } else {
1914 pm_serialize_node(parser, (pm_node_t *)((pm_unless_node_t *)node)->else_clause, buffer);
1915 }
1916 if (((pm_unless_node_t *)node)->end_keyword_loc.start == NULL) {
1917 pm_buffer_append_byte(buffer, 0);
1918 } else {
1919 pm_buffer_append_byte(buffer, 1);
1920 pm_serialize_location(parser, &((pm_unless_node_t *)node)->end_keyword_loc, buffer);
1921 }
1922 break;
1923 }
1924 case PM_UNTIL_NODE: {
1925 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
1926 pm_serialize_location(parser, &((pm_until_node_t *)node)->keyword_loc, buffer);
1927 if (((pm_until_node_t *)node)->do_keyword_loc.start == NULL) {
1928 pm_buffer_append_byte(buffer, 0);
1929 } else {
1930 pm_buffer_append_byte(buffer, 1);
1931 pm_serialize_location(parser, &((pm_until_node_t *)node)->do_keyword_loc, buffer);
1932 }
1933 if (((pm_until_node_t *)node)->closing_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)->closing_loc, buffer);
1938 }
1939 pm_serialize_node(parser, (pm_node_t *)((pm_until_node_t *)node)->predicate, buffer);
1940 if (((pm_until_node_t *)node)->statements == NULL) {
1941 pm_buffer_append_byte(buffer, 0);
1942 } else {
1943 pm_serialize_node(parser, (pm_node_t *)((pm_until_node_t *)node)->statements, buffer);
1944 }
1945 break;
1946 }
1947 case PM_WHEN_NODE: {
1948 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
1949 pm_serialize_location(parser, &((pm_when_node_t *)node)->keyword_loc, buffer);
1950 uint32_t conditions_size = pm_sizet_to_u32(((pm_when_node_t *)node)->conditions.size);
1951 pm_buffer_append_varuint(buffer, conditions_size);
1952 for (uint32_t index = 0; index < conditions_size; index++) {
1953 pm_serialize_node(parser, (pm_node_t *) ((pm_when_node_t *)node)->conditions.nodes[index], buffer);
1954 }
1955 if (((pm_when_node_t *)node)->then_keyword_loc.start == NULL) {
1956 pm_buffer_append_byte(buffer, 0);
1957 } else {
1958 pm_buffer_append_byte(buffer, 1);
1959 pm_serialize_location(parser, &((pm_when_node_t *)node)->then_keyword_loc, buffer);
1960 }
1961 if (((pm_when_node_t *)node)->statements == NULL) {
1962 pm_buffer_append_byte(buffer, 0);
1963 } else {
1964 pm_serialize_node(parser, (pm_node_t *)((pm_when_node_t *)node)->statements, buffer);
1965 }
1966 break;
1967 }
1968 case PM_WHILE_NODE: {
1969 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
1970 pm_serialize_location(parser, &((pm_while_node_t *)node)->keyword_loc, buffer);
1971 if (((pm_while_node_t *)node)->do_keyword_loc.start == NULL) {
1972 pm_buffer_append_byte(buffer, 0);
1973 } else {
1974 pm_buffer_append_byte(buffer, 1);
1975 pm_serialize_location(parser, &((pm_while_node_t *)node)->do_keyword_loc, buffer);
1976 }
1977 if (((pm_while_node_t *)node)->closing_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)->closing_loc, buffer);
1982 }
1983 pm_serialize_node(parser, (pm_node_t *)((pm_while_node_t *)node)->predicate, buffer);
1984 if (((pm_while_node_t *)node)->statements == NULL) {
1985 pm_buffer_append_byte(buffer, 0);
1986 } else {
1987 pm_serialize_node(parser, (pm_node_t *)((pm_while_node_t *)node)->statements, buffer);
1988 }
1989 break;
1990 }
1991 case PM_X_STRING_NODE: {
1992 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
1993 pm_serialize_location(parser, &((pm_x_string_node_t *)node)->opening_loc, buffer);
1994 pm_serialize_location(parser, &((pm_x_string_node_t *)node)->content_loc, buffer);
1995 pm_serialize_location(parser, &((pm_x_string_node_t *)node)->closing_loc, buffer);
1996 pm_serialize_string(parser, &((pm_x_string_node_t *)node)->unescaped, buffer);
1997 break;
1998 }
1999 case PM_YIELD_NODE: {
2000 pm_buffer_append_varuint(buffer, (uint32_t) node->flags);
2001 pm_serialize_location(parser, &((pm_yield_node_t *)node)->keyword_loc, buffer);
2002 if (((pm_yield_node_t *)node)->lparen_loc.start == NULL) {
2003 pm_buffer_append_byte(buffer, 0);
2004 } else {
2005 pm_buffer_append_byte(buffer, 1);
2006 pm_serialize_location(parser, &((pm_yield_node_t *)node)->lparen_loc, buffer);
2007 }
2008 if (((pm_yield_node_t *)node)->arguments == NULL) {
2009 pm_buffer_append_byte(buffer, 0);
2010 } else {
2011 pm_serialize_node(parser, (pm_node_t *)((pm_yield_node_t *)node)->arguments, buffer);
2012 }
2013 if (((pm_yield_node_t *)node)->rparen_loc.start == NULL) {
2014 pm_buffer_append_byte(buffer, 0);
2015 } else {
2016 pm_buffer_append_byte(buffer, 1);
2017 pm_serialize_location(parser, &((pm_yield_node_t *)node)->rparen_loc, buffer);
2018 }
2019 break;
2020 }
2021 }
2022}
2023
2024static void
2025pm_serialize_newline_list(pm_newline_list_t *list, pm_buffer_t *buffer) {
2026 uint32_t size = pm_sizet_to_u32(list->size);
2027 pm_buffer_append_varuint(buffer, size);
2028
2029 for (uint32_t i = 0; i < size; i++) {
2030 uint32_t offset = pm_sizet_to_u32(list->offsets[i]);
2031 pm_buffer_append_varuint(buffer, offset);
2032 }
2033}
2034
2035static void
2036pm_serialize_comment(pm_parser_t *parser, pm_comment_t *comment, pm_buffer_t *buffer) {
2037 // serialize type
2038 pm_buffer_append_byte(buffer, (uint8_t) comment->type);
2039
2040 // serialize location
2041 pm_serialize_location(parser, &comment->location, buffer);
2042}
2043
2047void
2048pm_serialize_comment_list(pm_parser_t *parser, pm_list_t *list, pm_buffer_t *buffer) {
2049 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(pm_list_size(list)));
2050
2051 pm_comment_t *comment;
2052 for (comment = (pm_comment_t *) list->head; comment != NULL; comment = (pm_comment_t *) comment->node.next) {
2053 pm_serialize_comment(parser, comment, buffer);
2054 }
2055}
2056
2057static void
2058pm_serialize_magic_comment(pm_parser_t *parser, pm_magic_comment_t *magic_comment, pm_buffer_t *buffer) {
2059 // serialize key location
2060 pm_buffer_append_varuint(buffer, pm_ptrdifft_to_u32(magic_comment->key_start - parser->start));
2061 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(magic_comment->key_length));
2062
2063 // serialize value location
2064 pm_buffer_append_varuint(buffer, pm_ptrdifft_to_u32(magic_comment->value_start - parser->start));
2065 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(magic_comment->value_length));
2066}
2067
2068static void
2069pm_serialize_magic_comment_list(pm_parser_t *parser, pm_list_t *list, pm_buffer_t *buffer) {
2070 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(pm_list_size(list)));
2071
2072 pm_magic_comment_t *magic_comment;
2073 for (magic_comment = (pm_magic_comment_t *) list->head; magic_comment != NULL; magic_comment = (pm_magic_comment_t *) magic_comment->node.next) {
2074 pm_serialize_magic_comment(parser, magic_comment, buffer);
2075 }
2076}
2077
2078static void
2079pm_serialize_data_loc(const pm_parser_t *parser, pm_buffer_t *buffer) {
2080 if (parser->data_loc.end == NULL) {
2081 pm_buffer_append_byte(buffer, 0);
2082 } else {
2083 pm_buffer_append_byte(buffer, 1);
2084 pm_serialize_location(parser, &parser->data_loc, buffer);
2085 }
2086}
2087
2088static void
2089pm_serialize_diagnostic(pm_parser_t *parser, pm_diagnostic_t *diagnostic, pm_buffer_t *buffer) {
2090 // serialize the type
2091 pm_buffer_append_varuint(buffer, (uint32_t) diagnostic->diag_id);
2092
2093 // serialize message
2094 size_t message_length = strlen(diagnostic->message);
2095 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(message_length));
2096 pm_buffer_append_string(buffer, diagnostic->message, message_length);
2097
2098 // serialize location
2099 pm_serialize_location(parser, &diagnostic->location, buffer);
2100
2101 pm_buffer_append_byte(buffer, diagnostic->level);
2102}
2103
2104static void
2105pm_serialize_diagnostic_list(pm_parser_t *parser, pm_list_t *list, pm_buffer_t *buffer) {
2106 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(pm_list_size(list)));
2107
2108 pm_diagnostic_t *diagnostic;
2109 for (diagnostic = (pm_diagnostic_t *) list->head; diagnostic != NULL; diagnostic = (pm_diagnostic_t *) diagnostic->node.next) {
2110 pm_serialize_diagnostic(parser, diagnostic, buffer);
2111 }
2112}
2113
2117void
2118pm_serialize_encoding(const pm_encoding_t *encoding, pm_buffer_t *buffer) {
2119 size_t encoding_length = strlen(encoding->name);
2120 pm_buffer_append_varuint(buffer, pm_sizet_to_u32(encoding_length));
2121 pm_buffer_append_string(buffer, encoding->name, encoding_length);
2122}
2123
2124static void
2125pm_serialize_metadata(pm_parser_t *parser, pm_buffer_t *buffer) {
2126 pm_serialize_encoding(parser->encoding, buffer);
2127 pm_buffer_append_varsint(buffer, parser->start_line);
2128 pm_serialize_newline_list(&parser->newline_list, buffer);
2129 pm_serialize_comment_list(parser, &parser->comment_list, buffer);
2130 pm_serialize_magic_comment_list(parser, &parser->magic_comment_list, buffer);
2131 pm_serialize_data_loc(parser, buffer);
2132 pm_serialize_diagnostic_list(parser, &parser->error_list, buffer);
2133 pm_serialize_diagnostic_list(parser, &parser->warning_list, buffer);
2134}
2135
2136#line 275 "prism/templates/src/serialize.c.erb"
2140void
2141pm_serialize_content(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) {
2142 pm_serialize_metadata(parser, buffer);
2143
2144 // Here we're going to leave space for the offset of the constant pool in
2145 // the buffer.
2146 size_t offset = buffer->length;
2147 pm_buffer_append_zeroes(buffer, 4);
2148
2149 // Next, encode the length of the constant pool.
2150 pm_buffer_append_varuint(buffer, parser->constant_pool.size);
2151
2152 // Now we're going to serialize the content of the node.
2153 pm_serialize_node(parser, node, buffer);
2154
2155 // Now we're going to serialize the offset of the constant pool back where
2156 // we left space for it.
2157 uint32_t length = pm_sizet_to_u32(buffer->length);
2158 memcpy(buffer->value + offset, &length, sizeof(uint32_t));
2159
2160 // Now we're going to serialize the constant pool.
2161 offset = buffer->length;
2162 pm_buffer_append_zeroes(buffer, parser->constant_pool.size * 8);
2163
2164 for (uint32_t index = 0; index < parser->constant_pool.capacity; index++) {
2165 pm_constant_pool_bucket_t *bucket = &parser->constant_pool.buckets[index];
2166
2167 // If we find a constant at this index, serialize it at the correct
2168 // index in the buffer.
2169 if (bucket->id != 0) {
2170 pm_constant_t *constant = &parser->constant_pool.constants[bucket->id - 1];
2171 size_t buffer_offset = offset + ((((size_t)bucket->id) - 1) * 8);
2172
2173 if (bucket->type == PM_CONSTANT_POOL_BUCKET_OWNED || bucket->type == PM_CONSTANT_POOL_BUCKET_CONSTANT) {
2174 // Since this is an owned or constant constant, we are going to
2175 // write its contents into the buffer after the constant pool.
2176 // So effectively in place of the source offset, we have a
2177 // buffer offset. We will add a leading 1 to indicate that this
2178 // is a buffer offset.
2179 uint32_t content_offset = pm_sizet_to_u32(buffer->length);
2180 uint32_t owned_mask = (uint32_t) (1 << 31);
2181
2182 assert(content_offset < owned_mask);
2183 content_offset |= owned_mask;
2184
2185 memcpy(buffer->value + buffer_offset, &content_offset, 4);
2186 pm_buffer_append_bytes(buffer, constant->start, constant->length);
2187 } else {
2188 // Since this is a shared constant, we are going to write its
2189 // source offset directly into the buffer.
2190 uint32_t source_offset = pm_ptrdifft_to_u32(constant->start - parser->start);
2191 memcpy(buffer->value + buffer_offset, &source_offset, 4);
2192 }
2193
2194 // Now we can write the length of the constant into the buffer.
2195 uint32_t constant_length = pm_sizet_to_u32(constant->length);
2196 memcpy(buffer->value + buffer_offset + 4, &constant_length, 4);
2197 }
2198 }
2199}
2200
2201static void
2202serialize_token(void *data, pm_parser_t *parser, pm_token_t *token) {
2203 pm_buffer_t *buffer = (pm_buffer_t *) data;
2204
2205 pm_buffer_append_varuint(buffer, token->type);
2206 pm_buffer_append_varuint(buffer, pm_ptrdifft_to_u32(token->start - parser->start));
2207 pm_buffer_append_varuint(buffer, pm_ptrdifft_to_u32(token->end - token->start));
2208 pm_buffer_append_varuint(buffer, parser->lex_state);
2209}
2210
2214 PRISM_EXPORTED_FUNCTION void
2215pm_serialize_lex(pm_buffer_t *buffer, const uint8_t *source, size_t size, const char *data) {
2216 pm_options_t options = { 0 };
2217 pm_options_read(&options, data);
2218
2219 pm_parser_t parser;
2220 pm_parser_init(&parser, source, size, &options);
2221
2222 pm_lex_callback_t lex_callback = (pm_lex_callback_t) {
2223 .data = (void *) buffer,
2224 .callback = serialize_token,
2225 };
2226
2227 parser.lex_callback = &lex_callback;
2228 pm_node_t *node = pm_parse(&parser);
2229
2230 // Append 0 to mark end of tokens.
2231 pm_buffer_append_byte(buffer, 0);
2232
2233 pm_serialize_metadata(&parser, buffer);
2234
2235 pm_node_destroy(&parser, node);
2236 pm_parser_free(&parser);
2237 pm_options_free(&options);
2238}
2239
2244 PRISM_EXPORTED_FUNCTION void
2245pm_serialize_parse_lex(pm_buffer_t *buffer, const uint8_t *source, size_t size, const char *data) {
2246 pm_options_t options = { 0 };
2247 pm_options_read(&options, data);
2248
2249 pm_parser_t parser;
2250 pm_parser_init(&parser, source, size, &options);
2251
2252 pm_lex_callback_t lex_callback = (pm_lex_callback_t) {
2253 .data = (void *) buffer,
2254 .callback = serialize_token,
2255 };
2256
2257 parser.lex_callback = &lex_callback;
2258 pm_node_t *node = pm_parse(&parser);
2259
2260 pm_buffer_append_byte(buffer, 0);
2261 pm_serialize(&parser, node, buffer);
2262
2263 pm_node_destroy(&parser, node);
2264 pm_parser_free(&parser);
2265 pm_options_free(&options);
2266}
2267
2268#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:2215
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:2141
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:2245
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:2118
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:2048
magic_comment
Definition parse.c:20345
pm_buffer_t
A pm_buffer_t is a simple memory buffer that stores data in a contiguous block of memory.
Definition pm_buffer.h:22
pm_buffer_t::length
size_t length
The length of the buffer in bytes.
Definition pm_buffer.h:24
pm_buffer_t::value
char * value
A pointer to the start of the buffer.
Definition pm_buffer.h:30
pm_comment::node
pm_list_node_t node
The embedded base node.
Definition parser.h:460
pm_comment::type
pm_comment_type_t type
The type of comment that we've found.
Definition parser.h:466
pm_comment::location
pm_location_t location
The location of the comment in the source.
Definition parser.h:463
pm_constant_pool_bucket_t
A bucket in the hash map.
Definition pm_constant_pool.h:113
pm_constant_pool_bucket_t::id
unsigned int id
The incremental ID used for indexing back into the pool.
Definition pm_constant_pool.h:115
pm_constant_pool_bucket_t::type
pm_constant_pool_bucket_type_t type
The type of the bucket, which determines how to free it.
Definition pm_constant_pool.h:118
pm_constant_pool_t::capacity
uint32_t capacity
The number of buckets that have been allocated in the hash map.
Definition pm_constant_pool.h:145
pm_constant_pool_t::buckets
pm_constant_pool_bucket_t * buckets
The buckets in the hash map.
Definition pm_constant_pool.h:136
pm_constant_pool_t::size
uint32_t size
The number of buckets in the hash map.
Definition pm_constant_pool.h:142
pm_constant_pool_t::constants
pm_constant_t * constants
The constants that are stored in the buckets.
Definition pm_constant_pool.h:139
pm_constant_t
A constant in the pool which effectively stores a string.
Definition pm_constant_pool.h:125
pm_constant_t::length
size_t length
The length of the string.
Definition pm_constant_pool.h:130
pm_constant_t::start
const uint8_t * start
A pointer to the start of the string.
Definition pm_constant_pool.h:127
pm_diagnostic_t
This struct represents a diagnostic generated during parsing.
Definition diagnostic.h:364
pm_diagnostic_t::location
pm_location_t location
The location of the diagnostic in the source.
Definition diagnostic.h:369
pm_diagnostic_t::message
const char * message
The message associated with the diagnostic.
Definition diagnostic.h:375
pm_diagnostic_t::node
pm_list_node_t node
The embedded base node.
Definition diagnostic.h:366
pm_diagnostic_t::diag_id
pm_diagnostic_id_t diag_id
The ID of the diagnostic.
Definition diagnostic.h:372
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:388
pm_encoding_t
This struct defines the functions necessary to implement the encoding interface so we can determine h...
Definition encoding.h:23
pm_encoding_t::name
const char * name
The name of the encoding.
Definition encoding.h:56
pm_integer_t
A structure represents an arbitrary-sized integer.
Definition pm_integer.h:20
pm_integer_t::length
size_t length
The number of allocated values.
Definition pm_integer.h:25
pm_integer_t::value
uint32_t value
Embedded value for small integer.
Definition pm_integer.h:36
pm_integer_t::values
uint32_t * values
List of 32-bit integers.
Definition pm_integer.h:30
pm_integer_t::negative
bool negative
Whether or not the integer is negative.
Definition pm_integer.h:42
pm_lex_callback_t
When you are lexing through a file, the lexer needs all of the information that the parser additional...
Definition parser.h:506
pm_list_node::next
struct pm_list_node * next
A pointer to the next node in the list.
Definition pm_list.h:48
pm_list_t
This represents the overall linked list.
Definition pm_list.h:55
pm_list_t::head
pm_list_node_t * head
A pointer to the head of the list.
Definition pm_list.h:60
pm_location_t
This represents a range of bytes in the source string to which a node or token corresponds.
Definition ast.h: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:475
pm_newline_list_t
A list of offsets of newlines in a string.
Definition pm_newline_list.h:28
pm_newline_list_t::offsets
size_t * offsets
The list of offsets.
Definition pm_newline_list.h:39
pm_newline_list_t::size
size_t size
The number of offsets in the list.
Definition pm_newline_list.h:33
pm_node::node_id
uint32_t node_id
The unique identifier for this node, which is deterministic based on the source.
Definition ast.h:1085
pm_node::flags
pm_node_flags_t flags
This represents any flags on the node.
Definition ast.h:1079
pm_node::location
pm_location_t location
This is the location of the node in the source.
Definition ast.h:1091
pm_parser::lex_state
pm_lex_state_t lex_state
The current state of the lexer.
Definition parser.h:649
pm_parser::encoding
const pm_encoding_t * encoding
The encoding functions for the current file is attached to the parser as it's parsing so that it can ...
Definition parser.h:755
pm_parser::constant_pool
pm_constant_pool_t constant_pool
This constant pool keeps all of the constants defined throughout the file so that we can reference th...
Definition parser.h:786
pm_parser::magic_comment_list
pm_list_t magic_comment_list
The list of magic comments that have been found while parsing.
Definition parser.h:721
pm_parser::lex_callback
pm_lex_callback_t * lex_callback
This is an optional callback that can be attached to the parser that will be called whenever a new to...
Definition parser.h:774
pm_parser::data_loc
pm_location_t data_loc
An optional location that represents the location of the END marker and the rest of the content of th...
Definition parser.h:728
pm_parser::start
const uint8_t * start
The pointer to the start of the source.
Definition parser.h:691
pm_parser::error_list
pm_list_t error_list
The list of errors that have been found while parsing.
Definition parser.h:734
pm_parser::warning_list
pm_list_t warning_list
The list of warnings that have been found while parsing.
Definition parser.h:731
pm_parser::start_line
int32_t start_line
The line number at the start of the parse.
Definition parser.h:809
pm_parser::comment_list
pm_list_t comment_list
The list of comments that have been found while parsing.
Definition parser.h:718
pm_parser::newline_list
pm_newline_list_t newline_list
This is the list of newline offsets in the source file.
Definition parser.h:789
pm_string_t
A generic string type that can have various ownership semantics.
Definition pm_string.h:33
pm_string_t::type
enum pm_string_t::@346265266332060241255337121126133217326336224105 type
The type of the string.
pm_token_t
This struct represents a token in the Ruby source.
Definition ast.h:529