1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* parse.y: remove static variables. [ruby-dev:26530]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8758 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2005-07-13 13:44:21 +00:00
parent 1ee65ab7bb
commit 032248d337
7 changed files with 101 additions and 40 deletions

View file

@ -1,3 +1,7 @@
Wed Jul 13 22:44:00 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
* parse.y: remove static variables. [ruby-dev:26530]
Wed Jul 13 19:36:29 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp> Wed Jul 13 19:36:29 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
* win32/win32.c (rb_w32_mkdir): should set EEXIST (not EACCES) * win32/win32.c (rb_w32_mkdir): should set EEXIST (not EACCES)

View file

@ -154,7 +154,7 @@ $(srcdir)/configure: $(srcdir)/configure.in
lex.c: keywords lex.c: keywords
@-$(RM) $@ @-$(RM) $@
gperf -p -j1 -i 1 -g -o -t -N rb_reserved_word -k1,3,$$ $? > $@ || \ gperf -C -p -j1 -i 1 -g -o -t -N rb_reserved_word -k1,3,$$ $? > $@ || \
cp "$(srcdir)/$@" . cp "$(srcdir)/$@" .
.y.c: .y.c:

View file

@ -1,5 +1,5 @@
struct kwtable {char *name; int id[2]; enum lex_state_e state;}; struct kwtable {char *name; int id[2]; enum lex_state_e state;};
struct kwtable *rb_reserved_word _((const char *, unsigned int)); const struct kwtable *rb_reserved_word _((const char *, unsigned int));
#ifndef RIPPER #ifndef RIPPER
%% %%

10
lex.c
View file

@ -1,7 +1,7 @@
/* C code produced by gperf version 2.7.2 */ /* C code produced by gperf version 2.7.2 */
/* Command-line: gperf -p -j1 -i 1 -g -o -t -N rb_reserved_word -k'1,3,$' keywords */ /* Command-line: gperf -C -p -j1 -i 1 -g -o -t -N rb_reserved_word -k'1,3,$' keywords */
struct kwtable {char *name; int id[2]; enum lex_state_e state;}; struct kwtable {char *name; int id[2]; enum lex_state_e state;};
struct kwtable *rb_reserved_word _((const char *, unsigned int)); const struct kwtable *rb_reserved_word _((const char *, unsigned int));
#ifndef RIPPER #ifndef RIPPER
; ;
@ -24,7 +24,7 @@ hash (str, len)
register const char *str; register const char *str;
register unsigned int len; register unsigned int len;
{ {
static unsigned char asso_values[] = static const unsigned char asso_values[] =
{ {
56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56,
56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56,
@ -71,12 +71,12 @@ hash (str, len)
#ifdef __GNUC__ #ifdef __GNUC__
__inline __inline
#endif #endif
struct kwtable * const struct kwtable *
rb_reserved_word (str, len) rb_reserved_word (str, len)
register const char *str; register const char *str;
register unsigned int len; register unsigned int len;
{ {
static struct kwtable wordlist[] = static const struct kwtable wordlist[] =
{ {
{""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""},
{"end", {kEND, kEND}, EXPR_END}, {"end", {kEND, kEND}, EXPR_END},

7
node.h
View file

@ -350,6 +350,13 @@ typedef struct RNode {
#define NOEX_UNDEF NOEX_NOSUPER #define NOEX_UNDEF NOEX_NOSUPER
VALUE rb_parser_new _((void));
VALUE rb_parser_end_seen_p _((VALUE));
NODE *rb_parser_compile_cstr _((volatile VALUE, const char*, const char*, int, int));
NODE *rb_parser_compile_string _((volatile VALUE, const char*, VALUE, int));
NODE *rb_parser_compile_file _((volatile VALUE, const char*, VALUE, int));
NODE *rb_compile_cstr _((const char*, const char*, int, int)); NODE *rb_compile_cstr _((const char*, const char*, int, int));
NODE *rb_compile_string _((const char*, VALUE, int)); NODE *rb_compile_string _((const char*, VALUE, int));
NODE *rb_compile_file _((const char*, VALUE, int)); NODE *rb_compile_file _((const char*, VALUE, int));

106
parse.y
View file

@ -144,13 +144,14 @@ struct parser_params {
int parser_lex_gets_ptr; int parser_lex_gets_ptr;
VALUE (*parser_lex_gets) _((struct parser_params*,VALUE)); VALUE (*parser_lex_gets) _((struct parser_params*,VALUE));
struct local_vars *parser_lvtbl; struct local_vars *parser_lvtbl;
int parser_ruby__end__seen;
#ifndef RIPPER #ifndef RIPPER
/* Ruby core only */ /* Ruby core only */
NODE *parser_eval_tree_begin; NODE *parser_eval_tree_begin;
NODE *parser_eval_tree; NODE *parser_eval_tree;
VALUE debug_lines;
#else #else
/* Ripper only */ /* Ripper only */
int parser_ruby__end__seen;
int parser_ruby_sourceline; int parser_ruby_sourceline;
VALUE parser_ruby_sourcefile; VALUE parser_ruby_sourcefile;
char *tokp; char *tokp;
@ -199,10 +200,12 @@ static int parser_yyerror _((struct parser_params*, const char*));
#define lex_gets_ptr (parser->parser_lex_gets_ptr) #define lex_gets_ptr (parser->parser_lex_gets_ptr)
#define lex_gets (parser->parser_lex_gets) #define lex_gets (parser->parser_lex_gets)
#define lvtbl (parser->parser_lvtbl) #define lvtbl (parser->parser_lvtbl)
#ifdef RIPPER
#define ruby__end__seen (parser->parser_ruby__end__seen) #define ruby__end__seen (parser->parser_ruby__end__seen)
#ifdef RIPPER
#define ruby_sourceline (parser->parser_ruby_sourceline) #define ruby_sourceline (parser->parser_ruby_sourceline)
#define ruby_sourcefile (parser->parser_ruby_sourcefile) #define ruby_sourcefile (parser->parser_ruby_sourcefile)
#else
#define ruby_debug_lines (parser->debug_lines)
#endif #endif
static int yylex _((void*, void*)); static int yylex _((void*, void*));
@ -4438,9 +4441,6 @@ parser_yyerror(parser, msg)
static void parser_prepare _((struct parser_params *parser)); static void parser_prepare _((struct parser_params *parser));
#ifndef RIPPER #ifndef RIPPER
int ruby__end__seen;
static VALUE ruby_debug_lines;
static NODE* static NODE*
yycompile(parser, f, line) yycompile(parser, f, line)
struct parser_params *parser; struct parser_params *parser;
@ -4547,7 +4547,18 @@ rb_compile_string(f, s, line)
VALUE s; VALUE s;
int line; int line;
{ {
VALUE volatile vparser = rb_parser_s_new(); VALUE volatile vparser = rb_parser_new();
return rb_parser_compile_string(vparser, f, s, line);
}
NODE*
rb_parser_compile_string(vparser, f, s, line)
volatile VALUE vparser;
const char *f;
VALUE s;
int line;
{
struct parser_params *parser; struct parser_params *parser;
Data_Get_Struct(vparser, struct parser_params, parser); Data_Get_Struct(vparser, struct parser_params, parser);
@ -4568,6 +4579,15 @@ rb_compile_cstr(f, s, len, line)
return rb_compile_string(f, rb_str_new(s, len), line); return rb_compile_string(f, rb_str_new(s, len), line);
} }
NODE*
rb_parser_compile_cstr(vparser, f, s, len, line)
volatile VALUE vparser;
const char *f, *s;
int len, line;
{
return rb_parser_compile_string(vparser, f, rb_str_new(s, len), line);
}
static VALUE lex_io_gets _((struct parser_params *, VALUE)); static VALUE lex_io_gets _((struct parser_params *, VALUE));
static VALUE static VALUE
lex_io_gets(parser, io) lex_io_gets(parser, io)
@ -4583,7 +4603,18 @@ rb_compile_file(f, file, start)
VALUE file; VALUE file;
int start; int start;
{ {
VALUE volatile vparser = rb_parser_s_new(); VALUE volatile vparser = rb_parser_new();
return rb_parser_compile_file(vparser, f, file, start);
}
NODE*
rb_parser_compile_file(vparser, f, file, start)
volatile VALUE vparser;
const char *f;
VALUE file;
int start;
{
struct parser_params *parser; struct parser_params *parser;
Data_Get_Struct(vparser, struct parser_params, parser); Data_Get_Struct(vparser, struct parser_params, parser);
@ -6673,7 +6704,7 @@ parser_yylex(parser)
} }
if (lex_state != EXPR_DOT) { if (lex_state != EXPR_DOT) {
struct kwtable *kw; const struct kwtable *kw;
/* See if it is a reserved word. */ /* See if it is a reserved word. */
kw = rb_reserved_word(tok(), toklen()); kw = rb_reserved_word(tok(), toklen());
@ -8159,7 +8190,6 @@ dyna_init_gen(parser, node, pre)
void void
rb_gc_mark_parser() rb_gc_mark_parser()
{ {
rb_gc_mark(ruby_debug_lines);
} }
NODE* NODE*
@ -8211,7 +8241,7 @@ rb_parser_while_loop(node, chop, split)
return node; return node;
} }
static struct { static const struct {
ID token; ID token;
char *name; char *name;
} op_tbl[] = { } op_tbl[] = {
@ -8257,22 +8287,23 @@ static struct {
{0, 0} {0, 0}
}; };
static st_table *sym_tbl; static struct symbols {
static st_table *sym_rev_tbl; ID last_id;
st_table *tbl;
st_table *rev;
} global_symbols = {tLAST_TOKEN};
void void
Init_sym() Init_sym()
{ {
sym_tbl = st_init_strtable_with_size(200); global_symbols.tbl = st_init_strtable_with_size(200);
sym_rev_tbl = st_init_numtable_with_size(200); global_symbols.rev = st_init_numtable_with_size(200);
} }
static ID last_id = tLAST_TOKEN;
static ID static ID
internal_id() internal_id()
{ {
return ID_INTERNAL | (++last_id << ID_SCOPE_SHIFT); return ID_INTERNAL | (++global_symbols.last_id << ID_SCOPE_SHIFT);
} }
ID ID
@ -8283,7 +8314,7 @@ rb_intern(name)
ID id; ID id;
int last; int last;
if (st_lookup(sym_tbl, (st_data_t)name, (st_data_t *)&id)) if (st_lookup(global_symbols.tbl, (st_data_t)name, (st_data_t *)&id))
return id; return id;
last = strlen(name)-1; last = strlen(name)-1;
@ -8343,11 +8374,11 @@ rb_intern(name)
m += mbclen(*m); m += mbclen(*m);
} }
if (*m) id = ID_JUNK; if (*m) id = ID_JUNK;
id |= ++last_id << ID_SCOPE_SHIFT; id |= ++global_symbols.last_id << ID_SCOPE_SHIFT;
id_regist: id_regist:
name = strdup(name); name = strdup(name);
st_add_direct(sym_tbl, (st_data_t)name, id); st_add_direct(global_symbols.tbl, (st_data_t)name, id);
st_add_direct(sym_rev_tbl, id, (st_data_t)name); st_add_direct(global_symbols.rev, id, (st_data_t)name);
return id; return id;
} }
@ -8366,7 +8397,7 @@ rb_id2name(id)
} }
} }
if (st_lookup(sym_rev_tbl, id, (st_data_t *)&name)) if (st_lookup(global_symbols.rev, id, (st_data_t *)&name))
return name; return name;
if (is_attrset_id(id)) { if (is_attrset_id(id)) {
@ -8419,9 +8450,9 @@ symbols_i(key, value, ary)
VALUE VALUE
rb_sym_all_symbols() rb_sym_all_symbols()
{ {
VALUE ary = rb_ary_new2(sym_tbl->num_entries); VALUE ary = rb_ary_new2(global_symbols.tbl->num_entries);
st_foreach(sym_tbl, symbols_i, ary); st_foreach(global_symbols.tbl, symbols_i, ary);
return ary; return ary;
} }
@ -8470,7 +8501,7 @@ special_local_set(c, val)
char c; char c;
VALUE val; VALUE val;
{ {
VALUE volatile vparser = rb_parser_s_new(); VALUE volatile vparser = rb_parser_new();
struct parser_params *parser; struct parser_params *parser;
int cnt; int cnt;
@ -8552,6 +8583,7 @@ parser_initialize(parser)
parser->parser_lex_p = 0; parser->parser_lex_p = 0;
parser->parser_lex_pend = 0; parser->parser_lex_pend = 0;
parser->parser_lvtbl = 0; parser->parser_lvtbl = 0;
parser->parser_ruby__end__seen = 0;
#ifndef RIPPER #ifndef RIPPER
parser->parser_eval_tree_begin = 0; parser->parser_eval_tree_begin = 0;
parser->parser_eval_tree = 0; parser->parser_eval_tree = 0;
@ -8577,6 +8609,7 @@ parser_mark(ptr)
#ifndef RIPPER #ifndef RIPPER
rb_gc_mark((VALUE)p->parser_eval_tree_begin) ; rb_gc_mark((VALUE)p->parser_eval_tree_begin) ;
rb_gc_mark((VALUE)p->parser_eval_tree) ; rb_gc_mark((VALUE)p->parser_eval_tree) ;
rb_gc_mark(p->debug_lines);
#else #else
rb_gc_mark(p->parser_ruby_sourcefile); rb_gc_mark(p->parser_ruby_sourcefile);
rb_gc_mark(p->delayed); rb_gc_mark(p->delayed);
@ -8616,8 +8649,8 @@ parser_new()
return p; return p;
} }
static VALUE VALUE
rb_parser_s_new() rb_parser_new()
{ {
struct parser_params *p = parser_new(); struct parser_params *p = parser_new();
@ -8625,6 +8658,23 @@ rb_parser_s_new()
} }
#endif #endif
/*
* call-seq:
* ripper#end_seen? -> Boolean
*
* Return if parsed source ended by +\_\_END\_\_+.
* This number starts from 1.
*/
VALUE
rb_parser_end_seen_p(vparser)
VALUE vparser;
{
struct parser_params *parser;
Data_Get_Struct(vparser, struct parser_params, parser);
return ruby__end__seen ? Qtrue : Qfalse;
}
#ifdef RIPPER #ifdef RIPPER
#ifdef RIPPER_DEBUG #ifdef RIPPER_DEBUG
extern int rb_is_pointer_to_heap _((VALUE)); extern int rb_is_pointer_to_heap _((VALUE));
@ -8976,7 +9026,6 @@ ripper_initialize(argc, argv, self)
parser_initialize(parser); parser_initialize(parser);
parser->parser_ruby_sourcefile = fname; parser->parser_ruby_sourcefile = fname;
parser->parser_ruby_sourceline = NIL_P(lineno) ? 0 : NUM2INT(lineno) - 1; parser->parser_ruby_sourceline = NIL_P(lineno) ? 0 : NUM2INT(lineno) - 1;
parser->parser_ruby__end__seen = 0;
return Qnil; return Qnil;
} }
@ -9147,6 +9196,7 @@ Init_ripper()
rb_define_method(Ripper, "parse", ripper_parse, 0); rb_define_method(Ripper, "parse", ripper_parse, 0);
rb_define_method(Ripper, "column", ripper_column, 0); rb_define_method(Ripper, "column", ripper_column, 0);
rb_define_method(Ripper, "lineno", ripper_lineno, 0); rb_define_method(Ripper, "lineno", ripper_lineno, 0);
rb_define_method(Ripper, "end_seen?", rb_parser_end_seen_p, 0);
#ifdef RIPPER_DEBUG #ifdef RIPPER_DEBUG
rb_define_method(rb_mKernel, "assert_Qundef", ripper_assert_Qundef, 2); rb_define_method(rb_mKernel, "assert_Qundef", ripper_assert_Qundef, 2);
rb_define_method(rb_mKernel, "rawVALUE", ripper_value, 1); rb_define_method(rb_mKernel, "rawVALUE", ripper_value, 1);

10
ruby.c
View file

@ -388,7 +388,7 @@ require_libraries()
int state; int state;
ruby_current_node = 0; ruby_current_node = 0;
rb_protect((VALUE (*)(VALUE))rb_require, (VALUE)list->name, &state); rb_protect((VALUE (*)_((VALUE)))rb_require, (VALUE)list->name, &state);
if (state) rb_jump_tag(state); if (state) rb_jump_tag(state);
tmp = list->next; tmp = list->next;
free(list->name); free(list->name);
@ -864,14 +864,13 @@ proc_options(argc, argv)
} }
} }
extern int ruby__end__seen;
static void static void
load_file(fname, script) load_file(fname, script)
const char *fname; const char *fname;
int script; int script;
{ {
extern VALUE rb_stdin; extern VALUE rb_stdin;
VALUE parser;
VALUE f; VALUE f;
int line_start = 1; int line_start = 1;
@ -984,8 +983,9 @@ load_file(fname, script)
require_libraries(); /* Why here? unnatural */ require_libraries(); /* Why here? unnatural */
if (NIL_P(c)) return; if (NIL_P(c)) return;
} }
ruby_eval_tree = rb_compile_file(fname, f, line_start); parser = rb_parser_new();
if (script && ruby__end__seen) { ruby_eval_tree = rb_parser_compile_file(parser, fname, f, line_start);
if (script && rb_parser_end_seen_p(parser)) {
rb_define_global_const("DATA", f); rb_define_global_const("DATA", f);
} }
else if (f != rb_stdin) { else if (f != rb_stdin) {