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
This commit is contained in:
mame 2018-08-22 10:38:56 +00:00
Родитель 52bd0d1900
Коммит d65f7458bc
6 изменённых файлов: 13 добавлений и 31 удалений

Просмотреть файл

@ -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,

8
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);
}

1
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;

24
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);

Просмотреть файл

@ -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]'

1
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);