yarp 0.7.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/src/serialize.c CHANGED
@@ -1,6 +1,6 @@
1
1
  /******************************************************************************/
2
- /* This file is generated by the bin/template script and should not be */
3
- /* modified manually. See */
2
+ /* This file is generated by the templates/template.rb script and should not */
3
+ /* be modified manually. See */
4
4
  /* templates/src/serialize.c.erb */
5
5
  /* if you are looking to modify the */
6
6
  /* template */
@@ -22,7 +22,7 @@ yp_sizet_to_u32(size_t value) {
22
22
  }
23
23
 
24
24
  static void
25
- serialize_location(yp_parser_t *parser, yp_location_t *location, yp_buffer_t *buffer) {
25
+ yp_serialize_location(yp_parser_t *parser, yp_location_t *location, yp_buffer_t *buffer) {
26
26
  assert(location->start);
27
27
  assert(location->end);
28
28
  assert(location->start <= location->end);
@@ -31,31 +31,58 @@ serialize_location(yp_parser_t *parser, yp_location_t *location, yp_buffer_t *bu
31
31
  yp_buffer_append_u32(buffer, yp_ptrdifft_to_u32(location->end - location->start));
32
32
  }
33
33
 
34
+ static void
35
+ yp_serialize_string(yp_parser_t *parser, yp_string_t *string, yp_buffer_t *buffer) {
36
+ switch (string->type) {
37
+ case YP_STRING_SHARED: {
38
+ yp_buffer_append_u8(buffer, 1);
39
+ yp_buffer_append_u32(buffer, yp_ptrdifft_to_u32(yp_string_source(string) - parser->start));
40
+ yp_buffer_append_u32(buffer, yp_sizet_to_u32(yp_string_length(string)));
41
+ break;
42
+ }
43
+ case YP_STRING_OWNED:
44
+ case YP_STRING_CONSTANT: {
45
+ uint32_t length = yp_sizet_to_u32(yp_string_length(string));
46
+ yp_buffer_append_u8(buffer, 2);
47
+ yp_buffer_append_u32(buffer, length);
48
+ yp_buffer_append_str(buffer, yp_string_source(string), length);
49
+ break;
50
+ }
51
+ case YP_STRING_MAPPED:
52
+ assert(false && "Cannot serialize mapped strings.");
53
+ break;
54
+ }
55
+ }
56
+
34
57
  void
35
58
  yp_serialize_node(yp_parser_t *parser, yp_node_t *node, yp_buffer_t *buffer) {
36
59
  yp_buffer_append_u8(buffer, (uint8_t) YP_NODE_TYPE(node));
37
60
 
38
61
  size_t offset = buffer->length;
39
62
 
40
- serialize_location(parser, &node->location, buffer);
63
+ yp_serialize_location(parser, &node->location, buffer);
41
64
 
42
65
  switch (YP_NODE_TYPE(node)) {
66
+ // We do not need to serialize a ScopeNode ever as
67
+ // it is not part of the AST
68
+ case YP_NODE_SCOPE_NODE:
69
+ return;
43
70
  case YP_NODE_ALIAS_NODE: {
44
71
  yp_serialize_node(parser, (yp_node_t *)((yp_alias_node_t *)node)->new_name, buffer);
45
72
  yp_serialize_node(parser, (yp_node_t *)((yp_alias_node_t *)node)->old_name, buffer);
46
- serialize_location(parser, &((yp_alias_node_t *)node)->keyword_loc, buffer);
73
+ yp_serialize_location(parser, &((yp_alias_node_t *)node)->keyword_loc, buffer);
47
74
  break;
48
75
  }
49
76
  case YP_NODE_ALTERNATION_PATTERN_NODE: {
50
77
  yp_serialize_node(parser, (yp_node_t *)((yp_alternation_pattern_node_t *)node)->left, buffer);
51
78
  yp_serialize_node(parser, (yp_node_t *)((yp_alternation_pattern_node_t *)node)->right, buffer);
52
- serialize_location(parser, &((yp_alternation_pattern_node_t *)node)->operator_loc, buffer);
79
+ yp_serialize_location(parser, &((yp_alternation_pattern_node_t *)node)->operator_loc, buffer);
53
80
  break;
54
81
  }
55
82
  case YP_NODE_AND_NODE: {
56
83
  yp_serialize_node(parser, (yp_node_t *)((yp_and_node_t *)node)->left, buffer);
57
84
  yp_serialize_node(parser, (yp_node_t *)((yp_and_node_t *)node)->right, buffer);
58
- serialize_location(parser, &((yp_and_node_t *)node)->operator_loc, buffer);
85
+ yp_serialize_location(parser, &((yp_and_node_t *)node)->operator_loc, buffer);
59
86
  break;
60
87
  }
61
88
  case YP_NODE_ARGUMENTS_NODE: {
@@ -76,13 +103,13 @@ yp_serialize_node(yp_parser_t *parser, yp_node_t *node, yp_buffer_t *buffer) {
76
103
  yp_buffer_append_u8(buffer, 0);
77
104
  } else {
78
105
  yp_buffer_append_u8(buffer, 1);
79
- serialize_location(parser, &((yp_array_node_t *)node)->opening_loc, buffer);
106
+ yp_serialize_location(parser, &((yp_array_node_t *)node)->opening_loc, buffer);
80
107
  }
81
108
  if (((yp_array_node_t *)node)->closing_loc.start == NULL) {
82
109
  yp_buffer_append_u8(buffer, 0);
83
110
  } else {
84
111
  yp_buffer_append_u8(buffer, 1);
85
- serialize_location(parser, &((yp_array_node_t *)node)->closing_loc, buffer);
112
+ yp_serialize_location(parser, &((yp_array_node_t *)node)->closing_loc, buffer);
86
113
  }
87
114
  break;
88
115
  }
@@ -111,13 +138,13 @@ yp_serialize_node(yp_parser_t *parser, yp_node_t *node, yp_buffer_t *buffer) {
111
138
  yp_buffer_append_u8(buffer, 0);
112
139
  } else {
113
140
  yp_buffer_append_u8(buffer, 1);
114
- serialize_location(parser, &((yp_array_pattern_node_t *)node)->opening_loc, buffer);
141
+ yp_serialize_location(parser, &((yp_array_pattern_node_t *)node)->opening_loc, buffer);
115
142
  }
116
143
  if (((yp_array_pattern_node_t *)node)->closing_loc.start == NULL) {
117
144
  yp_buffer_append_u8(buffer, 0);
118
145
  } else {
119
146
  yp_buffer_append_u8(buffer, 1);
120
- serialize_location(parser, &((yp_array_pattern_node_t *)node)->closing_loc, buffer);
147
+ yp_serialize_location(parser, &((yp_array_pattern_node_t *)node)->closing_loc, buffer);
121
148
  }
122
149
  break;
123
150
  }
@@ -132,7 +159,7 @@ yp_serialize_node(yp_parser_t *parser, yp_node_t *node, yp_buffer_t *buffer) {
132
159
  yp_buffer_append_u8(buffer, 0);
133
160
  } else {
134
161
  yp_buffer_append_u8(buffer, 1);
135
- serialize_location(parser, &((yp_assoc_node_t *)node)->operator_loc, buffer);
162
+ yp_serialize_location(parser, &((yp_assoc_node_t *)node)->operator_loc, buffer);
136
163
  }
137
164
  break;
138
165
  }
@@ -142,7 +169,7 @@ yp_serialize_node(yp_parser_t *parser, yp_node_t *node, yp_buffer_t *buffer) {
142
169
  } else {
143
170
  yp_serialize_node(parser, (yp_node_t *)((yp_assoc_splat_node_t *)node)->value, buffer);
144
171
  }
145
- serialize_location(parser, &((yp_assoc_splat_node_t *)node)->operator_loc, buffer);
172
+ yp_serialize_location(parser, &((yp_assoc_splat_node_t *)node)->operator_loc, buffer);
146
173
  break;
147
174
  }
148
175
  case YP_NODE_BACK_REFERENCE_READ_NODE: {
@@ -153,7 +180,7 @@ yp_serialize_node(yp_parser_t *parser, yp_node_t *node, yp_buffer_t *buffer) {
153
180
  yp_buffer_append_u8(buffer, 0);
154
181
  } else {
155
182
  yp_buffer_append_u8(buffer, 1);
156
- serialize_location(parser, &((yp_begin_node_t *)node)->begin_keyword_loc, buffer);
183
+ yp_serialize_location(parser, &((yp_begin_node_t *)node)->begin_keyword_loc, buffer);
157
184
  }
158
185
  if (((yp_begin_node_t *)node)->statements == NULL) {
159
186
  yp_buffer_append_u8(buffer, 0);
@@ -179,7 +206,7 @@ yp_serialize_node(yp_parser_t *parser, yp_node_t *node, yp_buffer_t *buffer) {
179
206
  yp_buffer_append_u8(buffer, 0);
180
207
  } else {
181
208
  yp_buffer_append_u8(buffer, 1);
182
- serialize_location(parser, &((yp_begin_node_t *)node)->end_keyword_loc, buffer);
209
+ yp_serialize_location(parser, &((yp_begin_node_t *)node)->end_keyword_loc, buffer);
183
210
  }
184
211
  break;
185
212
  }
@@ -189,7 +216,7 @@ yp_serialize_node(yp_parser_t *parser, yp_node_t *node, yp_buffer_t *buffer) {
189
216
  } else {
190
217
  yp_serialize_node(parser, (yp_node_t *)((yp_block_argument_node_t *)node)->expression, buffer);
191
218
  }
192
- serialize_location(parser, &((yp_block_argument_node_t *)node)->operator_loc, buffer);
219
+ yp_serialize_location(parser, &((yp_block_argument_node_t *)node)->operator_loc, buffer);
193
220
  break;
194
221
  }
195
222
  case YP_NODE_BLOCK_NODE: {
@@ -203,13 +230,13 @@ yp_serialize_node(yp_parser_t *parser, yp_node_t *node, yp_buffer_t *buffer) {
203
230
  } else {
204
231
  yp_serialize_node(parser, (yp_node_t *)((yp_block_node_t *)node)->parameters, buffer);
205
232
  }
206
- if (((yp_block_node_t *)node)->statements == NULL) {
233
+ if (((yp_block_node_t *)node)->body == NULL) {
207
234
  yp_buffer_append_u8(buffer, 0);
208
235
  } else {
209
- yp_serialize_node(parser, (yp_node_t *)((yp_block_node_t *)node)->statements, buffer);
236
+ yp_serialize_node(parser, (yp_node_t *)((yp_block_node_t *)node)->body, buffer);
210
237
  }
211
- serialize_location(parser, &((yp_block_node_t *)node)->opening_loc, buffer);
212
- serialize_location(parser, &((yp_block_node_t *)node)->closing_loc, buffer);
238
+ yp_serialize_location(parser, &((yp_block_node_t *)node)->opening_loc, buffer);
239
+ yp_serialize_location(parser, &((yp_block_node_t *)node)->closing_loc, buffer);
213
240
  break;
214
241
  }
215
242
  case YP_NODE_BLOCK_PARAMETER_NODE: {
@@ -217,9 +244,9 @@ yp_serialize_node(yp_parser_t *parser, yp_node_t *node, yp_buffer_t *buffer) {
217
244
  yp_buffer_append_u8(buffer, 0);
218
245
  } else {
219
246
  yp_buffer_append_u8(buffer, 1);
220
- serialize_location(parser, &((yp_block_parameter_node_t *)node)->name_loc, buffer);
247
+ yp_serialize_location(parser, &((yp_block_parameter_node_t *)node)->name_loc, buffer);
221
248
  }
222
- serialize_location(parser, &((yp_block_parameter_node_t *)node)->operator_loc, buffer);
249
+ yp_serialize_location(parser, &((yp_block_parameter_node_t *)node)->operator_loc, buffer);
223
250
  break;
224
251
  }
225
252
  case YP_NODE_BLOCK_PARAMETERS_NODE: {
@@ -231,19 +258,19 @@ yp_serialize_node(yp_parser_t *parser, yp_node_t *node, yp_buffer_t *buffer) {
231
258
  uint32_t locals_size = yp_sizet_to_u32(((yp_block_parameters_node_t *)node)->locals.size);
232
259
  yp_buffer_append_u32(buffer, locals_size);
233
260
  for (uint32_t index = 0; index < locals_size; index++) {
234
- serialize_location(parser, &((yp_block_parameters_node_t *)node)->locals.locations[index], buffer);
261
+ yp_serialize_location(parser, &((yp_block_parameters_node_t *)node)->locals.locations[index], buffer);
235
262
  }
236
263
  if (((yp_block_parameters_node_t *)node)->opening_loc.start == NULL) {
237
264
  yp_buffer_append_u8(buffer, 0);
238
265
  } else {
239
266
  yp_buffer_append_u8(buffer, 1);
240
- serialize_location(parser, &((yp_block_parameters_node_t *)node)->opening_loc, buffer);
267
+ yp_serialize_location(parser, &((yp_block_parameters_node_t *)node)->opening_loc, buffer);
241
268
  }
242
269
  if (((yp_block_parameters_node_t *)node)->closing_loc.start == NULL) {
243
270
  yp_buffer_append_u8(buffer, 0);
244
271
  } else {
245
272
  yp_buffer_append_u8(buffer, 1);
246
- serialize_location(parser, &((yp_block_parameters_node_t *)node)->closing_loc, buffer);
273
+ yp_serialize_location(parser, &((yp_block_parameters_node_t *)node)->closing_loc, buffer);
247
274
  }
248
275
  break;
249
276
  }
@@ -253,7 +280,7 @@ yp_serialize_node(yp_parser_t *parser, yp_node_t *node, yp_buffer_t *buffer) {
253
280
  } else {
254
281
  yp_serialize_node(parser, (yp_node_t *)((yp_break_node_t *)node)->arguments, buffer);
255
282
  }
256
- serialize_location(parser, &((yp_break_node_t *)node)->keyword_loc, buffer);
283
+ yp_serialize_location(parser, &((yp_break_node_t *)node)->keyword_loc, buffer);
257
284
  break;
258
285
  }
259
286
  case YP_NODE_CALL_NODE: {
@@ -266,19 +293,19 @@ yp_serialize_node(yp_parser_t *parser, yp_node_t *node, yp_buffer_t *buffer) {
266
293
  yp_buffer_append_u8(buffer, 0);
267
294
  } else {
268
295
  yp_buffer_append_u8(buffer, 1);
269
- serialize_location(parser, &((yp_call_node_t *)node)->operator_loc, buffer);
296
+ yp_serialize_location(parser, &((yp_call_node_t *)node)->operator_loc, buffer);
270
297
  }
271
298
  if (((yp_call_node_t *)node)->message_loc.start == NULL) {
272
299
  yp_buffer_append_u8(buffer, 0);
273
300
  } else {
274
301
  yp_buffer_append_u8(buffer, 1);
275
- serialize_location(parser, &((yp_call_node_t *)node)->message_loc, buffer);
302
+ yp_serialize_location(parser, &((yp_call_node_t *)node)->message_loc, buffer);
276
303
  }
277
304
  if (((yp_call_node_t *)node)->opening_loc.start == NULL) {
278
305
  yp_buffer_append_u8(buffer, 0);
279
306
  } else {
280
307
  yp_buffer_append_u8(buffer, 1);
281
- serialize_location(parser, &((yp_call_node_t *)node)->opening_loc, buffer);
308
+ yp_serialize_location(parser, &((yp_call_node_t *)node)->opening_loc, buffer);
282
309
  }
283
310
  if (((yp_call_node_t *)node)->arguments == NULL) {
284
311
  yp_buffer_append_u8(buffer, 0);
@@ -289,7 +316,7 @@ yp_serialize_node(yp_parser_t *parser, yp_node_t *node, yp_buffer_t *buffer) {
289
316
  yp_buffer_append_u8(buffer, 0);
290
317
  } else {
291
318
  yp_buffer_append_u8(buffer, 1);
292
- serialize_location(parser, &((yp_call_node_t *)node)->closing_loc, buffer);
319
+ yp_serialize_location(parser, &((yp_call_node_t *)node)->closing_loc, buffer);
293
320
  }
294
321
  if (((yp_call_node_t *)node)->block == NULL) {
295
322
  yp_buffer_append_u8(buffer, 0);
@@ -297,26 +324,24 @@ yp_serialize_node(yp_parser_t *parser, yp_node_t *node, yp_buffer_t *buffer) {
297
324
  yp_serialize_node(parser, (yp_node_t *)((yp_call_node_t *)node)->block, buffer);
298
325
  }
299
326
  yp_buffer_append_u32(buffer, node->flags >> 1);
300
- uint32_t name_length = yp_sizet_to_u32(yp_string_length(&((yp_call_node_t *)node)->name));
301
- yp_buffer_append_u32(buffer, name_length);
302
- yp_buffer_append_str(buffer, yp_string_source(&((yp_call_node_t *)node)->name), name_length);
327
+ yp_serialize_string(parser, &((yp_call_node_t *)node)->name, buffer);
303
328
  break;
304
329
  }
305
330
  case YP_NODE_CALL_OPERATOR_AND_WRITE_NODE: {
306
331
  yp_serialize_node(parser, (yp_node_t *)((yp_call_operator_and_write_node_t *)node)->target, buffer);
307
- serialize_location(parser, &((yp_call_operator_and_write_node_t *)node)->operator_loc, buffer);
332
+ yp_serialize_location(parser, &((yp_call_operator_and_write_node_t *)node)->operator_loc, buffer);
308
333
  yp_serialize_node(parser, (yp_node_t *)((yp_call_operator_and_write_node_t *)node)->value, buffer);
309
334
  break;
310
335
  }
311
336
  case YP_NODE_CALL_OPERATOR_OR_WRITE_NODE: {
312
337
  yp_serialize_node(parser, (yp_node_t *)((yp_call_operator_or_write_node_t *)node)->target, buffer);
313
338
  yp_serialize_node(parser, (yp_node_t *)((yp_call_operator_or_write_node_t *)node)->value, buffer);
314
- serialize_location(parser, &((yp_call_operator_or_write_node_t *)node)->operator_loc, buffer);
339
+ yp_serialize_location(parser, &((yp_call_operator_or_write_node_t *)node)->operator_loc, buffer);
315
340
  break;
316
341
  }
317
342
  case YP_NODE_CALL_OPERATOR_WRITE_NODE: {
318
343
  yp_serialize_node(parser, (yp_node_t *)((yp_call_operator_write_node_t *)node)->target, buffer);
319
- serialize_location(parser, &((yp_call_operator_write_node_t *)node)->operator_loc, buffer);
344
+ yp_serialize_location(parser, &((yp_call_operator_write_node_t *)node)->operator_loc, buffer);
320
345
  yp_serialize_node(parser, (yp_node_t *)((yp_call_operator_write_node_t *)node)->value, buffer);
321
346
  yp_buffer_append_u32(buffer, yp_sizet_to_u32(((yp_call_operator_write_node_t *)node)->operator_id));
322
347
  break;
@@ -324,7 +349,7 @@ yp_serialize_node(yp_parser_t *parser, yp_node_t *node, yp_buffer_t *buffer) {
324
349
  case YP_NODE_CAPTURE_PATTERN_NODE: {
325
350
  yp_serialize_node(parser, (yp_node_t *)((yp_capture_pattern_node_t *)node)->value, buffer);
326
351
  yp_serialize_node(parser, (yp_node_t *)((yp_capture_pattern_node_t *)node)->target, buffer);
327
- serialize_location(parser, &((yp_capture_pattern_node_t *)node)->operator_loc, buffer);
352
+ yp_serialize_location(parser, &((yp_capture_pattern_node_t *)node)->operator_loc, buffer);
328
353
  break;
329
354
  }
330
355
  case YP_NODE_CASE_NODE: {
@@ -343,8 +368,8 @@ yp_serialize_node(yp_parser_t *parser, yp_node_t *node, yp_buffer_t *buffer) {
343
368
  } else {
344
369
  yp_serialize_node(parser, (yp_node_t *)((yp_case_node_t *)node)->consequent, buffer);
345
370
  }
346
- serialize_location(parser, &((yp_case_node_t *)node)->case_keyword_loc, buffer);
347
- serialize_location(parser, &((yp_case_node_t *)node)->end_keyword_loc, buffer);
371
+ yp_serialize_location(parser, &((yp_case_node_t *)node)->case_keyword_loc, buffer);
372
+ yp_serialize_location(parser, &((yp_case_node_t *)node)->end_keyword_loc, buffer);
348
373
  break;
349
374
  }
350
375
  case YP_NODE_CLASS_NODE: {
@@ -353,51 +378,55 @@ yp_serialize_node(yp_parser_t *parser, yp_node_t *node, yp_buffer_t *buffer) {
353
378
  for (uint32_t index = 0; index < locals_size; index++) {
354
379
  yp_buffer_append_u32(buffer, yp_sizet_to_u32(((yp_class_node_t *)node)->locals.ids[index]));
355
380
  }
356
- serialize_location(parser, &((yp_class_node_t *)node)->class_keyword_loc, buffer);
381
+ yp_serialize_location(parser, &((yp_class_node_t *)node)->class_keyword_loc, buffer);
357
382
  yp_serialize_node(parser, (yp_node_t *)((yp_class_node_t *)node)->constant_path, buffer);
358
383
  if (((yp_class_node_t *)node)->inheritance_operator_loc.start == NULL) {
359
384
  yp_buffer_append_u8(buffer, 0);
360
385
  } else {
361
386
  yp_buffer_append_u8(buffer, 1);
362
- serialize_location(parser, &((yp_class_node_t *)node)->inheritance_operator_loc, buffer);
387
+ yp_serialize_location(parser, &((yp_class_node_t *)node)->inheritance_operator_loc, buffer);
363
388
  }
364
389
  if (((yp_class_node_t *)node)->superclass == NULL) {
365
390
  yp_buffer_append_u8(buffer, 0);
366
391
  } else {
367
392
  yp_serialize_node(parser, (yp_node_t *)((yp_class_node_t *)node)->superclass, buffer);
368
393
  }
369
- if (((yp_class_node_t *)node)->statements == NULL) {
394
+ if (((yp_class_node_t *)node)->body == NULL) {
370
395
  yp_buffer_append_u8(buffer, 0);
371
396
  } else {
372
- yp_serialize_node(parser, (yp_node_t *)((yp_class_node_t *)node)->statements, buffer);
397
+ yp_serialize_node(parser, (yp_node_t *)((yp_class_node_t *)node)->body, buffer);
373
398
  }
374
- serialize_location(parser, &((yp_class_node_t *)node)->end_keyword_loc, buffer);
375
- break;
376
- }
377
- case YP_NODE_CLASS_VARIABLE_OPERATOR_AND_WRITE_NODE: {
378
- serialize_location(parser, &((yp_class_variable_operator_and_write_node_t *)node)->name_loc, buffer);
379
- serialize_location(parser, &((yp_class_variable_operator_and_write_node_t *)node)->operator_loc, buffer);
380
- yp_serialize_node(parser, (yp_node_t *)((yp_class_variable_operator_and_write_node_t *)node)->value, buffer);
399
+ yp_serialize_location(parser, &((yp_class_node_t *)node)->end_keyword_loc, buffer);
400
+ yp_serialize_string(parser, &((yp_class_node_t *)node)->name, buffer);
381
401
  break;
382
402
  }
383
- case YP_NODE_CLASS_VARIABLE_OPERATOR_OR_WRITE_NODE: {
384
- serialize_location(parser, &((yp_class_variable_operator_or_write_node_t *)node)->name_loc, buffer);
385
- serialize_location(parser, &((yp_class_variable_operator_or_write_node_t *)node)->operator_loc, buffer);
386
- yp_serialize_node(parser, (yp_node_t *)((yp_class_variable_operator_or_write_node_t *)node)->value, buffer);
403
+ case YP_NODE_CLASS_VARIABLE_AND_WRITE_NODE: {
404
+ yp_serialize_location(parser, &((yp_class_variable_and_write_node_t *)node)->name_loc, buffer);
405
+ yp_serialize_location(parser, &((yp_class_variable_and_write_node_t *)node)->operator_loc, buffer);
406
+ yp_serialize_node(parser, (yp_node_t *)((yp_class_variable_and_write_node_t *)node)->value, buffer);
387
407
  break;
388
408
  }
389
409
  case YP_NODE_CLASS_VARIABLE_OPERATOR_WRITE_NODE: {
390
- serialize_location(parser, &((yp_class_variable_operator_write_node_t *)node)->name_loc, buffer);
391
- serialize_location(parser, &((yp_class_variable_operator_write_node_t *)node)->operator_loc, buffer);
410
+ yp_serialize_location(parser, &((yp_class_variable_operator_write_node_t *)node)->name_loc, buffer);
411
+ yp_serialize_location(parser, &((yp_class_variable_operator_write_node_t *)node)->operator_loc, buffer);
392
412
  yp_serialize_node(parser, (yp_node_t *)((yp_class_variable_operator_write_node_t *)node)->value, buffer);
393
413
  yp_buffer_append_u32(buffer, yp_sizet_to_u32(((yp_class_variable_operator_write_node_t *)node)->operator));
394
414
  break;
395
415
  }
416
+ case YP_NODE_CLASS_VARIABLE_OR_WRITE_NODE: {
417
+ yp_serialize_location(parser, &((yp_class_variable_or_write_node_t *)node)->name_loc, buffer);
418
+ yp_serialize_location(parser, &((yp_class_variable_or_write_node_t *)node)->operator_loc, buffer);
419
+ yp_serialize_node(parser, (yp_node_t *)((yp_class_variable_or_write_node_t *)node)->value, buffer);
420
+ break;
421
+ }
396
422
  case YP_NODE_CLASS_VARIABLE_READ_NODE: {
397
423
  break;
398
424
  }
425
+ case YP_NODE_CLASS_VARIABLE_TARGET_NODE: {
426
+ break;
427
+ }
399
428
  case YP_NODE_CLASS_VARIABLE_WRITE_NODE: {
400
- serialize_location(parser, &((yp_class_variable_write_node_t *)node)->name_loc, buffer);
429
+ yp_serialize_location(parser, &((yp_class_variable_write_node_t *)node)->name_loc, buffer);
401
430
  if (((yp_class_variable_write_node_t *)node)->value == NULL) {
402
431
  yp_buffer_append_u8(buffer, 0);
403
432
  } else {
@@ -407,29 +436,35 @@ yp_serialize_node(yp_parser_t *parser, yp_node_t *node, yp_buffer_t *buffer) {
407
436
  yp_buffer_append_u8(buffer, 0);
408
437
  } else {
409
438
  yp_buffer_append_u8(buffer, 1);
410
- serialize_location(parser, &((yp_class_variable_write_node_t *)node)->operator_loc, buffer);
439
+ yp_serialize_location(parser, &((yp_class_variable_write_node_t *)node)->operator_loc, buffer);
411
440
  }
412
441
  break;
413
442
  }
414
- case YP_NODE_CONSTANT_OPERATOR_AND_WRITE_NODE: {
415
- serialize_location(parser, &((yp_constant_operator_and_write_node_t *)node)->name_loc, buffer);
416
- serialize_location(parser, &((yp_constant_operator_and_write_node_t *)node)->operator_loc, buffer);
417
- yp_serialize_node(parser, (yp_node_t *)((yp_constant_operator_and_write_node_t *)node)->value, buffer);
418
- break;
419
- }
420
- case YP_NODE_CONSTANT_OPERATOR_OR_WRITE_NODE: {
421
- serialize_location(parser, &((yp_constant_operator_or_write_node_t *)node)->name_loc, buffer);
422
- serialize_location(parser, &((yp_constant_operator_or_write_node_t *)node)->operator_loc, buffer);
423
- yp_serialize_node(parser, (yp_node_t *)((yp_constant_operator_or_write_node_t *)node)->value, buffer);
443
+ case YP_NODE_CONSTANT_AND_WRITE_NODE: {
444
+ yp_serialize_location(parser, &((yp_constant_and_write_node_t *)node)->name_loc, buffer);
445
+ yp_serialize_location(parser, &((yp_constant_and_write_node_t *)node)->operator_loc, buffer);
446
+ yp_serialize_node(parser, (yp_node_t *)((yp_constant_and_write_node_t *)node)->value, buffer);
424
447
  break;
425
448
  }
426
449
  case YP_NODE_CONSTANT_OPERATOR_WRITE_NODE: {
427
- serialize_location(parser, &((yp_constant_operator_write_node_t *)node)->name_loc, buffer);
428
- serialize_location(parser, &((yp_constant_operator_write_node_t *)node)->operator_loc, buffer);
450
+ yp_serialize_location(parser, &((yp_constant_operator_write_node_t *)node)->name_loc, buffer);
451
+ yp_serialize_location(parser, &((yp_constant_operator_write_node_t *)node)->operator_loc, buffer);
429
452
  yp_serialize_node(parser, (yp_node_t *)((yp_constant_operator_write_node_t *)node)->value, buffer);
430
453
  yp_buffer_append_u32(buffer, yp_sizet_to_u32(((yp_constant_operator_write_node_t *)node)->operator));
431
454
  break;
432
455
  }
456
+ case YP_NODE_CONSTANT_OR_WRITE_NODE: {
457
+ yp_serialize_location(parser, &((yp_constant_or_write_node_t *)node)->name_loc, buffer);
458
+ yp_serialize_location(parser, &((yp_constant_or_write_node_t *)node)->operator_loc, buffer);
459
+ yp_serialize_node(parser, (yp_node_t *)((yp_constant_or_write_node_t *)node)->value, buffer);
460
+ break;
461
+ }
462
+ case YP_NODE_CONSTANT_PATH_AND_WRITE_NODE: {
463
+ yp_serialize_node(parser, (yp_node_t *)((yp_constant_path_and_write_node_t *)node)->target, buffer);
464
+ yp_serialize_location(parser, &((yp_constant_path_and_write_node_t *)node)->operator_loc, buffer);
465
+ yp_serialize_node(parser, (yp_node_t *)((yp_constant_path_and_write_node_t *)node)->value, buffer);
466
+ break;
467
+ }
433
468
  case YP_NODE_CONSTANT_PATH_NODE: {
434
469
  if (((yp_constant_path_node_t *)node)->parent == NULL) {
435
470
  yp_buffer_append_u8(buffer, 0);
@@ -437,59 +472,48 @@ yp_serialize_node(yp_parser_t *parser, yp_node_t *node, yp_buffer_t *buffer) {
437
472
  yp_serialize_node(parser, (yp_node_t *)((yp_constant_path_node_t *)node)->parent, buffer);
438
473
  }
439
474
  yp_serialize_node(parser, (yp_node_t *)((yp_constant_path_node_t *)node)->child, buffer);
440
- serialize_location(parser, &((yp_constant_path_node_t *)node)->delimiter_loc, buffer);
441
- break;
442
- }
443
- case YP_NODE_CONSTANT_PATH_OPERATOR_AND_WRITE_NODE: {
444
- yp_serialize_node(parser, (yp_node_t *)((yp_constant_path_operator_and_write_node_t *)node)->target, buffer);
445
- serialize_location(parser, &((yp_constant_path_operator_and_write_node_t *)node)->operator_loc, buffer);
446
- yp_serialize_node(parser, (yp_node_t *)((yp_constant_path_operator_and_write_node_t *)node)->value, buffer);
447
- break;
448
- }
449
- case YP_NODE_CONSTANT_PATH_OPERATOR_OR_WRITE_NODE: {
450
- yp_serialize_node(parser, (yp_node_t *)((yp_constant_path_operator_or_write_node_t *)node)->target, buffer);
451
- serialize_location(parser, &((yp_constant_path_operator_or_write_node_t *)node)->operator_loc, buffer);
452
- yp_serialize_node(parser, (yp_node_t *)((yp_constant_path_operator_or_write_node_t *)node)->value, buffer);
475
+ yp_serialize_location(parser, &((yp_constant_path_node_t *)node)->delimiter_loc, buffer);
453
476
  break;
454
477
  }
455
478
  case YP_NODE_CONSTANT_PATH_OPERATOR_WRITE_NODE: {
456
479
  yp_serialize_node(parser, (yp_node_t *)((yp_constant_path_operator_write_node_t *)node)->target, buffer);
457
- serialize_location(parser, &((yp_constant_path_operator_write_node_t *)node)->operator_loc, buffer);
480
+ yp_serialize_location(parser, &((yp_constant_path_operator_write_node_t *)node)->operator_loc, buffer);
458
481
  yp_serialize_node(parser, (yp_node_t *)((yp_constant_path_operator_write_node_t *)node)->value, buffer);
459
482
  yp_buffer_append_u32(buffer, yp_sizet_to_u32(((yp_constant_path_operator_write_node_t *)node)->operator));
460
483
  break;
461
484
  }
462
- case YP_NODE_CONSTANT_PATH_WRITE_NODE: {
463
- yp_serialize_node(parser, (yp_node_t *)((yp_constant_path_write_node_t *)node)->target, buffer);
464
- if (((yp_constant_path_write_node_t *)node)->operator_loc.start == NULL) {
465
- yp_buffer_append_u8(buffer, 0);
466
- } else {
467
- yp_buffer_append_u8(buffer, 1);
468
- serialize_location(parser, &((yp_constant_path_write_node_t *)node)->operator_loc, buffer);
469
- }
470
- if (((yp_constant_path_write_node_t *)node)->value == NULL) {
485
+ case YP_NODE_CONSTANT_PATH_OR_WRITE_NODE: {
486
+ yp_serialize_node(parser, (yp_node_t *)((yp_constant_path_or_write_node_t *)node)->target, buffer);
487
+ yp_serialize_location(parser, &((yp_constant_path_or_write_node_t *)node)->operator_loc, buffer);
488
+ yp_serialize_node(parser, (yp_node_t *)((yp_constant_path_or_write_node_t *)node)->value, buffer);
489
+ break;
490
+ }
491
+ case YP_NODE_CONSTANT_PATH_TARGET_NODE: {
492
+ if (((yp_constant_path_target_node_t *)node)->parent == NULL) {
471
493
  yp_buffer_append_u8(buffer, 0);
472
494
  } else {
473
- yp_serialize_node(parser, (yp_node_t *)((yp_constant_path_write_node_t *)node)->value, buffer);
495
+ yp_serialize_node(parser, (yp_node_t *)((yp_constant_path_target_node_t *)node)->parent, buffer);
474
496
  }
497
+ yp_serialize_node(parser, (yp_node_t *)((yp_constant_path_target_node_t *)node)->child, buffer);
498
+ yp_serialize_location(parser, &((yp_constant_path_target_node_t *)node)->delimiter_loc, buffer);
499
+ break;
500
+ }
501
+ case YP_NODE_CONSTANT_PATH_WRITE_NODE: {
502
+ yp_serialize_node(parser, (yp_node_t *)((yp_constant_path_write_node_t *)node)->target, buffer);
503
+ yp_serialize_location(parser, &((yp_constant_path_write_node_t *)node)->operator_loc, buffer);
504
+ yp_serialize_node(parser, (yp_node_t *)((yp_constant_path_write_node_t *)node)->value, buffer);
475
505
  break;
476
506
  }
477
507
  case YP_NODE_CONSTANT_READ_NODE: {
478
508
  break;
479
509
  }
510
+ case YP_NODE_CONSTANT_TARGET_NODE: {
511
+ break;
512
+ }
480
513
  case YP_NODE_CONSTANT_WRITE_NODE: {
481
- serialize_location(parser, &((yp_constant_write_node_t *)node)->name_loc, buffer);
482
- if (((yp_constant_write_node_t *)node)->value == NULL) {
483
- yp_buffer_append_u8(buffer, 0);
484
- } else {
485
- yp_serialize_node(parser, (yp_node_t *)((yp_constant_write_node_t *)node)->value, buffer);
486
- }
487
- if (((yp_constant_write_node_t *)node)->operator_loc.start == NULL) {
488
- yp_buffer_append_u8(buffer, 0);
489
- } else {
490
- yp_buffer_append_u8(buffer, 1);
491
- serialize_location(parser, &((yp_constant_write_node_t *)node)->operator_loc, buffer);
492
- }
514
+ yp_serialize_location(parser, &((yp_constant_write_node_t *)node)->name_loc, buffer);
515
+ yp_serialize_node(parser, (yp_node_t *)((yp_constant_write_node_t *)node)->value, buffer);
516
+ yp_serialize_location(parser, &((yp_constant_write_node_t *)node)->operator_loc, buffer);
493
517
  break;
494
518
  }
495
519
  case YP_NODE_DEF_NODE: {
@@ -497,7 +521,7 @@ yp_serialize_node(yp_parser_t *parser, yp_node_t *node, yp_buffer_t *buffer) {
497
521
  // encoding of location u32s make us need to save this offset.
498
522
  size_t length_offset = buffer->length;
499
523
  yp_buffer_append_str(buffer, "\0\0\0\0", 4); /* consume 4 bytes, updated below */
500
- serialize_location(parser, &((yp_def_node_t *)node)->name_loc, buffer);
524
+ yp_serialize_location(parser, &((yp_def_node_t *)node)->name_loc, buffer);
501
525
  if (((yp_def_node_t *)node)->receiver == NULL) {
502
526
  yp_buffer_append_u8(buffer, 0);
503
527
  } else {
@@ -508,46 +532,46 @@ yp_serialize_node(yp_parser_t *parser, yp_node_t *node, yp_buffer_t *buffer) {
508
532
  } else {
509
533
  yp_serialize_node(parser, (yp_node_t *)((yp_def_node_t *)node)->parameters, buffer);
510
534
  }
511
- if (((yp_def_node_t *)node)->statements == NULL) {
535
+ if (((yp_def_node_t *)node)->body == NULL) {
512
536
  yp_buffer_append_u8(buffer, 0);
513
537
  } else {
514
- yp_serialize_node(parser, (yp_node_t *)((yp_def_node_t *)node)->statements, buffer);
538
+ yp_serialize_node(parser, (yp_node_t *)((yp_def_node_t *)node)->body, buffer);
515
539
  }
516
540
  uint32_t locals_size = yp_sizet_to_u32(((yp_def_node_t *)node)->locals.size);
517
541
  yp_buffer_append_u32(buffer, locals_size);
518
542
  for (uint32_t index = 0; index < locals_size; index++) {
519
543
  yp_buffer_append_u32(buffer, yp_sizet_to_u32(((yp_def_node_t *)node)->locals.ids[index]));
520
544
  }
521
- serialize_location(parser, &((yp_def_node_t *)node)->def_keyword_loc, buffer);
545
+ yp_serialize_location(parser, &((yp_def_node_t *)node)->def_keyword_loc, buffer);
522
546
  if (((yp_def_node_t *)node)->operator_loc.start == NULL) {
523
547
  yp_buffer_append_u8(buffer, 0);
524
548
  } else {
525
549
  yp_buffer_append_u8(buffer, 1);
526
- serialize_location(parser, &((yp_def_node_t *)node)->operator_loc, buffer);
550
+ yp_serialize_location(parser, &((yp_def_node_t *)node)->operator_loc, buffer);
527
551
  }
528
552
  if (((yp_def_node_t *)node)->lparen_loc.start == NULL) {
529
553
  yp_buffer_append_u8(buffer, 0);
530
554
  } else {
531
555
  yp_buffer_append_u8(buffer, 1);
532
- serialize_location(parser, &((yp_def_node_t *)node)->lparen_loc, buffer);
556
+ yp_serialize_location(parser, &((yp_def_node_t *)node)->lparen_loc, buffer);
533
557
  }
534
558
  if (((yp_def_node_t *)node)->rparen_loc.start == NULL) {
535
559
  yp_buffer_append_u8(buffer, 0);
536
560
  } else {
537
561
  yp_buffer_append_u8(buffer, 1);
538
- serialize_location(parser, &((yp_def_node_t *)node)->rparen_loc, buffer);
562
+ yp_serialize_location(parser, &((yp_def_node_t *)node)->rparen_loc, buffer);
539
563
  }
540
564
  if (((yp_def_node_t *)node)->equal_loc.start == NULL) {
541
565
  yp_buffer_append_u8(buffer, 0);
542
566
  } else {
543
567
  yp_buffer_append_u8(buffer, 1);
544
- serialize_location(parser, &((yp_def_node_t *)node)->equal_loc, buffer);
568
+ yp_serialize_location(parser, &((yp_def_node_t *)node)->equal_loc, buffer);
545
569
  }
546
570
  if (((yp_def_node_t *)node)->end_keyword_loc.start == NULL) {
547
571
  yp_buffer_append_u8(buffer, 0);
548
572
  } else {
549
573
  yp_buffer_append_u8(buffer, 1);
550
- serialize_location(parser, &((yp_def_node_t *)node)->end_keyword_loc, buffer);
574
+ yp_serialize_location(parser, &((yp_def_node_t *)node)->end_keyword_loc, buffer);
551
575
  }
552
576
  // serialize length
553
577
  uint32_t length = yp_sizet_to_u32(buffer->length - offset - sizeof(uint32_t));
@@ -559,20 +583,20 @@ yp_serialize_node(yp_parser_t *parser, yp_node_t *node, yp_buffer_t *buffer) {
559
583
  yp_buffer_append_u8(buffer, 0);
560
584
  } else {
561
585
  yp_buffer_append_u8(buffer, 1);
562
- serialize_location(parser, &((yp_defined_node_t *)node)->lparen_loc, buffer);
586
+ yp_serialize_location(parser, &((yp_defined_node_t *)node)->lparen_loc, buffer);
563
587
  }
564
588
  yp_serialize_node(parser, (yp_node_t *)((yp_defined_node_t *)node)->value, buffer);
565
589
  if (((yp_defined_node_t *)node)->rparen_loc.start == NULL) {
566
590
  yp_buffer_append_u8(buffer, 0);
567
591
  } else {
568
592
  yp_buffer_append_u8(buffer, 1);
569
- serialize_location(parser, &((yp_defined_node_t *)node)->rparen_loc, buffer);
593
+ yp_serialize_location(parser, &((yp_defined_node_t *)node)->rparen_loc, buffer);
570
594
  }
571
- serialize_location(parser, &((yp_defined_node_t *)node)->keyword_loc, buffer);
595
+ yp_serialize_location(parser, &((yp_defined_node_t *)node)->keyword_loc, buffer);
572
596
  break;
573
597
  }
574
598
  case YP_NODE_ELSE_NODE: {
575
- serialize_location(parser, &((yp_else_node_t *)node)->else_keyword_loc, buffer);
599
+ yp_serialize_location(parser, &((yp_else_node_t *)node)->else_keyword_loc, buffer);
576
600
  if (((yp_else_node_t *)node)->statements == NULL) {
577
601
  yp_buffer_append_u8(buffer, 0);
578
602
  } else {
@@ -582,33 +606,33 @@ yp_serialize_node(yp_parser_t *parser, yp_node_t *node, yp_buffer_t *buffer) {
582
606
  yp_buffer_append_u8(buffer, 0);
583
607
  } else {
584
608
  yp_buffer_append_u8(buffer, 1);
585
- serialize_location(parser, &((yp_else_node_t *)node)->end_keyword_loc, buffer);
609
+ yp_serialize_location(parser, &((yp_else_node_t *)node)->end_keyword_loc, buffer);
586
610
  }
587
611
  break;
588
612
  }
589
613
  case YP_NODE_EMBEDDED_STATEMENTS_NODE: {
590
- serialize_location(parser, &((yp_embedded_statements_node_t *)node)->opening_loc, buffer);
614
+ yp_serialize_location(parser, &((yp_embedded_statements_node_t *)node)->opening_loc, buffer);
591
615
  if (((yp_embedded_statements_node_t *)node)->statements == NULL) {
592
616
  yp_buffer_append_u8(buffer, 0);
593
617
  } else {
594
618
  yp_serialize_node(parser, (yp_node_t *)((yp_embedded_statements_node_t *)node)->statements, buffer);
595
619
  }
596
- serialize_location(parser, &((yp_embedded_statements_node_t *)node)->closing_loc, buffer);
620
+ yp_serialize_location(parser, &((yp_embedded_statements_node_t *)node)->closing_loc, buffer);
597
621
  break;
598
622
  }
599
623
  case YP_NODE_EMBEDDED_VARIABLE_NODE: {
600
- serialize_location(parser, &((yp_embedded_variable_node_t *)node)->operator_loc, buffer);
624
+ yp_serialize_location(parser, &((yp_embedded_variable_node_t *)node)->operator_loc, buffer);
601
625
  yp_serialize_node(parser, (yp_node_t *)((yp_embedded_variable_node_t *)node)->variable, buffer);
602
626
  break;
603
627
  }
604
628
  case YP_NODE_ENSURE_NODE: {
605
- serialize_location(parser, &((yp_ensure_node_t *)node)->ensure_keyword_loc, buffer);
629
+ yp_serialize_location(parser, &((yp_ensure_node_t *)node)->ensure_keyword_loc, buffer);
606
630
  if (((yp_ensure_node_t *)node)->statements == NULL) {
607
631
  yp_buffer_append_u8(buffer, 0);
608
632
  } else {
609
633
  yp_serialize_node(parser, (yp_node_t *)((yp_ensure_node_t *)node)->statements, buffer);
610
634
  }
611
- serialize_location(parser, &((yp_ensure_node_t *)node)->end_keyword_loc, buffer);
635
+ yp_serialize_location(parser, &((yp_ensure_node_t *)node)->end_keyword_loc, buffer);
612
636
  break;
613
637
  }
614
638
  case YP_NODE_FALSE_NODE: {
@@ -631,13 +655,13 @@ yp_serialize_node(yp_parser_t *parser, yp_node_t *node, yp_buffer_t *buffer) {
631
655
  yp_buffer_append_u8(buffer, 0);
632
656
  } else {
633
657
  yp_buffer_append_u8(buffer, 1);
634
- serialize_location(parser, &((yp_find_pattern_node_t *)node)->opening_loc, buffer);
658
+ yp_serialize_location(parser, &((yp_find_pattern_node_t *)node)->opening_loc, buffer);
635
659
  }
636
660
  if (((yp_find_pattern_node_t *)node)->closing_loc.start == NULL) {
637
661
  yp_buffer_append_u8(buffer, 0);
638
662
  } else {
639
663
  yp_buffer_append_u8(buffer, 1);
640
- serialize_location(parser, &((yp_find_pattern_node_t *)node)->closing_loc, buffer);
664
+ yp_serialize_location(parser, &((yp_find_pattern_node_t *)node)->closing_loc, buffer);
641
665
  }
642
666
  break;
643
667
  }
@@ -652,7 +676,7 @@ yp_serialize_node(yp_parser_t *parser, yp_node_t *node, yp_buffer_t *buffer) {
652
676
  } else {
653
677
  yp_serialize_node(parser, (yp_node_t *)((yp_flip_flop_node_t *)node)->right, buffer);
654
678
  }
655
- serialize_location(parser, &((yp_flip_flop_node_t *)node)->operator_loc, buffer);
679
+ yp_serialize_location(parser, &((yp_flip_flop_node_t *)node)->operator_loc, buffer);
656
680
  yp_buffer_append_u32(buffer, node->flags >> 1);
657
681
  break;
658
682
  }
@@ -667,15 +691,15 @@ yp_serialize_node(yp_parser_t *parser, yp_node_t *node, yp_buffer_t *buffer) {
667
691
  } else {
668
692
  yp_serialize_node(parser, (yp_node_t *)((yp_for_node_t *)node)->statements, buffer);
669
693
  }
670
- serialize_location(parser, &((yp_for_node_t *)node)->for_keyword_loc, buffer);
671
- serialize_location(parser, &((yp_for_node_t *)node)->in_keyword_loc, buffer);
694
+ yp_serialize_location(parser, &((yp_for_node_t *)node)->for_keyword_loc, buffer);
695
+ yp_serialize_location(parser, &((yp_for_node_t *)node)->in_keyword_loc, buffer);
672
696
  if (((yp_for_node_t *)node)->do_keyword_loc.start == NULL) {
673
697
  yp_buffer_append_u8(buffer, 0);
674
698
  } else {
675
699
  yp_buffer_append_u8(buffer, 1);
676
- serialize_location(parser, &((yp_for_node_t *)node)->do_keyword_loc, buffer);
700
+ yp_serialize_location(parser, &((yp_for_node_t *)node)->do_keyword_loc, buffer);
677
701
  }
678
- serialize_location(parser, &((yp_for_node_t *)node)->end_keyword_loc, buffer);
702
+ yp_serialize_location(parser, &((yp_for_node_t *)node)->end_keyword_loc, buffer);
679
703
  break;
680
704
  }
681
705
  case YP_NODE_FORWARDING_ARGUMENTS_NODE: {
@@ -692,51 +716,45 @@ yp_serialize_node(yp_parser_t *parser, yp_node_t *node, yp_buffer_t *buffer) {
692
716
  }
693
717
  break;
694
718
  }
695
- case YP_NODE_GLOBAL_VARIABLE_OPERATOR_AND_WRITE_NODE: {
696
- serialize_location(parser, &((yp_global_variable_operator_and_write_node_t *)node)->name_loc, buffer);
697
- serialize_location(parser, &((yp_global_variable_operator_and_write_node_t *)node)->operator_loc, buffer);
698
- yp_serialize_node(parser, (yp_node_t *)((yp_global_variable_operator_and_write_node_t *)node)->value, buffer);
699
- break;
700
- }
701
- case YP_NODE_GLOBAL_VARIABLE_OPERATOR_OR_WRITE_NODE: {
702
- serialize_location(parser, &((yp_global_variable_operator_or_write_node_t *)node)->name_loc, buffer);
703
- serialize_location(parser, &((yp_global_variable_operator_or_write_node_t *)node)->operator_loc, buffer);
704
- yp_serialize_node(parser, (yp_node_t *)((yp_global_variable_operator_or_write_node_t *)node)->value, buffer);
719
+ case YP_NODE_GLOBAL_VARIABLE_AND_WRITE_NODE: {
720
+ yp_serialize_location(parser, &((yp_global_variable_and_write_node_t *)node)->name_loc, buffer);
721
+ yp_serialize_location(parser, &((yp_global_variable_and_write_node_t *)node)->operator_loc, buffer);
722
+ yp_serialize_node(parser, (yp_node_t *)((yp_global_variable_and_write_node_t *)node)->value, buffer);
705
723
  break;
706
724
  }
707
725
  case YP_NODE_GLOBAL_VARIABLE_OPERATOR_WRITE_NODE: {
708
- serialize_location(parser, &((yp_global_variable_operator_write_node_t *)node)->name_loc, buffer);
709
- serialize_location(parser, &((yp_global_variable_operator_write_node_t *)node)->operator_loc, buffer);
726
+ yp_serialize_location(parser, &((yp_global_variable_operator_write_node_t *)node)->name_loc, buffer);
727
+ yp_serialize_location(parser, &((yp_global_variable_operator_write_node_t *)node)->operator_loc, buffer);
710
728
  yp_serialize_node(parser, (yp_node_t *)((yp_global_variable_operator_write_node_t *)node)->value, buffer);
711
729
  yp_buffer_append_u32(buffer, yp_sizet_to_u32(((yp_global_variable_operator_write_node_t *)node)->operator));
712
730
  break;
713
731
  }
732
+ case YP_NODE_GLOBAL_VARIABLE_OR_WRITE_NODE: {
733
+ yp_serialize_location(parser, &((yp_global_variable_or_write_node_t *)node)->name_loc, buffer);
734
+ yp_serialize_location(parser, &((yp_global_variable_or_write_node_t *)node)->operator_loc, buffer);
735
+ yp_serialize_node(parser, (yp_node_t *)((yp_global_variable_or_write_node_t *)node)->value, buffer);
736
+ break;
737
+ }
714
738
  case YP_NODE_GLOBAL_VARIABLE_READ_NODE: {
715
739
  break;
716
740
  }
741
+ case YP_NODE_GLOBAL_VARIABLE_TARGET_NODE: {
742
+ break;
743
+ }
717
744
  case YP_NODE_GLOBAL_VARIABLE_WRITE_NODE: {
718
- serialize_location(parser, &((yp_global_variable_write_node_t *)node)->name_loc, buffer);
719
- if (((yp_global_variable_write_node_t *)node)->operator_loc.start == NULL) {
720
- yp_buffer_append_u8(buffer, 0);
721
- } else {
722
- yp_buffer_append_u8(buffer, 1);
723
- serialize_location(parser, &((yp_global_variable_write_node_t *)node)->operator_loc, buffer);
724
- }
725
- if (((yp_global_variable_write_node_t *)node)->value == NULL) {
726
- yp_buffer_append_u8(buffer, 0);
727
- } else {
728
- yp_serialize_node(parser, (yp_node_t *)((yp_global_variable_write_node_t *)node)->value, buffer);
729
- }
745
+ yp_serialize_location(parser, &((yp_global_variable_write_node_t *)node)->name_loc, buffer);
746
+ yp_serialize_location(parser, &((yp_global_variable_write_node_t *)node)->operator_loc, buffer);
747
+ yp_serialize_node(parser, (yp_node_t *)((yp_global_variable_write_node_t *)node)->value, buffer);
730
748
  break;
731
749
  }
732
750
  case YP_NODE_HASH_NODE: {
733
- serialize_location(parser, &((yp_hash_node_t *)node)->opening_loc, buffer);
751
+ yp_serialize_location(parser, &((yp_hash_node_t *)node)->opening_loc, buffer);
734
752
  uint32_t elements_size = yp_sizet_to_u32(((yp_hash_node_t *)node)->elements.size);
735
753
  yp_buffer_append_u32(buffer, elements_size);
736
754
  for (uint32_t index = 0; index < elements_size; index++) {
737
755
  yp_serialize_node(parser, (yp_node_t *) ((yp_hash_node_t *)node)->elements.nodes[index], buffer);
738
756
  }
739
- serialize_location(parser, &((yp_hash_node_t *)node)->closing_loc, buffer);
757
+ yp_serialize_location(parser, &((yp_hash_node_t *)node)->closing_loc, buffer);
740
758
  break;
741
759
  }
742
760
  case YP_NODE_HASH_PATTERN_NODE: {
@@ -759,13 +777,13 @@ yp_serialize_node(yp_parser_t *parser, yp_node_t *node, yp_buffer_t *buffer) {
759
777
  yp_buffer_append_u8(buffer, 0);
760
778
  } else {
761
779
  yp_buffer_append_u8(buffer, 1);
762
- serialize_location(parser, &((yp_hash_pattern_node_t *)node)->opening_loc, buffer);
780
+ yp_serialize_location(parser, &((yp_hash_pattern_node_t *)node)->opening_loc, buffer);
763
781
  }
764
782
  if (((yp_hash_pattern_node_t *)node)->closing_loc.start == NULL) {
765
783
  yp_buffer_append_u8(buffer, 0);
766
784
  } else {
767
785
  yp_buffer_append_u8(buffer, 1);
768
- serialize_location(parser, &((yp_hash_pattern_node_t *)node)->closing_loc, buffer);
786
+ yp_serialize_location(parser, &((yp_hash_pattern_node_t *)node)->closing_loc, buffer);
769
787
  }
770
788
  break;
771
789
  }
@@ -774,7 +792,7 @@ yp_serialize_node(yp_parser_t *parser, yp_node_t *node, yp_buffer_t *buffer) {
774
792
  yp_buffer_append_u8(buffer, 0);
775
793
  } else {
776
794
  yp_buffer_append_u8(buffer, 1);
777
- serialize_location(parser, &((yp_if_node_t *)node)->if_keyword_loc, buffer);
795
+ yp_serialize_location(parser, &((yp_if_node_t *)node)->if_keyword_loc, buffer);
778
796
  }
779
797
  yp_serialize_node(parser, (yp_node_t *)((yp_if_node_t *)node)->predicate, buffer);
780
798
  if (((yp_if_node_t *)node)->statements == NULL) {
@@ -791,7 +809,7 @@ yp_serialize_node(yp_parser_t *parser, yp_node_t *node, yp_buffer_t *buffer) {
791
809
  yp_buffer_append_u8(buffer, 0);
792
810
  } else {
793
811
  yp_buffer_append_u8(buffer, 1);
794
- serialize_location(parser, &((yp_if_node_t *)node)->end_keyword_loc, buffer);
812
+ yp_serialize_location(parser, &((yp_if_node_t *)node)->end_keyword_loc, buffer);
795
813
  }
796
814
  break;
797
815
  }
@@ -806,63 +824,57 @@ yp_serialize_node(yp_parser_t *parser, yp_node_t *node, yp_buffer_t *buffer) {
806
824
  } else {
807
825
  yp_serialize_node(parser, (yp_node_t *)((yp_in_node_t *)node)->statements, buffer);
808
826
  }
809
- serialize_location(parser, &((yp_in_node_t *)node)->in_loc, buffer);
827
+ yp_serialize_location(parser, &((yp_in_node_t *)node)->in_loc, buffer);
810
828
  if (((yp_in_node_t *)node)->then_loc.start == NULL) {
811
829
  yp_buffer_append_u8(buffer, 0);
812
830
  } else {
813
831
  yp_buffer_append_u8(buffer, 1);
814
- serialize_location(parser, &((yp_in_node_t *)node)->then_loc, buffer);
832
+ yp_serialize_location(parser, &((yp_in_node_t *)node)->then_loc, buffer);
815
833
  }
816
834
  break;
817
835
  }
818
- case YP_NODE_INSTANCE_VARIABLE_OPERATOR_AND_WRITE_NODE: {
819
- serialize_location(parser, &((yp_instance_variable_operator_and_write_node_t *)node)->name_loc, buffer);
820
- serialize_location(parser, &((yp_instance_variable_operator_and_write_node_t *)node)->operator_loc, buffer);
821
- yp_serialize_node(parser, (yp_node_t *)((yp_instance_variable_operator_and_write_node_t *)node)->value, buffer);
822
- break;
823
- }
824
- case YP_NODE_INSTANCE_VARIABLE_OPERATOR_OR_WRITE_NODE: {
825
- serialize_location(parser, &((yp_instance_variable_operator_or_write_node_t *)node)->name_loc, buffer);
826
- serialize_location(parser, &((yp_instance_variable_operator_or_write_node_t *)node)->operator_loc, buffer);
827
- yp_serialize_node(parser, (yp_node_t *)((yp_instance_variable_operator_or_write_node_t *)node)->value, buffer);
836
+ case YP_NODE_INSTANCE_VARIABLE_AND_WRITE_NODE: {
837
+ yp_serialize_location(parser, &((yp_instance_variable_and_write_node_t *)node)->name_loc, buffer);
838
+ yp_serialize_location(parser, &((yp_instance_variable_and_write_node_t *)node)->operator_loc, buffer);
839
+ yp_serialize_node(parser, (yp_node_t *)((yp_instance_variable_and_write_node_t *)node)->value, buffer);
828
840
  break;
829
841
  }
830
842
  case YP_NODE_INSTANCE_VARIABLE_OPERATOR_WRITE_NODE: {
831
- serialize_location(parser, &((yp_instance_variable_operator_write_node_t *)node)->name_loc, buffer);
832
- serialize_location(parser, &((yp_instance_variable_operator_write_node_t *)node)->operator_loc, buffer);
843
+ yp_serialize_location(parser, &((yp_instance_variable_operator_write_node_t *)node)->name_loc, buffer);
844
+ yp_serialize_location(parser, &((yp_instance_variable_operator_write_node_t *)node)->operator_loc, buffer);
833
845
  yp_serialize_node(parser, (yp_node_t *)((yp_instance_variable_operator_write_node_t *)node)->value, buffer);
834
846
  yp_buffer_append_u32(buffer, yp_sizet_to_u32(((yp_instance_variable_operator_write_node_t *)node)->operator));
835
847
  break;
836
848
  }
849
+ case YP_NODE_INSTANCE_VARIABLE_OR_WRITE_NODE: {
850
+ yp_serialize_location(parser, &((yp_instance_variable_or_write_node_t *)node)->name_loc, buffer);
851
+ yp_serialize_location(parser, &((yp_instance_variable_or_write_node_t *)node)->operator_loc, buffer);
852
+ yp_serialize_node(parser, (yp_node_t *)((yp_instance_variable_or_write_node_t *)node)->value, buffer);
853
+ break;
854
+ }
837
855
  case YP_NODE_INSTANCE_VARIABLE_READ_NODE: {
838
856
  break;
839
857
  }
858
+ case YP_NODE_INSTANCE_VARIABLE_TARGET_NODE: {
859
+ break;
860
+ }
840
861
  case YP_NODE_INSTANCE_VARIABLE_WRITE_NODE: {
841
- serialize_location(parser, &((yp_instance_variable_write_node_t *)node)->name_loc, buffer);
842
- if (((yp_instance_variable_write_node_t *)node)->value == NULL) {
843
- yp_buffer_append_u8(buffer, 0);
844
- } else {
845
- yp_serialize_node(parser, (yp_node_t *)((yp_instance_variable_write_node_t *)node)->value, buffer);
846
- }
847
- if (((yp_instance_variable_write_node_t *)node)->operator_loc.start == NULL) {
848
- yp_buffer_append_u8(buffer, 0);
849
- } else {
850
- yp_buffer_append_u8(buffer, 1);
851
- serialize_location(parser, &((yp_instance_variable_write_node_t *)node)->operator_loc, buffer);
852
- }
862
+ yp_serialize_location(parser, &((yp_instance_variable_write_node_t *)node)->name_loc, buffer);
863
+ yp_serialize_node(parser, (yp_node_t *)((yp_instance_variable_write_node_t *)node)->value, buffer);
864
+ yp_serialize_location(parser, &((yp_instance_variable_write_node_t *)node)->operator_loc, buffer);
853
865
  break;
854
866
  }
855
867
  case YP_NODE_INTEGER_NODE: {
856
868
  break;
857
869
  }
858
870
  case YP_NODE_INTERPOLATED_REGULAR_EXPRESSION_NODE: {
859
- serialize_location(parser, &((yp_interpolated_regular_expression_node_t *)node)->opening_loc, buffer);
871
+ yp_serialize_location(parser, &((yp_interpolated_regular_expression_node_t *)node)->opening_loc, buffer);
860
872
  uint32_t parts_size = yp_sizet_to_u32(((yp_interpolated_regular_expression_node_t *)node)->parts.size);
861
873
  yp_buffer_append_u32(buffer, parts_size);
862
874
  for (uint32_t index = 0; index < parts_size; index++) {
863
875
  yp_serialize_node(parser, (yp_node_t *) ((yp_interpolated_regular_expression_node_t *)node)->parts.nodes[index], buffer);
864
876
  }
865
- serialize_location(parser, &((yp_interpolated_regular_expression_node_t *)node)->closing_loc, buffer);
877
+ yp_serialize_location(parser, &((yp_interpolated_regular_expression_node_t *)node)->closing_loc, buffer);
866
878
  yp_buffer_append_u32(buffer, node->flags >> 1);
867
879
  break;
868
880
  }
@@ -871,7 +883,7 @@ yp_serialize_node(yp_parser_t *parser, yp_node_t *node, yp_buffer_t *buffer) {
871
883
  yp_buffer_append_u8(buffer, 0);
872
884
  } else {
873
885
  yp_buffer_append_u8(buffer, 1);
874
- serialize_location(parser, &((yp_interpolated_string_node_t *)node)->opening_loc, buffer);
886
+ yp_serialize_location(parser, &((yp_interpolated_string_node_t *)node)->opening_loc, buffer);
875
887
  }
876
888
  uint32_t parts_size = yp_sizet_to_u32(((yp_interpolated_string_node_t *)node)->parts.size);
877
889
  yp_buffer_append_u32(buffer, parts_size);
@@ -882,7 +894,7 @@ yp_serialize_node(yp_parser_t *parser, yp_node_t *node, yp_buffer_t *buffer) {
882
894
  yp_buffer_append_u8(buffer, 0);
883
895
  } else {
884
896
  yp_buffer_append_u8(buffer, 1);
885
- serialize_location(parser, &((yp_interpolated_string_node_t *)node)->closing_loc, buffer);
897
+ yp_serialize_location(parser, &((yp_interpolated_string_node_t *)node)->closing_loc, buffer);
886
898
  }
887
899
  break;
888
900
  }
@@ -891,7 +903,7 @@ yp_serialize_node(yp_parser_t *parser, yp_node_t *node, yp_buffer_t *buffer) {
891
903
  yp_buffer_append_u8(buffer, 0);
892
904
  } else {
893
905
  yp_buffer_append_u8(buffer, 1);
894
- serialize_location(parser, &((yp_interpolated_symbol_node_t *)node)->opening_loc, buffer);
906
+ yp_serialize_location(parser, &((yp_interpolated_symbol_node_t *)node)->opening_loc, buffer);
895
907
  }
896
908
  uint32_t parts_size = yp_sizet_to_u32(((yp_interpolated_symbol_node_t *)node)->parts.size);
897
909
  yp_buffer_append_u32(buffer, parts_size);
@@ -902,18 +914,18 @@ yp_serialize_node(yp_parser_t *parser, yp_node_t *node, yp_buffer_t *buffer) {
902
914
  yp_buffer_append_u8(buffer, 0);
903
915
  } else {
904
916
  yp_buffer_append_u8(buffer, 1);
905
- serialize_location(parser, &((yp_interpolated_symbol_node_t *)node)->closing_loc, buffer);
917
+ yp_serialize_location(parser, &((yp_interpolated_symbol_node_t *)node)->closing_loc, buffer);
906
918
  }
907
919
  break;
908
920
  }
909
921
  case YP_NODE_INTERPOLATED_X_STRING_NODE: {
910
- serialize_location(parser, &((yp_interpolated_x_string_node_t *)node)->opening_loc, buffer);
922
+ yp_serialize_location(parser, &((yp_interpolated_x_string_node_t *)node)->opening_loc, buffer);
911
923
  uint32_t parts_size = yp_sizet_to_u32(((yp_interpolated_x_string_node_t *)node)->parts.size);
912
924
  yp_buffer_append_u32(buffer, parts_size);
913
925
  for (uint32_t index = 0; index < parts_size; index++) {
914
926
  yp_serialize_node(parser, (yp_node_t *) ((yp_interpolated_x_string_node_t *)node)->parts.nodes[index], buffer);
915
927
  }
916
- serialize_location(parser, &((yp_interpolated_x_string_node_t *)node)->closing_loc, buffer);
928
+ yp_serialize_location(parser, &((yp_interpolated_x_string_node_t *)node)->closing_loc, buffer);
917
929
  break;
918
930
  }
919
931
  case YP_NODE_KEYWORD_HASH_NODE: {
@@ -925,7 +937,7 @@ yp_serialize_node(yp_parser_t *parser, yp_node_t *node, yp_buffer_t *buffer) {
925
937
  break;
926
938
  }
927
939
  case YP_NODE_KEYWORD_PARAMETER_NODE: {
928
- serialize_location(parser, &((yp_keyword_parameter_node_t *)node)->name_loc, buffer);
940
+ yp_serialize_location(parser, &((yp_keyword_parameter_node_t *)node)->name_loc, buffer);
929
941
  if (((yp_keyword_parameter_node_t *)node)->value == NULL) {
930
942
  yp_buffer_append_u8(buffer, 0);
931
943
  } else {
@@ -934,12 +946,12 @@ yp_serialize_node(yp_parser_t *parser, yp_node_t *node, yp_buffer_t *buffer) {
934
946
  break;
935
947
  }
936
948
  case YP_NODE_KEYWORD_REST_PARAMETER_NODE: {
937
- serialize_location(parser, &((yp_keyword_rest_parameter_node_t *)node)->operator_loc, buffer);
949
+ yp_serialize_location(parser, &((yp_keyword_rest_parameter_node_t *)node)->operator_loc, buffer);
938
950
  if (((yp_keyword_rest_parameter_node_t *)node)->name_loc.start == NULL) {
939
951
  yp_buffer_append_u8(buffer, 0);
940
952
  } else {
941
953
  yp_buffer_append_u8(buffer, 1);
942
- serialize_location(parser, &((yp_keyword_rest_parameter_node_t *)node)->name_loc, buffer);
954
+ yp_serialize_location(parser, &((yp_keyword_rest_parameter_node_t *)node)->name_loc, buffer);
943
955
  }
944
956
  break;
945
957
  }
@@ -949,39 +961,44 @@ yp_serialize_node(yp_parser_t *parser, yp_node_t *node, yp_buffer_t *buffer) {
949
961
  for (uint32_t index = 0; index < locals_size; index++) {
950
962
  yp_buffer_append_u32(buffer, yp_sizet_to_u32(((yp_lambda_node_t *)node)->locals.ids[index]));
951
963
  }
952
- serialize_location(parser, &((yp_lambda_node_t *)node)->opening_loc, buffer);
964
+ yp_serialize_location(parser, &((yp_lambda_node_t *)node)->operator_loc, buffer);
965
+ yp_serialize_location(parser, &((yp_lambda_node_t *)node)->opening_loc, buffer);
966
+ yp_serialize_location(parser, &((yp_lambda_node_t *)node)->closing_loc, buffer);
953
967
  if (((yp_lambda_node_t *)node)->parameters == NULL) {
954
968
  yp_buffer_append_u8(buffer, 0);
955
969
  } else {
956
970
  yp_serialize_node(parser, (yp_node_t *)((yp_lambda_node_t *)node)->parameters, buffer);
957
971
  }
958
- if (((yp_lambda_node_t *)node)->statements == NULL) {
972
+ if (((yp_lambda_node_t *)node)->body == NULL) {
959
973
  yp_buffer_append_u8(buffer, 0);
960
974
  } else {
961
- yp_serialize_node(parser, (yp_node_t *)((yp_lambda_node_t *)node)->statements, buffer);
975
+ yp_serialize_node(parser, (yp_node_t *)((yp_lambda_node_t *)node)->body, buffer);
962
976
  }
963
977
  break;
964
978
  }
965
- case YP_NODE_LOCAL_VARIABLE_OPERATOR_AND_WRITE_NODE: {
966
- serialize_location(parser, &((yp_local_variable_operator_and_write_node_t *)node)->name_loc, buffer);
967
- serialize_location(parser, &((yp_local_variable_operator_and_write_node_t *)node)->operator_loc, buffer);
968
- yp_serialize_node(parser, (yp_node_t *)((yp_local_variable_operator_and_write_node_t *)node)->value, buffer);
969
- yp_buffer_append_u32(buffer, yp_sizet_to_u32(((yp_local_variable_operator_and_write_node_t *)node)->constant_id));
970
- break;
971
- }
972
- case YP_NODE_LOCAL_VARIABLE_OPERATOR_OR_WRITE_NODE: {
973
- serialize_location(parser, &((yp_local_variable_operator_or_write_node_t *)node)->name_loc, buffer);
974
- serialize_location(parser, &((yp_local_variable_operator_or_write_node_t *)node)->operator_loc, buffer);
975
- yp_serialize_node(parser, (yp_node_t *)((yp_local_variable_operator_or_write_node_t *)node)->value, buffer);
976
- yp_buffer_append_u32(buffer, yp_sizet_to_u32(((yp_local_variable_operator_or_write_node_t *)node)->constant_id));
979
+ case YP_NODE_LOCAL_VARIABLE_AND_WRITE_NODE: {
980
+ yp_serialize_location(parser, &((yp_local_variable_and_write_node_t *)node)->name_loc, buffer);
981
+ yp_serialize_location(parser, &((yp_local_variable_and_write_node_t *)node)->operator_loc, buffer);
982
+ yp_serialize_node(parser, (yp_node_t *)((yp_local_variable_and_write_node_t *)node)->value, buffer);
983
+ yp_buffer_append_u32(buffer, yp_sizet_to_u32(((yp_local_variable_and_write_node_t *)node)->constant_id));
984
+ yp_buffer_append_u32(buffer, ((yp_local_variable_and_write_node_t *)node)->depth);
977
985
  break;
978
986
  }
979
987
  case YP_NODE_LOCAL_VARIABLE_OPERATOR_WRITE_NODE: {
980
- serialize_location(parser, &((yp_local_variable_operator_write_node_t *)node)->name_loc, buffer);
981
- serialize_location(parser, &((yp_local_variable_operator_write_node_t *)node)->operator_loc, buffer);
988
+ yp_serialize_location(parser, &((yp_local_variable_operator_write_node_t *)node)->name_loc, buffer);
989
+ yp_serialize_location(parser, &((yp_local_variable_operator_write_node_t *)node)->operator_loc, buffer);
982
990
  yp_serialize_node(parser, (yp_node_t *)((yp_local_variable_operator_write_node_t *)node)->value, buffer);
983
991
  yp_buffer_append_u32(buffer, yp_sizet_to_u32(((yp_local_variable_operator_write_node_t *)node)->constant_id));
984
992
  yp_buffer_append_u32(buffer, yp_sizet_to_u32(((yp_local_variable_operator_write_node_t *)node)->operator_id));
993
+ yp_buffer_append_u32(buffer, ((yp_local_variable_operator_write_node_t *)node)->depth);
994
+ break;
995
+ }
996
+ case YP_NODE_LOCAL_VARIABLE_OR_WRITE_NODE: {
997
+ yp_serialize_location(parser, &((yp_local_variable_or_write_node_t *)node)->name_loc, buffer);
998
+ yp_serialize_location(parser, &((yp_local_variable_or_write_node_t *)node)->operator_loc, buffer);
999
+ yp_serialize_node(parser, (yp_node_t *)((yp_local_variable_or_write_node_t *)node)->value, buffer);
1000
+ yp_buffer_append_u32(buffer, yp_sizet_to_u32(((yp_local_variable_or_write_node_t *)node)->constant_id));
1001
+ yp_buffer_append_u32(buffer, ((yp_local_variable_or_write_node_t *)node)->depth);
985
1002
  break;
986
1003
  }
987
1004
  case YP_NODE_LOCAL_VARIABLE_READ_NODE: {
@@ -989,33 +1006,29 @@ yp_serialize_node(yp_parser_t *parser, yp_node_t *node, yp_buffer_t *buffer) {
989
1006
  yp_buffer_append_u32(buffer, ((yp_local_variable_read_node_t *)node)->depth);
990
1007
  break;
991
1008
  }
1009
+ case YP_NODE_LOCAL_VARIABLE_TARGET_NODE: {
1010
+ yp_buffer_append_u32(buffer, yp_sizet_to_u32(((yp_local_variable_target_node_t *)node)->constant_id));
1011
+ yp_buffer_append_u32(buffer, ((yp_local_variable_target_node_t *)node)->depth);
1012
+ break;
1013
+ }
992
1014
  case YP_NODE_LOCAL_VARIABLE_WRITE_NODE: {
993
1015
  yp_buffer_append_u32(buffer, yp_sizet_to_u32(((yp_local_variable_write_node_t *)node)->constant_id));
994
1016
  yp_buffer_append_u32(buffer, ((yp_local_variable_write_node_t *)node)->depth);
995
- if (((yp_local_variable_write_node_t *)node)->value == NULL) {
996
- yp_buffer_append_u8(buffer, 0);
997
- } else {
998
- yp_serialize_node(parser, (yp_node_t *)((yp_local_variable_write_node_t *)node)->value, buffer);
999
- }
1000
- serialize_location(parser, &((yp_local_variable_write_node_t *)node)->name_loc, buffer);
1001
- if (((yp_local_variable_write_node_t *)node)->operator_loc.start == NULL) {
1002
- yp_buffer_append_u8(buffer, 0);
1003
- } else {
1004
- yp_buffer_append_u8(buffer, 1);
1005
- serialize_location(parser, &((yp_local_variable_write_node_t *)node)->operator_loc, buffer);
1006
- }
1017
+ yp_serialize_node(parser, (yp_node_t *)((yp_local_variable_write_node_t *)node)->value, buffer);
1018
+ yp_serialize_location(parser, &((yp_local_variable_write_node_t *)node)->name_loc, buffer);
1019
+ yp_serialize_location(parser, &((yp_local_variable_write_node_t *)node)->operator_loc, buffer);
1007
1020
  break;
1008
1021
  }
1009
1022
  case YP_NODE_MATCH_PREDICATE_NODE: {
1010
1023
  yp_serialize_node(parser, (yp_node_t *)((yp_match_predicate_node_t *)node)->value, buffer);
1011
1024
  yp_serialize_node(parser, (yp_node_t *)((yp_match_predicate_node_t *)node)->pattern, buffer);
1012
- serialize_location(parser, &((yp_match_predicate_node_t *)node)->operator_loc, buffer);
1025
+ yp_serialize_location(parser, &((yp_match_predicate_node_t *)node)->operator_loc, buffer);
1013
1026
  break;
1014
1027
  }
1015
1028
  case YP_NODE_MATCH_REQUIRED_NODE: {
1016
1029
  yp_serialize_node(parser, (yp_node_t *)((yp_match_required_node_t *)node)->value, buffer);
1017
1030
  yp_serialize_node(parser, (yp_node_t *)((yp_match_required_node_t *)node)->pattern, buffer);
1018
- serialize_location(parser, &((yp_match_required_node_t *)node)->operator_loc, buffer);
1031
+ yp_serialize_location(parser, &((yp_match_required_node_t *)node)->operator_loc, buffer);
1019
1032
  break;
1020
1033
  }
1021
1034
  case YP_NODE_MISSING_NODE: {
@@ -1027,14 +1040,15 @@ yp_serialize_node(yp_parser_t *parser, yp_node_t *node, yp_buffer_t *buffer) {
1027
1040
  for (uint32_t index = 0; index < locals_size; index++) {
1028
1041
  yp_buffer_append_u32(buffer, yp_sizet_to_u32(((yp_module_node_t *)node)->locals.ids[index]));
1029
1042
  }
1030
- serialize_location(parser, &((yp_module_node_t *)node)->module_keyword_loc, buffer);
1043
+ yp_serialize_location(parser, &((yp_module_node_t *)node)->module_keyword_loc, buffer);
1031
1044
  yp_serialize_node(parser, (yp_node_t *)((yp_module_node_t *)node)->constant_path, buffer);
1032
- if (((yp_module_node_t *)node)->statements == NULL) {
1045
+ if (((yp_module_node_t *)node)->body == NULL) {
1033
1046
  yp_buffer_append_u8(buffer, 0);
1034
1047
  } else {
1035
- yp_serialize_node(parser, (yp_node_t *)((yp_module_node_t *)node)->statements, buffer);
1048
+ yp_serialize_node(parser, (yp_node_t *)((yp_module_node_t *)node)->body, buffer);
1036
1049
  }
1037
- serialize_location(parser, &((yp_module_node_t *)node)->end_keyword_loc, buffer);
1050
+ yp_serialize_location(parser, &((yp_module_node_t *)node)->end_keyword_loc, buffer);
1051
+ yp_serialize_string(parser, &((yp_module_node_t *)node)->name, buffer);
1038
1052
  break;
1039
1053
  }
1040
1054
  case YP_NODE_MULTI_WRITE_NODE: {
@@ -1047,7 +1061,7 @@ yp_serialize_node(yp_parser_t *parser, yp_node_t *node, yp_buffer_t *buffer) {
1047
1061
  yp_buffer_append_u8(buffer, 0);
1048
1062
  } else {
1049
1063
  yp_buffer_append_u8(buffer, 1);
1050
- serialize_location(parser, &((yp_multi_write_node_t *)node)->operator_loc, buffer);
1064
+ yp_serialize_location(parser, &((yp_multi_write_node_t *)node)->operator_loc, buffer);
1051
1065
  }
1052
1066
  if (((yp_multi_write_node_t *)node)->value == NULL) {
1053
1067
  yp_buffer_append_u8(buffer, 0);
@@ -1058,13 +1072,13 @@ yp_serialize_node(yp_parser_t *parser, yp_node_t *node, yp_buffer_t *buffer) {
1058
1072
  yp_buffer_append_u8(buffer, 0);
1059
1073
  } else {
1060
1074
  yp_buffer_append_u8(buffer, 1);
1061
- serialize_location(parser, &((yp_multi_write_node_t *)node)->lparen_loc, buffer);
1075
+ yp_serialize_location(parser, &((yp_multi_write_node_t *)node)->lparen_loc, buffer);
1062
1076
  }
1063
1077
  if (((yp_multi_write_node_t *)node)->rparen_loc.start == NULL) {
1064
1078
  yp_buffer_append_u8(buffer, 0);
1065
1079
  } else {
1066
1080
  yp_buffer_append_u8(buffer, 1);
1067
- serialize_location(parser, &((yp_multi_write_node_t *)node)->rparen_loc, buffer);
1081
+ yp_serialize_location(parser, &((yp_multi_write_node_t *)node)->rparen_loc, buffer);
1068
1082
  }
1069
1083
  break;
1070
1084
  }
@@ -1074,15 +1088,15 @@ yp_serialize_node(yp_parser_t *parser, yp_node_t *node, yp_buffer_t *buffer) {
1074
1088
  } else {
1075
1089
  yp_serialize_node(parser, (yp_node_t *)((yp_next_node_t *)node)->arguments, buffer);
1076
1090
  }
1077
- serialize_location(parser, &((yp_next_node_t *)node)->keyword_loc, buffer);
1091
+ yp_serialize_location(parser, &((yp_next_node_t *)node)->keyword_loc, buffer);
1078
1092
  break;
1079
1093
  }
1080
1094
  case YP_NODE_NIL_NODE: {
1081
1095
  break;
1082
1096
  }
1083
1097
  case YP_NODE_NO_KEYWORDS_PARAMETER_NODE: {
1084
- serialize_location(parser, &((yp_no_keywords_parameter_node_t *)node)->operator_loc, buffer);
1085
- serialize_location(parser, &((yp_no_keywords_parameter_node_t *)node)->keyword_loc, buffer);
1098
+ yp_serialize_location(parser, &((yp_no_keywords_parameter_node_t *)node)->operator_loc, buffer);
1099
+ yp_serialize_location(parser, &((yp_no_keywords_parameter_node_t *)node)->keyword_loc, buffer);
1086
1100
  break;
1087
1101
  }
1088
1102
  case YP_NODE_NUMBERED_REFERENCE_READ_NODE: {
@@ -1090,15 +1104,15 @@ yp_serialize_node(yp_parser_t *parser, yp_node_t *node, yp_buffer_t *buffer) {
1090
1104
  }
1091
1105
  case YP_NODE_OPTIONAL_PARAMETER_NODE: {
1092
1106
  yp_buffer_append_u32(buffer, yp_sizet_to_u32(((yp_optional_parameter_node_t *)node)->constant_id));
1093
- serialize_location(parser, &((yp_optional_parameter_node_t *)node)->name_loc, buffer);
1094
- serialize_location(parser, &((yp_optional_parameter_node_t *)node)->operator_loc, buffer);
1107
+ yp_serialize_location(parser, &((yp_optional_parameter_node_t *)node)->name_loc, buffer);
1108
+ yp_serialize_location(parser, &((yp_optional_parameter_node_t *)node)->operator_loc, buffer);
1095
1109
  yp_serialize_node(parser, (yp_node_t *)((yp_optional_parameter_node_t *)node)->value, buffer);
1096
1110
  break;
1097
1111
  }
1098
1112
  case YP_NODE_OR_NODE: {
1099
1113
  yp_serialize_node(parser, (yp_node_t *)((yp_or_node_t *)node)->left, buffer);
1100
1114
  yp_serialize_node(parser, (yp_node_t *)((yp_or_node_t *)node)->right, buffer);
1101
- serialize_location(parser, &((yp_or_node_t *)node)->operator_loc, buffer);
1115
+ yp_serialize_location(parser, &((yp_or_node_t *)node)->operator_loc, buffer);
1102
1116
  break;
1103
1117
  }
1104
1118
  case YP_NODE_PARAMETERS_NODE: {
@@ -1140,25 +1154,25 @@ yp_serialize_node(yp_parser_t *parser, yp_node_t *node, yp_buffer_t *buffer) {
1140
1154
  break;
1141
1155
  }
1142
1156
  case YP_NODE_PARENTHESES_NODE: {
1143
- if (((yp_parentheses_node_t *)node)->statements == NULL) {
1157
+ if (((yp_parentheses_node_t *)node)->body == NULL) {
1144
1158
  yp_buffer_append_u8(buffer, 0);
1145
1159
  } else {
1146
- yp_serialize_node(parser, (yp_node_t *)((yp_parentheses_node_t *)node)->statements, buffer);
1160
+ yp_serialize_node(parser, (yp_node_t *)((yp_parentheses_node_t *)node)->body, buffer);
1147
1161
  }
1148
- serialize_location(parser, &((yp_parentheses_node_t *)node)->opening_loc, buffer);
1149
- serialize_location(parser, &((yp_parentheses_node_t *)node)->closing_loc, buffer);
1162
+ yp_serialize_location(parser, &((yp_parentheses_node_t *)node)->opening_loc, buffer);
1163
+ yp_serialize_location(parser, &((yp_parentheses_node_t *)node)->closing_loc, buffer);
1150
1164
  break;
1151
1165
  }
1152
1166
  case YP_NODE_PINNED_EXPRESSION_NODE: {
1153
1167
  yp_serialize_node(parser, (yp_node_t *)((yp_pinned_expression_node_t *)node)->expression, buffer);
1154
- serialize_location(parser, &((yp_pinned_expression_node_t *)node)->operator_loc, buffer);
1155
- serialize_location(parser, &((yp_pinned_expression_node_t *)node)->lparen_loc, buffer);
1156
- serialize_location(parser, &((yp_pinned_expression_node_t *)node)->rparen_loc, buffer);
1168
+ yp_serialize_location(parser, &((yp_pinned_expression_node_t *)node)->operator_loc, buffer);
1169
+ yp_serialize_location(parser, &((yp_pinned_expression_node_t *)node)->lparen_loc, buffer);
1170
+ yp_serialize_location(parser, &((yp_pinned_expression_node_t *)node)->rparen_loc, buffer);
1157
1171
  break;
1158
1172
  }
1159
1173
  case YP_NODE_PINNED_VARIABLE_NODE: {
1160
1174
  yp_serialize_node(parser, (yp_node_t *)((yp_pinned_variable_node_t *)node)->variable, buffer);
1161
- serialize_location(parser, &((yp_pinned_variable_node_t *)node)->operator_loc, buffer);
1175
+ yp_serialize_location(parser, &((yp_pinned_variable_node_t *)node)->operator_loc, buffer);
1162
1176
  break;
1163
1177
  }
1164
1178
  case YP_NODE_POST_EXECUTION_NODE: {
@@ -1167,9 +1181,9 @@ yp_serialize_node(yp_parser_t *parser, yp_node_t *node, yp_buffer_t *buffer) {
1167
1181
  } else {
1168
1182
  yp_serialize_node(parser, (yp_node_t *)((yp_post_execution_node_t *)node)->statements, buffer);
1169
1183
  }
1170
- serialize_location(parser, &((yp_post_execution_node_t *)node)->keyword_loc, buffer);
1171
- serialize_location(parser, &((yp_post_execution_node_t *)node)->opening_loc, buffer);
1172
- serialize_location(parser, &((yp_post_execution_node_t *)node)->closing_loc, buffer);
1184
+ yp_serialize_location(parser, &((yp_post_execution_node_t *)node)->keyword_loc, buffer);
1185
+ yp_serialize_location(parser, &((yp_post_execution_node_t *)node)->opening_loc, buffer);
1186
+ yp_serialize_location(parser, &((yp_post_execution_node_t *)node)->closing_loc, buffer);
1173
1187
  break;
1174
1188
  }
1175
1189
  case YP_NODE_PRE_EXECUTION_NODE: {
@@ -1178,9 +1192,9 @@ yp_serialize_node(yp_parser_t *parser, yp_node_t *node, yp_buffer_t *buffer) {
1178
1192
  } else {
1179
1193
  yp_serialize_node(parser, (yp_node_t *)((yp_pre_execution_node_t *)node)->statements, buffer);
1180
1194
  }
1181
- serialize_location(parser, &((yp_pre_execution_node_t *)node)->keyword_loc, buffer);
1182
- serialize_location(parser, &((yp_pre_execution_node_t *)node)->opening_loc, buffer);
1183
- serialize_location(parser, &((yp_pre_execution_node_t *)node)->closing_loc, buffer);
1195
+ yp_serialize_location(parser, &((yp_pre_execution_node_t *)node)->keyword_loc, buffer);
1196
+ yp_serialize_location(parser, &((yp_pre_execution_node_t *)node)->opening_loc, buffer);
1197
+ yp_serialize_location(parser, &((yp_pre_execution_node_t *)node)->closing_loc, buffer);
1184
1198
  break;
1185
1199
  }
1186
1200
  case YP_NODE_PROGRAM_NODE: {
@@ -1203,7 +1217,7 @@ yp_serialize_node(yp_parser_t *parser, yp_node_t *node, yp_buffer_t *buffer) {
1203
1217
  } else {
1204
1218
  yp_serialize_node(parser, (yp_node_t *)((yp_range_node_t *)node)->right, buffer);
1205
1219
  }
1206
- serialize_location(parser, &((yp_range_node_t *)node)->operator_loc, buffer);
1220
+ yp_serialize_location(parser, &((yp_range_node_t *)node)->operator_loc, buffer);
1207
1221
  yp_buffer_append_u32(buffer, node->flags >> 1);
1208
1222
  break;
1209
1223
  }
@@ -1215,12 +1229,10 @@ yp_serialize_node(yp_parser_t *parser, yp_node_t *node, yp_buffer_t *buffer) {
1215
1229
  break;
1216
1230
  }
1217
1231
  case YP_NODE_REGULAR_EXPRESSION_NODE: {
1218
- serialize_location(parser, &((yp_regular_expression_node_t *)node)->opening_loc, buffer);
1219
- serialize_location(parser, &((yp_regular_expression_node_t *)node)->content_loc, buffer);
1220
- serialize_location(parser, &((yp_regular_expression_node_t *)node)->closing_loc, buffer);
1221
- uint32_t unescaped_length = yp_sizet_to_u32(yp_string_length(&((yp_regular_expression_node_t *)node)->unescaped));
1222
- yp_buffer_append_u32(buffer, unescaped_length);
1223
- yp_buffer_append_str(buffer, yp_string_source(&((yp_regular_expression_node_t *)node)->unescaped), unescaped_length);
1232
+ yp_serialize_location(parser, &((yp_regular_expression_node_t *)node)->opening_loc, buffer);
1233
+ yp_serialize_location(parser, &((yp_regular_expression_node_t *)node)->content_loc, buffer);
1234
+ yp_serialize_location(parser, &((yp_regular_expression_node_t *)node)->closing_loc, buffer);
1235
+ yp_serialize_string(parser, &((yp_regular_expression_node_t *)node)->unescaped, buffer);
1224
1236
  yp_buffer_append_u32(buffer, node->flags >> 1);
1225
1237
  break;
1226
1238
  }
@@ -1230,8 +1242,8 @@ yp_serialize_node(yp_parser_t *parser, yp_node_t *node, yp_buffer_t *buffer) {
1230
1242
  for (uint32_t index = 0; index < parameters_size; index++) {
1231
1243
  yp_serialize_node(parser, (yp_node_t *) ((yp_required_destructured_parameter_node_t *)node)->parameters.nodes[index], buffer);
1232
1244
  }
1233
- serialize_location(parser, &((yp_required_destructured_parameter_node_t *)node)->opening_loc, buffer);
1234
- serialize_location(parser, &((yp_required_destructured_parameter_node_t *)node)->closing_loc, buffer);
1245
+ yp_serialize_location(parser, &((yp_required_destructured_parameter_node_t *)node)->opening_loc, buffer);
1246
+ yp_serialize_location(parser, &((yp_required_destructured_parameter_node_t *)node)->closing_loc, buffer);
1235
1247
  break;
1236
1248
  }
1237
1249
  case YP_NODE_REQUIRED_PARAMETER_NODE: {
@@ -1240,12 +1252,12 @@ yp_serialize_node(yp_parser_t *parser, yp_node_t *node, yp_buffer_t *buffer) {
1240
1252
  }
1241
1253
  case YP_NODE_RESCUE_MODIFIER_NODE: {
1242
1254
  yp_serialize_node(parser, (yp_node_t *)((yp_rescue_modifier_node_t *)node)->expression, buffer);
1243
- serialize_location(parser, &((yp_rescue_modifier_node_t *)node)->keyword_loc, buffer);
1255
+ yp_serialize_location(parser, &((yp_rescue_modifier_node_t *)node)->keyword_loc, buffer);
1244
1256
  yp_serialize_node(parser, (yp_node_t *)((yp_rescue_modifier_node_t *)node)->rescue_expression, buffer);
1245
1257
  break;
1246
1258
  }
1247
1259
  case YP_NODE_RESCUE_NODE: {
1248
- serialize_location(parser, &((yp_rescue_node_t *)node)->keyword_loc, buffer);
1260
+ yp_serialize_location(parser, &((yp_rescue_node_t *)node)->keyword_loc, buffer);
1249
1261
  uint32_t exceptions_size = yp_sizet_to_u32(((yp_rescue_node_t *)node)->exceptions.size);
1250
1262
  yp_buffer_append_u32(buffer, exceptions_size);
1251
1263
  for (uint32_t index = 0; index < exceptions_size; index++) {
@@ -1255,7 +1267,7 @@ yp_serialize_node(yp_parser_t *parser, yp_node_t *node, yp_buffer_t *buffer) {
1255
1267
  yp_buffer_append_u8(buffer, 0);
1256
1268
  } else {
1257
1269
  yp_buffer_append_u8(buffer, 1);
1258
- serialize_location(parser, &((yp_rescue_node_t *)node)->operator_loc, buffer);
1270
+ yp_serialize_location(parser, &((yp_rescue_node_t *)node)->operator_loc, buffer);
1259
1271
  }
1260
1272
  if (((yp_rescue_node_t *)node)->reference == NULL) {
1261
1273
  yp_buffer_append_u8(buffer, 0);
@@ -1275,12 +1287,12 @@ yp_serialize_node(yp_parser_t *parser, yp_node_t *node, yp_buffer_t *buffer) {
1275
1287
  break;
1276
1288
  }
1277
1289
  case YP_NODE_REST_PARAMETER_NODE: {
1278
- serialize_location(parser, &((yp_rest_parameter_node_t *)node)->operator_loc, buffer);
1290
+ yp_serialize_location(parser, &((yp_rest_parameter_node_t *)node)->operator_loc, buffer);
1279
1291
  if (((yp_rest_parameter_node_t *)node)->name_loc.start == NULL) {
1280
1292
  yp_buffer_append_u8(buffer, 0);
1281
1293
  } else {
1282
1294
  yp_buffer_append_u8(buffer, 1);
1283
- serialize_location(parser, &((yp_rest_parameter_node_t *)node)->name_loc, buffer);
1295
+ yp_serialize_location(parser, &((yp_rest_parameter_node_t *)node)->name_loc, buffer);
1284
1296
  }
1285
1297
  break;
1286
1298
  }
@@ -1288,7 +1300,7 @@ yp_serialize_node(yp_parser_t *parser, yp_node_t *node, yp_buffer_t *buffer) {
1288
1300
  break;
1289
1301
  }
1290
1302
  case YP_NODE_RETURN_NODE: {
1291
- serialize_location(parser, &((yp_return_node_t *)node)->keyword_loc, buffer);
1303
+ yp_serialize_location(parser, &((yp_return_node_t *)node)->keyword_loc, buffer);
1292
1304
  if (((yp_return_node_t *)node)->arguments == NULL) {
1293
1305
  yp_buffer_append_u8(buffer, 0);
1294
1306
  } else {
@@ -1305,31 +1317,29 @@ yp_serialize_node(yp_parser_t *parser, yp_node_t *node, yp_buffer_t *buffer) {
1305
1317
  for (uint32_t index = 0; index < locals_size; index++) {
1306
1318
  yp_buffer_append_u32(buffer, yp_sizet_to_u32(((yp_singleton_class_node_t *)node)->locals.ids[index]));
1307
1319
  }
1308
- serialize_location(parser, &((yp_singleton_class_node_t *)node)->class_keyword_loc, buffer);
1309
- serialize_location(parser, &((yp_singleton_class_node_t *)node)->operator_loc, buffer);
1320
+ yp_serialize_location(parser, &((yp_singleton_class_node_t *)node)->class_keyword_loc, buffer);
1321
+ yp_serialize_location(parser, &((yp_singleton_class_node_t *)node)->operator_loc, buffer);
1310
1322
  yp_serialize_node(parser, (yp_node_t *)((yp_singleton_class_node_t *)node)->expression, buffer);
1311
- if (((yp_singleton_class_node_t *)node)->statements == NULL) {
1323
+ if (((yp_singleton_class_node_t *)node)->body == NULL) {
1312
1324
  yp_buffer_append_u8(buffer, 0);
1313
1325
  } else {
1314
- yp_serialize_node(parser, (yp_node_t *)((yp_singleton_class_node_t *)node)->statements, buffer);
1326
+ yp_serialize_node(parser, (yp_node_t *)((yp_singleton_class_node_t *)node)->body, buffer);
1315
1327
  }
1316
- serialize_location(parser, &((yp_singleton_class_node_t *)node)->end_keyword_loc, buffer);
1328
+ yp_serialize_location(parser, &((yp_singleton_class_node_t *)node)->end_keyword_loc, buffer);
1317
1329
  break;
1318
1330
  }
1319
1331
  case YP_NODE_SOURCE_ENCODING_NODE: {
1320
1332
  break;
1321
1333
  }
1322
1334
  case YP_NODE_SOURCE_FILE_NODE: {
1323
- uint32_t filepath_length = yp_sizet_to_u32(yp_string_length(&((yp_source_file_node_t *)node)->filepath));
1324
- yp_buffer_append_u32(buffer, filepath_length);
1325
- yp_buffer_append_str(buffer, yp_string_source(&((yp_source_file_node_t *)node)->filepath), filepath_length);
1335
+ yp_serialize_string(parser, &((yp_source_file_node_t *)node)->filepath, buffer);
1326
1336
  break;
1327
1337
  }
1328
1338
  case YP_NODE_SOURCE_LINE_NODE: {
1329
1339
  break;
1330
1340
  }
1331
1341
  case YP_NODE_SPLAT_NODE: {
1332
- serialize_location(parser, &((yp_splat_node_t *)node)->operator_loc, buffer);
1342
+ yp_serialize_location(parser, &((yp_splat_node_t *)node)->operator_loc, buffer);
1333
1343
  if (((yp_splat_node_t *)node)->expression == NULL) {
1334
1344
  yp_buffer_append_u8(buffer, 0);
1335
1345
  } else {
@@ -1355,27 +1365,25 @@ yp_serialize_node(yp_parser_t *parser, yp_node_t *node, yp_buffer_t *buffer) {
1355
1365
  yp_buffer_append_u8(buffer, 0);
1356
1366
  } else {
1357
1367
  yp_buffer_append_u8(buffer, 1);
1358
- serialize_location(parser, &((yp_string_node_t *)node)->opening_loc, buffer);
1368
+ yp_serialize_location(parser, &((yp_string_node_t *)node)->opening_loc, buffer);
1359
1369
  }
1360
- serialize_location(parser, &((yp_string_node_t *)node)->content_loc, buffer);
1370
+ yp_serialize_location(parser, &((yp_string_node_t *)node)->content_loc, buffer);
1361
1371
  if (((yp_string_node_t *)node)->closing_loc.start == NULL) {
1362
1372
  yp_buffer_append_u8(buffer, 0);
1363
1373
  } else {
1364
1374
  yp_buffer_append_u8(buffer, 1);
1365
- serialize_location(parser, &((yp_string_node_t *)node)->closing_loc, buffer);
1375
+ yp_serialize_location(parser, &((yp_string_node_t *)node)->closing_loc, buffer);
1366
1376
  }
1367
- uint32_t unescaped_length = yp_sizet_to_u32(yp_string_length(&((yp_string_node_t *)node)->unescaped));
1368
- yp_buffer_append_u32(buffer, unescaped_length);
1369
- yp_buffer_append_str(buffer, yp_string_source(&((yp_string_node_t *)node)->unescaped), unescaped_length);
1377
+ yp_serialize_string(parser, &((yp_string_node_t *)node)->unescaped, buffer);
1370
1378
  break;
1371
1379
  }
1372
1380
  case YP_NODE_SUPER_NODE: {
1373
- serialize_location(parser, &((yp_super_node_t *)node)->keyword_loc, buffer);
1381
+ yp_serialize_location(parser, &((yp_super_node_t *)node)->keyword_loc, buffer);
1374
1382
  if (((yp_super_node_t *)node)->lparen_loc.start == NULL) {
1375
1383
  yp_buffer_append_u8(buffer, 0);
1376
1384
  } else {
1377
1385
  yp_buffer_append_u8(buffer, 1);
1378
- serialize_location(parser, &((yp_super_node_t *)node)->lparen_loc, buffer);
1386
+ yp_serialize_location(parser, &((yp_super_node_t *)node)->lparen_loc, buffer);
1379
1387
  }
1380
1388
  if (((yp_super_node_t *)node)->arguments == NULL) {
1381
1389
  yp_buffer_append_u8(buffer, 0);
@@ -1386,7 +1394,7 @@ yp_serialize_node(yp_parser_t *parser, yp_node_t *node, yp_buffer_t *buffer) {
1386
1394
  yp_buffer_append_u8(buffer, 0);
1387
1395
  } else {
1388
1396
  yp_buffer_append_u8(buffer, 1);
1389
- serialize_location(parser, &((yp_super_node_t *)node)->rparen_loc, buffer);
1397
+ yp_serialize_location(parser, &((yp_super_node_t *)node)->rparen_loc, buffer);
1390
1398
  }
1391
1399
  if (((yp_super_node_t *)node)->block == NULL) {
1392
1400
  yp_buffer_append_u8(buffer, 0);
@@ -1400,18 +1408,21 @@ yp_serialize_node(yp_parser_t *parser, yp_node_t *node, yp_buffer_t *buffer) {
1400
1408
  yp_buffer_append_u8(buffer, 0);
1401
1409
  } else {
1402
1410
  yp_buffer_append_u8(buffer, 1);
1403
- serialize_location(parser, &((yp_symbol_node_t *)node)->opening_loc, buffer);
1411
+ yp_serialize_location(parser, &((yp_symbol_node_t *)node)->opening_loc, buffer);
1412
+ }
1413
+ if (((yp_symbol_node_t *)node)->value_loc.start == NULL) {
1414
+ yp_buffer_append_u8(buffer, 0);
1415
+ } else {
1416
+ yp_buffer_append_u8(buffer, 1);
1417
+ yp_serialize_location(parser, &((yp_symbol_node_t *)node)->value_loc, buffer);
1404
1418
  }
1405
- serialize_location(parser, &((yp_symbol_node_t *)node)->value_loc, buffer);
1406
1419
  if (((yp_symbol_node_t *)node)->closing_loc.start == NULL) {
1407
1420
  yp_buffer_append_u8(buffer, 0);
1408
1421
  } else {
1409
1422
  yp_buffer_append_u8(buffer, 1);
1410
- serialize_location(parser, &((yp_symbol_node_t *)node)->closing_loc, buffer);
1423
+ yp_serialize_location(parser, &((yp_symbol_node_t *)node)->closing_loc, buffer);
1411
1424
  }
1412
- uint32_t unescaped_length = yp_sizet_to_u32(yp_string_length(&((yp_symbol_node_t *)node)->unescaped));
1413
- yp_buffer_append_u32(buffer, unescaped_length);
1414
- yp_buffer_append_str(buffer, yp_string_source(&((yp_symbol_node_t *)node)->unescaped), unescaped_length);
1425
+ yp_serialize_string(parser, &((yp_symbol_node_t *)node)->unescaped, buffer);
1415
1426
  break;
1416
1427
  }
1417
1428
  case YP_NODE_TRUE_NODE: {
@@ -1423,11 +1434,11 @@ yp_serialize_node(yp_parser_t *parser, yp_node_t *node, yp_buffer_t *buffer) {
1423
1434
  for (uint32_t index = 0; index < names_size; index++) {
1424
1435
  yp_serialize_node(parser, (yp_node_t *) ((yp_undef_node_t *)node)->names.nodes[index], buffer);
1425
1436
  }
1426
- serialize_location(parser, &((yp_undef_node_t *)node)->keyword_loc, buffer);
1437
+ yp_serialize_location(parser, &((yp_undef_node_t *)node)->keyword_loc, buffer);
1427
1438
  break;
1428
1439
  }
1429
1440
  case YP_NODE_UNLESS_NODE: {
1430
- serialize_location(parser, &((yp_unless_node_t *)node)->keyword_loc, buffer);
1441
+ yp_serialize_location(parser, &((yp_unless_node_t *)node)->keyword_loc, buffer);
1431
1442
  yp_serialize_node(parser, (yp_node_t *)((yp_unless_node_t *)node)->predicate, buffer);
1432
1443
  if (((yp_unless_node_t *)node)->statements == NULL) {
1433
1444
  yp_buffer_append_u8(buffer, 0);
@@ -1443,12 +1454,18 @@ yp_serialize_node(yp_parser_t *parser, yp_node_t *node, yp_buffer_t *buffer) {
1443
1454
  yp_buffer_append_u8(buffer, 0);
1444
1455
  } else {
1445
1456
  yp_buffer_append_u8(buffer, 1);
1446
- serialize_location(parser, &((yp_unless_node_t *)node)->end_keyword_loc, buffer);
1457
+ yp_serialize_location(parser, &((yp_unless_node_t *)node)->end_keyword_loc, buffer);
1447
1458
  }
1448
1459
  break;
1449
1460
  }
1450
1461
  case YP_NODE_UNTIL_NODE: {
1451
- serialize_location(parser, &((yp_until_node_t *)node)->keyword_loc, buffer);
1462
+ yp_serialize_location(parser, &((yp_until_node_t *)node)->keyword_loc, buffer);
1463
+ if (((yp_until_node_t *)node)->closing_loc.start == NULL) {
1464
+ yp_buffer_append_u8(buffer, 0);
1465
+ } else {
1466
+ yp_buffer_append_u8(buffer, 1);
1467
+ yp_serialize_location(parser, &((yp_until_node_t *)node)->closing_loc, buffer);
1468
+ }
1452
1469
  yp_serialize_node(parser, (yp_node_t *)((yp_until_node_t *)node)->predicate, buffer);
1453
1470
  if (((yp_until_node_t *)node)->statements == NULL) {
1454
1471
  yp_buffer_append_u8(buffer, 0);
@@ -1459,7 +1476,7 @@ yp_serialize_node(yp_parser_t *parser, yp_node_t *node, yp_buffer_t *buffer) {
1459
1476
  break;
1460
1477
  }
1461
1478
  case YP_NODE_WHEN_NODE: {
1462
- serialize_location(parser, &((yp_when_node_t *)node)->keyword_loc, buffer);
1479
+ yp_serialize_location(parser, &((yp_when_node_t *)node)->keyword_loc, buffer);
1463
1480
  uint32_t conditions_size = yp_sizet_to_u32(((yp_when_node_t *)node)->conditions.size);
1464
1481
  yp_buffer_append_u32(buffer, conditions_size);
1465
1482
  for (uint32_t index = 0; index < conditions_size; index++) {
@@ -1473,7 +1490,13 @@ yp_serialize_node(yp_parser_t *parser, yp_node_t *node, yp_buffer_t *buffer) {
1473
1490
  break;
1474
1491
  }
1475
1492
  case YP_NODE_WHILE_NODE: {
1476
- serialize_location(parser, &((yp_while_node_t *)node)->keyword_loc, buffer);
1493
+ yp_serialize_location(parser, &((yp_while_node_t *)node)->keyword_loc, buffer);
1494
+ if (((yp_while_node_t *)node)->closing_loc.start == NULL) {
1495
+ yp_buffer_append_u8(buffer, 0);
1496
+ } else {
1497
+ yp_buffer_append_u8(buffer, 1);
1498
+ yp_serialize_location(parser, &((yp_while_node_t *)node)->closing_loc, buffer);
1499
+ }
1477
1500
  yp_serialize_node(parser, (yp_node_t *)((yp_while_node_t *)node)->predicate, buffer);
1478
1501
  if (((yp_while_node_t *)node)->statements == NULL) {
1479
1502
  yp_buffer_append_u8(buffer, 0);
@@ -1484,21 +1507,19 @@ yp_serialize_node(yp_parser_t *parser, yp_node_t *node, yp_buffer_t *buffer) {
1484
1507
  break;
1485
1508
  }
1486
1509
  case YP_NODE_X_STRING_NODE: {
1487
- serialize_location(parser, &((yp_x_string_node_t *)node)->opening_loc, buffer);
1488
- serialize_location(parser, &((yp_x_string_node_t *)node)->content_loc, buffer);
1489
- serialize_location(parser, &((yp_x_string_node_t *)node)->closing_loc, buffer);
1490
- uint32_t unescaped_length = yp_sizet_to_u32(yp_string_length(&((yp_x_string_node_t *)node)->unescaped));
1491
- yp_buffer_append_u32(buffer, unescaped_length);
1492
- yp_buffer_append_str(buffer, yp_string_source(&((yp_x_string_node_t *)node)->unescaped), unescaped_length);
1510
+ yp_serialize_location(parser, &((yp_x_string_node_t *)node)->opening_loc, buffer);
1511
+ yp_serialize_location(parser, &((yp_x_string_node_t *)node)->content_loc, buffer);
1512
+ yp_serialize_location(parser, &((yp_x_string_node_t *)node)->closing_loc, buffer);
1513
+ yp_serialize_string(parser, &((yp_x_string_node_t *)node)->unescaped, buffer);
1493
1514
  break;
1494
1515
  }
1495
1516
  case YP_NODE_YIELD_NODE: {
1496
- serialize_location(parser, &((yp_yield_node_t *)node)->keyword_loc, buffer);
1517
+ yp_serialize_location(parser, &((yp_yield_node_t *)node)->keyword_loc, buffer);
1497
1518
  if (((yp_yield_node_t *)node)->lparen_loc.start == NULL) {
1498
1519
  yp_buffer_append_u8(buffer, 0);
1499
1520
  } else {
1500
1521
  yp_buffer_append_u8(buffer, 1);
1501
- serialize_location(parser, &((yp_yield_node_t *)node)->lparen_loc, buffer);
1522
+ yp_serialize_location(parser, &((yp_yield_node_t *)node)->lparen_loc, buffer);
1502
1523
  }
1503
1524
  if (((yp_yield_node_t *)node)->arguments == NULL) {
1504
1525
  yp_buffer_append_u8(buffer, 0);
@@ -1509,14 +1530,15 @@ yp_serialize_node(yp_parser_t *parser, yp_node_t *node, yp_buffer_t *buffer) {
1509
1530
  yp_buffer_append_u8(buffer, 0);
1510
1531
  } else {
1511
1532
  yp_buffer_append_u8(buffer, 1);
1512
- serialize_location(parser, &((yp_yield_node_t *)node)->rparen_loc, buffer);
1533
+ yp_serialize_location(parser, &((yp_yield_node_t *)node)->rparen_loc, buffer);
1513
1534
  }
1514
1535
  break;
1515
1536
  }
1516
1537
  }
1517
1538
  }
1518
1539
 
1519
- void yp_serialize_comment(yp_parser_t *parser, yp_comment_t *comment, yp_buffer_t *buffer) {
1540
+ static void
1541
+ yp_serialize_comment(yp_parser_t *parser, yp_comment_t *comment, yp_buffer_t *buffer) {
1520
1542
  // serialize type
1521
1543
  yp_buffer_append_u8(buffer, (uint8_t) comment->type);
1522
1544
 
@@ -1525,16 +1547,18 @@ void yp_serialize_comment(yp_parser_t *parser, yp_comment_t *comment, yp_buffer_
1525
1547
  yp_buffer_append_u32(buffer, yp_ptrdifft_to_u32(comment->end - comment->start));
1526
1548
  }
1527
1549
 
1528
- void yp_serialize_comment_list(yp_parser_t *parser, yp_list_t list, yp_buffer_t *buffer) {
1529
- yp_buffer_append_u32(buffer, yp_list_size(&list));
1550
+ static void
1551
+ yp_serialize_comment_list(yp_parser_t *parser, yp_list_t *list, yp_buffer_t *buffer) {
1552
+ yp_buffer_append_u32(buffer, yp_sizet_to_u32(yp_list_size(list)));
1530
1553
 
1531
1554
  yp_comment_t *comment;
1532
- for (comment = (yp_comment_t *) list.head; comment != NULL; comment = (yp_comment_t *) comment->node.next) {
1555
+ for (comment = (yp_comment_t *) list->head; comment != NULL; comment = (yp_comment_t *) comment->node.next) {
1533
1556
  yp_serialize_comment(parser, comment, buffer);
1534
1557
  }
1535
1558
  }
1536
1559
 
1537
- void yp_serialize_diagnostic(yp_parser_t *parser, yp_diagnostic_t *diagnostic, yp_buffer_t *buffer) {
1560
+ static void
1561
+ yp_serialize_diagnostic(yp_parser_t *parser, yp_diagnostic_t *diagnostic, yp_buffer_t *buffer) {
1538
1562
  // serialize message
1539
1563
  size_t message_length = strlen(diagnostic->message);
1540
1564
  yp_buffer_append_u32(buffer, yp_sizet_to_u32(message_length));
@@ -1545,31 +1569,30 @@ void yp_serialize_diagnostic(yp_parser_t *parser, yp_diagnostic_t *diagnostic, y
1545
1569
  yp_buffer_append_u32(buffer, yp_ptrdifft_to_u32(diagnostic->end - diagnostic->start));
1546
1570
  }
1547
1571
 
1548
- void yp_serialize_diagnostic_list(yp_parser_t *parser, yp_list_t list, yp_buffer_t *buffer) {
1549
- yp_buffer_append_u32(buffer, yp_list_size(&list));
1572
+ static void
1573
+ yp_serialize_diagnostic_list(yp_parser_t *parser, yp_list_t *list, yp_buffer_t *buffer) {
1574
+ yp_buffer_append_u32(buffer, yp_sizet_to_u32(yp_list_size(list)));
1550
1575
 
1551
1576
  yp_diagnostic_t *diagnostic;
1552
- for (diagnostic = (yp_diagnostic_t *) list.head; diagnostic != NULL; diagnostic = (yp_diagnostic_t *) diagnostic->node.next) {
1577
+ for (diagnostic = (yp_diagnostic_t *) list->head; diagnostic != NULL; diagnostic = (yp_diagnostic_t *) diagnostic->node.next) {
1553
1578
  yp_serialize_diagnostic(parser, diagnostic, buffer);
1554
1579
  }
1555
1580
  }
1556
1581
 
1557
- #line 145 "serialize.c.erb"
1558
- void
1559
- yp_serialize_content(yp_parser_t *parser, yp_node_t *node, yp_buffer_t *buffer) {
1560
- // First, serialize the encoding of the parser.
1561
- size_t encoding_length = strlen(parser->encoding.name);
1582
+ static void
1583
+ yp_serialize_encoding(yp_encoding_t *encoding, yp_buffer_t *buffer) {
1584
+ size_t encoding_length = strlen(encoding->name);
1562
1585
  yp_buffer_append_u32(buffer, yp_sizet_to_u32(encoding_length));
1563
- yp_buffer_append_str(buffer, parser->encoding.name, encoding_length);
1564
-
1565
- // Serialize the comments
1566
- yp_serialize_comment_list(parser, parser->comment_list, buffer);
1567
-
1568
- // Serialize the errors
1569
- yp_serialize_diagnostic_list(parser, parser->error_list, buffer);
1586
+ yp_buffer_append_str(buffer, encoding->name, encoding_length);
1587
+ }
1570
1588
 
1571
- // Serialize the warnings
1572
- yp_serialize_diagnostic_list(parser, parser->warning_list, buffer);
1589
+ #line 181 "serialize.c.erb"
1590
+ void
1591
+ yp_serialize_content(yp_parser_t *parser, yp_node_t *node, yp_buffer_t *buffer) {
1592
+ yp_serialize_encoding(&parser->encoding, buffer);
1593
+ yp_serialize_comment_list(parser, &parser->comment_list, buffer);
1594
+ yp_serialize_diagnostic_list(parser, &parser->error_list, buffer);
1595
+ yp_serialize_diagnostic_list(parser, &parser->warning_list, buffer);
1573
1596
 
1574
1597
  // Here we're going to leave space for the offset of the constant pool in
1575
1598
  // the buffer.
@@ -1633,16 +1656,35 @@ yp_lex_serialize(const char *source, size_t size, const char *filepath, yp_buffe
1633
1656
  yp_node_t *node = yp_parse(&parser);
1634
1657
 
1635
1658
  // Append 0 to mark end of tokens
1636
- yp_buffer_append_u32(buffer, 0);
1659
+ yp_buffer_append_u8(buffer, 0);
1660
+
1661
+ yp_serialize_encoding(&parser.encoding, buffer);
1662
+ yp_serialize_comment_list(&parser, &parser.comment_list, buffer);
1663
+ yp_serialize_diagnostic_list(&parser, &parser.error_list, buffer);
1664
+ yp_serialize_diagnostic_list(&parser, &parser.warning_list, buffer);
1665
+
1666
+ yp_node_destroy(&parser, node);
1667
+ yp_parser_free(&parser);
1668
+ }
1637
1669
 
1638
- // Serialize the comments
1639
- yp_serialize_comment_list(&parser, parser.comment_list, buffer);
1670
+ // Parse and serialize both the AST and the tokens represented by the given
1671
+ // source to the given buffer.
1672
+ YP_EXPORTED_FUNCTION void
1673
+ yp_parse_lex_serialize(const char *source, size_t size, yp_buffer_t *buffer, const char *metadata) {
1674
+ yp_parser_t parser;
1675
+ yp_parser_init(&parser, source, size, NULL);
1676
+ if (metadata) yp_parser_metadata(&parser, metadata);
1640
1677
 
1641
- // Serialize the errors
1642
- yp_serialize_diagnostic_list(&parser, parser.error_list, buffer);
1678
+ yp_lex_callback_t lex_callback = (yp_lex_callback_t) {
1679
+ .data = (void *) buffer,
1680
+ .callback = serialize_token,
1681
+ };
1682
+
1683
+ parser.lex_callback = &lex_callback;
1684
+ yp_node_t *node = yp_parse(&parser);
1643
1685
 
1644
- // Serialize the warnings
1645
- yp_serialize_diagnostic_list(&parser, parser.warning_list, buffer);
1686
+ yp_buffer_append_u8(buffer, 0);
1687
+ yp_serialize(&parser, node, buffer);
1646
1688
 
1647
1689
  yp_node_destroy(&parser, node);
1648
1690
  yp_parser_free(&parser);