diff options
Diffstat (limited to 'compile.c')
-rw-r--r-- | compile.c | 43 |
1 files changed, 25 insertions, 18 deletions
@@ -251,7 +251,7 @@ struct iseq_compile_data_ensure_node_stack { ADD_INSN2((seq), (line), trace2, INT2FIX(RUBY_EVENT_COVERAGE), INT2FIX(COVERAGE_INDEX_LINES)); \ } \ } while (0) -#define DECL_BRANCH_BASE(branches, line, type) \ +#define DECL_BRANCH_BASE(branches, line, column, type) \ do { \ if (ISEQ_COVERAGE(iseq) && \ ISEQ_BRANCH_COVERAGE(iseq) && \ @@ -261,9 +261,10 @@ struct iseq_compile_data_ensure_node_stack { rb_ary_push(structure, branches); \ rb_ary_push(branches, ID2SYM(rb_intern(type))); \ rb_ary_push(branches, INT2FIX(line)); \ + rb_ary_push(branches, INT2FIX(column)); \ } \ } while (0) -#define ADD_TRACE_BRANCH_COVERAGE(seq, line, type, branches) \ +#define ADD_TRACE_BRANCH_COVERAGE(seq, line, column, type, branches) \ do { \ if (ISEQ_COVERAGE(iseq) && \ ISEQ_BRANCH_COVERAGE(iseq) && \ @@ -273,6 +274,7 @@ struct iseq_compile_data_ensure_node_stack { rb_ary_push(counters, INT2FIX(0)); \ rb_ary_push(branches, ID2SYM(rb_intern(type))); \ rb_ary_push(branches, INT2FIX(line)); \ + rb_ary_push(branches, INT2FIX(column)); \ rb_ary_push(branches, INT2FIX(counter_idx)); \ ADD_INSN2((seq), (line), trace2, INT2FIX(RUBY_EVENT_COVERAGE), INT2FIX(counter_idx * 16 + COVERAGE_INDEX_BRANCHES)); \ } \ @@ -4258,6 +4260,7 @@ compile_if(rb_iseq_t *iseq, LINK_ANCHOR *const ret, NODE *node, int popped, cons NODE *node_else = type == NODE_IF ? node->nd_else : node->nd_body; const int line = nd_line(node); + const int column = nd_column(node); DECL_ANCHOR(cond_seq); DECL_ANCHOR(then_seq); DECL_ANCHOR(else_seq); @@ -4279,13 +4282,13 @@ compile_if(rb_iseq_t *iseq, LINK_ANCHOR *const ret, NODE *node, int popped, cons ADD_SEQ(ret, cond_seq); if (then_label->refcnt && else_label->refcnt) { - DECL_BRANCH_BASE(branches, line, type == NODE_IF ? "if" : "unless"); + DECL_BRANCH_BASE(branches, line, 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, type == NODE_IF ? "then" : "else", branches); + 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_SEQ(ret, then_seq); end_label = NEW_LABEL(line); @@ -4295,7 +4298,7 @@ compile_if(rb_iseq_t *iseq, LINK_ANCHOR *const ret, NODE *node, int popped, cons 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, type == NODE_IF ? "else" : "then", branches); + 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_SEQ(ret, else_seq); } @@ -4318,7 +4321,7 @@ compile_case(rb_iseq_t *iseq, LINK_ANCHOR *const ret, NODE *node, int popped) DECL_ANCHOR(cond_seq); int only_special_literals = 1; VALUE literals = rb_hash_new(); - int line; + int line, column; enum node_type type; VALUE branches = 0; @@ -4334,11 +4337,12 @@ compile_case(rb_iseq_t *iseq, LINK_ANCHOR *const ret, NODE *node, int popped) } CHECK(COMPILE(head, "case base", node->nd_head)); - DECL_BRANCH_BASE(branches, nd_line(node), "case"); + DECL_BRANCH_BASE(branches, nd_line(node), nd_column(node), "case"); node = node->nd_body; type = nd_type(node); line = nd_line(node); + column = nd_column(node); if (type != NODE_WHEN) { COMPILE_ERROR(ERROR_ARGS "NODE_CASE: unexpected node. must be NODE_WHEN, but %s", ruby_node_name(type)); @@ -4356,7 +4360,7 @@ compile_case(rb_iseq_t *iseq, LINK_ANCHOR *const ret, NODE *node, int popped) 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, "when", branches); + 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); CHECK(COMPILE_(body_seq, "when body", node->nd_body, popped)); ADD_INSNL(body_seq, line, jump, endlabel); @@ -4389,12 +4393,13 @@ compile_case(rb_iseq_t *iseq, LINK_ANCHOR *const ret, NODE *node, int popped) } type = nd_type(node); line = nd_line(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), "else", branches); + ADD_TRACE_BRANCH_COVERAGE(cond_seq, nd_line(node), nd_column(node), "else", branches); CHECK(COMPILE_(cond_seq, "else", node, popped)); ADD_INSNL(cond_seq, line, jump, endlabel); } @@ -4402,7 +4407,7 @@ compile_case(rb_iseq_t *iseq, LINK_ANCHOR *const ret, NODE *node, int popped) debugs("== else (implicit)\n"); ADD_LABEL(cond_seq, elselabel); ADD_INSN(cond_seq, nd_line(tempnode), pop); - ADD_TRACE_BRANCH_COVERAGE(cond_seq, nd_line(tempnode), "else", branches); + ADD_TRACE_BRANCH_COVERAGE(cond_seq, nd_line(tempnode), nd_column(tempnode), "else", branches); if (!popped) { ADD_INSN(cond_seq, nd_line(tempnode), putnil); } @@ -4433,16 +4438,17 @@ compile_when(rb_iseq_t *iseq, LINK_ANCHOR *const ret, NODE *node, int popped) DECL_ANCHOR(body_seq); VALUE branches = 0; - DECL_BRANCH_BASE(branches, nd_line(node), "case"); + DECL_BRANCH_BASE(branches, nd_line(node), nd_column(node), "case"); INIT_ANCHOR(body_seq); endlabel = NEW_LABEL(nd_line(node)); while (node && nd_type(node) == NODE_WHEN) { const int line = nd_line(node); + const int column = nd_column(node); LABEL *l1 = NEW_LABEL(line); ADD_LABEL(body_seq, l1); - ADD_TRACE_BRANCH_COVERAGE(body_seq, node->nd_body ? nd_line(node->nd_body) : line, "when", branches); + 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); CHECK(COMPILE_(body_seq, "when", node->nd_body, popped)); ADD_INSNL(body_seq, line, jump, endlabel); @@ -4474,7 +4480,7 @@ compile_when(rb_iseq_t *iseq, LINK_ANCHOR *const ret, NODE *node, int popped) node = node->nd_next; } /* else */ - ADD_TRACE_BRANCH_COVERAGE(ret, node ? nd_line(node) : nd_line(orig_node), "else", branches); + ADD_TRACE_BRANCH_COVERAGE(ret, node ? nd_line(node) : nd_line(orig_node), node ? nd_column(node) : nd_column(orig_node), "else", branches); CHECK(COMPILE_(ret, "else", node, popped)); ADD_INSNL(ret, nd_line(orig_node), jump, endlabel); @@ -4487,6 +4493,7 @@ static int compile_loop(rb_iseq_t *iseq, LINK_ANCHOR *const ret, NODE *node, int popped, const enum node_type type) { const int line = (int)nd_line(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; LABEL *prev_redo_label = ISEQ_COMPILE_DATA(iseq)->redo_label; @@ -4522,8 +4529,8 @@ compile_loop(rb_iseq_t *iseq, LINK_ANCHOR *const ret, NODE *node, int popped, co if (tmp_label) ADD_LABEL(ret, tmp_label); ADD_LABEL(ret, redo_label); - DECL_BRANCH_BASE(branches, line, type == NODE_WHILE ? "while" : "until"); - ADD_TRACE_BRANCH_COVERAGE(ret, node->nd_body ? nd_line(node->nd_body) : line, "body", branches); + 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); CHECK(COMPILE_POPPED(ret, "while body", node->nd_body)); ADD_LABEL(ret, next_label); /* next */ @@ -5723,10 +5730,10 @@ iseq_compile_each0(rb_iseq_t *iseq, LINK_ANCHOR *const ret, NODE *node, int popp else_label = NEW_LABEL(line); end_label = NEW_LABEL(line); - DECL_BRANCH_BASE(branches, nd_line(node), "&."); + DECL_BRANCH_BASE(branches, nd_line(node), nd_column(node), "&."); ADD_INSN(recv, line, dup); ADD_INSNL(recv, line, branchnil, else_label); - ADD_TRACE_BRANCH_COVERAGE(recv, nd_line(node), "then", branches); + ADD_TRACE_BRANCH_COVERAGE(recv, nd_line(node), nd_column(node), "then", branches); } } else if (type == NODE_FCALL || type == NODE_VCALL) { @@ -5761,7 +5768,7 @@ iseq_compile_each0(rb_iseq_t *iseq, LINK_ANCHOR *const ret, NODE *node, int popp 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), "else", branches); + ADD_TRACE_BRANCH_COVERAGE(ret, nd_line(node), nd_column(node), "else", branches); ADD_LABEL(ret, end_label); } if (popped) { |