summaryrefslogtreecommitdiff
path: root/eval.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-02-20 03:35:44 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-02-20 03:35:44 +0000
commitd88376b1352ad96e35bfc08f2bfce885ed6d72ca (patch)
tree0cd9c4945bf199c8173a37a39407288b31cb342f /eval.c
parentafca4f0cfd0bcc769451d5160320c7a33b3c4ed1 (diff)
* parse.y (clhs): allow "Foo::Bar = x".
* parse.y (primary): "self[n]=x" can be legal even when "[]=" is private. changes submitted in [ruby-talk:63982] * parse.y (aryset): ditto. * parse.y (attrset): "self.foo=x" can be legal even when "foo=" is private. * eval.c (is_defined): private "[]=" and "foo=" support. * eval.c (rb_eval): ditto. * eval.c (assign): ditto. * eval.c (rb_eval): "foo=" should not always be public. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3509 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'eval.c')
-rw-r--r--eval.c54
1 files changed, 39 insertions, 15 deletions
diff --git a/eval.c b/eval.c
index 6cb8224479..ee34bdac66 100644
--- a/eval.c
+++ b/eval.c
@@ -1923,8 +1923,9 @@ is_defined(self, node, buf)
val = self;
goto check_bound;
- case NODE_CALL:
case NODE_ATTRASGN:
+ if (node->nd_recv == (NODE *)1) goto check_bound;
+ case NODE_CALL:
PUSH_TAG(PROT_NONE);
if ((state = EXEC_TAG()) == 0) {
val = rb_eval(self, node->nd_recv);
@@ -2776,15 +2777,23 @@ rb_eval(self, n)
{
VALUE recv;
int argc; VALUE *argv; /* used in SETUP_ARGS */
+ int scope;
TMP_PROTECT;
BEGIN_CALLARGS;
- recv = rb_eval(self, node->nd_recv);
+ if (node->nd_recv == (NODE *)1) {
+ recv = self;
+ scope = 1;
+ }
+ else {
+ recv = rb_eval(self, node->nd_recv);
+ scope = 0;
+ }
SETUP_ARGS(node->nd_args);
END_CALLARGS;
SET_CURRENT_SOURCE();
- rb_call(CLASS_OF(recv),recv,node->nd_mid,argc,argv,0);
+ rb_call(CLASS_OF(recv),recv,node->nd_mid,argc,argv,scope);
result = argv[argc-1];
}
break;
@@ -3000,11 +3009,16 @@ rb_eval(self, n)
break;
case NODE_CDECL:
- if (NIL_P(ruby_cbase)) {
- rb_raise(rb_eTypeError, "no class/module to define constant");
- }
result = rb_eval(self, node->nd_value);
- rb_const_set(ruby_cbase, node->nd_vid, result);
+ if (node->nd_vid == 0) {
+ rb_const_set(class_prefix(self, node->nd_else), node->nd_else->nd_mid, result);
+ }
+ else {
+ if (NIL_P(ruby_cbase)) {
+ rb_raise(rb_eTypeError, "no class/module to define constant");
+ }
+ rb_const_set(ruby_cbase, node->nd_vid, result);
+ }
break;
case NODE_CVDECL:
@@ -3239,10 +3253,7 @@ rb_eval(self, n)
}
}
- if (node->nd_noex == NOEX_PUBLIC) {
- noex = NOEX_PUBLIC; /* means is is an attrset */
- }
- else if (SCOPE_TEST(SCOPE_PRIVATE) || node->nd_mid == init) {
+ if (SCOPE_TEST(SCOPE_PRIVATE) || node->nd_mid == init) {
noex = NOEX_PRIVATE;
}
else if (SCOPE_TEST(SCOPE_PROTECTED)) {
@@ -4106,7 +4117,12 @@ assign(self, lhs, val, pcall)
break;
case NODE_CDECL:
- rb_const_set(ruby_cbase, lhs->nd_vid, val);
+ if (lhs->nd_vid == 0) {
+ rb_const_set(class_prefix(self, lhs->nd_else), lhs->nd_else->nd_mid, val);
+ }
+ else {
+ rb_const_set(ruby_cbase, lhs->nd_vid, val);
+ }
break;
case NODE_CVDECL:
@@ -4128,12 +4144,20 @@ assign(self, lhs, val, pcall)
case NODE_ATTRASGN:
{
VALUE recv;
- recv = rb_eval(self, lhs->nd_recv);
+ int scope;
+ if (lhs->nd_recv == (NODE *)1) {
+ recv = self;
+ scope = 1;
+ }
+ else {
+ recv = rb_eval(self, lhs->nd_recv);
+ scope = 0;
+ }
if (!lhs->nd_args) {
/* attr set */
ruby_current_node = lhs;
SET_CURRENT_SOURCE();
- rb_call(CLASS_OF(recv), recv, lhs->nd_mid, 1, &val, 0);
+ rb_call(CLASS_OF(recv), recv, lhs->nd_mid, 1, &val, scope);
}
else {
/* array set */
@@ -4144,7 +4168,7 @@ assign(self, lhs, val, pcall)
ruby_current_node = lhs;
SET_CURRENT_SOURCE();
rb_call(CLASS_OF(recv), recv, lhs->nd_mid,
- RARRAY(args)->len, RARRAY(args)->ptr, 0);
+ RARRAY(args)->len, RARRAY(args)->ptr, scope);
}
}
break;