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