yarp 0.6.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/yarp.rb CHANGED
@@ -7,7 +7,7 @@ module YARP
7
7
  class Source
8
8
  attr_reader :source, :offsets
9
9
 
10
- def initialize(source, offsets)
10
+ def initialize(source, offsets = compute_offsets(source))
11
11
  @source = source
12
12
  @offsets = offsets
13
13
  end
@@ -23,6 +23,14 @@ module YARP
23
23
  def column(value)
24
24
  value - offsets[line(value) - 1]
25
25
  end
26
+
27
+ private
28
+
29
+ def compute_offsets(code)
30
+ offsets = [0]
31
+ code.b.scan("\n") { offsets << $~.end(0) }
32
+ offsets
33
+ end
26
34
  end
27
35
 
28
36
  # This represents a location in the source.
@@ -101,6 +109,8 @@ module YARP
101
109
 
102
110
  # This represents a comment that was encountered during parsing.
103
111
  class Comment
112
+ TYPES = [:inline, :embdoc, :__END__]
113
+
104
114
  attr_reader :type, :location
105
115
 
106
116
  def initialize(type, location)
@@ -226,6 +236,12 @@ module YARP
226
236
  value.accept(visitor)
227
237
  value
228
238
  end
239
+
240
+ # Construct a new ParseResult with the same internal values, but with the
241
+ # given source.
242
+ def with_source(source)
243
+ ParseResult.new(value, comments, errors, warnings, source)
244
+ end
229
245
  end
230
246
 
231
247
  # This represents a token from the Ruby source.
@@ -279,6 +295,11 @@ module YARP
279
295
  end
280
296
  end
281
297
 
298
+ # Slice the location of the node from the source.
299
+ def slice
300
+ location.slice
301
+ end
302
+
282
303
  def pretty_print(q)
283
304
  q.group do
284
305
  q.text(self.class.name.split("::").last)
@@ -306,6 +327,146 @@ module YARP
306
327
  # This module is used for testing and debugging and is not meant to be used by
307
328
  # consumers of this library.
308
329
  module Debug
330
+ class ISeq
331
+ attr_reader :parts
332
+
333
+ def initialize(parts)
334
+ @parts = parts
335
+ end
336
+
337
+ def type
338
+ parts[0]
339
+ end
340
+
341
+ def local_table
342
+ parts[10]
343
+ end
344
+
345
+ def instructions
346
+ parts[13]
347
+ end
348
+
349
+ def each_child
350
+ instructions.each do |instruction|
351
+ # Only look at arrays. Other instructions are line numbers or
352
+ # tracepoint events.
353
+ next unless instruction.is_a?(Array)
354
+
355
+ instruction.each do |opnd|
356
+ # Only look at arrays. Other operands are literals.
357
+ next unless opnd.is_a?(Array)
358
+
359
+ # Only look at instruction sequences. Other operands are literals.
360
+ next unless opnd[0] == "YARVInstructionSequence/SimpleDataFormat"
361
+
362
+ yield ISeq.new(opnd)
363
+ end
364
+ end
365
+ end
366
+ end
367
+
368
+ # For the given source, compiles with CRuby and returns a list of all of the
369
+ # sets of local variables that were encountered.
370
+ def self.cruby_locals(source)
371
+ verbose = $VERBOSE
372
+ $VERBOSE = nil
373
+
374
+ begin
375
+ locals = []
376
+ stack = [ISeq.new(RubyVM::InstructionSequence.compile(source).to_a)]
377
+
378
+ while (iseq = stack.pop)
379
+ if iseq.type != :once
380
+ names = iseq.local_table
381
+
382
+ # CRuby will push on a special local variable when there are keyword
383
+ # arguments. We get rid of that here.
384
+ names = names.grep_v(Integer)
385
+
386
+ # TODO: We don't support numbered local variables yet, so we get rid
387
+ # of those here.
388
+ names = names.grep_v(/^_\d$/)
389
+
390
+ # Now push them onto the list of locals.
391
+ locals << names
392
+ end
393
+
394
+ iseq.each_child { |child| stack << child }
395
+ end
396
+
397
+ locals
398
+ ensure
399
+ $VERBOSE = verbose
400
+ end
401
+ end
402
+
403
+ # For the given source, parses with YARP and returns a list of all of the
404
+ # sets of local variables that were encountered.
405
+ def self.yarp_locals(source)
406
+ locals = []
407
+ stack = [YARP.parse(source).value]
408
+
409
+ while (node = stack.pop)
410
+ case node
411
+ when BlockNode, DefNode, LambdaNode
412
+ names = node.locals
413
+
414
+ params = node.parameters
415
+ params = params&.parameters unless node.is_a?(DefNode)
416
+
417
+ # YARP places parameters in the same order that they appear in the
418
+ # source. CRuby places them in the order that they need to appear
419
+ # according to their own internal calling convention. We mimic that
420
+ # order here so that we can compare properly.
421
+ if params
422
+ sorted = [
423
+ *params.requireds.grep(RequiredParameterNode).map(&:constant_id),
424
+ *params.optionals.map(&:constant_id),
425
+ *((params.rest.name ? params.rest.name.to_sym : :*) if params.rest && params.rest.operator != ","),
426
+ *params.posts.grep(RequiredParameterNode).map(&:constant_id),
427
+ *params.keywords.reject(&:value).map { |param| param.name.chomp(":").to_sym },
428
+ *params.keywords.select(&:value).map { |param| param.name.chomp(":").to_sym }
429
+ ]
430
+
431
+ # TODO: When we get a ... parameter, we should be pushing * and &
432
+ # onto the local list. We don't do that yet, so we need to add them
433
+ # in here.
434
+ if params.keyword_rest.is_a?(ForwardingParameterNode)
435
+ sorted.push(:*, :&, :"...")
436
+ end
437
+
438
+ # Recurse down the parameter tree to find any destructured
439
+ # parameters and add them after the other parameters.
440
+ param_stack = params.requireds.concat(params.posts).grep(RequiredDestructuredParameterNode).reverse
441
+ while (param = param_stack.pop)
442
+ case param
443
+ when RequiredDestructuredParameterNode
444
+ param_stack.concat(param.parameters.reverse)
445
+ when RequiredParameterNode
446
+ sorted << param.constant_id
447
+ when SplatNode
448
+ sorted << param.expression.constant_id if param.expression
449
+ end
450
+ end
451
+
452
+ names = sorted.concat(names - sorted)
453
+ end
454
+
455
+ locals << names
456
+ when ClassNode, ModuleNode, ProgramNode, SingletonClassNode
457
+ locals << node.locals
458
+ when ForNode
459
+ locals << []
460
+ when PostExecutionNode
461
+ locals.push([], [])
462
+ end
463
+
464
+ stack.concat(node.child_nodes.compact)
465
+ end
466
+
467
+ locals
468
+ end
469
+
309
470
  def self.newlines(source)
310
471
  YARP.parse(source).source.offsets
311
472
  end
@@ -327,4 +488,8 @@ require_relative "yarp/ripper_compat"
327
488
  require_relative "yarp/serialize"
328
489
  require_relative "yarp/pack"
329
490
 
330
- require "yarp/yarp"
491
+ if RUBY_ENGINE == "ruby" and !ENV["YARP_FFI_BACKEND"]
492
+ require "yarp/yarp"
493
+ else
494
+ require "yarp/ffi"
495
+ end
data/src/enc/yp_unicode.c CHANGED
@@ -2318,3 +2318,12 @@ yp_encoding_t yp_encoding_utf_8 = {
2318
2318
  .isupper_char = yp_encoding_utf_8_isupper_char,
2319
2319
  .multibyte = true
2320
2320
  };
2321
+
2322
+ yp_encoding_t yp_encoding_utf8_mac = {
2323
+ .name = "utf8-mac",
2324
+ .char_width = yp_encoding_utf_8_char_width,
2325
+ .alnum_char = yp_encoding_utf_8_alnum_char,
2326
+ .alpha_char = yp_encoding_utf_8_alpha_char,
2327
+ .isupper_char = yp_encoding_utf_8_isupper_char,
2328
+ .multibyte = true
2329
+ };
data/src/node.c CHANGED
@@ -356,6 +356,15 @@ yp_node_destroy(yp_parser_t *parser, yp_node_t *node) {
356
356
  yp_node_list_free(parser, &((yp_find_pattern_node_t *)node)->requireds);
357
357
  yp_node_destroy(parser, (yp_node_t *)((yp_find_pattern_node_t *)node)->right);
358
358
  break;
359
+ #line 81 "node.c.erb"
360
+ case YP_NODE_FLIP_FLOP_NODE:
361
+ if (((yp_flip_flop_node_t *)node)->left != NULL) {
362
+ yp_node_destroy(parser, (yp_node_t *)((yp_flip_flop_node_t *)node)->left);
363
+ }
364
+ if (((yp_flip_flop_node_t *)node)->right != NULL) {
365
+ yp_node_destroy(parser, (yp_node_t *)((yp_flip_flop_node_t *)node)->right);
366
+ }
367
+ break;
359
368
  #line 81 "node.c.erb"
360
369
  case YP_NODE_FLOAT_NODE:
361
370
  break;
@@ -1152,6 +1161,17 @@ yp_node_memsize_node(yp_node_t *node, yp_memsize_t *memsize) {
1152
1161
  yp_node_memsize_node((yp_node_t *)((yp_find_pattern_node_t *)node)->right, memsize);
1153
1162
  break;
1154
1163
  }
1164
+ #line 120 "node.c.erb"
1165
+ case YP_NODE_FLIP_FLOP_NODE: {
1166
+ memsize->memsize += sizeof(yp_flip_flop_node_t);
1167
+ if (((yp_flip_flop_node_t *)node)->left != NULL) {
1168
+ yp_node_memsize_node((yp_node_t *)((yp_flip_flop_node_t *)node)->left, memsize);
1169
+ }
1170
+ if (((yp_flip_flop_node_t *)node)->right != NULL) {
1171
+ yp_node_memsize_node((yp_node_t *)((yp_flip_flop_node_t *)node)->right, memsize);
1172
+ }
1173
+ break;
1174
+ }
1155
1175
  #line 120 "node.c.erb"
1156
1176
  case YP_NODE_FLOAT_NODE: {
1157
1177
  memsize->memsize += sizeof(yp_float_node_t);
@@ -1842,6 +1862,8 @@ yp_node_type_to_str(yp_node_type_t node_type)
1842
1862
  return "YP_NODE_FALSE_NODE";
1843
1863
  case YP_NODE_FIND_PATTERN_NODE:
1844
1864
  return "YP_NODE_FIND_PATTERN_NODE";
1865
+ case YP_NODE_FLIP_FLOP_NODE:
1866
+ return "YP_NODE_FLIP_FLOP_NODE";
1845
1867
  case YP_NODE_FLOAT_NODE:
1846
1868
  return "YP_NODE_FLOAT_NODE";
1847
1869
  case YP_NODE_FOR_NODE:
data/src/prettyprint.c CHANGED
@@ -16,7 +16,7 @@
16
16
  static void
17
17
  prettyprint_location(yp_buffer_t *buffer, yp_parser_t *parser, yp_location_t *location) {
18
18
  char printed[] = "[0000-0000]";
19
- yp_snprintf(printed, sizeof(printed), "[%04ld-%04ld]", (long int)(location->start - parser->start), (long int)(location->end - parser->start));
19
+ snprintf(printed, sizeof(printed), "[%04ld-%04ld]", (long int)(location->start - parser->start), (long int)(location->end - parser->start));
20
20
  yp_buffer_append_str(buffer, printed, strlen(printed));
21
21
  }
22
22
 
@@ -200,7 +200,7 @@ prettyprint_node(yp_buffer_t *buffer, yp_parser_t *parser, yp_node_t *node) {
200
200
  for (uint32_t index = 0; index < ((yp_block_node_t *)node)->locals.size; index++) {
201
201
  if (index != 0) yp_buffer_append_str(buffer, ", ", 2);
202
202
  char locals_buffer[12];
203
- yp_snprintf(locals_buffer, sizeof(locals_buffer), "%u", ((yp_block_node_t *)node)->locals.ids[index]);
203
+ snprintf(locals_buffer, sizeof(locals_buffer), "%u", ((yp_block_node_t *)node)->locals.ids[index]);
204
204
  yp_buffer_append_str(buffer, locals_buffer, strlen(locals_buffer));
205
205
  }
206
206
  yp_buffer_append_str(buffer, "]", 1);
@@ -305,7 +305,7 @@ prettyprint_node(yp_buffer_t *buffer, yp_parser_t *parser, yp_node_t *node) {
305
305
  prettyprint_node(buffer, parser, (yp_node_t *)((yp_call_node_t *)node)->block);
306
306
  }
307
307
  yp_buffer_append_str(buffer, ", ", 2); char flags_buffer[12];
308
- yp_snprintf(flags_buffer, sizeof(flags_buffer), "+%d", ((yp_call_node_t *)node)->flags);
308
+ snprintf(flags_buffer, sizeof(flags_buffer), "+%d", node->flags >> 1);
309
309
  yp_buffer_append_str(buffer, flags_buffer, strlen(flags_buffer));
310
310
  yp_buffer_append_str(buffer, ", ", 2); yp_buffer_append_str(buffer, "\"", 1);
311
311
  yp_buffer_append_str(buffer, yp_string_source(&((yp_call_node_t *)node)->name), yp_string_length(&((yp_call_node_t *)node)->name));
@@ -335,7 +335,7 @@ prettyprint_node(yp_buffer_t *buffer, yp_parser_t *parser, yp_node_t *node) {
335
335
  yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_call_operator_write_node_t *)node)->operator_loc);
336
336
  yp_buffer_append_str(buffer, ", ", 2); prettyprint_node(buffer, parser, (yp_node_t *)((yp_call_operator_write_node_t *)node)->value);
337
337
  yp_buffer_append_str(buffer, ", ", 2); char operator_id_buffer[12];
338
- yp_snprintf(operator_id_buffer, sizeof(operator_id_buffer), "%u", ((yp_call_operator_write_node_t *)node)->operator_id);
338
+ snprintf(operator_id_buffer, sizeof(operator_id_buffer), "%u", ((yp_call_operator_write_node_t *)node)->operator_id);
339
339
  yp_buffer_append_str(buffer, operator_id_buffer, strlen(operator_id_buffer));
340
340
  yp_buffer_append_str(buffer, ")", 1);
341
341
  break;
@@ -377,7 +377,7 @@ prettyprint_node(yp_buffer_t *buffer, yp_parser_t *parser, yp_node_t *node) {
377
377
  for (uint32_t index = 0; index < ((yp_class_node_t *)node)->locals.size; index++) {
378
378
  if (index != 0) yp_buffer_append_str(buffer, ", ", 2);
379
379
  char locals_buffer[12];
380
- yp_snprintf(locals_buffer, sizeof(locals_buffer), "%u", ((yp_class_node_t *)node)->locals.ids[index]);
380
+ snprintf(locals_buffer, sizeof(locals_buffer), "%u", ((yp_class_node_t *)node)->locals.ids[index]);
381
381
  yp_buffer_append_str(buffer, locals_buffer, strlen(locals_buffer));
382
382
  }
383
383
  yp_buffer_append_str(buffer, "]", 1);
@@ -424,7 +424,7 @@ prettyprint_node(yp_buffer_t *buffer, yp_parser_t *parser, yp_node_t *node) {
424
424
  yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_class_variable_operator_write_node_t *)node)->operator_loc);
425
425
  yp_buffer_append_str(buffer, ", ", 2); prettyprint_node(buffer, parser, (yp_node_t *)((yp_class_variable_operator_write_node_t *)node)->value);
426
426
  yp_buffer_append_str(buffer, ", ", 2); char operator_buffer[12];
427
- yp_snprintf(operator_buffer, sizeof(operator_buffer), "%u", ((yp_class_variable_operator_write_node_t *)node)->operator);
427
+ snprintf(operator_buffer, sizeof(operator_buffer), "%u", ((yp_class_variable_operator_write_node_t *)node)->operator);
428
428
  yp_buffer_append_str(buffer, operator_buffer, strlen(operator_buffer));
429
429
  yp_buffer_append_str(buffer, ")", 1);
430
430
  break;
@@ -472,7 +472,7 @@ prettyprint_node(yp_buffer_t *buffer, yp_parser_t *parser, yp_node_t *node) {
472
472
  yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_constant_operator_write_node_t *)node)->operator_loc);
473
473
  yp_buffer_append_str(buffer, ", ", 2); prettyprint_node(buffer, parser, (yp_node_t *)((yp_constant_operator_write_node_t *)node)->value);
474
474
  yp_buffer_append_str(buffer, ", ", 2); char operator_buffer[12];
475
- yp_snprintf(operator_buffer, sizeof(operator_buffer), "%u", ((yp_constant_operator_write_node_t *)node)->operator);
475
+ snprintf(operator_buffer, sizeof(operator_buffer), "%u", ((yp_constant_operator_write_node_t *)node)->operator);
476
476
  yp_buffer_append_str(buffer, operator_buffer, strlen(operator_buffer));
477
477
  yp_buffer_append_str(buffer, ")", 1);
478
478
  break;
@@ -511,7 +511,7 @@ prettyprint_node(yp_buffer_t *buffer, yp_parser_t *parser, yp_node_t *node) {
511
511
  yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_constant_path_operator_write_node_t *)node)->operator_loc);
512
512
  yp_buffer_append_str(buffer, ", ", 2); prettyprint_node(buffer, parser, (yp_node_t *)((yp_constant_path_operator_write_node_t *)node)->value);
513
513
  yp_buffer_append_str(buffer, ", ", 2); char operator_buffer[12];
514
- yp_snprintf(operator_buffer, sizeof(operator_buffer), "%u", ((yp_constant_path_operator_write_node_t *)node)->operator);
514
+ snprintf(operator_buffer, sizeof(operator_buffer), "%u", ((yp_constant_path_operator_write_node_t *)node)->operator);
515
515
  yp_buffer_append_str(buffer, operator_buffer, strlen(operator_buffer));
516
516
  yp_buffer_append_str(buffer, ")", 1);
517
517
  break;
@@ -575,7 +575,7 @@ prettyprint_node(yp_buffer_t *buffer, yp_parser_t *parser, yp_node_t *node) {
575
575
  for (uint32_t index = 0; index < ((yp_def_node_t *)node)->locals.size; index++) {
576
576
  if (index != 0) yp_buffer_append_str(buffer, ", ", 2);
577
577
  char locals_buffer[12];
578
- yp_snprintf(locals_buffer, sizeof(locals_buffer), "%u", ((yp_def_node_t *)node)->locals.ids[index]);
578
+ snprintf(locals_buffer, sizeof(locals_buffer), "%u", ((yp_def_node_t *)node)->locals.ids[index]);
579
579
  yp_buffer_append_str(buffer, locals_buffer, strlen(locals_buffer));
580
580
  }
581
581
  yp_buffer_append_str(buffer, "]", 1);
@@ -705,6 +705,25 @@ prettyprint_node(yp_buffer_t *buffer, yp_parser_t *parser, yp_node_t *node) {
705
705
  yp_buffer_append_str(buffer, ")", 1);
706
706
  break;
707
707
  }
708
+ case YP_NODE_FLIP_FLOP_NODE: {
709
+ yp_buffer_append_str(buffer, "FlipFlopNode(", 13);
710
+ if (((yp_flip_flop_node_t *)node)->left == NULL) {
711
+ yp_buffer_append_str(buffer, "nil", 3);
712
+ } else {
713
+ prettyprint_node(buffer, parser, (yp_node_t *)((yp_flip_flop_node_t *)node)->left);
714
+ }
715
+ yp_buffer_append_str(buffer, ", ", 2); if (((yp_flip_flop_node_t *)node)->right == NULL) {
716
+ yp_buffer_append_str(buffer, "nil", 3);
717
+ } else {
718
+ prettyprint_node(buffer, parser, (yp_node_t *)((yp_flip_flop_node_t *)node)->right);
719
+ }
720
+ yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_flip_flop_node_t *)node)->operator_loc);
721
+ yp_buffer_append_str(buffer, ", ", 2); char flags_buffer[12];
722
+ snprintf(flags_buffer, sizeof(flags_buffer), "+%d", node->flags >> 1);
723
+ yp_buffer_append_str(buffer, flags_buffer, strlen(flags_buffer));
724
+ yp_buffer_append_str(buffer, ")", 1);
725
+ break;
726
+ }
708
727
  case YP_NODE_FLOAT_NODE: {
709
728
  yp_buffer_append_str(buffer, "FloatNode(", 10);
710
729
  yp_buffer_append_str(buffer, ")", 1);
@@ -772,7 +791,7 @@ prettyprint_node(yp_buffer_t *buffer, yp_parser_t *parser, yp_node_t *node) {
772
791
  yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_global_variable_operator_write_node_t *)node)->operator_loc);
773
792
  yp_buffer_append_str(buffer, ", ", 2); prettyprint_node(buffer, parser, (yp_node_t *)((yp_global_variable_operator_write_node_t *)node)->value);
774
793
  yp_buffer_append_str(buffer, ", ", 2); char operator_buffer[12];
775
- yp_snprintf(operator_buffer, sizeof(operator_buffer), "%u", ((yp_global_variable_operator_write_node_t *)node)->operator);
794
+ snprintf(operator_buffer, sizeof(operator_buffer), "%u", ((yp_global_variable_operator_write_node_t *)node)->operator);
776
795
  yp_buffer_append_str(buffer, operator_buffer, strlen(operator_buffer));
777
796
  yp_buffer_append_str(buffer, ")", 1);
778
797
  break;
@@ -913,7 +932,7 @@ prettyprint_node(yp_buffer_t *buffer, yp_parser_t *parser, yp_node_t *node) {
913
932
  yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_instance_variable_operator_write_node_t *)node)->operator_loc);
914
933
  yp_buffer_append_str(buffer, ", ", 2); prettyprint_node(buffer, parser, (yp_node_t *)((yp_instance_variable_operator_write_node_t *)node)->value);
915
934
  yp_buffer_append_str(buffer, ", ", 2); char operator_buffer[12];
916
- yp_snprintf(operator_buffer, sizeof(operator_buffer), "%u", ((yp_instance_variable_operator_write_node_t *)node)->operator);
935
+ snprintf(operator_buffer, sizeof(operator_buffer), "%u", ((yp_instance_variable_operator_write_node_t *)node)->operator);
917
936
  yp_buffer_append_str(buffer, operator_buffer, strlen(operator_buffer));
918
937
  yp_buffer_append_str(buffer, ")", 1);
919
938
  break;
@@ -955,7 +974,7 @@ prettyprint_node(yp_buffer_t *buffer, yp_parser_t *parser, yp_node_t *node) {
955
974
  yp_buffer_append_str(buffer, "]", 1);
956
975
  yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_interpolated_regular_expression_node_t *)node)->closing_loc);
957
976
  yp_buffer_append_str(buffer, ", ", 2); char flags_buffer[12];
958
- yp_snprintf(flags_buffer, sizeof(flags_buffer), "+%d", ((yp_interpolated_regular_expression_node_t *)node)->flags);
977
+ snprintf(flags_buffer, sizeof(flags_buffer), "+%d", node->flags >> 1);
959
978
  yp_buffer_append_str(buffer, flags_buffer, strlen(flags_buffer));
960
979
  yp_buffer_append_str(buffer, ")", 1);
961
980
  break;
@@ -1054,7 +1073,7 @@ prettyprint_node(yp_buffer_t *buffer, yp_parser_t *parser, yp_node_t *node) {
1054
1073
  for (uint32_t index = 0; index < ((yp_lambda_node_t *)node)->locals.size; index++) {
1055
1074
  if (index != 0) yp_buffer_append_str(buffer, ", ", 2);
1056
1075
  char locals_buffer[12];
1057
- yp_snprintf(locals_buffer, sizeof(locals_buffer), "%u", ((yp_lambda_node_t *)node)->locals.ids[index]);
1076
+ snprintf(locals_buffer, sizeof(locals_buffer), "%u", ((yp_lambda_node_t *)node)->locals.ids[index]);
1058
1077
  yp_buffer_append_str(buffer, locals_buffer, strlen(locals_buffer));
1059
1078
  }
1060
1079
  yp_buffer_append_str(buffer, "]", 1);
@@ -1078,7 +1097,7 @@ prettyprint_node(yp_buffer_t *buffer, yp_parser_t *parser, yp_node_t *node) {
1078
1097
  yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_local_variable_operator_and_write_node_t *)node)->operator_loc);
1079
1098
  yp_buffer_append_str(buffer, ", ", 2); prettyprint_node(buffer, parser, (yp_node_t *)((yp_local_variable_operator_and_write_node_t *)node)->value);
1080
1099
  yp_buffer_append_str(buffer, ", ", 2); char constant_id_buffer[12];
1081
- yp_snprintf(constant_id_buffer, sizeof(constant_id_buffer), "%u", ((yp_local_variable_operator_and_write_node_t *)node)->constant_id);
1100
+ snprintf(constant_id_buffer, sizeof(constant_id_buffer), "%u", ((yp_local_variable_operator_and_write_node_t *)node)->constant_id);
1082
1101
  yp_buffer_append_str(buffer, constant_id_buffer, strlen(constant_id_buffer));
1083
1102
  yp_buffer_append_str(buffer, ")", 1);
1084
1103
  break;
@@ -1089,7 +1108,7 @@ prettyprint_node(yp_buffer_t *buffer, yp_parser_t *parser, yp_node_t *node) {
1089
1108
  yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_local_variable_operator_or_write_node_t *)node)->operator_loc);
1090
1109
  yp_buffer_append_str(buffer, ", ", 2); prettyprint_node(buffer, parser, (yp_node_t *)((yp_local_variable_operator_or_write_node_t *)node)->value);
1091
1110
  yp_buffer_append_str(buffer, ", ", 2); char constant_id_buffer[12];
1092
- yp_snprintf(constant_id_buffer, sizeof(constant_id_buffer), "%u", ((yp_local_variable_operator_or_write_node_t *)node)->constant_id);
1111
+ snprintf(constant_id_buffer, sizeof(constant_id_buffer), "%u", ((yp_local_variable_operator_or_write_node_t *)node)->constant_id);
1093
1112
  yp_buffer_append_str(buffer, constant_id_buffer, strlen(constant_id_buffer));
1094
1113
  yp_buffer_append_str(buffer, ")", 1);
1095
1114
  break;
@@ -1100,10 +1119,10 @@ prettyprint_node(yp_buffer_t *buffer, yp_parser_t *parser, yp_node_t *node) {
1100
1119
  yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_local_variable_operator_write_node_t *)node)->operator_loc);
1101
1120
  yp_buffer_append_str(buffer, ", ", 2); prettyprint_node(buffer, parser, (yp_node_t *)((yp_local_variable_operator_write_node_t *)node)->value);
1102
1121
  yp_buffer_append_str(buffer, ", ", 2); char constant_id_buffer[12];
1103
- yp_snprintf(constant_id_buffer, sizeof(constant_id_buffer), "%u", ((yp_local_variable_operator_write_node_t *)node)->constant_id);
1122
+ snprintf(constant_id_buffer, sizeof(constant_id_buffer), "%u", ((yp_local_variable_operator_write_node_t *)node)->constant_id);
1104
1123
  yp_buffer_append_str(buffer, constant_id_buffer, strlen(constant_id_buffer));
1105
1124
  yp_buffer_append_str(buffer, ", ", 2); char operator_id_buffer[12];
1106
- yp_snprintf(operator_id_buffer, sizeof(operator_id_buffer), "%u", ((yp_local_variable_operator_write_node_t *)node)->operator_id);
1125
+ snprintf(operator_id_buffer, sizeof(operator_id_buffer), "%u", ((yp_local_variable_operator_write_node_t *)node)->operator_id);
1107
1126
  yp_buffer_append_str(buffer, operator_id_buffer, strlen(operator_id_buffer));
1108
1127
  yp_buffer_append_str(buffer, ")", 1);
1109
1128
  break;
@@ -1111,10 +1130,10 @@ prettyprint_node(yp_buffer_t *buffer, yp_parser_t *parser, yp_node_t *node) {
1111
1130
  case YP_NODE_LOCAL_VARIABLE_READ_NODE: {
1112
1131
  yp_buffer_append_str(buffer, "LocalVariableReadNode(", 22);
1113
1132
  char constant_id_buffer[12];
1114
- yp_snprintf(constant_id_buffer, sizeof(constant_id_buffer), "%u", ((yp_local_variable_read_node_t *)node)->constant_id);
1133
+ snprintf(constant_id_buffer, sizeof(constant_id_buffer), "%u", ((yp_local_variable_read_node_t *)node)->constant_id);
1115
1134
  yp_buffer_append_str(buffer, constant_id_buffer, strlen(constant_id_buffer));
1116
1135
  yp_buffer_append_str(buffer, ", ", 2); char depth_buffer[12];
1117
- yp_snprintf(depth_buffer, sizeof(depth_buffer), "+%d", ((yp_local_variable_read_node_t *)node)->depth);
1136
+ snprintf(depth_buffer, sizeof(depth_buffer), "+%d", ((yp_local_variable_read_node_t *)node)->depth);
1118
1137
  yp_buffer_append_str(buffer, depth_buffer, strlen(depth_buffer));
1119
1138
  yp_buffer_append_str(buffer, ")", 1);
1120
1139
  break;
@@ -1122,10 +1141,10 @@ prettyprint_node(yp_buffer_t *buffer, yp_parser_t *parser, yp_node_t *node) {
1122
1141
  case YP_NODE_LOCAL_VARIABLE_WRITE_NODE: {
1123
1142
  yp_buffer_append_str(buffer, "LocalVariableWriteNode(", 23);
1124
1143
  char constant_id_buffer[12];
1125
- yp_snprintf(constant_id_buffer, sizeof(constant_id_buffer), "%u", ((yp_local_variable_write_node_t *)node)->constant_id);
1144
+ snprintf(constant_id_buffer, sizeof(constant_id_buffer), "%u", ((yp_local_variable_write_node_t *)node)->constant_id);
1126
1145
  yp_buffer_append_str(buffer, constant_id_buffer, strlen(constant_id_buffer));
1127
1146
  yp_buffer_append_str(buffer, ", ", 2); char depth_buffer[12];
1128
- yp_snprintf(depth_buffer, sizeof(depth_buffer), "+%d", ((yp_local_variable_write_node_t *)node)->depth);
1147
+ snprintf(depth_buffer, sizeof(depth_buffer), "+%d", ((yp_local_variable_write_node_t *)node)->depth);
1129
1148
  yp_buffer_append_str(buffer, depth_buffer, strlen(depth_buffer));
1130
1149
  yp_buffer_append_str(buffer, ", ", 2); if (((yp_local_variable_write_node_t *)node)->value == NULL) {
1131
1150
  yp_buffer_append_str(buffer, "nil", 3);
@@ -1168,7 +1187,7 @@ prettyprint_node(yp_buffer_t *buffer, yp_parser_t *parser, yp_node_t *node) {
1168
1187
  for (uint32_t index = 0; index < ((yp_module_node_t *)node)->locals.size; index++) {
1169
1188
  if (index != 0) yp_buffer_append_str(buffer, ", ", 2);
1170
1189
  char locals_buffer[12];
1171
- yp_snprintf(locals_buffer, sizeof(locals_buffer), "%u", ((yp_module_node_t *)node)->locals.ids[index]);
1190
+ snprintf(locals_buffer, sizeof(locals_buffer), "%u", ((yp_module_node_t *)node)->locals.ids[index]);
1172
1191
  yp_buffer_append_str(buffer, locals_buffer, strlen(locals_buffer));
1173
1192
  }
1174
1193
  yp_buffer_append_str(buffer, "]", 1);
@@ -1245,7 +1264,7 @@ prettyprint_node(yp_buffer_t *buffer, yp_parser_t *parser, yp_node_t *node) {
1245
1264
  case YP_NODE_OPTIONAL_PARAMETER_NODE: {
1246
1265
  yp_buffer_append_str(buffer, "OptionalParameterNode(", 22);
1247
1266
  char constant_id_buffer[12];
1248
- yp_snprintf(constant_id_buffer, sizeof(constant_id_buffer), "%u", ((yp_optional_parameter_node_t *)node)->constant_id);
1267
+ snprintf(constant_id_buffer, sizeof(constant_id_buffer), "%u", ((yp_optional_parameter_node_t *)node)->constant_id);
1249
1268
  yp_buffer_append_str(buffer, constant_id_buffer, strlen(constant_id_buffer));
1250
1269
  yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_optional_parameter_node_t *)node)->name_loc);
1251
1270
  yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_optional_parameter_node_t *)node)->operator_loc);
@@ -1365,7 +1384,7 @@ prettyprint_node(yp_buffer_t *buffer, yp_parser_t *parser, yp_node_t *node) {
1365
1384
  for (uint32_t index = 0; index < ((yp_program_node_t *)node)->locals.size; index++) {
1366
1385
  if (index != 0) yp_buffer_append_str(buffer, ", ", 2);
1367
1386
  char locals_buffer[12];
1368
- yp_snprintf(locals_buffer, sizeof(locals_buffer), "%u", ((yp_program_node_t *)node)->locals.ids[index]);
1387
+ snprintf(locals_buffer, sizeof(locals_buffer), "%u", ((yp_program_node_t *)node)->locals.ids[index]);
1369
1388
  yp_buffer_append_str(buffer, locals_buffer, strlen(locals_buffer));
1370
1389
  }
1371
1390
  yp_buffer_append_str(buffer, "]", 1);
@@ -1387,7 +1406,7 @@ prettyprint_node(yp_buffer_t *buffer, yp_parser_t *parser, yp_node_t *node) {
1387
1406
  }
1388
1407
  yp_buffer_append_str(buffer, ", ", 2); prettyprint_location(buffer, parser, &((yp_range_node_t *)node)->operator_loc);
1389
1408
  yp_buffer_append_str(buffer, ", ", 2); char flags_buffer[12];
1390
- yp_snprintf(flags_buffer, sizeof(flags_buffer), "+%d", ((yp_range_node_t *)node)->flags);
1409
+ snprintf(flags_buffer, sizeof(flags_buffer), "+%d", node->flags >> 1);
1391
1410
  yp_buffer_append_str(buffer, flags_buffer, strlen(flags_buffer));
1392
1411
  yp_buffer_append_str(buffer, ")", 1);
1393
1412
  break;
@@ -1412,7 +1431,7 @@ prettyprint_node(yp_buffer_t *buffer, yp_parser_t *parser, yp_node_t *node) {
1412
1431
  yp_buffer_append_str(buffer, yp_string_source(&((yp_regular_expression_node_t *)node)->unescaped), yp_string_length(&((yp_regular_expression_node_t *)node)->unescaped));
1413
1432
  yp_buffer_append_str(buffer, "\"", 1);
1414
1433
  yp_buffer_append_str(buffer, ", ", 2); char flags_buffer[12];
1415
- yp_snprintf(flags_buffer, sizeof(flags_buffer), "+%d", ((yp_regular_expression_node_t *)node)->flags);
1434
+ snprintf(flags_buffer, sizeof(flags_buffer), "+%d", node->flags >> 1);
1416
1435
  yp_buffer_append_str(buffer, flags_buffer, strlen(flags_buffer));
1417
1436
  yp_buffer_append_str(buffer, ")", 1);
1418
1437
  break;
@@ -1433,7 +1452,7 @@ prettyprint_node(yp_buffer_t *buffer, yp_parser_t *parser, yp_node_t *node) {
1433
1452
  case YP_NODE_REQUIRED_PARAMETER_NODE: {
1434
1453
  yp_buffer_append_str(buffer, "RequiredParameterNode(", 22);
1435
1454
  char constant_id_buffer[12];
1436
- yp_snprintf(constant_id_buffer, sizeof(constant_id_buffer), "%u", ((yp_required_parameter_node_t *)node)->constant_id);
1455
+ snprintf(constant_id_buffer, sizeof(constant_id_buffer), "%u", ((yp_required_parameter_node_t *)node)->constant_id);
1437
1456
  yp_buffer_append_str(buffer, constant_id_buffer, strlen(constant_id_buffer));
1438
1457
  yp_buffer_append_str(buffer, ")", 1);
1439
1458
  break;
@@ -1516,7 +1535,7 @@ prettyprint_node(yp_buffer_t *buffer, yp_parser_t *parser, yp_node_t *node) {
1516
1535
  for (uint32_t index = 0; index < ((yp_singleton_class_node_t *)node)->locals.size; index++) {
1517
1536
  if (index != 0) yp_buffer_append_str(buffer, ", ", 2);
1518
1537
  char locals_buffer[12];
1519
- yp_snprintf(locals_buffer, sizeof(locals_buffer), "%u", ((yp_singleton_class_node_t *)node)->locals.ids[index]);
1538
+ snprintf(locals_buffer, sizeof(locals_buffer), "%u", ((yp_singleton_class_node_t *)node)->locals.ids[index]);
1520
1539
  yp_buffer_append_str(buffer, locals_buffer, strlen(locals_buffer));
1521
1540
  }
1522
1541
  yp_buffer_append_str(buffer, "]", 1);
@@ -1692,7 +1711,7 @@ prettyprint_node(yp_buffer_t *buffer, yp_parser_t *parser, yp_node_t *node) {
1692
1711
  prettyprint_node(buffer, parser, (yp_node_t *)((yp_until_node_t *)node)->statements);
1693
1712
  }
1694
1713
  yp_buffer_append_str(buffer, ", ", 2); char flags_buffer[12];
1695
- yp_snprintf(flags_buffer, sizeof(flags_buffer), "+%d", ((yp_until_node_t *)node)->flags);
1714
+ snprintf(flags_buffer, sizeof(flags_buffer), "+%d", node->flags >> 1);
1696
1715
  yp_buffer_append_str(buffer, flags_buffer, strlen(flags_buffer));
1697
1716
  yp_buffer_append_str(buffer, ")", 1);
1698
1717
  break;
@@ -1724,7 +1743,7 @@ prettyprint_node(yp_buffer_t *buffer, yp_parser_t *parser, yp_node_t *node) {
1724
1743
  prettyprint_node(buffer, parser, (yp_node_t *)((yp_while_node_t *)node)->statements);
1725
1744
  }
1726
1745
  yp_buffer_append_str(buffer, ", ", 2); char flags_buffer[12];
1727
- yp_snprintf(flags_buffer, sizeof(flags_buffer), "+%d", ((yp_while_node_t *)node)->flags);
1746
+ snprintf(flags_buffer, sizeof(flags_buffer), "+%d", node->flags >> 1);
1728
1747
  yp_buffer_append_str(buffer, flags_buffer, strlen(flags_buffer));
1729
1748
  yp_buffer_append_str(buffer, ")", 1);
1730
1749
  break;