Project

General

Profile

Backport #2180 ยป source_location.diff

nobu (Nobuyoshi Nakada), 10/07/2009 10:39 AM

View differences:

eval.c (working copy)
rb_raise(rb_eArgError, "argument needs to be symbol or string");
}
ruby_set_current_source();
len = strlen(name)+2;
buf = ALLOCA_N(char,len);
......
#define SET_CURRENT_SOURCE() ((void)0)
#endif
#define SET_CURRENT_NODE(node) (ruby_current_node = (node), SET_CURRENT_SOURCE())
void
......
ruby_sourcefile = rb_source_filename("(eval)");
v = eval(ruby_top_self, rb_str_new2(str), Qnil, 0, 0);
ruby_current_node = oldsrc;
SET_CURRENT_NODE(oldsrc);
return v;
......
NODE *rval;
{
NODE *copy = NEW_NODE(NODE_SCOPE,0,rval,node->nd_next);
NODE *copy = (ruby_set_current_source(), NEW_NODE(NODE_SCOPE,0,rval,node->nd_next));
if (node->nd_tbl) {
......
tracing = 0;
ruby_current_node = node_save;
SET_CURRENT_SOURCE();
SET_CURRENT_NODE(node_save);
if (state) JUMP_TAG(state);
}
......
if (!node) RETURN(Qnil);
ruby_current_node = node;
SET_CURRENT_NODE(node);
switch (nd_type(node)) {
case NODE_BLOCK:
......
recv = rb_eval(self, node->nd_iter);
END_CALLARGS;
ruby_current_node = node;
SET_CURRENT_SOURCE();
SET_CURRENT_NODE(node);
result = rb_call(CLASS_OF(recv),recv,each,0,0,0,self);
}
......
if (node->nd_head) {
result = rb_eval(self, node->nd_head);
ruby_current_node = node;
SET_CURRENT_NODE(node);
}
else {
result = Qundef; /* no arg */
}
SET_CURRENT_SOURCE();
result = rb_yield_0(result, 0, 0, 0, node->nd_state);
break;
......
rescuing = -1;
while (resq) {
ruby_current_node = resq;
SET_CURRENT_NODE(resq);
if (handle_rescue(self, resq)) {
state = 0;
......
END_CALLARGS;
ruby_current_node = node;
SET_CURRENT_SOURCE();
SET_CURRENT_NODE(node);
rb_call(CLASS_OF(recv),recv,node->nd_mid,argc,argv,scope,self);
result = argv[argc-1];
......
END_CALLARGS;
ruby_current_node = node;
SET_CURRENT_SOURCE();
SET_CURRENT_NODE(node);
result = rb_call(CLASS_OF(recv),recv,node->nd_mid,argc,argv,0,self);
}
......
END_CALLARGS;
ruby_current_node = node;
SET_CURRENT_SOURCE();
SET_CURRENT_NODE(node);
result = rb_call(CLASS_OF(self),self,node->nd_mid,argc,argv,1,self);
}
......
case NODE_VCALL:
SET_CURRENT_SOURCE();
result = rb_call(CLASS_OF(self),self,node->nd_mid,0,0,2,self);
break;
......
SETUP_ARGS(node->nd_args);
END_CALLARGS;
ruby_current_node = node;
SET_CURRENT_NODE(node);
}
SET_CURRENT_SOURCE();
result = rb_call_super(argc, argv);
}
......
rb_warn("multiple values for a block parameter (%d for 1)\n\tfrom %s:%d",
len, cnode->nd_file, nd_line(cnode));
ruby_current_node = cnode;
SET_CURRENT_NODE(cnode);
}
}
......
goto pop_state;
}
ruby_current_node = node;
SET_CURRENT_NODE(node);
PUSH_ITER(block->iter);
......
break;
}
ruby_current_node = cnode;
SET_CURRENT_NODE(cnode);
return result;
}
......
int pcall;
{
ruby_current_node = lhs;
SET_CURRENT_NODE(lhs);
if (val == Qundef) {
rb_warning("assigning void value");
......
if (!lhs->nd_args) {
/* attr set */
ruby_current_node = lhs;
SET_CURRENT_SOURCE();
SET_CURRENT_NODE(lhs);
rb_call(CLASS_OF(recv), recv, lhs->nd_mid, 1, &val, scope, self);
}
......
args = rb_eval(self, lhs->nd_args);
rb_ary_push(args, val);
ruby_current_node = lhs;
SET_CURRENT_SOURCE();
SET_CURRENT_NODE(lhs);
rb_call(CLASS_OF(recv), recv, lhs->nd_mid,
RARRAY(args)->len, RARRAY(args)->ptr, scope, self);
......
}
ruby_current_node = cnode;
SET_CURRENT_NODE(cnode);
{
int n = 0;
......
rb_raise(rb_eArgError, "wrong number of arguments (%d for 1)", argc);
}
ruby_set_current_source();
if (RDATA(body)->dmark == (RUBY_DATA_FUNC)bm_mark) {
node = NEW_DMETHOD(method_unbind(body));
......
/*
* 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)
{
struct BLOCK *data;
NODE *node;
Data_Get_Struct(self, struct BLOCK, data);
if ((node = data->frame.node) || (node = data->body)) {
const char *filename = node->nd_file;
int lineno = nd_line(node);
if (filename) {
return rb_assoc_new(rb_str_new2(filename), INT2FIX(lineno));
}
}
return Qnil;
}
/*
* 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)
{
struct METHOD *data;
NODE *node;
Data_Get_Struct(method, struct METHOD, data);
if (node = data->body) {
const char *filename = node->nd_file;
int lineno = nd_line(node);
if (filename) {
return rb_assoc_new(rb_str_new2(filename), INT2FIX(lineno));
}
}
return Qnil;
}
/*
* <code>Proc</code> objects are blocks of code that have been bound to
* a set of local variables. Once bound, the code may be called in
......
rb_define_method(rb_cProc, "to_proc", proc_to_self, 0);
rb_define_method(rb_cProc, "binding", proc_binding, 0);
rb_define_method(rb_cProc, "source_location", rb_proc_location, 0);
rb_define_global_function("proc", proc_lambda, 0);
......
rb_define_method(rb_cMethod, "unbind", method_unbind, 0);
rb_define_method(rb_mKernel, "method", rb_obj_method, 1);
rb_define_method(rb_cMethod, "source_location", rb_method_location, 0);
rb_cUnboundMethod = rb_define_class("UnboundMethod", rb_cObject);
......
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);
rb_define_method(rb_cModule, "instance_method", rb_mod_method, 1);
}
    (1-1/1)