summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-08-22 10:38:56 +0000
committermame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-08-22 10:38:56 +0000
commitd65f7458bc8b4fa4404c41713cfa1ece5260fc8a (patch)
treeedb94c2a2caf7c5727b9b2f87a94db94d8669321
parent52bd0d190042f739a80e76f43e7ef3cbc8ae0969 (diff)
parse.y: remove coverage-related code fragments
The code fragments that initializes coverage data were scattered into both parse.y and compile.c. parse.y allocated a coverage data, and compile.c initialize the data. To remove this cross-cutting concern, this change moves the allocation from "coverage" function of parse.y to "rb_iseq_new_top" of iseq.c. For the sake, parse.y just counts the line number of the original source code, and the number is passed via rb_ast_body_t. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64508 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--compile.c1
-rw-r--r--iseq.c8
-rw-r--r--node.h1
-rw-r--r--parse.y24
-rw-r--r--test/coverage/test_coverage.rb9
-rw-r--r--vm.c1
6 files changed, 13 insertions, 31 deletions
diff --git a/compile.c b/compile.c
index 2788372..c424092 100644
--- a/compile.c
+++ b/compile.c
@@ -1244,6 +1244,7 @@ new_child_iseq(rb_iseq_t *iseq, const NODE *const node,
ast.root = node;
ast.compile_option = 0;
+ ast.line_count = -1;
debugs("[new_child_iseq]> ---------------------------------------\n");
ret_iseq = rb_iseq_new_with_opt(&ast, name,
diff --git a/iseq.c b/iseq.c
index 935c69d..04b55bb 100644
--- a/iseq.c
+++ b/iseq.c
@@ -647,6 +647,14 @@ rb_iseq_new(const rb_ast_body_t *ast, VALUE name, VALUE path, VALUE realpath,
rb_iseq_t *
rb_iseq_new_top(const rb_ast_body_t *ast, VALUE name, VALUE path, VALUE realpath, const rb_iseq_t *parent)
{
+ VALUE coverages = rb_get_coverages();
+ if (RTEST(coverages)) {
+ if (ast->line_count >= 0) {
+ VALUE coverage = rb_default_coverage(ast->line_count);
+ rb_hash_aset(coverages, path, coverage);
+ }
+ }
+
return rb_iseq_new_with_opt(ast, name, path, realpath, INT2FIX(0), parent, ISEQ_TYPE_TOP,
&COMPILE_OPTION_DEFAULT);
}
diff --git a/node.h b/node.h
index 4040d07..fefb15f 100644
--- a/node.h
+++ b/node.h
@@ -470,6 +470,7 @@ typedef struct node_buffer_struct node_buffer_t;
typedef struct rb_ast_body_struct {
const NODE *root;
VALUE compile_option;
+ int line_count;
} rb_ast_body_t;
typedef struct rb_ast_struct {
VALUE flags;
diff --git a/parse.y b/parse.y
index 94f6276..9971ba0 100644
--- a/parse.y
+++ b/parse.y
@@ -266,7 +266,6 @@ struct parser_params {
NODE *eval_tree;
VALUE error_buffer;
VALUE debug_lines;
- VALUE coverage;
const struct rb_block *base_block;
#else
/* Ripper only */
@@ -4845,21 +4844,6 @@ debug_lines(VALUE fname)
return 0;
}
-static VALUE
-coverage(VALUE fname, int n)
-{
- VALUE coverages = rb_get_coverages();
- if (RTEST(coverages) && RBASIC(coverages)->klass == 0) {
- VALUE coverage = rb_default_coverage(n);
- VALUE lines = RARRAY_AREF(coverage, COVERAGE_INDEX_LINES);
-
- rb_hash_aset(coverages, fname, coverage);
-
- return lines == Qnil ? Qfalse : lines;
- }
- return 0;
-}
-
static int
e_option_supplied(struct parser_params *p)
{
@@ -4885,7 +4869,6 @@ yycompile0(VALUE arg)
}
if (!e_option_supplied(p)) {
- p->coverage = coverage(p->ruby_sourcefile_string, p->ruby_sourceline);
cov = Qtrue;
}
}
@@ -4899,7 +4882,6 @@ yycompile0(VALUE arg)
n = yyparse(p);
RUBY_DTRACE_PARSE_HOOK(END);
p->debug_lines = 0;
- p->coverage = 0;
p->lex.strterm = 0;
p->lex.pcur = p->lex.pbeg = p->lex.pend = 0;
@@ -4928,6 +4910,7 @@ yycompile0(VALUE arg)
p->ast->body.compile_option = opt;
}
p->ast->body.root = tree;
+ p->ast->body.line_count = p->line_count;
return TRUE;
}
@@ -4989,10 +4972,8 @@ lex_getline(struct parser_params *p)
rb_enc_associate(line, p->enc);
rb_ary_push(p->debug_lines, line);
}
- if (p->coverage) {
- rb_ary_push(p->coverage, Qnil);
- }
#endif
+ p->line_count++;
return line;
}
@@ -5173,7 +5154,6 @@ nextline(struct parser_params *p)
p->heredoc_end = 0;
}
p->ruby_sourceline++;
- p->line_count++;
p->lex.pbeg = p->lex.pcur = RSTRING_PTR(v);
p->lex.pend = p->lex.pcur + RSTRING_LEN(v);
token_flush(p);
diff --git a/test/coverage/test_coverage.rb b/test/coverage/test_coverage.rb
index 940f5d3..0b150b8 100644
--- a/test/coverage/test_coverage.rb
+++ b/test/coverage/test_coverage.rb
@@ -127,15 +127,6 @@ class TestCoverage < Test::Unit::TestCase
}
end
- def test_nonpositive_linenumber
- bug12517 = '[ruby-core:76141] [Bug #12517]'
- assert_in_out_err(%w[-W0 -rcoverage], <<-"end;", ['{"<compiled>"=>[nil]}'], [], bug12517)
- Coverage.start
- RubyVM::InstructionSequence.compile(":ok", nil, "<compiled>", 0)
- p Coverage.result
- end;
- end
-
def test_eval
bug13305 = '[ruby-core:80079] [Bug #13305]'
diff --git a/vm.c b/vm.c
index b43a30e..5c33cfb 100644
--- a/vm.c
+++ b/vm.c
@@ -970,6 +970,7 @@ rb_binding_add_dynavars(VALUE bindval, rb_binding_t *bind, int dyncount, const I
rb_node_init(&tmp_node, NODE_SCOPE, (VALUE)dyns, 0, 0);
ast.root = &tmp_node;
ast.compile_option = 0;
+ ast.line_count = -1;
if (base_iseq) {
iseq = rb_iseq_new(&ast, base_iseq->body->location.label, path, realpath, base_iseq, ISEQ_TYPE_EVAL);