[#20036] Re: Roundoff problem with Float and Marshal — matz@... (Yukihiro Matsumoto)

まつもと ゆきひろです

16 messages 2003/04/18
[#20045] Re: Roundoff problem with Float and Marshal — nobu.nakada@... 2003/04/20

なかだです。

[#20063] Re: Roundoff problem with Float and Marshal — matz@... (Yukihiro Matsumoto) 2003/04/22

まつもと ゆきひろです

[#20097] jcode.rb — akira yamada / やまだあきら <akira@...>

25 messages 2003/04/26
[#20098] Re: jcode.rb — matz@... (Yukihiro Matsumoto) 2003/04/27

まつもと ゆきひろです

[#20105] Re: jcode.rb — WATANABE Hirofumi <eban@...> 2003/04/28

わたなべです。

[#20108] Re: jcode.rb — matz@... (Yukihiro Matsumoto) 2003/04/28

まつもと ゆきひろです

[ruby-dev:20049] line number in warning

From: nobu.nakada@...
Date: 2003-04-21 07:02:06 UTC
List: ruby-dev #20049
なかだです。

パーザで出るwarningで表示される行番号が正しくないものがあります。
すでに作った構文木に対して遡って警告するときに、現在の行番号を
使ってしまってます。

$ ruby -v
ruby 1.8.0 (2003-04-20) [i686-linux]
$ ruby -w -e if -e 1 -e end
-e:3: warning: literal in condition
$ ruby -w -e if -e 1 -e '' -e end
-e:4: warning: literal in condition


Index: parse.y
===================================================================
RCS file: /pub/cvs/ruby/src/ruby/parse.y,v
retrieving revision 1.270
diff -u -2 -p -r1.270 parse.y
--- parse.y	19 Apr 2003 18:17:59 -0000	1.270
+++ parse.y	21 Apr 2003 06:55:10 -0000
@@ -4474,4 +4474,26 @@ fixpos(node, orig)
 }
 
+static void
+warning_to_node(node, mesg)
+    NODE *node;
+    const char *mesg;
+{
+    int line = ruby_sourceline;
+    ruby_sourceline = nd_line(node);
+    rb_warning(mesg);
+    ruby_sourceline = line;
+}
+
+static void
+warn_to_node(node, mesg)
+    NODE *node;
+    const char *mesg;
+{
+    int line = ruby_sourceline;
+    ruby_sourceline = nd_line(node);
+    rb_warn(mesg);
+    ruby_sourceline = line;
+}
+
 static NODE*
 block_append(head, tail)
@@ -4490,5 +4512,5 @@ block_append(head, tail)
       case NODE_LIT:
       case NODE_STR:
-	rb_warning("unused literal ignored");
+	warning_to_node(h, "unused literal ignored");
 	return tail;
       default:
@@ -4512,5 +4534,5 @@ block_append(head, tail)
 	  case NODE_REDO:
 	  case NODE_RETRY:
-	    rb_warning("statement not reached");
+	    warning_to_node(nd, "statement not reached");
 	    break;
 
@@ -4928,5 +4950,5 @@ value_expr0(node)
 	  case NODE_DEFN:
 	  case NODE_DEFS:
-	    rb_warning("void value expression");
+	    warning_to_node(node, "void value expression");
 	    return Qfalse;
 
@@ -5131,5 +5153,5 @@ assign_in_cond(node)
       case NODE_FALSE:
 	/* reports always */
-	rb_warn("found = in conditional, should be ==");
+	warn_to_node(node->nd_value, "found = in conditional, should be ==");
 	return 1;
 
@@ -5144,5 +5166,5 @@ assign_in_cond(node)
 #if 0
     if (assign_in_cond(node->nd_value) == 0) {
-	rb_warning("assignment in condition");
+	warning_to_node(node->nd_value, "assignment in condition");
     }
 #endif
@@ -5159,15 +5181,17 @@ e_option_supplied()
 
 static void
-warn_unless_e_option(str)
+warn_unless_e_option(node, str)
+    NODE *node;
     const char *str;
 {
-    if (!e_option_supplied()) rb_warn(str);
+    if (!e_option_supplied()) warn_to_node(node, str);
 }
 
 static void
-warning_unless_e_option(str)
+warning_unless_e_option(node, str)
+    NODE *node;
     const char *str;
 {
-    if (!e_option_supplied()) rb_warning(str);
+    if (!e_option_supplied()) warning_to_node(node, str);
 }
 
@@ -5191,5 +5215,5 @@ range_op(node)
     }
     if (type == NODE_LIT && FIXNUM_P(node->nd_lit)) {
-	warn_unless_e_option("integer literal in conditional range");
+	warn_unless_e_option(node, "integer literal in conditional range");
 	return call_op(node,tEQ,1,NEW_GVAR(rb_intern("$.")));
     }
@@ -5236,5 +5260,5 @@ cond0(node)
       case NODE_DREGX:
       case NODE_DREGX_ONCE:
-	warning_unless_e_option("regex literal in condition");
+	warning_unless_e_option(node, "regex literal in condition");
 	local_cnt('_');
 	local_cnt('~');
@@ -5258,5 +5282,5 @@ cond0(node)
 	    int e = literal_node(node->nd_end);
 	    if ((b == 1 && e == 1) || (b + e >= 2 && RTEST(ruby_verbose))) {
-		rb_warn("range literal in condition");
+		warn_to_node(node, "range literal in condition");
 	    }
 	}
@@ -5264,10 +5288,10 @@ cond0(node)
 
       case NODE_DSYM:
-	rb_warning("literal in condition");
+	warning_to_node(node, "literal in condition");
 	break;
 
       case NODE_LIT:
 	if (TYPE(node->nd_lit) == T_REGEXP) {
-	    warn_unless_e_option("regex literal in condition");
+	    warn_unless_e_option(node, "regex literal in condition");
 	    nd_set_type(node, NODE_MATCH);
 	    local_cnt('_');
@@ -5275,5 +5299,5 @@ cond0(node)
 	}
 	else {
-	    rb_warning("literal in condition");
+	    warning_to_node(node, "literal in condition");
 	}
       default:


-- 
--- 僕の前にBugはない。
--- 僕の後ろにBugはできる。
    中田 伸悦

In This Thread

Prev Next