[前][次][番号順一覧][スレッド一覧]

ruby-changes:16365

From: naruse <ko1@a...>
Date: Thu, 17 Jun 2010 10:04:28 +0900 (JST)
Subject: [ruby-changes:16365] Ruby:r28342 (trunk): Revert "* parse.y (warn_unused_var): warn unused variables."

naruse	2010-06-17 10:04:09 +0900 (Thu, 17 Jun 2010)

  New Revision: 28342

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=28342

  Log:
    Revert "* parse.y (warn_unused_var): warn unused variables."
    
    This reverts commit r28339 and r28340
    because they prevents test-all on boron.

  Modified files:
    trunk/ChangeLog
    trunk/parse.y
    trunk/test/ruby/test_rubyoptions.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 28341)
+++ ChangeLog	(revision 28342)
@@ -1,12 +1,3 @@
-Wed Jun 16 18:34:54 2010  NAKAMURA Usaku  <usa@r...>
-
-	* parse.y: ripper needs warn_unused_var(), too.
-
-Wed Jun 16 18:20:00 2010  Nobuyoshi Nakada  <nobu@r...>
-
-	* parse.y (warn_unused_var): warn unused variables.
-	  [ruby-dev:41620]
-
 Wed Jun 16 15:40:53 2010  NAKAMURA Usaku  <usa@r...>
 
 	* error.c (rb_bug): existance of _set_abort_behavior() depends on
Index: parse.y
===================================================================
--- parse.y	(revision 28341)
+++ parse.y	(revision 28342)
@@ -99,7 +99,6 @@
 struct local_vars {
     struct vtable *args;
     struct vtable *vars;
-    struct vtable *used;
     struct local_vars *prev;
 };
 
@@ -168,7 +167,7 @@
     if (POINTER_P(tbl)) {
         for (i = 0; i < tbl->pos; i++) {
             if (tbl->tbl[i] == id) {
-                return i+1;
+                return 1;
             }
         }
     }
@@ -8919,28 +8918,7 @@
 }
 #endif /* !RIPPER */
 
-#define LVAR_USED (1UL << (sizeof(ID) * CHAR_BIT - 1))
-
 static void
-warn_unused_var(struct parser_params *parser, struct local_vars *local)
-{
-    int i, cnt;
-    ID *v, *u;
-
-    if (!local->used) return;
-    v = local->vars->tbl;
-    u = local->used->tbl;
-    cnt = local->used->pos;
-    if (cnt != local->vars->pos) {
-	rb_bug("local->used->pos != local->vars->pos");
-    }
-    for (i = 0; i < cnt; ++i) {
-	if (!v[i] || (u[i] & LVAR_USED)) continue;
-	rb_compile_warn(ruby_sourcefile, (int)u[i], "assigned but unused variable %s", rb_id2name(v[i]));
-    }
-}
-
-static void
 local_push_gen(struct parser_params *parser, int inherit_dvars)
 {
     struct local_vars *local;
@@ -8949,7 +8927,6 @@
     local->prev = lvtbl;
     local->args = vtable_alloc(0);
     local->vars = vtable_alloc(inherit_dvars ? DVARS_INHERIT : DVARS_TOPSCOPE);
-    local->used = RTEST(ruby_verbose) ? vtable_alloc(0) : 0;
     lvtbl = local;
 }
 
@@ -8957,10 +8934,6 @@
 local_pop_gen(struct parser_params *parser)
 {
     struct local_vars *local = lvtbl->prev;
-    if (lvtbl->used) {
-	warn_unused_var(parser, lvtbl);
-	vtable_free(lvtbl->used);
-    }
     vtable_free(lvtbl->args);
     vtable_free(lvtbl->vars);
     xfree(lvtbl);
@@ -9009,37 +8982,28 @@
 local_var_gen(struct parser_params *parser, ID id)
 {
     vtable_add(lvtbl->vars, id);
-    if (lvtbl->used) {
-	vtable_add(lvtbl->used, (ID)ruby_sourceline);
-    }
     return vtable_size(lvtbl->vars) - 1;
 }
 
 static int
 local_id_gen(struct parser_params *parser, ID id)
 {
-    struct vtable *vars, *args, *used;
+    struct vtable *vars, *args;
 
     vars = lvtbl->vars;
     args = lvtbl->args;
-    used = lvtbl->used;
 
     while (vars && POINTER_P(vars->prev)) {
 	vars = vars->prev;
 	args = args->prev;
-	if (used) used = used->prev;
     }
 
     if (vars && vars->prev == DVARS_INHERIT) {
 	return rb_local_defined(id);
     }
-    else if (vtable_included(args, id)) {
-	return 1;
-    }
     else {
-	int i = vtable_included(vars, id);
-	if (i && used) used->tbl[i-1] |= LVAR_USED;
-	return i != 0;
+	return (vtable_included(args, id) ||
+		vtable_included(vars, id));
     }
 }
 
@@ -9048,9 +9012,6 @@
 {
     lvtbl->args = vtable_alloc(lvtbl->args);
     lvtbl->vars = vtable_alloc(lvtbl->vars);
-    if (lvtbl->used) {
-	lvtbl->used = vtable_alloc(lvtbl->used);
-    }
     return lvtbl->args;
 }
 
@@ -9059,11 +9020,6 @@
 {
     struct vtable *tmp;
 
-    if ((tmp = lvtbl->used) != 0) {
-	warn_unused_var(parser, lvtbl);
-	lvtbl->used = lvtbl->used->prev;
-	vtable_free(tmp);
-    }
     tmp = lvtbl->args;
     lvtbl->args = lvtbl->args->prev;
     vtable_free(tmp);
@@ -9095,24 +9051,20 @@
 static int
 dvar_defined_gen(struct parser_params *parser, ID id)
 {
-    struct vtable *vars, *args, *used;
-    int i;
+    struct vtable *vars, *args;
 
     args = lvtbl->args;
     vars = lvtbl->vars;
-    used = lvtbl->used;
 
     while (POINTER_P(vars)) {
 	if (vtable_included(args, id)) {
 	    return 1;
 	}
-	if ((i = vtable_included(vars, id)) != 0) {
-	    if (used) used->tbl[i-1] |= LVAR_USED;
+	if (vtable_included(vars, id)) {
 	    return 1;
 	}
 	args = args->prev;
 	vars = vars->prev;
-	if (used) used = used->prev;
     }
 
     if (vars == DVARS_INHERIT) {
Index: test/ruby/test_rubyoptions.rb
===================================================================
--- test/ruby/test_rubyoptions.rb	(revision 28341)
+++ test/ruby/test_rubyoptions.rb	(revision 28342)
@@ -415,10 +415,4 @@
   ensure
     t.close(true) if t
   end
-
-  def test_unused_variable
-    feature3446 = '[ruby-dev:41620]'
-    assert_in_out_err(["-we", "a=1"], "", [], ["-e:1: warning: assigned but unused variable a"], feature3446)
-    assert_in_out_err(["-we", "1.times do\n  a=1\nend"], "", [], ["-e:2: warning: assigned but unused variable a"], feature3446)
-  end
 end

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]