ParseTree 2.0.2 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +27 -0
- data/bin/parse_tree_show +20 -3
- data/lib/parse_tree.rb +139 -134
- data/lib/sexp.rb +1 -1
- data/lib/sexp_processor.rb +10 -11
- data/lib/unified_ruby.rb +18 -4
- data/test/pt_testcase.rb +1155 -97
- data/test/test_parse_tree.rb +6 -5
- metadata +64 -57
data/History.txt
CHANGED
@@ -1,3 +1,30 @@
|
|
1
|
+
=== 2.1.0 / 2007-10-30
|
2
|
+
|
3
|
+
* 13 minor enhancements:
|
4
|
+
|
5
|
+
* Added (partial) regexp flag support, currently numerical. ugh.
|
6
|
+
* Added -a flag to parse_tree_show to turn on newline (all) nodes.
|
7
|
+
* Added -r to parse_tree_show for raw arrays instead of sexps.
|
8
|
+
* Added Unifier (SexpProcessor) class to unified_ruby.rb.
|
9
|
+
* Added a ton of tests while working on ruby_parser.
|
10
|
+
* Added ability to tell proc {} (nil arg slot) from proc {||} (0 arg slot)
|
11
|
+
* Added context tracking to rewriting phase... slightly broken.
|
12
|
+
* Added evstr support. (I hate evan)
|
13
|
+
* Added usage for parse_tree_show.
|
14
|
+
* Changed verbose to be true all the time in parse_tree_for_string.
|
15
|
+
* Removed process_level from SexpProcessor... just look at context size instead.
|
16
|
+
* Revamped ParseTree. No more passing around newline. Pass around self instead.
|
17
|
+
* I'm starting to dislike ruby's AST. It is REALLY inconsistent.
|
18
|
+
|
19
|
+
* 6 bug fix:
|
20
|
+
|
21
|
+
* SexpProcessor#assert_type now a bit safer with bad values.
|
22
|
+
* Uncovered a bug in ruby (AST changes when -v used), added handler code.
|
23
|
+
* Fixed NODE_BLOCK and massively simplified in the process.
|
24
|
+
* Fixed rewrite_defs to deal with non-block asts.
|
25
|
+
* Fixed test/unit hack so it does not die under miniunit.
|
26
|
+
* Found a bug in PT where parse_tree_for_string had some shadowed variables.
|
27
|
+
|
1
28
|
=== 2.0.2 / 2007-09-20
|
2
29
|
|
3
30
|
* 2 minor enhancements:
|
data/bin/parse_tree_show
CHANGED
@@ -5,11 +5,27 @@ begin require 'rubygems' rescue LoadError end
|
|
5
5
|
require 'parse_tree'
|
6
6
|
require 'sexp'
|
7
7
|
|
8
|
-
$
|
8
|
+
$a ||= false
|
9
|
+
$h ||= false
|
9
10
|
$n ||= false
|
11
|
+
$r ||= false
|
10
12
|
$s ||= false
|
13
|
+
$u ||= false
|
11
14
|
$n = $n.intern if $n
|
12
15
|
|
16
|
+
if $h then
|
17
|
+
puts "usage: #{File.basename $0} [options] [file...]"
|
18
|
+
puts "options:"
|
19
|
+
puts "-h : display usage"
|
20
|
+
puts "-a : all nodes, including newline"
|
21
|
+
puts "-n=node : only display matching nodes"
|
22
|
+
puts "-r : raw arrays, no sexps"
|
23
|
+
puts "-s : structural sexps, strip all content and show bare tree"
|
24
|
+
puts "-u : unified sexps"
|
25
|
+
|
26
|
+
exit 1
|
27
|
+
end
|
28
|
+
|
13
29
|
ARGV.push "-" if ARGV.empty?
|
14
30
|
|
15
31
|
if $u then
|
@@ -21,13 +37,14 @@ if $u then
|
|
21
37
|
end
|
22
38
|
end
|
23
39
|
|
24
|
-
parse_tree = ParseTree.new
|
40
|
+
parse_tree = ParseTree.new($a)
|
25
41
|
unifier = Unifier.new if $u
|
26
42
|
|
27
43
|
ARGV.each do |file|
|
28
44
|
ruby = file == "-" ? $stdin.read : File.read(file)
|
29
45
|
|
30
|
-
sexp =
|
46
|
+
sexp = parse_tree.parse_tree_for_string(ruby, file).first
|
47
|
+
sexp = Sexp.from_array sexp unless $r
|
31
48
|
sexp = unifier.process(sexp) if $u
|
32
49
|
sexp = sexp.structure if $s
|
33
50
|
|
data/lib/parse_tree.rb
CHANGED
@@ -41,7 +41,7 @@ end
|
|
41
41
|
|
42
42
|
class ParseTree
|
43
43
|
|
44
|
-
VERSION = '2.0
|
44
|
+
VERSION = '2.1.0'
|
45
45
|
|
46
46
|
##
|
47
47
|
# Front end translation method.
|
@@ -78,9 +78,6 @@ class ParseTree
|
|
78
78
|
# +include_newlines+ which defaults to +$DEBUG+.
|
79
79
|
|
80
80
|
def initialize(include_newlines=$DEBUG)
|
81
|
-
if include_newlines then
|
82
|
-
warn "WAR\NING: include_newlines=true from #{caller[0..9].join(', ')}"
|
83
|
-
end
|
84
81
|
@include_newlines = include_newlines
|
85
82
|
end
|
86
83
|
|
@@ -149,7 +146,7 @@ class ParseTree
|
|
149
146
|
|
150
147
|
def parse_tree_for_method(klass, method, is_cls_meth=false)
|
151
148
|
$stderr.puts "** parse_tree_for_method(#{klass}, #{method}):" if $DEBUG
|
152
|
-
r = parse_tree_for_meth(klass, method.to_sym,
|
149
|
+
r = parse_tree_for_meth(klass, method.to_sym, is_cls_meth)
|
153
150
|
r
|
154
151
|
end
|
155
152
|
|
@@ -160,11 +157,15 @@ class ParseTree
|
|
160
157
|
#
|
161
158
|
# [[sexps] ... ]
|
162
159
|
|
163
|
-
def parse_tree_for_string(source, filename =
|
164
|
-
|
165
|
-
filename
|
166
|
-
|
167
|
-
|
160
|
+
def parse_tree_for_string(source, filename = '(string)', line = 1)
|
161
|
+
old_verbose, $VERBOSE = $VERBOSE, true
|
162
|
+
return parse_tree_for_str0(source, filename, line)
|
163
|
+
ensure
|
164
|
+
$VERBOSE = old_verbose
|
165
|
+
end
|
166
|
+
|
167
|
+
def parse_tree_for_str0(*__1args2__) # :nodoc:
|
168
|
+
parse_tree_for_str(*__1args2__) # just helps clean up the binding
|
168
169
|
end
|
169
170
|
|
170
171
|
if RUBY_VERSION < "1.8.4" then
|
@@ -282,13 +283,15 @@ class ParseTree
|
|
282
283
|
builder.prefix %{
|
283
284
|
#define nd_3rd u3.node
|
284
285
|
static unsigned case_level = 0;
|
286
|
+
static unsigned when_level = 0;
|
287
|
+
static unsigned inside_case_args = 0;
|
285
288
|
}
|
286
289
|
|
287
290
|
builder.prefix %{
|
288
291
|
static VALUE wrap_into_node(const char * name, VALUE val) {
|
289
292
|
VALUE n = rb_ary_new();
|
290
293
|
rb_ary_push(n, ID2SYM(rb_intern(name)));
|
291
|
-
rb_ary_push(n, val);
|
294
|
+
if (val) rb_ary_push(n, val);
|
292
295
|
return n;
|
293
296
|
}
|
294
297
|
}
|
@@ -326,15 +329,11 @@ class ParseTree
|
|
326
329
|
} unless RUBY_VERSION >= "1.9" # we got matz to add this to env.h
|
327
330
|
|
328
331
|
##
|
329
|
-
# add_to_parse_tree(ary, node,
|
332
|
+
# add_to_parse_tree(self, ary, node, local_variables)
|
330
333
|
|
331
334
|
builder.prefix %Q@
|
332
|
-
void add_to_parse_tree(VALUE ary,
|
333
|
-
NODE * n,
|
334
|
-
VALUE newlines,
|
335
|
-
ID * locals) {
|
335
|
+
void add_to_parse_tree(VALUE self, VALUE ary, NODE * n, ID * locals) {
|
336
336
|
NODE * volatile node = n;
|
337
|
-
NODE * volatile contnode = NULL;
|
338
337
|
VALUE old_ary = Qnil;
|
339
338
|
VALUE current;
|
340
339
|
VALUE node_name;
|
@@ -370,54 +369,45 @@ again_no_block:
|
|
370
369
|
switch (nd_type(node)) {
|
371
370
|
|
372
371
|
case NODE_BLOCK:
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
/* FIX: this will break the moment there is a block w/in a block */
|
380
|
-
old_ary = ary;
|
381
|
-
ary = current;
|
382
|
-
node = node->nd_head;
|
383
|
-
if (nd_type(node) == NODE_DASGN_CURR
|
384
|
-
&& (!node->nd_value || nd_type(node->nd_value) == NODE_DASGN_CURR)) {
|
385
|
-
goto finish;
|
372
|
+
{
|
373
|
+
while (node) {
|
374
|
+
add_to_parse_tree(self, current, node->nd_head, locals);
|
375
|
+
node = node->nd_next;
|
376
|
+
}
|
386
377
|
}
|
387
|
-
goto again;
|
388
378
|
break;
|
389
379
|
|
390
380
|
case NODE_FBODY:
|
391
381
|
case NODE_DEFINED:
|
392
|
-
add_to_parse_tree(current, node->nd_head,
|
382
|
+
add_to_parse_tree(self, current, node->nd_head, locals);
|
393
383
|
break;
|
394
384
|
|
395
385
|
case NODE_COLON2:
|
396
|
-
add_to_parse_tree(current, node->nd_head,
|
386
|
+
add_to_parse_tree(self, current, node->nd_head, locals);
|
397
387
|
rb_ary_push(current, ID2SYM(node->nd_mid));
|
398
388
|
break;
|
399
389
|
|
400
390
|
case NODE_MATCH2:
|
401
391
|
case NODE_MATCH3:
|
402
|
-
add_to_parse_tree(current, node->nd_recv,
|
403
|
-
add_to_parse_tree(current, node->nd_value,
|
392
|
+
add_to_parse_tree(self, current, node->nd_recv, locals);
|
393
|
+
add_to_parse_tree(self, current, node->nd_value, locals);
|
404
394
|
break;
|
405
395
|
|
406
396
|
case NODE_BEGIN:
|
407
397
|
case NODE_OPT_N:
|
408
398
|
case NODE_NOT:
|
409
|
-
add_to_parse_tree(current, node->nd_body,
|
399
|
+
add_to_parse_tree(self, current, node->nd_body, locals);
|
410
400
|
break;
|
411
401
|
|
412
402
|
case NODE_IF:
|
413
|
-
add_to_parse_tree(current, node->nd_cond,
|
403
|
+
add_to_parse_tree(self, current, node->nd_cond, locals);
|
414
404
|
if (node->nd_body) {
|
415
|
-
add_to_parse_tree(current, node->nd_body,
|
405
|
+
add_to_parse_tree(self, current, node->nd_body, locals);
|
416
406
|
} else {
|
417
407
|
rb_ary_push(current, Qnil);
|
418
408
|
}
|
419
409
|
if (node->nd_else) {
|
420
|
-
add_to_parse_tree(current, node->nd_else,
|
410
|
+
add_to_parse_tree(self, current, node->nd_else, locals);
|
421
411
|
} else {
|
422
412
|
rb_ary_push(current, Qnil);
|
423
413
|
}
|
@@ -426,13 +416,13 @@ again_no_block:
|
|
426
416
|
case NODE_CASE:
|
427
417
|
case_level++;
|
428
418
|
if (node->nd_head != NULL) {
|
429
|
-
add_to_parse_tree(current, node->nd_head,
|
419
|
+
add_to_parse_tree(self, current, node->nd_head, locals); /* expr */
|
430
420
|
} else {
|
431
421
|
rb_ary_push(current, Qnil);
|
432
422
|
}
|
433
423
|
node = node->nd_body;
|
434
424
|
while (node) {
|
435
|
-
add_to_parse_tree(current, node,
|
425
|
+
add_to_parse_tree(self, current, node, locals);
|
436
426
|
if (nd_type(node) == NODE_WHEN) { /* when */
|
437
427
|
node = node->nd_next;
|
438
428
|
} else {
|
@@ -446,24 +436,31 @@ again_no_block:
|
|
446
436
|
break;
|
447
437
|
|
448
438
|
case NODE_WHEN:
|
449
|
-
|
439
|
+
when_level++;
|
440
|
+
if (!inside_case_args && case_level < when_level) { /* when without case, ie, no expr in case */
|
441
|
+
when_level--; if (when_level < 0) when_level = 0;
|
450
442
|
rb_ary_pop(ary); /* reset what current is pointing at */
|
451
443
|
node = NEW_CASE(0, node);
|
452
444
|
goto again;
|
453
445
|
}
|
454
|
-
|
446
|
+
inside_case_args++;
|
447
|
+
add_to_parse_tree(self, current, node->nd_head, locals); /* args */
|
448
|
+
inside_case_args--;
|
449
|
+
|
455
450
|
if (node->nd_body) {
|
456
|
-
add_to_parse_tree(current, node->nd_body,
|
451
|
+
add_to_parse_tree(self, current, node->nd_body, locals); /* body */
|
457
452
|
} else {
|
458
453
|
rb_ary_push(current, Qnil);
|
459
454
|
}
|
455
|
+
|
456
|
+
when_level--; if (when_level < 0) when_level = 0;
|
460
457
|
break;
|
461
458
|
|
462
459
|
case NODE_WHILE:
|
463
460
|
case NODE_UNTIL:
|
464
|
-
add_to_parse_tree(current, node->nd_cond,
|
461
|
+
add_to_parse_tree(self, current, node->nd_cond, locals);
|
465
462
|
if (node->nd_body) {
|
466
|
-
add_to_parse_tree(current, node->nd_body,
|
463
|
+
add_to_parse_tree(self, current, node->nd_body, locals);
|
467
464
|
} else {
|
468
465
|
rb_ary_push(current, Qnil);
|
469
466
|
}
|
@@ -471,34 +468,40 @@ again_no_block:
|
|
471
468
|
break;
|
472
469
|
|
473
470
|
case NODE_BLOCK_PASS:
|
474
|
-
add_to_parse_tree(current, node->nd_body,
|
475
|
-
add_to_parse_tree(current, node->nd_iter,
|
471
|
+
add_to_parse_tree(self, current, node->nd_body, locals);
|
472
|
+
add_to_parse_tree(self, current, node->nd_iter, locals);
|
476
473
|
break;
|
477
474
|
|
478
475
|
case NODE_ITER:
|
479
476
|
case NODE_FOR:
|
480
|
-
add_to_parse_tree(current, node->nd_iter,
|
477
|
+
add_to_parse_tree(self, current, node->nd_iter, locals);
|
481
478
|
if (node->nd_var != (NODE *)1
|
482
479
|
&& node->nd_var != (NODE *)2
|
483
480
|
&& node->nd_var != NULL) {
|
484
|
-
add_to_parse_tree(current, node->nd_var,
|
481
|
+
add_to_parse_tree(self, current, node->nd_var, locals);
|
485
482
|
} else {
|
486
|
-
|
483
|
+
if (node->nd_var == NULL) {
|
484
|
+
// e.g. proc {}
|
485
|
+
rb_ary_push(current, Qnil);
|
486
|
+
} else {
|
487
|
+
// e.g. proc {||}
|
488
|
+
rb_ary_push(current, INT2FIX(0));
|
489
|
+
}
|
487
490
|
}
|
488
|
-
add_to_parse_tree(current, node->nd_body,
|
491
|
+
add_to_parse_tree(self, current, node->nd_body, locals);
|
489
492
|
break;
|
490
493
|
|
491
494
|
case NODE_BREAK:
|
492
495
|
case NODE_NEXT:
|
493
496
|
case NODE_YIELD:
|
494
497
|
if (node->nd_stts)
|
495
|
-
add_to_parse_tree(current, node->nd_stts,
|
498
|
+
add_to_parse_tree(self, current, node->nd_stts, locals);
|
496
499
|
break;
|
497
500
|
|
498
501
|
case NODE_RESCUE:
|
499
|
-
add_to_parse_tree(current, node->nd_1st,
|
500
|
-
add_to_parse_tree(current, node->nd_2nd,
|
501
|
-
add_to_parse_tree(current, node->nd_3rd,
|
502
|
+
add_to_parse_tree(self, current, node->nd_1st, locals);
|
503
|
+
add_to_parse_tree(self, current, node->nd_2nd, locals);
|
504
|
+
add_to_parse_tree(self, current, node->nd_3rd, locals);
|
502
505
|
break;
|
503
506
|
|
504
507
|
/*
|
@@ -510,58 +513,58 @@ again_no_block:
|
|
510
513
|
|
511
514
|
case NODE_RESBODY:
|
512
515
|
if (node->nd_3rd) {
|
513
|
-
add_to_parse_tree(current, node->nd_3rd,
|
516
|
+
add_to_parse_tree(self, current, node->nd_3rd, locals);
|
514
517
|
} else {
|
515
518
|
rb_ary_push(current, Qnil);
|
516
519
|
}
|
517
|
-
add_to_parse_tree(current, node->nd_2nd,
|
518
|
-
add_to_parse_tree(current, node->nd_1st,
|
520
|
+
add_to_parse_tree(self, current, node->nd_2nd, locals);
|
521
|
+
add_to_parse_tree(self, current, node->nd_1st, locals);
|
519
522
|
break;
|
520
523
|
|
521
524
|
case NODE_ENSURE:
|
522
|
-
add_to_parse_tree(current, node->nd_head,
|
525
|
+
add_to_parse_tree(self, current, node->nd_head, locals);
|
523
526
|
if (node->nd_ensr) {
|
524
|
-
add_to_parse_tree(current, node->nd_ensr,
|
527
|
+
add_to_parse_tree(self, current, node->nd_ensr, locals);
|
525
528
|
}
|
526
529
|
break;
|
527
530
|
|
528
531
|
case NODE_AND:
|
529
532
|
case NODE_OR:
|
530
|
-
add_to_parse_tree(current, node->nd_1st,
|
531
|
-
add_to_parse_tree(current, node->nd_2nd,
|
533
|
+
add_to_parse_tree(self, current, node->nd_1st, locals);
|
534
|
+
add_to_parse_tree(self, current, node->nd_2nd, locals);
|
532
535
|
break;
|
533
536
|
|
534
537
|
case NODE_DOT2:
|
535
538
|
case NODE_DOT3:
|
536
539
|
case NODE_FLIP2:
|
537
540
|
case NODE_FLIP3:
|
538
|
-
add_to_parse_tree(current, node->nd_beg,
|
539
|
-
add_to_parse_tree(current, node->nd_end,
|
541
|
+
add_to_parse_tree(self, current, node->nd_beg, locals);
|
542
|
+
add_to_parse_tree(self, current, node->nd_end, locals);
|
540
543
|
break;
|
541
544
|
|
542
545
|
case NODE_RETURN:
|
543
546
|
if (node->nd_stts)
|
544
|
-
add_to_parse_tree(current, node->nd_stts,
|
547
|
+
add_to_parse_tree(self, current, node->nd_stts, locals);
|
545
548
|
break;
|
546
549
|
|
547
550
|
case NODE_ARGSCAT:
|
548
551
|
case NODE_ARGSPUSH:
|
549
|
-
add_to_parse_tree(current, node->nd_head,
|
550
|
-
add_to_parse_tree(current, node->nd_body,
|
552
|
+
add_to_parse_tree(self, current, node->nd_head, locals);
|
553
|
+
add_to_parse_tree(self, current, node->nd_body, locals);
|
551
554
|
break;
|
552
555
|
|
553
556
|
case NODE_CALL:
|
554
557
|
case NODE_FCALL:
|
555
558
|
case NODE_VCALL:
|
556
559
|
if (nd_type(node) != NODE_FCALL)
|
557
|
-
add_to_parse_tree(current, node->nd_recv,
|
560
|
+
add_to_parse_tree(self, current, node->nd_recv, locals);
|
558
561
|
rb_ary_push(current, ID2SYM(node->nd_mid));
|
559
562
|
if (node->nd_args || nd_type(node) != NODE_FCALL)
|
560
|
-
add_to_parse_tree(current, node->nd_args,
|
563
|
+
add_to_parse_tree(self, current, node->nd_args, locals);
|
561
564
|
break;
|
562
565
|
|
563
566
|
case NODE_SUPER:
|
564
|
-
add_to_parse_tree(current, node->nd_args,
|
567
|
+
add_to_parse_tree(self, current, node->nd_args, locals);
|
565
568
|
break;
|
566
569
|
|
567
570
|
case NODE_BMETHOD:
|
@@ -571,9 +574,9 @@ again_no_block:
|
|
571
574
|
if (data->var == 0 || data->var == (NODE *)1 || data->var == (NODE *)2) {
|
572
575
|
rb_ary_push(current, Qnil);
|
573
576
|
} else {
|
574
|
-
add_to_parse_tree(current, data->var,
|
577
|
+
add_to_parse_tree(self, current, data->var, locals);
|
575
578
|
}
|
576
|
-
add_to_parse_tree(current, data->body,
|
579
|
+
add_to_parse_tree(self, current, data->body, locals);
|
577
580
|
break;
|
578
581
|
}
|
579
582
|
break;
|
@@ -584,26 +587,26 @@ again_no_block:
|
|
584
587
|
struct METHOD *data;
|
585
588
|
Data_Get_Struct(node->nd_cval, struct METHOD, data);
|
586
589
|
rb_ary_push(current, ID2SYM(data->id));
|
587
|
-
add_to_parse_tree(current, data->body,
|
590
|
+
add_to_parse_tree(self, current, data->body, locals);
|
588
591
|
break;
|
589
592
|
}
|
590
593
|
#endif
|
591
594
|
|
592
595
|
case NODE_METHOD:
|
593
|
-
add_to_parse_tree(current, node->nd_3rd,
|
596
|
+
add_to_parse_tree(self, current, node->nd_3rd, locals);
|
594
597
|
break;
|
595
598
|
|
596
599
|
case NODE_SCOPE:
|
597
|
-
add_to_parse_tree(current, node->nd_next,
|
600
|
+
add_to_parse_tree(self, current, node->nd_next, node->nd_tbl);
|
598
601
|
break;
|
599
602
|
|
600
603
|
case NODE_OP_ASGN1:
|
601
|
-
add_to_parse_tree(current, node->nd_recv,
|
604
|
+
add_to_parse_tree(self, current, node->nd_recv, locals);
|
602
605
|
#if RUBY_VERSION_CODE < 185
|
603
|
-
add_to_parse_tree(current, node->nd_args->nd_next,
|
606
|
+
add_to_parse_tree(self, current, node->nd_args->nd_next, locals);
|
604
607
|
rb_ary_pop(rb_ary_entry(current, -1)); /* no idea why I need this */
|
605
608
|
#else
|
606
|
-
add_to_parse_tree(current, node->nd_args->nd_2nd,
|
609
|
+
add_to_parse_tree(self, current, node->nd_args->nd_2nd, locals);
|
607
610
|
#endif
|
608
611
|
switch (node->nd_mid) {
|
609
612
|
case 0:
|
@@ -616,11 +619,11 @@ again_no_block:
|
|
616
619
|
rb_ary_push(current, ID2SYM(node->nd_mid));
|
617
620
|
break;
|
618
621
|
}
|
619
|
-
add_to_parse_tree(current, node->nd_args->nd_head,
|
622
|
+
add_to_parse_tree(self, current, node->nd_args->nd_head, locals);
|
620
623
|
break;
|
621
624
|
|
622
625
|
case NODE_OP_ASGN2:
|
623
|
-
add_to_parse_tree(current, node->nd_recv,
|
626
|
+
add_to_parse_tree(self, current, node->nd_recv, locals);
|
624
627
|
rb_ary_push(current, ID2SYM(node->nd_next->nd_aid));
|
625
628
|
|
626
629
|
switch (node->nd_next->nd_mid) {
|
@@ -635,21 +638,25 @@ again_no_block:
|
|
635
638
|
break;
|
636
639
|
}
|
637
640
|
|
638
|
-
add_to_parse_tree(current, node->nd_value,
|
641
|
+
add_to_parse_tree(self, current, node->nd_value, locals);
|
639
642
|
break;
|
640
643
|
|
641
644
|
case NODE_OP_ASGN_AND:
|
642
645
|
case NODE_OP_ASGN_OR:
|
643
|
-
add_to_parse_tree(current, node->nd_head,
|
644
|
-
add_to_parse_tree(current, node->nd_value,
|
646
|
+
add_to_parse_tree(self, current, node->nd_head, locals);
|
647
|
+
add_to_parse_tree(self, current, node->nd_value, locals);
|
645
648
|
break;
|
646
649
|
|
647
650
|
case NODE_MASGN:
|
648
|
-
add_to_parse_tree(current, node->nd_head,
|
649
|
-
if (node->nd_args
|
650
|
-
|
651
|
+
add_to_parse_tree(self, current, node->nd_head, locals);
|
652
|
+
if (node->nd_args) {
|
653
|
+
if (node->nd_args != (NODE *)-1) {
|
654
|
+
add_to_parse_tree(self, current, node->nd_args, locals);
|
655
|
+
} else {
|
656
|
+
rb_ary_push(current, wrap_into_node("splat", 0));
|
657
|
+
}
|
651
658
|
}
|
652
|
-
add_to_parse_tree(current, node->nd_value,
|
659
|
+
add_to_parse_tree(self, current, node->nd_value, locals);
|
653
660
|
break;
|
654
661
|
|
655
662
|
case NODE_LASGN:
|
@@ -661,7 +668,7 @@ again_no_block:
|
|
661
668
|
case NODE_CVDECL:
|
662
669
|
case NODE_GASGN:
|
663
670
|
rb_ary_push(current, ID2SYM(node->nd_vid));
|
664
|
-
add_to_parse_tree(current, node->nd_value,
|
671
|
+
add_to_parse_tree(self, current, node->nd_value, locals);
|
665
672
|
break;
|
666
673
|
|
667
674
|
case NODE_VALIAS: /* u1 u2 (alias $global $global2) */
|
@@ -678,8 +685,8 @@ again_no_block:
|
|
678
685
|
rb_ary_push(current, wrap_into_node("lit", ID2SYM(node->u2.id)));
|
679
686
|
rb_ary_push(current, wrap_into_node("lit", ID2SYM(node->u1.id)));
|
680
687
|
#else
|
681
|
-
add_to_parse_tree(current, node->nd_1st,
|
682
|
-
add_to_parse_tree(current, node->nd_2nd,
|
688
|
+
add_to_parse_tree(self, current, node->nd_1st, locals);
|
689
|
+
add_to_parse_tree(self, current, node->nd_2nd, locals);
|
683
690
|
#endif
|
684
691
|
break;
|
685
692
|
|
@@ -687,7 +694,7 @@ again_no_block:
|
|
687
694
|
#if RUBY_VERSION_CODE < 185
|
688
695
|
rb_ary_push(current, wrap_into_node("lit", ID2SYM(node->u2.id)));
|
689
696
|
#else
|
690
|
-
add_to_parse_tree(current, node->nd_value,
|
697
|
+
add_to_parse_tree(self, current, node->nd_value, locals);
|
691
698
|
#endif
|
692
699
|
break;
|
693
700
|
|
@@ -701,11 +708,11 @@ again_no_block:
|
|
701
708
|
|
702
709
|
list = node->nd_head;
|
703
710
|
while (list) {
|
704
|
-
add_to_parse_tree(current, list->nd_head,
|
711
|
+
add_to_parse_tree(self, current, list->nd_head, locals);
|
705
712
|
list = list->nd_next;
|
706
713
|
if (list == 0)
|
707
714
|
rb_bug("odd number list for Hash");
|
708
|
-
add_to_parse_tree(current, list->nd_head,
|
715
|
+
add_to_parse_tree(self, current, list->nd_head, locals);
|
709
716
|
list = list->nd_next;
|
710
717
|
}
|
711
718
|
}
|
@@ -713,7 +720,7 @@ again_no_block:
|
|
713
720
|
|
714
721
|
case NODE_ARRAY:
|
715
722
|
while (node) {
|
716
|
-
add_to_parse_tree(current, node->nd_head,
|
723
|
+
add_to_parse_tree(self, current, node->nd_head, locals);
|
717
724
|
node = node->nd_next;
|
718
725
|
}
|
719
726
|
break;
|
@@ -730,18 +737,25 @@ again_no_block:
|
|
730
737
|
if (list->nd_head) {
|
731
738
|
switch (nd_type(list->nd_head)) {
|
732
739
|
case NODE_STR:
|
733
|
-
add_to_parse_tree(current, list->nd_head,
|
740
|
+
add_to_parse_tree(self, current, list->nd_head, locals);
|
734
741
|
break;
|
735
742
|
case NODE_EVSTR:
|
736
|
-
add_to_parse_tree(current, list->nd_head
|
743
|
+
add_to_parse_tree(self, current, list->nd_head, locals);
|
737
744
|
break;
|
738
745
|
default:
|
739
|
-
add_to_parse_tree(current, list->nd_head,
|
746
|
+
add_to_parse_tree(self, current, list->nd_head, locals);
|
740
747
|
break;
|
741
748
|
}
|
742
749
|
}
|
743
750
|
list = list->nd_next;
|
744
751
|
}
|
752
|
+
switch (nd_type(node)) {
|
753
|
+
case NODE_DREGX:
|
754
|
+
case NODE_DREGX_ONCE:
|
755
|
+
if (node->nd_cflag) {
|
756
|
+
rb_ary_push(current, INT2FIX(node->nd_cflag));
|
757
|
+
}
|
758
|
+
}
|
745
759
|
}
|
746
760
|
break;
|
747
761
|
|
@@ -749,9 +763,9 @@ again_no_block:
|
|
749
763
|
case NODE_DEFS:
|
750
764
|
if (node->nd_defn) {
|
751
765
|
if (nd_type(node) == NODE_DEFS)
|
752
|
-
add_to_parse_tree(current, node->nd_recv,
|
766
|
+
add_to_parse_tree(self, current, node->nd_recv, locals);
|
753
767
|
rb_ary_push(current, ID2SYM(node->nd_mid));
|
754
|
-
add_to_parse_tree(current, node->nd_defn,
|
768
|
+
add_to_parse_tree(self, current, node->nd_defn, locals);
|
755
769
|
}
|
756
770
|
break;
|
757
771
|
|
@@ -760,17 +774,17 @@ again_no_block:
|
|
760
774
|
rb_ary_push(current, ID2SYM((ID)node->nd_cpath->nd_mid));
|
761
775
|
if (nd_type(node) == NODE_CLASS) {
|
762
776
|
if (node->nd_super) {
|
763
|
-
add_to_parse_tree(current, node->nd_super,
|
777
|
+
add_to_parse_tree(self, current, node->nd_super, locals);
|
764
778
|
} else {
|
765
779
|
rb_ary_push(current, Qnil);
|
766
780
|
}
|
767
781
|
}
|
768
|
-
add_to_parse_tree(current, node->nd_body,
|
782
|
+
add_to_parse_tree(self, current, node->nd_body, locals);
|
769
783
|
break;
|
770
784
|
|
771
785
|
case NODE_SCLASS:
|
772
|
-
add_to_parse_tree(current, node->nd_recv,
|
773
|
-
add_to_parse_tree(current, node->nd_body,
|
786
|
+
add_to_parse_tree(self, current, node->nd_recv, locals);
|
787
|
+
add_to_parse_tree(self, current, node->nd_body, locals);
|
774
788
|
break;
|
775
789
|
|
776
790
|
case NODE_ARGS: {
|
@@ -827,7 +841,7 @@ again_no_block:
|
|
827
841
|
|
828
842
|
optnode = node->nd_opt;
|
829
843
|
if (optnode) {
|
830
|
-
add_to_parse_tree(current, node->nd_opt,
|
844
|
+
add_to_parse_tree(self, current, node->nd_opt, locals);
|
831
845
|
}
|
832
846
|
} break;
|
833
847
|
|
@@ -845,6 +859,9 @@ again_no_block:
|
|
845
859
|
case NODE_STR: /* u1 */
|
846
860
|
case NODE_LIT:
|
847
861
|
rb_ary_push(current, node->nd_lit);
|
862
|
+
if (node->nd_cflag) {
|
863
|
+
rb_ary_push(current, INT2FIX(node->nd_cflag));
|
864
|
+
}
|
848
865
|
break;
|
849
866
|
|
850
867
|
case NODE_MATCH: /* u1 -> [:lit, u1] */
|
@@ -856,11 +873,13 @@ again_no_block:
|
|
856
873
|
case NODE_NEWLINE:
|
857
874
|
rb_ary_push(current, INT2FIX(nd_line(node)));
|
858
875
|
rb_ary_push(current, rb_str_new2(node->nd_file));
|
859
|
-
|
860
|
-
|
861
|
-
|
862
|
-
|
863
|
-
|
876
|
+
if (! RTEST(rb_iv_get(self, "\@include_newlines"))) {
|
877
|
+
rb_ary_pop(ary); /* nuke it */
|
878
|
+
node = node->nd_next;
|
879
|
+
goto again;
|
880
|
+
} else {
|
881
|
+
add_to_parse_tree(self, current, node->nd_next, locals);
|
882
|
+
}
|
864
883
|
break;
|
865
884
|
|
866
885
|
case NODE_NTH_REF: /* u2 u3 ($1) - u3 is local_cnt('~') ignorable? */
|
@@ -892,22 +911,22 @@ again_no_block:
|
|
892
911
|
case NODE_SPLAT:
|
893
912
|
case NODE_TO_ARY:
|
894
913
|
case NODE_SVALUE: /* a = b, c */
|
895
|
-
add_to_parse_tree(current, node->nd_head,
|
914
|
+
add_to_parse_tree(self, current, node->nd_head, locals);
|
896
915
|
break;
|
897
916
|
|
898
917
|
case NODE_ATTRASGN: /* literal.meth = y u1 u2 u3 */
|
899
918
|
/* node id node */
|
900
919
|
if (node->nd_1st == RNODE(1)) {
|
901
|
-
add_to_parse_tree(current, NEW_SELF(),
|
920
|
+
add_to_parse_tree(self, current, NEW_SELF(), locals);
|
902
921
|
} else {
|
903
|
-
add_to_parse_tree(current, node->nd_1st,
|
922
|
+
add_to_parse_tree(self, current, node->nd_1st, locals);
|
904
923
|
}
|
905
924
|
rb_ary_push(current, ID2SYM(node->u2.id));
|
906
|
-
add_to_parse_tree(current, node->nd_3rd,
|
925
|
+
add_to_parse_tree(self, current, node->nd_3rd, locals);
|
907
926
|
break;
|
908
927
|
|
909
928
|
case NODE_EVSTR:
|
910
|
-
add_to_parse_tree(current, node->nd_2nd,
|
929
|
+
add_to_parse_tree(self, current, node->nd_2nd, locals);
|
911
930
|
break;
|
912
931
|
|
913
932
|
case NODE_POSTEXE: /* END { ... } */
|
@@ -946,21 +965,11 @@ again_no_block:
|
|
946
965
|
rb_ary_push(current, INT2FIX(nd_type(node)));
|
947
966
|
break;
|
948
967
|
}
|
949
|
-
|
950
|
-
finish:
|
951
|
-
if (contnode) {
|
952
|
-
node = contnode;
|
953
|
-
contnode = NULL;
|
954
|
-
current = ary;
|
955
|
-
ary = old_ary;
|
956
|
-
old_ary = Qnil;
|
957
|
-
goto again_no_block;
|
958
|
-
}
|
959
968
|
}
|
960
969
|
@ # end of add_to_parse_tree block
|
961
970
|
|
962
971
|
builder.c %Q{
|
963
|
-
static VALUE parse_tree_for_meth(VALUE klass, VALUE method, VALUE
|
972
|
+
static VALUE parse_tree_for_meth(VALUE klass, VALUE method, VALUE is_cls_meth) {
|
964
973
|
VALUE n;
|
965
974
|
NODE *node = NULL;
|
966
975
|
ID id;
|
@@ -984,7 +993,7 @@ static VALUE parse_tree_for_meth(VALUE klass, VALUE method, VALUE newlines, VALU
|
|
984
993
|
rb_ary_push(result, rb_ary_new3(1, ID2SYM(rb_intern("self"))));
|
985
994
|
}
|
986
995
|
rb_ary_push(result, ID2SYM(id));
|
987
|
-
add_to_parse_tree(result, node->nd_body,
|
996
|
+
add_to_parse_tree(self, result, node->nd_body, NULL);
|
988
997
|
} else {
|
989
998
|
rb_ary_push(result, Qnil);
|
990
999
|
}
|
@@ -997,14 +1006,12 @@ static VALUE parse_tree_for_meth(VALUE klass, VALUE method, VALUE newlines, VALU
|
|
997
1006
|
if RUBY_VERSION < '1.9.0'
|
998
1007
|
|
999
1008
|
builder.c %Q{
|
1000
|
-
static VALUE parse_tree_for_str(VALUE source, VALUE filename, VALUE line
|
1001
|
-
VALUE newlines) {
|
1009
|
+
static VALUE parse_tree_for_str(VALUE source, VALUE filename, VALUE line) {
|
1002
1010
|
VALUE tmp;
|
1003
1011
|
VALUE result = rb_ary_new();
|
1004
1012
|
NODE *node = NULL;
|
1005
1013
|
int critical;
|
1006
|
-
|
1007
|
-
(void) self; /* quell warnings */
|
1014
|
+
int newlines = RTEST(rb_iv_get(self, "@include_newlines"));
|
1008
1015
|
|
1009
1016
|
tmp = rb_check_string_type(filename);
|
1010
1017
|
if (NIL_P(tmp)) {
|
@@ -1015,8 +1022,6 @@ static VALUE parse_tree_for_str(VALUE source, VALUE filename, VALUE line,
|
|
1015
1022
|
line = LONG2FIX(1);
|
1016
1023
|
}
|
1017
1024
|
|
1018
|
-
newlines = RTEST(newlines);
|
1019
|
-
|
1020
1025
|
ruby_nerrs = 0;
|
1021
1026
|
StringValue(source);
|
1022
1027
|
critical = rb_thread_critical;
|
@@ -1034,7 +1039,7 @@ static VALUE parse_tree_for_str(VALUE source, VALUE filename, VALUE line,
|
|
1034
1039
|
rb_exc_raise(ruby_errinfo);
|
1035
1040
|
}
|
1036
1041
|
|
1037
|
-
add_to_parse_tree(result, node,
|
1042
|
+
add_to_parse_tree(self, result, node, NULL);
|
1038
1043
|
|
1039
1044
|
return result;
|
1040
1045
|
}
|