Skip to content

Commit d458cea

Browse files
committed
merge revision(s) 18356:
* parse.y (deferred_nodes, compstmt, arg, fixup_nodes, range_op): fix up fixnum range literal in conditional as automagical line number comparison. [ruby-core:12124], [ruby-dev:35731] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8_7@21385 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent 46e4dcf commit d458cea

File tree

3 files changed

+54
-18
lines changed

3 files changed

+54
-18
lines changed

ChangeLog

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
Thu Jan 8 13:24:23 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
2+
3+
* parse.y (deferred_nodes, compstmt, arg, fixup_nodes, range_op): fix
4+
up fixnum range literal in conditional as automagical line number
5+
comparison. [ruby-core:12124], [ruby-dev:35731]
6+
17
Wed Jan 7 10:09:46 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
28

39
* eval.c (timeofday): use monotonic clock. based on a patch

parse.y

Lines changed: 44 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ static int compile_for_eval = 0;
124124
static ID cur_mid = 0;
125125
static int command_start = Qtrue;
126126

127+
static NODE *deferred_nodes;
128+
127129
static NODE *cond();
128130
static NODE *logop();
129131
static int cond_negative();
@@ -181,6 +183,8 @@ static NODE *dyna_init();
181183
static void top_local_init();
182184
static void top_local_setup();
183185

186+
static void fixup_nodes();
187+
184188
#define RE_OPTION_ONCE 0x80
185189

186190
#define NODE_STRTERM NODE_ZARRAY /* nothing to gc */
@@ -394,6 +398,7 @@ bodystmt : compstmt
394398
compstmt : stmts opt_terms
395399
{
396400
void_stmts($1);
401+
fixup_nodes(&deferred_nodes);
397402
$$ = $1;
398403
}
399404
;
@@ -1080,26 +1085,20 @@ arg : lhs '=' arg
10801085
{
10811086
value_expr($1);
10821087
value_expr($3);
1088+
$$ = NEW_DOT2($1, $3);
10831089
if (nd_type($1) == NODE_LIT && FIXNUM_P($1->nd_lit) &&
10841090
nd_type($3) == NODE_LIT && FIXNUM_P($3->nd_lit)) {
1085-
$1->nd_lit = rb_range_new($1->nd_lit, $3->nd_lit, Qfalse);
1086-
$$ = $1;
1087-
}
1088-
else {
1089-
$$ = NEW_DOT2($1, $3);
1091+
deferred_nodes = list_append(deferred_nodes, $$);
10901092
}
10911093
}
10921094
| arg tDOT3 arg
10931095
{
10941096
value_expr($1);
10951097
value_expr($3);
1098+
$$ = NEW_DOT3($1, $3);
10961099
if (nd_type($1) == NODE_LIT && FIXNUM_P($1->nd_lit) &&
10971100
nd_type($3) == NODE_LIT && FIXNUM_P($3->nd_lit)) {
1098-
$1->nd_lit = rb_range_new($1->nd_lit, $3->nd_lit, Qtrue);
1099-
$$ = $1;
1100-
}
1101-
else {
1102-
$$ = NEW_DOT3($1, $3);
1101+
deferred_nodes = list_append(deferred_nodes, $$);
11031102
}
11041103
}
11051104
| arg '+' arg
@@ -2689,6 +2688,7 @@ yycompile(f, line)
26892688
lex_strterm = 0;
26902689
ruby_current_node = 0;
26912690
ruby_sourcefile = rb_source_filename(f);
2691+
deferred_nodes = 0;
26922692
n = yyparse();
26932693
ruby_debug_lines = 0;
26942694
compile_for_eval = 0;
@@ -2700,6 +2700,7 @@ yycompile(f, line)
27002700
in_single = 0;
27012701
in_def = 0;
27022702
cur_mid = 0;
2703+
deferred_nodes = 0;
27032704

27042705
vp = ruby_dyna_vars;
27052706
ruby_dyna_vars = vars;
@@ -5376,6 +5377,36 @@ warning_unless_e_option(node, str)
53765377
if (!e_option_supplied()) parser_warning(node, str);
53775378
}
53785379

5380+
static void
5381+
fixup_nodes(rootnode)
5382+
NODE **rootnode;
5383+
{
5384+
NODE *node, *next, *head;
5385+
5386+
for (node = *rootnode; node; node = next) {
5387+
enum node_type type;
5388+
VALUE val;
5389+
5390+
next = node->nd_next;
5391+
head = node->nd_head;
5392+
rb_gc_force_recycle((VALUE)node);
5393+
*rootnode = next;
5394+
switch (type = nd_type(head)) {
5395+
case NODE_DOT2:
5396+
case NODE_DOT3:
5397+
val = rb_range_new(head->nd_beg->nd_lit, head->nd_end->nd_lit,
5398+
type == NODE_DOT3 ? Qtrue : Qfalse);
5399+
rb_gc_force_recycle((VALUE)head->nd_beg);
5400+
rb_gc_force_recycle((VALUE)head->nd_end);
5401+
nd_set_type(head, NODE_LIT);
5402+
head->nd_lit = val;
5403+
break;
5404+
default:
5405+
break;
5406+
}
5407+
}
5408+
}
5409+
53795410
static NODE *cond0();
53805411

53815412
static NODE*
@@ -5384,21 +5415,19 @@ range_op(node)
53845415
{
53855416
enum node_type type;
53865417

5387-
if (!e_option_supplied()) return node;
53885418
if (node == 0) return 0;
53895419

5390-
value_expr(node);
5391-
node = cond0(node);
53925420
type = nd_type(node);
53935421
if (type == NODE_NEWLINE) {
53945422
node = node->nd_next;
53955423
type = nd_type(node);
53965424
}
5425+
value_expr(node);
53975426
if (type == NODE_LIT && FIXNUM_P(node->nd_lit)) {
53985427
warn_unless_e_option(node, "integer literal in conditional range");
53995428
return call_op(node,tEQ,1,NEW_GVAR(rb_intern("$.")));
54005429
}
5401-
return node;
5430+
return cond0(node);
54025431
}
54035432

54045433
static int
@@ -5919,6 +5948,7 @@ rb_gc_mark_parser()
59195948
rb_gc_mark(lex_lastline);
59205949
rb_gc_mark(lex_input);
59215950
rb_gc_mark((VALUE)lex_strterm);
5951+
rb_gc_mark((VALUE)deferred_nodes);
59225952
}
59235953

59245954
void

version.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
#define RUBY_VERSION "1.8.7"
2-
#define RUBY_RELEASE_DATE "2009-01-07"
2+
#define RUBY_RELEASE_DATE "2009-01-08"
33
#define RUBY_VERSION_CODE 187
4-
#define RUBY_RELEASE_CODE 20090107
5-
#define RUBY_PATCHLEVEL 79
4+
#define RUBY_RELEASE_CODE 20090108
5+
#define RUBY_PATCHLEVEL 80
66

77
#define RUBY_VERSION_MAJOR 1
88
#define RUBY_VERSION_MINOR 8
99
#define RUBY_VERSION_TEENY 7
1010
#define RUBY_RELEASE_YEAR 2009
1111
#define RUBY_RELEASE_MONTH 1
12-
#define RUBY_RELEASE_DAY 7
12+
#define RUBY_RELEASE_DAY 8
1313

1414
#ifdef RUBY_EXTERN
1515
RUBY_EXTERN const char ruby_version[];

0 commit comments

Comments
 (0)