* eval.c (rb_eval): added NODE_DSYM, symbol literal with
interpolation. * node.h: ditto. * intern.h: prototypes; rb_is_junk_id, rb_str_dump, rb_str_intern * object.c (sym_inspect): escape and quote for non-alphanumeric symbols. * parse.y (dsym, tokadd_string, yylex): extended symbol literals. * parse.y (rb_is_junk_id): added. * string.c (rb_str_dump, rb_str_intern) : make extern. * lib/mkmf.rb (create_makefile): deffile should be removed by distclean, not clean. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2985 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
9562813d33
commit
d4f2f6a7f7
21
ChangeLog
21
ChangeLog
@ -1,3 +1,24 @@
|
|||||||
|
Wed Oct 23 19:16:06 2002 Nobuyoshi Nakada <nobu.nokada@softhome.net>
|
||||||
|
|
||||||
|
* eval.c (rb_eval): added NODE_DSYM, symbol literal with
|
||||||
|
interpolation.
|
||||||
|
|
||||||
|
* node.h: ditto.
|
||||||
|
|
||||||
|
* intern.h: prototypes; rb_is_junk_id, rb_str_dump, rb_str_intern
|
||||||
|
|
||||||
|
* object.c (sym_inspect): escape and quote for non-alphanumeric
|
||||||
|
symbols.
|
||||||
|
|
||||||
|
* parse.y (dsym, tokadd_string, yylex): extended symbol literals.
|
||||||
|
|
||||||
|
* parse.y (rb_is_junk_id): added.
|
||||||
|
|
||||||
|
* string.c (rb_str_dump, rb_str_intern) : make extern.
|
||||||
|
|
||||||
|
* lib/mkmf.rb (create_makefile): deffile should be removed by
|
||||||
|
distclean, not clean.
|
||||||
|
|
||||||
Tue Oct 22 23:56:41 2002 WATANABE Hirofumi <eban@ruby-lang.org>
|
Tue Oct 22 23:56:41 2002 WATANABE Hirofumi <eban@ruby-lang.org>
|
||||||
|
|
||||||
* lib/mkmf.rb (init_mkmf): add dir_config("opt").
|
* lib/mkmf.rb (init_mkmf): add dir_config("opt").
|
||||||
|
4
eval.c
4
eval.c
@ -3089,6 +3089,7 @@ rb_eval(self, n)
|
|||||||
case NODE_DXSTR:
|
case NODE_DXSTR:
|
||||||
case NODE_DREGX:
|
case NODE_DREGX:
|
||||||
case NODE_DREGX_ONCE:
|
case NODE_DREGX_ONCE:
|
||||||
|
case NODE_DSYM:
|
||||||
{
|
{
|
||||||
VALUE str, str2;
|
VALUE str, str2;
|
||||||
NODE *list = node->nd_next;
|
NODE *list = node->nd_next;
|
||||||
@ -3123,6 +3124,9 @@ rb_eval(self, n)
|
|||||||
case NODE_DXSTR:
|
case NODE_DXSTR:
|
||||||
result = rb_funcall(self, '`', 1, str);
|
result = rb_funcall(self, '`', 1, str);
|
||||||
break;
|
break;
|
||||||
|
case NODE_DSYM:
|
||||||
|
result = rb_str_intern(str);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
result = str;
|
result = str;
|
||||||
break;
|
break;
|
||||||
|
3
intern.h
3
intern.h
@ -297,6 +297,7 @@ int rb_is_const_id _((ID));
|
|||||||
int rb_is_instance_id _((ID));
|
int rb_is_instance_id _((ID));
|
||||||
int rb_is_class_id _((ID));
|
int rb_is_class_id _((ID));
|
||||||
int rb_is_local_id _((ID));
|
int rb_is_local_id _((ID));
|
||||||
|
int rb_is_junk_id _((ID));
|
||||||
VALUE rb_backref_get _((void));
|
VALUE rb_backref_get _((void));
|
||||||
void rb_backref_set _((VALUE));
|
void rb_backref_set _((VALUE));
|
||||||
VALUE rb_lastline_get _((void));
|
VALUE rb_lastline_get _((void));
|
||||||
@ -380,10 +381,12 @@ int rb_str_cmp _((VALUE, VALUE));
|
|||||||
VALUE rb_str_upto _((VALUE, VALUE, int));
|
VALUE rb_str_upto _((VALUE, VALUE, int));
|
||||||
void rb_str_update _((VALUE, long, long, VALUE));
|
void rb_str_update _((VALUE, long, long, VALUE));
|
||||||
VALUE rb_str_inspect _((VALUE));
|
VALUE rb_str_inspect _((VALUE));
|
||||||
|
VALUE rb_str_dump _((VALUE));
|
||||||
VALUE rb_str_split _((VALUE, const char*));
|
VALUE rb_str_split _((VALUE, const char*));
|
||||||
void rb_str_associate _((VALUE, VALUE));
|
void rb_str_associate _((VALUE, VALUE));
|
||||||
VALUE rb_str_associated _((VALUE));
|
VALUE rb_str_associated _((VALUE));
|
||||||
void rb_str_setter _((VALUE, ID, VALUE*));
|
void rb_str_setter _((VALUE, ID, VALUE*));
|
||||||
|
VALUE rb_str_intern _((VALUE));
|
||||||
/* struct.c */
|
/* struct.c */
|
||||||
VALUE rb_struct_new __((VALUE, ...));
|
VALUE rb_struct_new __((VALUE, ...));
|
||||||
VALUE rb_struct_define __((const char*, ...));
|
VALUE rb_struct_define __((const char*, ...));
|
||||||
|
@ -650,6 +650,7 @@ def create_makefile(target, srcprefix = nil)
|
|||||||
Config::expand(srcdir = srcprefix.dup)
|
Config::expand(srcdir = srcprefix.dup)
|
||||||
|
|
||||||
cleanfiles = []
|
cleanfiles = []
|
||||||
|
distcleanfiles = []
|
||||||
if EXPORT_PREFIX
|
if EXPORT_PREFIX
|
||||||
origdef = target + '.def'
|
origdef = target + '.def'
|
||||||
deffile = EXPORT_PREFIX + origdef
|
deffile = EXPORT_PREFIX + origdef
|
||||||
@ -668,14 +669,13 @@ def create_makefile(target, srcprefix = nil)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
cleanfiles << deffile
|
|
||||||
else
|
else
|
||||||
open(deffile, 'wb') do |f|
|
open(deffile, 'wb') do |f|
|
||||||
f.print "EXPORTS\n", EXPORT_PREFIX, "Init_", target, "\n"
|
f.print "EXPORTS\n", EXPORT_PREFIX, "Init_", target, "\n"
|
||||||
end
|
end
|
||||||
cleanfiles << deffile
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
distcleanfiles << deffile unless deffile == origdef
|
||||||
end
|
end
|
||||||
|
|
||||||
libpath = libpathflag(libpath)
|
libpath = libpathflag(libpath)
|
||||||
@ -699,7 +699,7 @@ LIBPATH = #{libpath}
|
|||||||
DEFFILE = #{deffile}
|
DEFFILE = #{deffile}
|
||||||
|
|
||||||
CLEANFILES = #{cleanfiles.join(' ')}
|
CLEANFILES = #{cleanfiles.join(' ')}
|
||||||
DISTCLEANFILES =
|
DISTCLEANFILES = #{distcleanfiles.join(' ')}
|
||||||
}
|
}
|
||||||
mfile.print makerules(target, target_prefix)
|
mfile.print makerules(target, target_prefix)
|
||||||
dirs = []
|
dirs = []
|
||||||
|
2
node.h
2
node.h
@ -122,6 +122,7 @@ enum node_type {
|
|||||||
NODE_BMETHOD,
|
NODE_BMETHOD,
|
||||||
NODE_MEMO,
|
NODE_MEMO,
|
||||||
NODE_IFUNC,
|
NODE_IFUNC,
|
||||||
|
NODE_DSYM,
|
||||||
NODE_LAST
|
NODE_LAST
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -294,6 +295,7 @@ typedef struct RNode {
|
|||||||
#define NEW_DSTR(s) rb_node_newnode(NODE_DSTR,s,0,0)
|
#define NEW_DSTR(s) rb_node_newnode(NODE_DSTR,s,0,0)
|
||||||
#define NEW_XSTR(s) rb_node_newnode(NODE_XSTR,s,0,0)
|
#define NEW_XSTR(s) rb_node_newnode(NODE_XSTR,s,0,0)
|
||||||
#define NEW_DXSTR(s) rb_node_newnode(NODE_DXSTR,s,0,0)
|
#define NEW_DXSTR(s) rb_node_newnode(NODE_DXSTR,s,0,0)
|
||||||
|
#define NEW_DSYM(s) rb_node_newnode(NODE_DSYM,s,0,0)
|
||||||
#define NEW_EVSTR(n) rb_node_newnode(NODE_EVSTR,0,(n),0)
|
#define NEW_EVSTR(n) rb_node_newnode(NODE_EVSTR,0,(n),0)
|
||||||
#define NEW_CALL(r,m,a) rb_node_newnode(NODE_CALL,r,m,a)
|
#define NEW_CALL(r,m,a) rb_node_newnode(NODE_CALL,r,m,a)
|
||||||
#define NEW_FCALL(m,a) rb_node_newnode(NODE_FCALL,0,m,a)
|
#define NEW_FCALL(m,a) rb_node_newnode(NODE_FCALL,0,m,a)
|
||||||
|
7
object.c
7
object.c
@ -519,11 +519,16 @@ sym_inspect(sym)
|
|||||||
{
|
{
|
||||||
VALUE str;
|
VALUE str;
|
||||||
char *name;
|
char *name;
|
||||||
|
ID id = SYM2ID(sym);
|
||||||
|
|
||||||
name = rb_id2name(SYM2ID(sym));
|
name = rb_id2name(id);
|
||||||
str = rb_str_new(0, strlen(name)+1);
|
str = rb_str_new(0, strlen(name)+1);
|
||||||
RSTRING(str)->ptr[0] = ':';
|
RSTRING(str)->ptr[0] = ':';
|
||||||
strcpy(RSTRING(str)->ptr+1, name);
|
strcpy(RSTRING(str)->ptr+1, name);
|
||||||
|
if (rb_is_junk_id(id)) {
|
||||||
|
str = rb_str_dump(str);
|
||||||
|
strncpy(RSTRING(str)->ptr, ":\"", 2);
|
||||||
|
}
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
63
parse.y
63
parse.y
@ -48,6 +48,7 @@
|
|||||||
#define is_attrset_id(id) (is_notop_id(id)&&((id)&ID_SCOPE_MASK)==ID_ATTRSET)
|
#define is_attrset_id(id) (is_notop_id(id)&&((id)&ID_SCOPE_MASK)==ID_ATTRSET)
|
||||||
#define is_const_id(id) (is_notop_id(id)&&((id)&ID_SCOPE_MASK)==ID_CONST)
|
#define is_const_id(id) (is_notop_id(id)&&((id)&ID_SCOPE_MASK)==ID_CONST)
|
||||||
#define is_class_id(id) (is_notop_id(id)&&((id)&ID_SCOPE_MASK)==ID_CLASS)
|
#define is_class_id(id) (is_notop_id(id)&&((id)&ID_SCOPE_MASK)==ID_CLASS)
|
||||||
|
#define is_junk_id(id) (is_notop_id(id)&&((id)&ID_SCOPE_MASK)==ID_JUNK)
|
||||||
|
|
||||||
#define is_asgn_or_id(id) ((is_notop_id(id)) && \
|
#define is_asgn_or_id(id) ((is_notop_id(id)) && \
|
||||||
(((id)&ID_SCOPE_MASK) == ID_GLOBAL || \
|
(((id)&ID_SCOPE_MASK) == ID_GLOBAL || \
|
||||||
@ -238,7 +239,7 @@ static void top_local_setup();
|
|||||||
%type <node> singleton strings string string1 xstring regexp
|
%type <node> singleton strings string string1 xstring regexp
|
||||||
%type <node> string_contents xstring_contents string_content
|
%type <node> string_contents xstring_contents string_content
|
||||||
%type <node> words qwords word_list qword_list word
|
%type <node> words qwords word_list qword_list word
|
||||||
%type <node> literal numeric
|
%type <node> literal numeric dsym
|
||||||
%type <node> bodystmt compstmt stmts stmt expr arg primary command command_call method_call
|
%type <node> bodystmt compstmt stmts stmt expr arg primary command command_call method_call
|
||||||
%type <node> expr_value arg_value primary_value
|
%type <node> expr_value arg_value primary_value
|
||||||
%type <node> if_tail opt_else case_body cases opt_rescue exc_list exc_var opt_ensure
|
%type <node> if_tail opt_else case_body cases opt_rescue exc_list exc_var opt_ensure
|
||||||
@ -1740,6 +1741,7 @@ literal : numeric
|
|||||||
{
|
{
|
||||||
$$ = NEW_LIT(ID2SYM($1));
|
$$ = NEW_LIT(ID2SYM($1));
|
||||||
}
|
}
|
||||||
|
| dsym
|
||||||
;
|
;
|
||||||
|
|
||||||
strings : string
|
strings : string
|
||||||
@ -1957,6 +1959,31 @@ sym : fname
|
|||||||
| tCVAR
|
| tCVAR
|
||||||
;
|
;
|
||||||
|
|
||||||
|
dsym : tSYMBEG xstring_contents tSTRING_END
|
||||||
|
{
|
||||||
|
lex_state = EXPR_END;
|
||||||
|
if (!$2) {
|
||||||
|
yyerror("empty symbol literal");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$$ = $2;
|
||||||
|
switch (nd_type($$)) {
|
||||||
|
case NODE_STR:
|
||||||
|
$$->nd_lit = ID2SYM(rb_intern(RSTRING($$->nd_lit)->ptr));
|
||||||
|
nd_set_type($$, NODE_LIT);
|
||||||
|
break;
|
||||||
|
case NODE_DSTR:
|
||||||
|
nd_set_type($$, NODE_DSYM);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$$ = rb_node_newnode(NODE_DSYM, rb_str_new(0, 0),
|
||||||
|
1, NEW_LIST($$));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
;
|
||||||
|
|
||||||
numeric : tINTEGER
|
numeric : tINTEGER
|
||||||
| tFLOAT
|
| tFLOAT
|
||||||
;
|
;
|
||||||
@ -2770,6 +2797,7 @@ regx_options()
|
|||||||
#define STR_FUNC_EXPAND 0x02
|
#define STR_FUNC_EXPAND 0x02
|
||||||
#define STR_FUNC_REGEXP 0x04
|
#define STR_FUNC_REGEXP 0x04
|
||||||
#define STR_FUNC_QWORDS 0x08
|
#define STR_FUNC_QWORDS 0x08
|
||||||
|
#define STR_FUNC_SYMBOL 0x10
|
||||||
#define STR_FUNC_INDENT 0x20
|
#define STR_FUNC_INDENT 0x20
|
||||||
|
|
||||||
enum string_type {
|
enum string_type {
|
||||||
@ -2779,6 +2807,8 @@ enum string_type {
|
|||||||
str_regexp = (STR_FUNC_REGEXP|STR_FUNC_ESCAPE|STR_FUNC_EXPAND),
|
str_regexp = (STR_FUNC_REGEXP|STR_FUNC_ESCAPE|STR_FUNC_EXPAND),
|
||||||
str_sword = (STR_FUNC_QWORDS),
|
str_sword = (STR_FUNC_QWORDS),
|
||||||
str_dword = (STR_FUNC_QWORDS|STR_FUNC_EXPAND),
|
str_dword = (STR_FUNC_QWORDS|STR_FUNC_EXPAND),
|
||||||
|
str_ssym = (STR_FUNC_SYMBOL),
|
||||||
|
str_dsym = (STR_FUNC_SYMBOL|STR_FUNC_EXPAND),
|
||||||
};
|
};
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@ -2851,6 +2881,11 @@ tokadd_string(func, term, paren)
|
|||||||
pushback(c);
|
pushback(c);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
if (!c && (func & STR_FUNC_SYMBOL)) {
|
||||||
|
func &= ~STR_FUNC_SYMBOL;
|
||||||
|
rb_compile_error("symbol cannot contain '\\0'");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
tokadd(c);
|
tokadd(c);
|
||||||
}
|
}
|
||||||
return c;
|
return c;
|
||||||
@ -3762,11 +3797,22 @@ yylex()
|
|||||||
lex_state = EXPR_DOT;
|
lex_state = EXPR_DOT;
|
||||||
return tCOLON2;
|
return tCOLON2;
|
||||||
}
|
}
|
||||||
pushback(c);
|
|
||||||
if (lex_state == EXPR_END || lex_state == EXPR_ENDARG || ISSPACE(c)) {
|
if (lex_state == EXPR_END || lex_state == EXPR_ENDARG || ISSPACE(c)) {
|
||||||
|
pushback(c);
|
||||||
lex_state = EXPR_BEG;
|
lex_state = EXPR_BEG;
|
||||||
return ':';
|
return ':';
|
||||||
}
|
}
|
||||||
|
switch (c) {
|
||||||
|
case '\'':
|
||||||
|
lex_strterm = NEW_STRTERM(str_ssym, c, 0);
|
||||||
|
break;
|
||||||
|
case '"':
|
||||||
|
lex_strterm = NEW_STRTERM(str_dsym, c, 0);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
pushback(c);
|
||||||
|
break;
|
||||||
|
}
|
||||||
lex_state = EXPR_FNAME;
|
lex_state = EXPR_FNAME;
|
||||||
return tSYMBEG;
|
return tSYMBEG;
|
||||||
|
|
||||||
@ -3968,6 +4014,11 @@ yylex()
|
|||||||
lex_strterm = NEW_STRTERM(str_regexp, term, paren);
|
lex_strterm = NEW_STRTERM(str_regexp, term, paren);
|
||||||
return tREGEXP_BEG;
|
return tREGEXP_BEG;
|
||||||
|
|
||||||
|
case 's':
|
||||||
|
lex_strterm = NEW_STRTERM(str_ssym, term, paren);
|
||||||
|
lex_state = EXPR_FNAME;
|
||||||
|
return tSYMBEG;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
yyerror("unknown type of %string");
|
yyerror("unknown type of %string");
|
||||||
return 0;
|
return 0;
|
||||||
@ -5605,6 +5656,14 @@ rb_is_local_id(id)
|
|||||||
return Qfalse;
|
return Qfalse;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
rb_is_junk_id(id)
|
||||||
|
ID id;
|
||||||
|
{
|
||||||
|
if (is_junk_id(id)) return Qtrue;
|
||||||
|
return Qfalse;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
special_local_set(c, val)
|
special_local_set(c, val)
|
||||||
char c;
|
char c;
|
||||||
|
4
string.c
4
string.c
@ -1873,7 +1873,7 @@ rb_str_inspect(str)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static VALUE
|
VALUE
|
||||||
rb_str_dump(str)
|
rb_str_dump(str)
|
||||||
VALUE str;
|
VALUE str;
|
||||||
{
|
{
|
||||||
@ -3003,7 +3003,7 @@ rb_str_crypt(str, salt)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static VALUE
|
VALUE
|
||||||
rb_str_intern(str)
|
rb_str_intern(str)
|
||||||
VALUE str;
|
VALUE str;
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user