Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fix a const lookup bug inside Foo::Bar modules

git-svn-id: http://svn.macosforge.org/repository/ruby/MacRuby/trunk@3319 23306eb0-4c56-4727-a40e-e92c0eb68959
  • Loading branch information...
commit e037cf28f9294a937fe1718556dc041bfaa58e93 1 parent ab61fd1
Laurent Sansonetti authored
View
40 compiler.cpp
@@ -1259,7 +1259,7 @@ RoxorCompiler::compile_constant_declaration(NODE *node, Value *val)
}
std::vector<Value *> params;
- bool outer = true;
+ int flags = 0;
if (node->nd_vid > 0) {
params.push_back(compile_current_class());
@@ -1267,13 +1267,13 @@ RoxorCompiler::compile_constant_declaration(NODE *node, Value *val)
}
else {
assert(node->nd_else != NULL);
- params.push_back(compile_class_path(node->nd_else, &outer));
+ params.push_back(compile_class_path(node->nd_else, &flags));
assert(node->nd_else->nd_mid > 0);
params.push_back(compile_id(node->nd_else->nd_mid));
}
params.push_back(val);
params.push_back(ConstantInt::get(Int8Ty,
- dynamic_class && outer ? 1 : 0));
+ dynamic_class && (flags & DEFINE_OUTER) ? 1 : 0));
CallInst::Create(setConstFunc, params.begin(), params.end(), "", bb);
@@ -1831,27 +1831,28 @@ RoxorCompiler::compile_set_has_ensure(Value *val)
}
Value *
-RoxorCompiler::compile_class_path(NODE *node, bool *outer)
+RoxorCompiler::compile_class_path(NODE *node, int *flags)
{
if (nd_type(node) == NODE_COLON3) {
// ::Foo
- if (outer != NULL) {
- *outer = false;
+ if (flags != NULL) {
+ *flags = 0;
}
return compile_nsobject();
}
else if (node->nd_head != NULL) {
// Bar::Foo
- if (outer != NULL) {
- *outer = false;
+ if (flags != NULL) {
+ *flags = DEFINE_SUB_OUTER;
}
return compile_node(node->nd_head);
}
-
- if (outer != NULL) {
- *outer = true;
+ else {
+ if (flags != NULL) {
+ *flags = DEFINE_OUTER;
+ }
+ return compile_current_class();
}
- return compile_current_class();
}
Value *
@@ -3961,22 +3962,21 @@ RoxorCompiler::compile_node(NODE *node)
}
std::vector<Value *> params;
- bool outer = false;
+ int flags = 0;
params.push_back(compile_id(path));
- params.push_back(compile_class_path(node->nd_cpath, &outer));
- params.push_back(super == NULL ? zeroVal : compile_node(super));
+ params.push_back(compile_class_path(node->nd_cpath,
+ &flags));
+ params.push_back(super == NULL
+ ? zeroVal : compile_node(super));
- int flags = 0;
if (nd_type(node) == NODE_MODULE) {
flags |= DEFINE_MODULE;
}
- if (outer) {
- flags |= DEFINE_OUTER;
- }
params.push_back(ConstantInt::get(Int32Ty, flags));
params.push_back(ConstantInt::get(Int8Ty,
- outer && dynamic_class ? 1 : 0));
+ (flags & DEFINE_OUTER) && dynamic_class
+ ? 1 : 0));
classVal = compile_protected_call(defineClassFunc, params);
}
View
2  compiler.h
@@ -279,7 +279,7 @@ class RoxorCompiler {
Value *compile_current_class(void);
virtual Value *compile_nsobject(void);
virtual Value *compile_standarderror(void);
- Value *compile_class_path(NODE *node, bool *outer);
+ Value *compile_class_path(NODE *node, int *flags);
Value *compile_const(ID id, Value *outer);
Value *compile_singleton_class(Value *obj);
Value *compile_defined_expression(NODE *node);
View
2  include/ruby/intern.h
@@ -633,7 +633,7 @@ struct timeval rb_time_interval(VALUE num);
//VALUE rb_mod_name(VALUE);
VALUE rb_class_path(VALUE);
void rb_set_class_path(VALUE, VALUE, const char*);
-void rb_set_class_path2(VALUE, VALUE, const char*, bool);
+void rb_set_class_path2(VALUE, VALUE, const char*, VALUE);
VALUE rb_path2class(const char*);
void rb_name_class(VALUE, ID);
VALUE rb_class_name(VALUE);
View
6 variable.c
@@ -259,7 +259,7 @@ rb_class_path(VALUE klass)
}
void
-rb_set_class_path2(VALUE klass, VALUE under, const char *name, bool set_outer)
+rb_set_class_path2(VALUE klass, VALUE under, const char *name, VALUE outer)
{
VALUE str;
@@ -274,13 +274,13 @@ rb_set_class_path2(VALUE klass, VALUE under, const char *name, bool set_outer)
OBJ_FREEZE(str);
rb_ivar_set(klass, classpath, str);
- rb_vm_set_outer(klass, set_outer ? under : rb_cObject);
+ rb_vm_set_outer(klass, outer);
}
void
rb_set_class_path(VALUE klass, VALUE under, const char *name)
{
- return rb_set_class_path2(klass, under, name, true);
+ return rb_set_class_path2(klass, under, name, under);
}
VALUE
View
27 vm.cpp
@@ -1298,6 +1298,7 @@ rb_vm_define_class(ID path, VALUE outer, VALUE super, int flags,
VALUE klass;
if (rb_const_defined_at(outer, path)) {
+ // Constant is already defined.
klass = rb_const_get_at(outer, path);
check_if_module(klass);
if (!(flags & DEFINE_MODULE) && super != 0) {
@@ -1308,11 +1309,30 @@ rb_vm_define_class(ID path, VALUE outer, VALUE super, int flags,
}
}
else {
+ // Prepare the constant outer.
+ VALUE const_outer;
+ if (flags & DEFINE_OUTER) {
+ const_outer = outer;
+ }
+ else if (flags & DEFINE_SUB_OUTER) {
+ // The Foo::Bar case, the outer here is the outer of the outer.
+ rb_vm_outer_t *o = GET_CORE()->get_outer((Class)outer);
+ if (o != NULL && o->outer != NULL) {
+ const_outer = (VALUE)o->outer->klass;
+ }
+ else {
+ const_outer = rb_cObject;
+ }
+ }
+ else {
+ const_outer = rb_cObject;
+ }
+
+ // Define the constant.
if (flags & DEFINE_MODULE) {
assert(super == 0);
klass = rb_define_module_id(path);
- rb_set_class_path2(klass, outer, rb_id2name(path),
- flags & DEFINE_OUTER);
+ rb_set_class_path2(klass, outer, rb_id2name(path), const_outer);
rb_const_set(outer, path, klass);
}
else {
@@ -1323,8 +1343,7 @@ rb_vm_define_class(ID path, VALUE outer, VALUE super, int flags,
check_if_module(super);
}
klass = rb_define_class_id(path, super);
- rb_set_class_path2(klass, outer, rb_id2name(path),
- flags & DEFINE_OUTER);
+ rb_set_class_path2(klass, outer, rb_id2name(path), const_outer);
rb_const_set(outer, path, klass);
rb_class_inherited(super, klass);
}
View
5 vm.h
@@ -554,8 +554,9 @@ struct ccache {
};
// For rb_vm_define_class()
-#define DEFINE_MODULE 0x1
-#define DEFINE_OUTER 0x2
+#define DEFINE_MODULE 0x1
+#define DEFINE_OUTER 0x2
+#define DEFINE_SUB_OUTER 0x4
class RoxorCompiler;
class RoxorJITManager;
Please sign in to comment.
Something went wrong with that request. Please try again.