зеркало из https://github.com/github/ruby.git
* parse.y (primary, brace_block): fix for line number.
* proc.c (rb_proc_location, rb_method_location): new methods {Proc,Method,UnboundMethod}#source_location. [ruby-core:18452] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19592 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
3e9276a538
Коммит
77a9d7c32f
|
@ -1,3 +1,10 @@
|
|||
Fri Sep 26 22:46:58 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* parse.y (primary, brace_block): fix for line number.
|
||||
|
||||
* proc.c (rb_proc_location, rb_method_location): new methods
|
||||
{Proc,Method,UnboundMethod}#source_location. [ruby-core:18452]
|
||||
|
||||
Fri Sep 26 21:36:33 2008 Koichi Sasada <ko1@atdot.net>
|
||||
|
||||
* vm_core.h (RUBY_VM_CHECK_INTS_TH): add an UNLIKELY hint.
|
||||
|
|
4
parse.y
4
parse.y
|
@ -2886,6 +2886,7 @@ primary : literal
|
|||
reduce_nodes(&body);
|
||||
$$ = NEW_DEFN($2, $4, body, NOEX_PRIVATE);
|
||||
fixpos($$, $4);
|
||||
fixpos($$->nd_defn, $4);
|
||||
local_pop();
|
||||
in_def--;
|
||||
cur_mid = $<id>3;
|
||||
|
@ -2913,6 +2914,7 @@ primary : literal
|
|||
reduce_nodes(&body);
|
||||
$$ = NEW_DEFS($2, $5, $7, body);
|
||||
fixpos($$, $2);
|
||||
fixpos($$->nd_defn, $2);
|
||||
local_pop();
|
||||
in_single--;
|
||||
/*%
|
||||
|
@ -3611,6 +3613,8 @@ brace_block : '{'
|
|||
/*%%%*/
|
||||
$$ = NEW_ITER($3,$4);
|
||||
nd_set_line($$, $<num>2);
|
||||
nd_set_line($$->nd_body, $<num>2);
|
||||
nd_set_line($$->nd_body->nd_body, $<num>2);
|
||||
dyna_pop();
|
||||
/*%
|
||||
$$ = dispatch2(brace_block, escape_Qundef($3), $4);
|
||||
|
|
61
proc.c
61
proc.c
|
@ -509,11 +509,11 @@ proc_call(int argc, VALUE *argv, VALUE procval)
|
|||
{
|
||||
rb_proc_t *proc;
|
||||
rb_block_t *blockptr = 0;
|
||||
rb_iseq_t *iseq;
|
||||
GetProcPtr(procval, proc);
|
||||
|
||||
if (BUILTIN_TYPE(proc->block.iseq) == T_NODE ||
|
||||
proc->block.iseq->arg_block != -1) {
|
||||
|
||||
iseq = proc->block.iseq;
|
||||
if (BUILTIN_TYPE(iseq) == T_NODE || iseq->arg_block != -1) {
|
||||
if (rb_block_given_p()) {
|
||||
rb_proc_t *proc;
|
||||
VALUE procval;
|
||||
|
@ -620,10 +620,9 @@ get_proc_iseq(VALUE self)
|
|||
return iseq;
|
||||
}
|
||||
|
||||
VALUE
|
||||
rb_proc_location(VALUE self)
|
||||
static VALUE
|
||||
iseq_location(rb_iseq_t *iseq)
|
||||
{
|
||||
rb_iseq_t *iseq = get_proc_iseq(self);
|
||||
VALUE loc[2];
|
||||
|
||||
if (!iseq) return Qnil;
|
||||
|
@ -637,6 +636,20 @@ rb_proc_location(VALUE self)
|
|||
return rb_ary_new4(2, loc);
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* prc.source_location => [String, Fixnum]
|
||||
*
|
||||
* returns the ruby source filename and line number containing this proc
|
||||
* or nil if this proc was not defined in ruby (i.e. native)
|
||||
*/
|
||||
|
||||
VALUE
|
||||
rb_proc_location(VALUE self)
|
||||
{
|
||||
return iseq_location(get_proc_iseq(self));
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* prc == other_proc => true or false
|
||||
|
@ -1437,6 +1450,39 @@ rb_obj_method_arity(VALUE obj, ID id)
|
|||
return rb_mod_method_arity(CLASS_OF(obj), id);
|
||||
}
|
||||
|
||||
static rb_iseq_t *
|
||||
get_method_iseq(VALUE method)
|
||||
{
|
||||
struct METHOD *data;
|
||||
NODE *body;
|
||||
rb_iseq_t *iseq;
|
||||
|
||||
Data_Get_Struct(method, struct METHOD, data);
|
||||
body = data->body;
|
||||
switch (nd_type(body)) {
|
||||
case RUBY_VM_METHOD_NODE:
|
||||
GetISeqPtr((VALUE)body->nd_body, iseq);
|
||||
if (RUBY_VM_NORMAL_ISEQ_P(iseq)) break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
return iseq;
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* meth.source_location => [String, Fixnum]
|
||||
*
|
||||
* returns the ruby source filename and line number containing this method
|
||||
* or nil if this method was not defined in ruby (i.e. native)
|
||||
*/
|
||||
|
||||
VALUE
|
||||
rb_method_location(VALUE method)
|
||||
{
|
||||
return iseq_location(get_method_iseq(method));
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* meth.to_s => string
|
||||
|
@ -1768,6 +1814,7 @@ Init_Proc(void)
|
|||
rb_define_method(rb_cProc, "lambda?", proc_lambda_p, 0);
|
||||
rb_define_method(rb_cProc, "binding", proc_binding, 0);
|
||||
rb_define_method(rb_cProc, "curry", proc_curry, -1);
|
||||
rb_define_method(rb_cProc, "source_location", rb_proc_location, 0);
|
||||
|
||||
/* Exceptions */
|
||||
rb_eLocalJumpError = rb_define_class("LocalJumpError", rb_eStandardError);
|
||||
|
@ -1802,6 +1849,7 @@ Init_Proc(void)
|
|||
rb_define_method(rb_cMethod, "name", method_name, 0);
|
||||
rb_define_method(rb_cMethod, "owner", method_owner, 0);
|
||||
rb_define_method(rb_cMethod, "unbind", method_unbind, 0);
|
||||
rb_define_method(rb_cMethod, "source_location", rb_method_location, 0);
|
||||
rb_define_method(rb_mKernel, "method", rb_obj_method, 1);
|
||||
rb_define_method(rb_mKernel, "public_method", rb_obj_public_method, 1);
|
||||
|
||||
|
@ -1819,6 +1867,7 @@ Init_Proc(void)
|
|||
rb_define_method(rb_cUnboundMethod, "name", method_name, 0);
|
||||
rb_define_method(rb_cUnboundMethod, "owner", method_owner, 0);
|
||||
rb_define_method(rb_cUnboundMethod, "bind", umethod_bind, 1);
|
||||
rb_define_method(rb_cUnboundMethod, "source_location", rb_method_location, 0);
|
||||
|
||||
/* Module#*_method */
|
||||
rb_define_method(rb_cModule, "instance_method", rb_mod_instance_method, 1);
|
||||
|
|
Загрузка…
Ссылка в новой задаче