summaryrefslogtreecommitdiff
path: root/compile.c
diff options
context:
space:
mode:
authoryui-knk <yui-knk@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-10-30 23:44:42 +0000
committeryui-knk <yui-knk@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-10-30 23:44:42 +0000
commit4eb38bf59dced7836375c81ae41105edc4496f1c (patch)
treef67a94ae9d2bfc3d8c9e969cf3911204f0e532e6 /compile.c
parent7a42b03b0c1f7e8b8bd45f86eca723b0012b9118 (diff)
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 ``` git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60581 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'compile.c')
-rw-r--r--compile.c30
1 files changed, 17 insertions, 13 deletions
diff --git a/compile.c b/compile.c
index 80e0a5d023..b0a67e49ce 100644
--- a/compile.c
+++ b/compile.c
@@ -4334,6 +4334,7 @@ compile_if(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const node, int
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 *const ret, const NODE *const node, int
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 *const ret, const NODE *const node, int
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_ANCHOR *const ret, const NODE *const orig_nod
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_ANCHOR *const ret, const NODE *const orig_nod
}
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_ANCHOR *const ret, const NODE *const orig_nod
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_ANCHOR *const ret, const NODE *const orig_nod
}
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_ANCHOR *const ret, const NODE *const orig_nod
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
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_ANCHOR *const ret, const NODE *const node, in
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_ANCHOR *const ret, const NODE *node, in
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_ANCHOR *const ret, const NODE *node, in
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) {