mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Mon Jan 19 14:06:13 JST 1998
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/v1_1r@23 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
d556e58fc0
commit
5c47ddf9e7
14 changed files with 316 additions and 160 deletions
133
variable.c
133
variable.c
|
@ -97,14 +97,14 @@ fc_i(key, value, res)
|
|||
}
|
||||
|
||||
static VALUE
|
||||
find_class_path(cls)
|
||||
VALUE cls;
|
||||
find_class_path(klass)
|
||||
VALUE klass;
|
||||
{
|
||||
struct fc_result arg;
|
||||
|
||||
arg.name = 0;
|
||||
arg.path = 0;
|
||||
arg.klass = cls;
|
||||
arg.klass = klass;
|
||||
arg.track = cObject;
|
||||
arg.prev = 0;
|
||||
if (RCLASS(cObject)->iv_tbl) {
|
||||
|
@ -114,30 +114,30 @@ find_class_path(cls)
|
|||
st_foreach(class_tbl, fc_i, &arg);
|
||||
}
|
||||
if (arg.name) {
|
||||
rb_iv_set(cls, "__classpath__", arg.path);
|
||||
rb_iv_set(klass, "__classpath__", arg.path);
|
||||
return arg.path;
|
||||
}
|
||||
return Qnil;
|
||||
}
|
||||
|
||||
static VALUE
|
||||
classname(cls)
|
||||
VALUE cls;
|
||||
classname(klass)
|
||||
VALUE klass;
|
||||
{
|
||||
VALUE path;
|
||||
|
||||
while (TYPE(cls) == T_ICLASS || FL_TEST(cls, FL_SINGLETON)) {
|
||||
cls = (VALUE)RCLASS(cls)->super;
|
||||
while (TYPE(klass) == T_ICLASS || FL_TEST(klass, FL_SINGLETON)) {
|
||||
klass = (VALUE)RCLASS(klass)->super;
|
||||
}
|
||||
path = rb_iv_get(cls, "__classpath__");
|
||||
path = rb_iv_get(klass, "__classpath__");
|
||||
if (NIL_P(path)) {
|
||||
path = rb_iv_get(cls, "__classid__");
|
||||
path = rb_iv_get(klass, "__classid__");
|
||||
if (!NIL_P(path)) {
|
||||
path = str_new2(rb_id2name(FIX2INT(path)));
|
||||
}
|
||||
}
|
||||
if (NIL_P(path)) {
|
||||
path = find_class_path(cls);
|
||||
path = find_class_path(klass);
|
||||
if (NIL_P(path)) {
|
||||
return 0;
|
||||
}
|
||||
|
@ -158,25 +158,25 @@ mod_name(mod)
|
|||
}
|
||||
|
||||
VALUE
|
||||
rb_class_path(cls)
|
||||
VALUE cls;
|
||||
rb_class_path(klass)
|
||||
VALUE klass;
|
||||
{
|
||||
VALUE path = classname(cls);
|
||||
VALUE path = classname(klass);
|
||||
|
||||
if (path) return path;
|
||||
else {
|
||||
char buf[256];
|
||||
char *s = "Class";
|
||||
|
||||
if (TYPE(cls) == T_MODULE) s = "Module";
|
||||
sprintf(buf, "#<%s 0x%x>", s, cls);
|
||||
if (TYPE(klass) == T_MODULE) s = "Module";
|
||||
sprintf(buf, "#<%s 0x%x>", s, klass);
|
||||
return str_new2(buf);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
rb_set_class_path(cls, under, name)
|
||||
VALUE cls, under;
|
||||
rb_set_class_path(klass, under, name)
|
||||
VALUE klass, under;
|
||||
char *name;
|
||||
{
|
||||
VALUE str;
|
||||
|
@ -189,7 +189,7 @@ rb_set_class_path(cls, under, name)
|
|||
str_cat(str, "::", 2);
|
||||
str_cat(str, name, strlen(name));
|
||||
}
|
||||
rb_iv_set(cls, "__classpath__", str);
|
||||
rb_iv_set(klass, "__classpath__", str);
|
||||
}
|
||||
|
||||
VALUE
|
||||
|
@ -203,17 +203,17 @@ rb_path2class(path)
|
|||
}
|
||||
|
||||
void
|
||||
rb_name_class(cls, id)
|
||||
VALUE cls;
|
||||
rb_name_class(klass, id)
|
||||
VALUE klass;
|
||||
ID id;
|
||||
{
|
||||
extern VALUE cString;
|
||||
|
||||
if (cString) {
|
||||
rb_iv_set(cls, "__classpath__", str_new2(rb_id2name(id)));
|
||||
rb_iv_set(klass, "__classpath__", str_new2(rb_id2name(id)));
|
||||
}
|
||||
else {
|
||||
rb_iv_set(cls, "__classid__", INT2FIX(id));
|
||||
rb_iv_set(klass, "__classid__", INT2FIX(id));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -235,17 +235,17 @@ rb_autoload_id(id, filename)
|
|||
}
|
||||
|
||||
void
|
||||
rb_autoload(cls, filename)
|
||||
char *cls, *filename;
|
||||
rb_autoload(klass, filename)
|
||||
char *klass, *filename;
|
||||
{
|
||||
rb_autoload_id(rb_intern(cls), filename);
|
||||
rb_autoload_id(rb_intern(klass), filename);
|
||||
}
|
||||
|
||||
VALUE
|
||||
f_autoload(obj, cls, file)
|
||||
VALUE obj, cls, file;
|
||||
f_autoload(obj, klass, file)
|
||||
VALUE obj, klass, file;
|
||||
{
|
||||
ID id = rb_to_id(cls);
|
||||
ID id = rb_to_id(klass);
|
||||
|
||||
Check_Type(file, T_STRING);
|
||||
rb_autoload_id(id, RSTRING(file)->ptr);
|
||||
|
@ -253,10 +253,10 @@ f_autoload(obj, cls, file)
|
|||
}
|
||||
|
||||
char *
|
||||
rb_class2name(cls)
|
||||
VALUE cls;
|
||||
rb_class2name(klass)
|
||||
VALUE klass;
|
||||
{
|
||||
return RSTRING(rb_class_path(cls))->ptr;
|
||||
return RSTRING(rb_class_path(klass))->ptr;
|
||||
}
|
||||
|
||||
struct trace_var {
|
||||
|
@ -702,7 +702,6 @@ rb_ivar_get(obj, id)
|
|||
case T_OBJECT:
|
||||
case T_CLASS:
|
||||
case T_MODULE:
|
||||
case T_FILE:
|
||||
if (ROBJECT(obj)->iv_tbl && st_lookup(ROBJECT(obj)->iv_tbl, id, &val))
|
||||
return val;
|
||||
return Qnil;
|
||||
|
@ -729,7 +728,6 @@ rb_ivar_set(obj, id, val)
|
|||
case T_OBJECT:
|
||||
case T_CLASS:
|
||||
case T_MODULE:
|
||||
case T_FILE:
|
||||
if (!ROBJECT(obj)->iv_tbl) ROBJECT(obj)->iv_tbl = new_idhash();
|
||||
st_insert(ROBJECT(obj)->iv_tbl, id, val);
|
||||
break;
|
||||
|
@ -752,7 +750,6 @@ rb_ivar_defined(obj, id)
|
|||
case T_OBJECT:
|
||||
case T_CLASS:
|
||||
case T_MODULE:
|
||||
case T_FILE:
|
||||
if (ROBJECT(obj)->iv_tbl && st_lookup(ROBJECT(obj)->iv_tbl, id, 0))
|
||||
return TRUE;
|
||||
break;
|
||||
|
@ -782,7 +779,6 @@ obj_instance_variables(obj)
|
|||
case T_OBJECT:
|
||||
case T_CLASS:
|
||||
case T_MODULE:
|
||||
case T_FILE:
|
||||
if (ROBJECT(obj)->iv_tbl) {
|
||||
st_foreach(ROBJECT(obj)->iv_tbl, ivar_i, hash);
|
||||
}
|
||||
|
@ -808,7 +804,6 @@ obj_remove_instance_variable(obj, name)
|
|||
case T_OBJECT:
|
||||
case T_CLASS:
|
||||
case T_MODULE:
|
||||
case T_FILE:
|
||||
if (ROBJECT(obj)->iv_tbl) {
|
||||
st_delete(ROBJECT(obj)->iv_tbl, &id, &val);
|
||||
}
|
||||
|
@ -822,41 +817,41 @@ obj_remove_instance_variable(obj, name)
|
|||
}
|
||||
|
||||
VALUE
|
||||
rb_const_get_at(cls, id)
|
||||
VALUE cls;
|
||||
rb_const_get_at(klass, id)
|
||||
VALUE klass;
|
||||
ID id;
|
||||
{
|
||||
VALUE value;
|
||||
|
||||
if (RCLASS(cls)->iv_tbl && st_lookup(RCLASS(cls)->iv_tbl, id, &value)) {
|
||||
if (RCLASS(klass)->iv_tbl && st_lookup(RCLASS(klass)->iv_tbl, id, &value)) {
|
||||
return value;
|
||||
}
|
||||
if (cls == cObject) {
|
||||
return rb_const_get(cls, id);
|
||||
if (klass == cObject) {
|
||||
return rb_const_get(klass, id);
|
||||
}
|
||||
NameError("Uninitialized constant %s::%s",
|
||||
RSTRING(rb_class_path(cls))->ptr,
|
||||
RSTRING(rb_class_path(klass))->ptr,
|
||||
rb_id2name(id));
|
||||
/* not reached */
|
||||
}
|
||||
|
||||
|
||||
VALUE
|
||||
rb_const_get(cls, id)
|
||||
VALUE cls;
|
||||
rb_const_get(klass, id)
|
||||
VALUE klass;
|
||||
ID id;
|
||||
{
|
||||
VALUE value;
|
||||
VALUE tmp;
|
||||
|
||||
tmp = cls;
|
||||
tmp = klass;
|
||||
while (tmp) {
|
||||
if (RCLASS(tmp)->iv_tbl && st_lookup(RCLASS(tmp)->iv_tbl,id,&value)) {
|
||||
return value;
|
||||
}
|
||||
tmp = RCLASS(tmp)->super;
|
||||
}
|
||||
if (BUILTIN_TYPE(cls) == T_MODULE) {
|
||||
if (BUILTIN_TYPE(klass) == T_MODULE) {
|
||||
return rb_const_get(cObject, id);
|
||||
}
|
||||
|
||||
|
@ -872,13 +867,13 @@ rb_const_get(cls, id)
|
|||
module = str_new2(modname);
|
||||
free(modname);
|
||||
f_require(0, module);
|
||||
return rb_const_get(cls, id);
|
||||
return rb_const_get(klass, id);
|
||||
}
|
||||
|
||||
/* Uninitialized constant */
|
||||
if (cls && cls != cObject)
|
||||
if (klass && klass != cObject)
|
||||
NameError("Uninitialized constant %s::%s",
|
||||
RSTRING(rb_class_path(cls))->ptr,
|
||||
RSTRING(rb_class_path(klass))->ptr,
|
||||
rb_id2name(id));
|
||||
else {
|
||||
NameError("Uninitialized constant %s",rb_id2name(id));
|
||||
|
@ -952,15 +947,15 @@ mod_const_of(mod, ary)
|
|||
}
|
||||
|
||||
int
|
||||
rb_const_defined_at(cls, id)
|
||||
VALUE cls;
|
||||
rb_const_defined_at(klass, id)
|
||||
VALUE klass;
|
||||
ID id;
|
||||
{
|
||||
if (RCLASS(cls)->iv_tbl && st_lookup(RCLASS(cls)->iv_tbl, id, 0)) {
|
||||
if (RCLASS(klass)->iv_tbl && st_lookup(RCLASS(klass)->iv_tbl, id, 0)) {
|
||||
return TRUE;
|
||||
}
|
||||
if (cls == cObject) {
|
||||
return rb_const_defined(cls, id);
|
||||
if (klass == cObject) {
|
||||
return rb_const_defined(klass, id);
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
@ -975,15 +970,15 @@ rb_autoload_defined(id)
|
|||
}
|
||||
|
||||
int
|
||||
rb_const_defined(cls, id)
|
||||
VALUE cls;
|
||||
rb_const_defined(klass, id)
|
||||
VALUE klass;
|
||||
ID id;
|
||||
{
|
||||
while (cls) {
|
||||
if (RCLASS(cls)->iv_tbl && st_lookup(RCLASS(cls)->iv_tbl, id, 0)) {
|
||||
while (klass) {
|
||||
if (RCLASS(klass)->iv_tbl && st_lookup(RCLASS(klass)->iv_tbl, id, 0)) {
|
||||
return TRUE;
|
||||
}
|
||||
cls = RCLASS(cls)->super;
|
||||
klass = RCLASS(klass)->super;
|
||||
}
|
||||
if (st_lookup(class_tbl, id, 0))
|
||||
return TRUE;
|
||||
|
@ -991,24 +986,24 @@ rb_const_defined(cls, id)
|
|||
}
|
||||
|
||||
void
|
||||
rb_const_set(cls, id, val)
|
||||
VALUE cls;
|
||||
rb_const_set(klass, id, val)
|
||||
VALUE klass;
|
||||
ID id;
|
||||
VALUE val;
|
||||
{
|
||||
if (!RCLASS(cls)->iv_tbl) {
|
||||
RCLASS(cls)->iv_tbl = new_idhash();
|
||||
if (!RCLASS(klass)->iv_tbl) {
|
||||
RCLASS(klass)->iv_tbl = new_idhash();
|
||||
}
|
||||
else if (st_lookup(RCLASS(cls)->iv_tbl, id, 0)) {
|
||||
else if (st_lookup(RCLASS(klass)->iv_tbl, id, 0)) {
|
||||
NameError("already initialized constant %s", rb_id2name(id));
|
||||
}
|
||||
|
||||
st_insert(RCLASS(cls)->iv_tbl, id, val);
|
||||
st_insert(RCLASS(klass)->iv_tbl, id, val);
|
||||
}
|
||||
|
||||
void
|
||||
rb_define_const(cls, name, val)
|
||||
VALUE cls;
|
||||
rb_define_const(klass, name, val)
|
||||
VALUE klass;
|
||||
char *name;
|
||||
VALUE val;
|
||||
{
|
||||
|
@ -1016,7 +1011,7 @@ rb_define_const(cls, name, val)
|
|||
if (!rb_is_const_id(id)) {
|
||||
NameError("wrong constant name %s", name);
|
||||
}
|
||||
rb_const_set(cls, id, val);
|
||||
rb_const_set(klass, id, val);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue