From ba8fc117c58e66672b4638450e76911e42a80f7b Mon Sep 17 00:00:00 2001 From: matz Date: Wed, 13 Feb 2002 09:01:11 +0000 Subject: * parse.y (stmt): local variable declaration order was changed since 1.6 * parse.y (arg): ditto. * pack.c (pack_pack): add templates 'q' and 'Q'. * pack.c (pack_unpack): ditto. * bignum.c (rb_quad_pack): new utility function. * bignum.c (rb_quad_unpack): ditto. * parse.y (assignable): should emit CVASGN within the method body. * dir.c (dir_s_glob): should not warn even if no match found. * eval.c (rb_eval): clean up class variable behavior. * eval.c (assign): ditto. * eval.c (is_defined): ditto. * variable.c (rb_mod_class_variables): need not to call rb_cvar_singleton(). * variable.c (rb_cvar_singleton): removed. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2063 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- parse.y | 54 +++++++++++++++++++++++++++++------------------------- 1 file changed, 29 insertions(+), 25 deletions(-) (limited to 'parse.y') diff --git a/parse.y b/parse.y index 0081e9fa81..da2a093e99 100644 --- a/parse.y +++ b/parse.y @@ -215,7 +215,7 @@ static void top_local_setup(); %type compstmt stmts stmt expr arg primary command command_call method_call %type if_tail opt_else case_body cases rescue exc_list exc_var ensure %type args when_args call_args call_args2 open_args paren_args opt_paren_args -%type command_args aref_args opt_block_arg block_arg var_ref +%type command_args aref_args opt_block_arg block_arg var_ref var_lhs %type mrhs mrhs_basic superclass block_call block_command %type f_arglist f_args f_optarg f_opt f_block_arg opt_f_block_arg %type assoc_list assocs assoc undef_list backref @@ -425,24 +425,24 @@ stmt : kALIAS fitem {lex_state = EXPR_FNAME;} fitem $1->nd_value = $3; $$ = $1; } - | variable tOP_ASGN command_call + | var_lhs tOP_ASGN command_call { - NODE *n = assignable($1, 0); - if (n) { + ID vid = $1->nd_vid; + if ($1) { if ($2 == tOROP) { - n->nd_value = $3; - $$ = NEW_OP_ASGN_OR(gettable($1), n); - if (is_instance_id($1)) { - $$->nd_aid = $1; + $1->nd_value = $3; + $$ = NEW_OP_ASGN_OR(gettable(vid), $1); + if (is_instance_id(vid)) { + $$->nd_aid = vid; } } else if ($2 == tANDOP) { - n->nd_value = $3; - $$ = NEW_OP_ASGN_AND(gettable($1), n); + $1->nd_value = $3; + $$ = NEW_OP_ASGN_AND(gettable(vid), $1); } else { - $$ = n; - $$->nd_value = call_op(gettable($1),$2,1,$3); + $$ = $1; + $$->nd_value = call_op(gettable(vid),$2,1,$3); } fixpos($$, $3); } @@ -770,24 +770,24 @@ arg : lhs '=' arg value_expr($3); $$ = node_assign($1, $3); } - | variable tOP_ASGN arg + | var_lhs tOP_ASGN arg { - NODE *n = assignable($1, 0); - if (n) { + ID vid = $1->nd_vid; + if ($1) { if ($2 == tOROP) { - n->nd_value = $3; - $$ = NEW_OP_ASGN_OR(gettable($1), n); - if (is_instance_id($1)) { - $$->nd_aid = $1; + $1->nd_value = $3; + $$ = NEW_OP_ASGN_OR(gettable(vid), $1); + if (is_instance_id(vid)) { + $$->nd_aid = vid; } } else if ($2 == tANDOP) { - n->nd_value = $3; - $$ = NEW_OP_ASGN_AND(gettable($1), n); + $1->nd_value = $3; + $$ = NEW_OP_ASGN_AND(gettable(vid), $1); } else { - $$ = n; - $$->nd_value = call_op(gettable($1),$2,1,$3); + $$ = $1; + $$->nd_value = call_op(gettable(vid),$2,1,$3); } fixpos($$, $3); } @@ -1798,6 +1798,11 @@ var_ref : variable $$ = gettable($1); } +var_lhs : variable + { + $$ = assignable($1); + } + backref : tNTH_REF | tBACK_REF @@ -4322,7 +4327,6 @@ gettable(id) return NEW_CONST(id); } else if (is_class_id(id)) { - if (in_single) return NEW_CVAR2(id); return NEW_CVAR(id); } rb_compile_error("identifier %s is not valid", rb_id2name(id)); @@ -4380,7 +4384,7 @@ assignable(id, val) return NEW_CDECL(id, val); } else if (is_class_id(id)) { - if (in_single) return NEW_CVASGN(id, val); + if (in_def || in_single) return NEW_CVASGN(id, val); return NEW_CVDECL(id, val); } else { -- cgit v1.2.3