From 5874de95e8df1d051001cf53614c1d245c1ac5ae Mon Sep 17 00:00:00 2001 From: mame Date: Tue, 1 Jul 2008 16:55:30 +0000 Subject: * Add coverage measurement constant COVERAGE__. This constant is not for casual use. Usage: (1) assign {} to COVERAGE__, (2) require or load Ruby source file, and (3) COVERAGE__["sourcefilepath"] will return an array whose elements represent number of executions per line of source code. * vm_core.h: add field of coverage array to iseq. * iseq.c (prepare_iseq_build): ditto. * insns.def (trace): update coverage array. * parse.y (coverage): create and initialize coverage array. * compile.h (ADD_TRACE): add trace instruction to update covearge array. * thread.c (clear_coverage): delete coverage array when forking. Otherwise, double count of coverage may occur. * lib/coverage.rb: sample coverage measurement tool. * error.c: distinguish explicitly between parse_in_eval and mild_compile_error. * load.c: ditto. * vm_eval.c: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@17781 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- iseq.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'iseq.c') diff --git a/iseq.c b/iseq.c index b2a3237f0b..8339073eb9 100644 --- a/iseq.c +++ b/iseq.c @@ -81,6 +81,7 @@ iseq_mark(void *ptr) RUBY_MARK_UNLESS_NULL(iseq->filename); RUBY_MARK_UNLESS_NULL((VALUE)iseq->cref_stack); RUBY_MARK_UNLESS_NULL(iseq->klass); + RUBY_MARK_UNLESS_NULL(iseq->coverage); /* RUBY_MARK_UNLESS_NULL((VALUE)iseq->node); */ /* RUBY_MARK_UNLESS_NULL(iseq->cached_special_block); */ @@ -191,6 +192,17 @@ prepare_iseq_build(rb_iseq_t *iseq, set_relation(iseq, parent); + iseq->coverage = Qfalse; + if (!GET_THREAD()->parse_in_eval) { + if (rb_const_defined_at(rb_cObject, rb_intern("COVERAGE__"))) { + VALUE hash = rb_const_get_at(rb_cObject, rb_intern("COVERAGE__")); + if (TYPE(hash) == T_HASH) { + iseq->coverage = rb_hash_aref(hash, filename); + if (NIL_P(iseq->coverage)) iseq->coverage = Qfalse; + } + } + } + return Qtrue; } -- cgit v1.2.3