mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* compile.c, insns.def: change return value of "defined?"
for $&, $1, ... . If such variables are defined, return "global-variable". * test/ruby/test_defined.rb: add tests. * bootstraptest/test_syntax.rb: fix a test. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@14031 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
8e09ab045f
commit
b0986a8f82
5 changed files with 46 additions and 10 deletions
10
ChangeLog
10
ChangeLog
|
@ -1,3 +1,13 @@
|
||||||
|
Tue Nov 27 12:47:23 2007 Koichi Sasada <ko1@atdot.net>
|
||||||
|
|
||||||
|
* compile.c, insns.def: change return value of "defined?"
|
||||||
|
for $&, $1, ... . If such variables are defined,
|
||||||
|
return "global-variable".
|
||||||
|
|
||||||
|
* test/ruby/test_defined.rb: add tests.
|
||||||
|
|
||||||
|
* bootstraptest/test_syntax.rb: fix a test.
|
||||||
|
|
||||||
Tue Nov 27 11:54:46 2007 Koichi Sasada <ko1@atdot.net>
|
Tue Nov 27 11:54:46 2007 Koichi Sasada <ko1@atdot.net>
|
||||||
|
|
||||||
* insns.def: fix typo.
|
* insns.def: fix typo.
|
||||||
|
|
|
@ -248,7 +248,7 @@ assert_equal %q{["method", "method", "method", "method", nil, nil, "method", "me
|
||||||
end
|
end
|
||||||
C.new.test + [defined?(C.new.m3)]
|
C.new.test + [defined?(C.new.m3)]
|
||||||
}
|
}
|
||||||
assert_equal %q{[nil, nil, nil, nil, "$1", "$2", nil, nil]}, %q{
|
assert_equal %q{[nil, nil, nil, nil, "global-variable", "global-variable", nil, nil]}, %q{
|
||||||
$ans = [defined?($1), defined?($2), defined?($3), defined?($4)]
|
$ans = [defined?($1), defined?($2), defined?($3), defined?($4)]
|
||||||
/(a)(b)/ =~ 'ab'
|
/(a)(b)/ =~ 'ab'
|
||||||
$ans + [defined?($1), defined?($2), defined?($3), defined?($4)]
|
$ans + [defined?($1), defined?($2), defined?($3), defined?($4)]
|
||||||
|
|
|
@ -2333,10 +2333,12 @@ defined_expr(rb_iseq_t *iseq, LINK_ANCHOR *ret,
|
||||||
needstr);
|
needstr);
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
|
case NODE_BACK_REF:
|
||||||
case NODE_NTH_REF:
|
case NODE_NTH_REF:
|
||||||
ADD_INSN(ret, nd_line(node), putnil);
|
ADD_INSN(ret, nd_line(node), putnil);
|
||||||
ADD_INSN3(ret, nd_line(node), defined, INT2FIX(DEFINED_REF),
|
ADD_INSN3(ret, nd_line(node), defined, INT2FIX(DEFINED_REF),
|
||||||
INT2FIX(node->nd_nth), needstr);
|
INT2FIX(node->nd_nth << 1 | type == NODE_BACK_REF),
|
||||||
|
needstr);
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
case NODE_ZSUPER:
|
case NODE_ZSUPER:
|
||||||
|
|
11
insns.def
11
insns.def
|
@ -795,8 +795,6 @@ defined
|
||||||
{
|
{
|
||||||
VALUE klass;
|
VALUE klass;
|
||||||
char *expr_type = 0;
|
char *expr_type = 0;
|
||||||
char buf[0x10];
|
|
||||||
|
|
||||||
val = Qnil;
|
val = Qnil;
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
|
@ -868,12 +866,9 @@ defined
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case DEFINED_REF:{
|
case DEFINED_REF:{
|
||||||
int nth = FIX2INT(obj);
|
val = vm_getspecial(th, GET_LFP(), Qfalse, FIX2INT(obj));
|
||||||
VALUE backref = lfp_svar_get(th, GET_LFP(), 1);
|
if (val != Qnil) {
|
||||||
|
expr_type = "global-variable";
|
||||||
if (rb_reg_nth_match(nth, backref) != Qnil) {
|
|
||||||
snprintf(buf, 0x10, "$%d", nth);
|
|
||||||
expr_type = buf;
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,5 +48,34 @@ class TestDefined < Test::Unit::TestCase
|
||||||
|
|
||||||
assert(defined_test) # not iterator
|
assert(defined_test) # not iterator
|
||||||
assert(!defined_test{}) # called as iterator
|
assert(!defined_test{}) # called as iterator
|
||||||
|
|
||||||
|
/a/ =~ ''
|
||||||
|
assert_equal nil, defined?($&)
|
||||||
|
assert_equal nil, defined?($`)
|
||||||
|
assert_equal nil, defined?($')
|
||||||
|
assert_equal nil, defined?($+)
|
||||||
|
assert_equal nil, defined?($1)
|
||||||
|
assert_equal nil, defined?($2)
|
||||||
|
/a/ =~ 'a'
|
||||||
|
assert_equal 'global-variable', defined?($&)
|
||||||
|
assert_equal 'global-variable', defined?($`)
|
||||||
|
assert_equal 'global-variable', defined?($')
|
||||||
|
assert_equal nil, defined?($+)
|
||||||
|
assert_equal nil, defined?($1)
|
||||||
|
assert_equal nil, defined?($2)
|
||||||
|
/(a)/ =~ 'a'
|
||||||
|
assert_equal 'global-variable', defined?($&)
|
||||||
|
assert_equal 'global-variable', defined?($`)
|
||||||
|
assert_equal 'global-variable', defined?($')
|
||||||
|
assert_equal 'global-variable', defined?($+)
|
||||||
|
assert_equal 'global-variable', defined?($1)
|
||||||
|
assert_equal nil, defined?($2)
|
||||||
|
/(a)b/ =~ 'ab'
|
||||||
|
assert_equal 'global-variable', defined?($&)
|
||||||
|
assert_equal 'global-variable', defined?($`)
|
||||||
|
assert_equal 'global-variable', defined?($')
|
||||||
|
assert_equal 'global-variable', defined?($+)
|
||||||
|
assert_equal 'global-variable', defined?($1)
|
||||||
|
assert_equal nil, defined?($2)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue