Skip to content

Commit 182f7e1

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_6@21383 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent af7147e commit 182f7e1

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:20:15 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:06:12 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 */
@@ -391,6 +395,7 @@ bodystmt : compstmt
391395
compstmt : stmts opt_terms
392396
{
393397
void_stmts($1);
398+
fixup_nodes(&deferred_nodes);
394399
$$ = $1;
395400
}
396401
;
@@ -1077,26 +1082,20 @@ arg : lhs '=' arg
10771082
{
10781083
value_expr($1);
10791084
value_expr($3);
1085+
$$ = NEW_DOT2($1, $3);
10801086
if (nd_type($1) == NODE_LIT && FIXNUM_P($1->nd_lit) &&
10811087
nd_type($3) == NODE_LIT && FIXNUM_P($3->nd_lit)) {
1082-
$1->nd_lit = rb_range_new($1->nd_lit, $3->nd_lit, Qfalse);
1083-
$$ = $1;
1084-
}
1085-
else {
1086-
$$ = NEW_DOT2($1, $3);
1088+
deferred_nodes = list_append(deferred_nodes, $$);
10871089
}
10881090
}
10891091
| arg tDOT3 arg
10901092
{
10911093
value_expr($1);
10921094
value_expr($3);
1095+
$$ = NEW_DOT3($1, $3);
10931096
if (nd_type($1) == NODE_LIT && FIXNUM_P($1->nd_lit) &&
10941097
nd_type($3) == NODE_LIT && FIXNUM_P($3->nd_lit)) {
1095-
$1->nd_lit = rb_range_new($1->nd_lit, $3->nd_lit, Qtrue);
1096-
$$ = $1;
1097-
}
1098-
else {
1099-
$$ = NEW_DOT3($1, $3);
1098+
deferred_nodes = list_append(deferred_nodes, $$);
11001099
}
11011100
}
11021101
| arg '+' arg
@@ -2621,6 +2620,7 @@ yycompile(f, line)
26212620
lex_strterm = 0;
26222621
ruby_current_node = 0;
26232622
ruby_sourcefile = rb_source_filename(f);
2623+
deferred_nodes = 0;
26242624
n = yyparse();
26252625
ruby_debug_lines = 0;
26262626
compile_for_eval = 0;
@@ -2632,6 +2632,7 @@ yycompile(f, line)
26322632
in_single = 0;
26332633
in_def = 0;
26342634
cur_mid = 0;
2635+
deferred_nodes = 0;
26352636

26362637
vp = ruby_dyna_vars;
26372638
ruby_dyna_vars = vars;
@@ -5308,6 +5309,36 @@ warning_unless_e_option(node, str)
53085309
if (!e_option_supplied()) parser_warning(node, str);
53095310
}
53105311

5312+
static void
5313+
fixup_nodes(rootnode)
5314+
NODE **rootnode;
5315+
{
5316+
NODE *node, *next, *head;
5317+
5318+
for (node = *rootnode; node; node = next) {
5319+
enum node_type type;
5320+
VALUE val;
5321+
5322+
next = node->nd_next;
5323+
head = node->nd_head;
5324+
rb_gc_force_recycle((VALUE)node);
5325+
*rootnode = next;
5326+
switch (type = nd_type(head)) {
5327+
case NODE_DOT2:
5328+
case NODE_DOT3:
5329+
val = rb_range_new(head->nd_beg->nd_lit, head->nd_end->nd_lit,
5330+
type == NODE_DOT3 ? Qtrue : Qfalse);
5331+
rb_gc_force_recycle((VALUE)head->nd_beg);
5332+
rb_gc_force_recycle((VALUE)head->nd_end);
5333+
nd_set_type(head, NODE_LIT);
5334+
head->nd_lit = val;
5335+
break;
5336+
default:
5337+
break;
5338+
}
5339+
}
5340+
}
5341+
53115342
static NODE *cond0();
53125343

53135344
static NODE*
@@ -5316,21 +5347,19 @@ range_op(node)
53165347
{
53175348
enum node_type type;
53185349

5319-
if (!e_option_supplied()) return node;
53205350
if (node == 0) return 0;
53215351

5322-
value_expr(node);
5323-
node = cond0(node);
53245352
type = nd_type(node);
53255353
if (type == NODE_NEWLINE) {
53265354
node = node->nd_next;
53275355
type = nd_type(node);
53285356
}
5357+
value_expr(node);
53295358
if (type == NODE_LIT && FIXNUM_P(node->nd_lit)) {
53305359
warn_unless_e_option(node, "integer literal in conditional range");
53315360
return call_op(node,tEQ,1,NEW_GVAR(rb_intern("$.")));
53325361
}
5333-
return node;
5362+
return cond0(node);
53345363
}
53355364

53365365
static int
@@ -5847,6 +5876,7 @@ rb_gc_mark_parser()
58475876
rb_gc_mark(lex_lastline);
58485877
rb_gc_mark(lex_input);
58495878
rb_gc_mark((VALUE)lex_strterm);
5879+
rb_gc_mark((VALUE)deferred_nodes);
58505880
}
58515881

58525882
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.6"
2-
#define RUBY_RELEASE_DATE "2009-01-07"
2+
#define RUBY_RELEASE_DATE "2009-01-08"
33
#define RUBY_VERSION_CODE 186
4-
#define RUBY_RELEASE_CODE 20090107
5-
#define RUBY_PATCHLEVEL 292
4+
#define RUBY_RELEASE_CODE 20090108
5+
#define RUBY_PATCHLEVEL 293
66

77
#define RUBY_VERSION_MAJOR 1
88
#define RUBY_VERSION_MINOR 8
99
#define RUBY_VERSION_TEENY 6
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)