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

* common.mk (parse.c), ext/ripper/depend (ripper.c): process after

bison with sed.  [ruby-dev:32204]

* ruby.c (proc_options): use yydebug in cmdline_options.

* ruby.c (process_options): set yydebug flag of parser.

* parse.y (yydebug): moved into struct parser_params.

* parse.y (rb_parser_get_yydebug, rb_parser_set_yydebug): parser
  generic methods.

* */Makefile.sub (parse.c): moved to common.mk.

* tool/ytab.sed: comment out yydebug definition, and substitute
  yyerror with parser_yyerror.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13908 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2007-11-13 12:41:41 +00:00
parent b7d363ead6
commit d5a3389886
10 changed files with 85 additions and 56 deletions

View file

@ -1,3 +1,22 @@
Tue Nov 13 21:41:39 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
* common.mk (parse.c), ext/ripper/depend (ripper.c): process after
bison with sed. [ruby-dev:32204]
* ruby.c (proc_options): use yydebug in cmdline_options.
* ruby.c (process_options): set yydebug flag of parser.
* parse.y (yydebug): moved into struct parser_params.
* parse.y (rb_parser_get_yydebug, rb_parser_set_yydebug): parser
generic methods.
* */Makefile.sub (parse.c): moved to common.mk.
* tool/ytab.sed: comment out yydebug definition, and substitute
yyerror with parser_yyerror.
Tue Nov 13 16:33:07 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
* numeric.c (flodivmod): work around for inifinity.

View file

@ -177,9 +177,6 @@ lex.c: keywords
cp $@ $(srcdir)/lex.c.blt; \
fi
.y.c:
$(YACC) $(YFLAGS) -o $@ $<
.c.@OBJEXT@:
$(CC) $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) -c $<

View file

@ -209,11 +209,6 @@ VPATH = $(arch_hdrdir)/ruby;$(hdrdir)/ruby;$(srcdir);$(srcdir)/enc;$(srcdir)/mis
.rc.res:
$(RC) $(RFLAGS) -I. -I$(<D). $(iconinc) -I$(srcdir)/win32 $(RFLAGS) -fo$@ $(<:/=\)
.y.c:
$(YACC) $(YFLAGS) $(<:\=/)
sed -e "s!^ *extern char \*getenv();!/* & */!;s/^\(#.*\)y\.tab/\1parse/" y.tab.c > $(@F)
@del y.tab.c
all: $(srcdir)/bcc32/Makefile.sub $(srcdir)/common.mk
ruby: $(PROGRAM)

View file

@ -351,6 +351,11 @@ PHONY:
{$(VPATH)}parse.c: parse.y
{$(VPATH)}.y.c:
$(YACC) $(YFLAGS) -o y.tab.c $<
sed -f $(srcdir)/tool/ytab.sed -e "/^#/s!y\.tab\.c!$@!" y.tab.c > $@
@$(RM) y.tab.c
acosh.$(OBJEXT): {$(VPATH)}acosh.c
alloca.$(OBJEXT): {$(VPATH)}alloca.c
crypt.$(OBJEXT): {$(VPATH)}crypt.c
@ -628,10 +633,10 @@ vm.inc: $(srcdir)/template/vm.inc.tmpl
incs: $(INSNS) node_name.inc
node_name.inc: {$(VPATH)}node.h
{$(VPATH)}node_name.inc: {$(VPATH)}node.h
$(BASERUBY) -n $(srcdir)/tool/node_name.rb $? > $@
prelude.c: $(srcdir)/tool/compile_prelude.rb $(srcdir)/prelude.rb
{$(VPATH)}prelude.c: $(srcdir)/tool/compile_prelude.rb $(srcdir)/prelude.rb
$(BASERUBY) $(srcdir)/tool/compile_prelude.rb $(srcdir)/prelude.rb $@
ext_prelude.c: $(srcdir)/tool/compile_prelude.rb $(srcdir)/prelude.rb $(srcdir)/gem_prelude.rb $(RBCONFIG)

View file

@ -8,7 +8,9 @@ src: ripper.c eventids1.c eventids2table.c
ripper.o: ripper.c lex.c eventids1.c eventids2.c eventids2table.c
.y.c:
$(BISON) -t -v -o$@ $<
$(BISON) -t -v -oy.tab.c $<
sed -f $(top_srcdir)/tool/ytab.sed -e "/^#/s!y\.tab\.c!$@!" y.tab.c > $@
@$(RM) y.tab.c
all: check
static: check

73
parse.y
View file

@ -240,6 +240,8 @@ struct parser_params {
rb_encoding *enc;
rb_encoding *utf8;
int parser_yydebug;
#ifndef RIPPER
/* Ruby core only */
char *parser_ruby_sourcefile; /* current source file */
@ -282,9 +284,7 @@ void rb_parser_free(struct parser_params *, void *);
static int parser_yyerror(struct parser_params*, const char*);
#define yyerror(msg) parser_yyerror(parser, msg)
#define YYPARSE_PARAM parser_v
#define YYLEX_PARAM parser_v
#define parser ((struct parser_params*)parser_v)
#define YYLEX_PARAM parser
#define ruby_eval_tree (parser->parser_eval_tree)
#define ruby_eval_tree_begin (parser->parser_eval_tree_begin)
@ -317,6 +317,7 @@ static int parser_yyerror(struct parser_params*, const char*);
#define ruby__end__seen (parser->parser_ruby__end__seen)
#define ruby_sourceline (parser->parser_ruby_sourceline)
#define ruby_sourcefile (parser->parser_ruby_sourcefile)
#define yydebug (parser->parser_yydebug)
#ifdef RIPPER
#else
#define ruby_debug_lines (parser->debug_lines)
@ -326,7 +327,6 @@ static int yylex(void*, void*);
#ifndef RIPPER
#define yyparse ruby_yyparse
#define yydebug ruby_yydebug
static NODE* node_newnode(struct parser_params *, enum node_type, VALUE, VALUE, VALUE);
#define rb_node_newnode(type, a1, a2, a3) node_newnode(parser, type, a1, a2, a3)
@ -489,7 +489,6 @@ static VALUE ripper_dispatch5(struct parser_params*,ID,VALUE,VALUE,VALUE,VALUE,V
#define dispatch5(n,a,b,c,d,e) ripper_dispatch5(parser, TOKEN_PASTE(ripper_id_, n), a, b, c, d, e)
#define yyparse ripper_yyparse
#define yydebug ripper_yydebug
static VALUE ripper_intern(const char*);
static VALUE ripper_id2sym(ID);
@ -587,6 +586,7 @@ static void ripper_compile_error(struct parser_params*, const char *fmt, ...);
%}
%pure_parser
%parse-param {struct parser_params *parser}
%union {
VALUE val;
@ -9141,6 +9141,9 @@ parser_free(void *ptr)
xfree(p);
}
VALUE rb_parser_get_yydebug(VALUE);
VALUE rb_parser_set_yydebug(VALUE, VALUE);
#ifndef RIPPER
static struct parser_params *
parser_new(void)
@ -9192,6 +9195,37 @@ rb_parser_encoding(VALUE vparser)
return rb_enc_from_encoding(parser->enc);
}
/*
* call-seq:
* ripper.yydebug -> true or false
*
* Get yydebug.
*/
VALUE
rb_parser_get_yydebug(VALUE self)
{
struct parser_params *parser;
Data_Get_Struct(self, struct parser_params, parser);
return yydebug ? Qtrue : Qfalse;
}
/*
* call-seq:
* ripper.yydebug = flag
*
* Set yydebug.
*/
VALUE
rb_parser_set_yydebug(VALUE self, VALUE flag)
{
struct parser_params *parser;
Data_Get_Struct(self, struct parser_params, parser);
yydebug = RTEST(flag);
return flag;
}
#ifdef YYMALLOC
#define HEAPCNT(n, size) ((n) * (size) / sizeof(YYSTYPE))
#define NEWHEAP() rb_node_newnode(NODE_ALLOCA, 0, (VALUE)parser->heap, 0)
@ -9554,31 +9588,6 @@ ripper_initialize(int argc, VALUE *argv, VALUE self)
return Qnil;
}
/*
* call-seq:
* Ripper.yydebug -> true or false
*
* Get yydebug.
*/
static VALUE
ripper_s_get_yydebug(VALUE self)
{
return ripper_yydebug ? Qtrue : Qfalse;
}
/*
* call-seq:
* Ripper.yydebug = flag
*
* Set yydebug.
*/
static VALUE
ripper_s_set_yydebug(VALUE self, VALUE flag)
{
ripper_yydebug = RTEST(flag);
return flag;
}
extern VALUE rb_thread_pass(void);
struct ripper_args {
@ -9704,8 +9713,6 @@ Init_ripper(void)
Ripper = rb_define_class("Ripper", rb_cObject);
rb_define_const(Ripper, "Version", rb_str_new2(RIPPER_VERSION));
rb_define_singleton_method(Ripper, "yydebug", ripper_s_get_yydebug, 0);
rb_define_singleton_method(Ripper, "yydebug=", ripper_s_set_yydebug, 1);
rb_define_alloc_func(Ripper, ripper_s_allocate);
rb_define_method(Ripper, "initialize", ripper_initialize, -1);
rb_define_method(Ripper, "parse", ripper_parse, 0);
@ -9713,6 +9720,8 @@ Init_ripper(void)
rb_define_method(Ripper, "lineno", ripper_lineno, 0);
rb_define_method(Ripper, "end_seen?", rb_parser_end_seen_p, 0);
rb_define_method(Ripper, "encoding", rb_parser_encoding, 0);
rb_define_method(Ripper, "yydebug", rb_parser_get_yydebug, 0);
rb_define_method(Ripper, "yydebug=", rb_parser_set_yydebug, 1);
#ifdef RIPPER_DEBUG
rb_define_method(rb_mKernel, "assert_Qundef", ripper_assert_Qundef, 2);
rb_define_method(rb_mKernel, "rawVALUE", ripper_value, 1);

8
ruby.c
View file

@ -61,7 +61,8 @@ char *getenv();
/* TODO: move to VM */
VALUE ruby_debug = Qfalse;
VALUE ruby_verbose = Qfalse;
extern int ruby_yydebug;
VALUE rb_parser_get_yydebug(VALUE);
VALUE rb_parser_set_yydebug(VALUE, VALUE);
char *ruby_inplace_mode = 0;
@ -593,7 +594,7 @@ proc_options(int argc, char **argv, struct cmdline_options *opt)
goto reswitch;
case 'y':
ruby_yydebug = 1;
opt->yydebug = 1;
s++;
goto reswitch;
@ -838,7 +839,7 @@ proc_options(int argc, char **argv, struct cmdline_options *opt)
ruby_verbose = Qtrue;
}
else if (strcmp("yydebug", s) == 0)
ruby_yydebug = 1;
opt->yydebug = 1;
else if (strcmp("help", s) == 0) {
usage(origarg.argv[0]);
rb_exit(EXIT_SUCCESS);
@ -993,6 +994,7 @@ process_options(VALUE arg)
ruby_init_loadpath();
ruby_init_gems(opt);
parser = rb_parser_new();
if (opt->yydebug) rb_parser_set_yydebug(parser, Qtrue);
if (opt->e_script) {
if (opt->enc_index >= 0)
rb_enc_associate_index(opt->e_script, opt->enc_index);

10
tool/ytab.sed Executable file
View file

@ -0,0 +1,10 @@
#!/bin/sed -f
/^int yydebug;/{
i\
#ifndef yydebug
a\
#endif
}
s/\<\(yyerror[ ]*([ ]*parser,\)/parser_\1/
s!^ *extern char \*getenv();!/* & */!
s/^\(#.*\)".*\.tab\.c"/\1"parse.c"/

View file

@ -578,11 +578,6 @@ $(RUBY_INSTALL_NAME).rc $(RUBYW_INSTALL_NAME).rc $(RUBY_SO_NAME).rc: $(RBCONFIG)
lex.c: {$(srcdir)}lex.c.blt
copy $(?:/=\) $@
{$(srcdir)}.y.c:
$(YACC) $(YFLAGS) $(<:\=/)
sed -e "s!^ *extern char \*getenv();!/* & */!;s/^\(#.*\)y\.tab/\1parse/" y.tab.c > $@
@del y.tab.c
$(OBJS): {$(hdrdir)/ruby}win32.h
dir.$(OBJEXT) win32.$(OBJEXT): {$(srcdir)}win32/dir.h

View file

@ -530,11 +530,6 @@ end
lex.c: {$(srcdir)}lex.c.blt
copy $(?:/=\) $@
{$(srcdir)}.y.c:
$(YACC) $(YFLAGS) $(<:\=/)
sed -e "s!^ *extern char \*getenv();!/* & */!;s/^\(#.*\)y\.tab/\1parse/" y.tab.c > $@
@del y.tab.c
!include $(srcdir)/common.mk
$(OBJS): {$(srcdir)}win32/win32.h