* 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:
nobu 2002-10-23 10:17:30 +00:00
Родитель 9562813d33
Коммит d4f2f6a7f7
8 изменённых файлов: 103 добавлений и 9 удалений

Просмотреть файл

@ -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>
* lib/mkmf.rb (init_mkmf): add dir_config("opt").

4
eval.c
Просмотреть файл

@ -3089,6 +3089,7 @@ rb_eval(self, n)
case NODE_DXSTR:
case NODE_DREGX:
case NODE_DREGX_ONCE:
case NODE_DSYM:
{
VALUE str, str2;
NODE *list = node->nd_next;
@ -3123,6 +3124,9 @@ rb_eval(self, n)
case NODE_DXSTR:
result = rb_funcall(self, '`', 1, str);
break;
case NODE_DSYM:
result = rb_str_intern(str);
break;
default:
result = str;
break;

Просмотреть файл

@ -297,6 +297,7 @@ int rb_is_const_id _((ID));
int rb_is_instance_id _((ID));
int rb_is_class_id _((ID));
int rb_is_local_id _((ID));
int rb_is_junk_id _((ID));
VALUE rb_backref_get _((void));
void rb_backref_set _((VALUE));
VALUE rb_lastline_get _((void));
@ -380,10 +381,12 @@ int rb_str_cmp _((VALUE, VALUE));
VALUE rb_str_upto _((VALUE, VALUE, int));
void rb_str_update _((VALUE, long, long, VALUE));
VALUE rb_str_inspect _((VALUE));
VALUE rb_str_dump _((VALUE));
VALUE rb_str_split _((VALUE, const char*));
void rb_str_associate _((VALUE, VALUE));
VALUE rb_str_associated _((VALUE));
void rb_str_setter _((VALUE, ID, VALUE*));
VALUE rb_str_intern _((VALUE));
/* struct.c */
VALUE rb_struct_new __((VALUE, ...));
VALUE rb_struct_define __((const char*, ...));

Просмотреть файл

@ -650,6 +650,7 @@ def create_makefile(target, srcprefix = nil)
Config::expand(srcdir = srcprefix.dup)
cleanfiles = []
distcleanfiles = []
if EXPORT_PREFIX
origdef = target + '.def'
deffile = EXPORT_PREFIX + origdef
@ -668,14 +669,13 @@ def create_makefile(target, srcprefix = nil)
end
end
end
cleanfiles << deffile
else
open(deffile, 'wb') do |f|
f.print "EXPORTS\n", EXPORT_PREFIX, "Init_", target, "\n"
end
cleanfiles << deffile
end
end
distcleanfiles << deffile unless deffile == origdef
end
libpath = libpathflag(libpath)
@ -699,7 +699,7 @@ LIBPATH = #{libpath}
DEFFILE = #{deffile}
CLEANFILES = #{cleanfiles.join(' ')}
DISTCLEANFILES =
DISTCLEANFILES = #{distcleanfiles.join(' ')}
}
mfile.print makerules(target, target_prefix)
dirs = []
@ -791,7 +791,7 @@ def init_mkmf(config = CONFIG)
$objs = nil
$libs = ""
if $configure_args['--enable-shared'] or config["LIBRUBY"] != config["LIBRUBY_A"]
$LIBPATH = ["$(topdir)"]
$LIBPATH = ["$(topdir)"]
$LIBPATH << "$(libdir)" unless $extmk or defined? CROSS_COMPILING
end
$LIBPATH << "$(archdir)"

2
node.h
Просмотреть файл

@ -122,6 +122,7 @@ enum node_type {
NODE_BMETHOD,
NODE_MEMO,
NODE_IFUNC,
NODE_DSYM,
NODE_LAST
};
@ -294,6 +295,7 @@ typedef struct RNode {
#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_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_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)

Просмотреть файл

@ -519,11 +519,16 @@ sym_inspect(sym)
{
VALUE str;
char *name;
ID id = SYM2ID(sym);
name = rb_id2name(SYM2ID(sym));
name = rb_id2name(id);
str = rb_str_new(0, strlen(name)+1);
RSTRING(str)->ptr[0] = ':';
strcpy(RSTRING(str)->ptr+1, name);
if (rb_is_junk_id(id)) {
str = rb_str_dump(str);
strncpy(RSTRING(str)->ptr, ":\"", 2);
}
return str;
}

63
parse.y
Просмотреть файл

@ -48,6 +48,7 @@
#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_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)) && \
(((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> string_contents xstring_contents string_content
%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> expr_value arg_value primary_value
%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));
}
| dsym
;
strings : string
@ -1957,6 +1959,31 @@ sym : fname
| 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
| tFLOAT
;
@ -2770,6 +2797,7 @@ regx_options()
#define STR_FUNC_EXPAND 0x02
#define STR_FUNC_REGEXP 0x04
#define STR_FUNC_QWORDS 0x08
#define STR_FUNC_SYMBOL 0x10
#define STR_FUNC_INDENT 0x20
enum string_type {
@ -2779,6 +2807,8 @@ enum string_type {
str_regexp = (STR_FUNC_REGEXP|STR_FUNC_ESCAPE|STR_FUNC_EXPAND),
str_sword = (STR_FUNC_QWORDS),
str_dword = (STR_FUNC_QWORDS|STR_FUNC_EXPAND),
str_ssym = (STR_FUNC_SYMBOL),
str_dsym = (STR_FUNC_SYMBOL|STR_FUNC_EXPAND),
};
static int
@ -2851,6 +2881,11 @@ tokadd_string(func, term, paren)
pushback(c);
break;
}
if (!c && (func & STR_FUNC_SYMBOL)) {
func &= ~STR_FUNC_SYMBOL;
rb_compile_error("symbol cannot contain '\\0'");
continue;
}
tokadd(c);
}
return c;
@ -3762,11 +3797,22 @@ yylex()
lex_state = EXPR_DOT;
return tCOLON2;
}
pushback(c);
if (lex_state == EXPR_END || lex_state == EXPR_ENDARG || ISSPACE(c)) {
pushback(c);
lex_state = EXPR_BEG;
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;
return tSYMBEG;
@ -3968,6 +4014,11 @@ yylex()
lex_strterm = NEW_STRTERM(str_regexp, term, paren);
return tREGEXP_BEG;
case 's':
lex_strterm = NEW_STRTERM(str_ssym, term, paren);
lex_state = EXPR_FNAME;
return tSYMBEG;
default:
yyerror("unknown type of %string");
return 0;
@ -5605,6 +5656,14 @@ rb_is_local_id(id)
return Qfalse;
}
int
rb_is_junk_id(id)
ID id;
{
if (is_junk_id(id)) return Qtrue;
return Qfalse;
}
static void
special_local_set(c, val)
char c;

Просмотреть файл

@ -1873,7 +1873,7 @@ rb_str_inspect(str)
return result;
}
static VALUE
VALUE
rb_str_dump(str)
VALUE str;
{
@ -3003,7 +3003,7 @@ rb_str_crypt(str, salt)
return result;
}
static VALUE
VALUE
rb_str_intern(str)
VALUE str;
{