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

ruby-changes:48467

From: yui-knk <ko1@a...>
Date: Tue, 31 Oct 2017 08:44:47 +0900 (JST)
Subject: [ruby-changes:48467] yui-knk:r60581 (trunk): Use nd_lineno instead of nd_line for branch coverages

yui-knk	2017-10-31 08:44:42 +0900 (Tue, 31 Oct 2017)

  New Revision: 60581

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=60581

  Log:
    Use nd_lineno instead of nd_line for branch coverages
    
    * compile.c (compile_if, compile_case, compile_loop, iseq_compile_each0):
      Use nd_lineno of nodes for branch coverages.
      nd_lineno is not adjusted line number of nodes.
      Sometimes nd_line is adjusted by fixpos. These
      adjustments lead to confusing result.
    
      For example, lineno of NODE_IF is 1, but
      line is 2 (line number is one-based).
    
      ```
      ;;;;;;;;;;;;;;;;;;;;if
        1 + 1
        2
      end
      ```

  Modified files:
    trunk/compile.c
Index: compile.c
===================================================================
--- compile.c	(revision 60580)
+++ compile.c	(revision 60581)
@@ -4334,6 +4334,7 @@ compile_if(rb_iseq_t *iseq, LINK_ANCHOR https://github.com/ruby/ruby/blob/trunk/compile.c#L4334
     const NODE *const node_else = type == NODE_IF ? node->nd_else : node->nd_body;
 
     const int line = nd_line(node);
+    const int lineno = nd_lineno(node);
     const int column = nd_column(node);
     DECL_ANCHOR(cond_seq);
     DECL_ANCHOR(then_seq);
@@ -4356,13 +4357,13 @@ compile_if(rb_iseq_t *iseq, LINK_ANCHOR https://github.com/ruby/ruby/blob/trunk/compile.c#L4357
     ADD_SEQ(ret, cond_seq);
 
     if (then_label->refcnt && else_label->refcnt) {
-	DECL_BRANCH_BASE(branches, line, column, type == NODE_IF ? "if" : "unless");
+	DECL_BRANCH_BASE(branches, lineno, column, type == NODE_IF ? "if" : "unless");
     }
 
     if (then_label->refcnt) {
 	ADD_LABEL(ret, then_label);
 	if (else_label->refcnt) {
-	    ADD_TRACE_BRANCH_COVERAGE(ret, node_body ? nd_line(node_body) : line, node_body ? nd_column(node_body) : column, type == NODE_IF ? "then" : "else", branches);
+	    ADD_TRACE_BRANCH_COVERAGE(ret, node_body ? nd_lineno(node_body) : lineno, node_body ? nd_column(node_body) : column, type == NODE_IF ? "then" : "else", branches);
 	}
 	ADD_SEQ(ret, then_seq);
 	end_label = NEW_LABEL(line);
@@ -4372,7 +4373,7 @@ compile_if(rb_iseq_t *iseq, LINK_ANCHOR https://github.com/ruby/ruby/blob/trunk/compile.c#L4373
     if (else_label->refcnt) {
 	ADD_LABEL(ret, else_label);
 	if (then_label->refcnt) {
-	    ADD_TRACE_BRANCH_COVERAGE(ret, node_else ? nd_line(node_else) : line, node_else ? nd_column(node_else) : column, type == NODE_IF ? "else" : "then", branches);
+	    ADD_TRACE_BRANCH_COVERAGE(ret, node_else ? nd_lineno(node_else) : lineno, node_else ? nd_column(node_else) : column, type == NODE_IF ? "else" : "then", branches);
 	}
 	ADD_SEQ(ret, else_seq);
     }
@@ -4395,7 +4396,7 @@ compile_case(rb_iseq_t *iseq, LINK_ANCHO https://github.com/ruby/ruby/blob/trunk/compile.c#L4396
     DECL_ANCHOR(cond_seq);
     int only_special_literals = 1;
     VALUE literals = rb_hash_new();
-    int line, column;
+    int line, lineno, column;
     enum node_type type;
     VALUE branches = 0;
 
@@ -4411,11 +4412,12 @@ compile_case(rb_iseq_t *iseq, LINK_ANCHO https://github.com/ruby/ruby/blob/trunk/compile.c#L4412
     }
     CHECK(COMPILE(head, "case base", node->nd_head));
 
-    DECL_BRANCH_BASE(branches, nd_line(node), nd_column(node), "case");
+    DECL_BRANCH_BASE(branches, nd_lineno(node), nd_column(node), "case");
 
     node = node->nd_body;
     type = nd_type(node);
     line = nd_line(node);
+    lineno = nd_lineno(node);
     column = nd_column(node);
 
     if (type != NODE_WHEN) {
@@ -4434,7 +4436,7 @@ compile_case(rb_iseq_t *iseq, LINK_ANCHO https://github.com/ruby/ruby/blob/trunk/compile.c#L4436
 	l1 = NEW_LABEL(line);
 	ADD_LABEL(body_seq, l1);
 	ADD_INSN(body_seq, line, pop);
-	ADD_TRACE_BRANCH_COVERAGE(body_seq, node->nd_body ? nd_line(node->nd_body) : line, node->nd_body ? nd_column(node->nd_body) : column, "when", branches);
+	ADD_TRACE_BRANCH_COVERAGE(body_seq, node->nd_body ? nd_lineno(node->nd_body) : lineno, node->nd_body ? nd_column(node->nd_body) : column, "when", branches);
 	CHECK(COMPILE_(body_seq, "when body", node->nd_body, popped));
 	ADD_INSNL(body_seq, line, jump, endlabel);
 
@@ -4467,13 +4469,14 @@ compile_case(rb_iseq_t *iseq, LINK_ANCHO https://github.com/ruby/ruby/blob/trunk/compile.c#L4469
 	}
 	type = nd_type(node);
 	line = nd_line(node);
+	lineno = nd_lineno(node);
 	column = nd_column(node);
     }
     /* else */
     if (node) {
 	ADD_LABEL(cond_seq, elselabel);
 	ADD_INSN(cond_seq, line, pop);
-	ADD_TRACE_BRANCH_COVERAGE(cond_seq, nd_line(node), nd_column(node), "else", branches);
+	ADD_TRACE_BRANCH_COVERAGE(cond_seq, nd_lineno(node), nd_column(node), "else", branches);
 	CHECK(COMPILE_(cond_seq, "else", node, popped));
 	ADD_INSNL(cond_seq, line, jump, endlabel);
     }
@@ -4481,7 +4484,7 @@ compile_case(rb_iseq_t *iseq, LINK_ANCHO https://github.com/ruby/ruby/blob/trunk/compile.c#L4484
 	debugs("== else (implicit)\n");
 	ADD_LABEL(cond_seq, elselabel);
 	ADD_INSN(cond_seq, nd_line(orig_node), pop);
-	ADD_TRACE_BRANCH_COVERAGE(cond_seq, nd_line(orig_node), nd_column(orig_node), "else", branches);
+	ADD_TRACE_BRANCH_COVERAGE(cond_seq, nd_lineno(orig_node), nd_column(orig_node), "else", branches);
 	if (!popped) {
 	    ADD_INSN(cond_seq, nd_line(orig_node), putnil);
 	}
@@ -4567,6 +4570,7 @@ static int https://github.com/ruby/ruby/blob/trunk/compile.c#L4570
 compile_loop(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const node, int popped, const enum node_type type)
 {
     const int line = (int)nd_line(node);
+    const int lineno = nd_lineno(node);
     const int column = nd_column(node);
     LABEL *prev_start_label = ISEQ_COMPILE_DATA(iseq)->start_label;
     LABEL *prev_end_label = ISEQ_COMPILE_DATA(iseq)->end_label;
@@ -4603,8 +4607,8 @@ compile_loop(rb_iseq_t *iseq, LINK_ANCHO https://github.com/ruby/ruby/blob/trunk/compile.c#L4607
     if (tmp_label) ADD_LABEL(ret, tmp_label);
 
     ADD_LABEL(ret, redo_label);
-    DECL_BRANCH_BASE(branches, line, column, type == NODE_WHILE ? "while" : "until");
-    ADD_TRACE_BRANCH_COVERAGE(ret, node->nd_body ? nd_line(node->nd_body) : line, node->nd_body ? nd_column(node->nd_body) : column, "body", branches);
+    DECL_BRANCH_BASE(branches, lineno, column, type == NODE_WHILE ? "while" : "until");
+    ADD_TRACE_BRANCH_COVERAGE(ret, node->nd_body ? nd_lineno(node->nd_body) : lineno, node->nd_body ? nd_column(node->nd_body) : column, "body", branches);
     CHECK(COMPILE_POPPED(ret, "while body", node->nd_body));
     ADD_LABEL(ret, next_label);	/* next */
 
@@ -5795,10 +5799,10 @@ iseq_compile_each0(rb_iseq_t *iseq, LINK https://github.com/ruby/ruby/blob/trunk/compile.c#L5799
 		else_label = NEW_LABEL(line);
 		end_label = NEW_LABEL(line);
 
-		DECL_BRANCH_BASE(branches, nd_line(node), nd_column(node), "&.");
+		DECL_BRANCH_BASE(branches, nd_lineno(node), nd_column(node), "&.");
 		ADD_INSN(recv, line, dup);
 		ADD_INSNL(recv, line, branchnil, else_label);
-		ADD_TRACE_BRANCH_COVERAGE(recv, nd_line(node), nd_column(node), "then", branches);
+		ADD_TRACE_BRANCH_COVERAGE(recv, nd_lineno(node), nd_column(node), "then", branches);
 	    }
 	}
 	else if (type == NODE_FCALL || type == NODE_VCALL) {
@@ -5833,7 +5837,7 @@ iseq_compile_each0(rb_iseq_t *iseq, LINK https://github.com/ruby/ruby/blob/trunk/compile.c#L5837
 	if (else_label && end_label) {
 	    ADD_INSNL(ret, line, jump, end_label);
 	    ADD_LABEL(ret, else_label);
-	    ADD_TRACE_BRANCH_COVERAGE(ret, nd_line(node), nd_column(node), "else", branches);
+	    ADD_TRACE_BRANCH_COVERAGE(ret, nd_lineno(node), nd_column(node), "else", branches);
 	    ADD_LABEL(ret, end_label);
 	}
 	if (popped) {

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

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