From b025ce46786ced077d67c2a2bbe53af3f819f9d7 Mon Sep 17 00:00:00 2001 From: nobu Date: Fri, 17 Oct 2008 10:46:23 +0000 Subject: [PATCH] * common.mk (ID_H_TARGET): phony target to update id.h. * tool/ifchange, win32/ifchange.bat: --timestamp option added. * tool/generic_erb.rb: --timestamp, --output and --if-change options added. * template/id.h.tmpl: moved from id.h. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19822 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 11 +++++++ common.mk | 53 +++++++++++++++++-------------- cygwin/GNUmakefile.in | 2 +- parse.y | 1 + id.h => template/id.h.tmpl | 64 ++++++++++++++++++++++++++++---------- tool/generic_erb.rb | 32 ++++++++++++++++++- tool/ifchange | 8 +++++ win32/ifchange.bat | 16 ++++++++-- 8 files changed, 142 insertions(+), 45 deletions(-) rename id.h => template/id.h.tmpl (51%) diff --git a/ChangeLog b/ChangeLog index f62cb069b0..384ffd3c36 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +Fri Oct 17 19:46:20 2008 Nobuyoshi Nakada + + * common.mk (ID_H_TARGET): phony target to update id.h. + + * tool/ifchange, win32/ifchange.bat: --timestamp option added. + + * tool/generic_erb.rb: --timestamp, --output and --if-change options + added. + + * template/id.h.tmpl: moved from id.h. + Fri Oct 17 18:33:12 2008 Yuki Sonoda (Yugui) * array.c (ary_resize_capa): renamed RESIZE_CAPA. diff --git a/common.mk b/common.mk index 8556b23c33..fa9d62b0bb 100644 --- a/common.mk +++ b/common.mk @@ -17,6 +17,7 @@ EXTCONF = extconf.rb RBCONFIG = ./.rbconfig.time LIBRUBY_EXTS = ./.libruby-with-ext.time RDOCOUT = $(EXTOUT)/rdoc +ID_H_TARGET = -id.h- DMYEXT = dmyext.$(OBJEXT) NORMALMAINOBJ = main.$(OBJEXT) @@ -441,7 +442,7 @@ win32.$(OBJEXT): {$(VPATH)}win32.c RUBY_H_INCLUDES = {$(VPATH)}ruby.h {$(VPATH)}config.h {$(VPATH)}defines.h \ {$(VPATH)}intern.h {$(VPATH)}missing.h {$(VPATH)}st.h ENCODING_H_INCLUDES= {$(VPATH)}encoding.h {$(VPATH)}oniguruma.h -ID_H_INCLUDES = {$(VPATH)}id.h {$(VPATH)}parse.h +ID_H_INCLUDES = {$(VPATH)}id.h VM_CORE_H_INCLUDES = {$(VPATH)}vm_core.h {$(VPATH)}vm_opts.h \ {$(VPATH)}vm.h {$(VPATH)}thread_$(THREAD_MODEL).h \ {$(VPATH)}node.h $(ID_H_INCLUDES) @@ -465,20 +466,20 @@ enum.$(OBJEXT): {$(VPATH)}enum.c $(RUBY_H_INCLUDES) {$(VPATH)}node.h \ {$(VPATH)}util.h enumerator.$(OBJEXT): {$(VPATH)}enumerator.c $(RUBY_H_INCLUDES) error.$(OBJEXT): {$(VPATH)}error.c {$(VPATH)}known_errors.inc $(RUBY_H_INCLUDES) \ - $(VM_CORE_H_INCLUDES) {$(VPATH)}debug.h {$(VPATH)}parse.y + $(VM_CORE_H_INCLUDES) {$(VPATH)}debug.h eval.$(OBJEXT): {$(VPATH)}eval.c {$(VPATH)}eval_intern.h \ $(RUBY_H_INCLUDES) $(VM_CORE_H_INCLUDES) {$(VPATH)}eval_error.c \ - {$(VPATH)}eval_jump.c {$(VPATH)}debug.h {$(VPATH)}parse.y \ + {$(VPATH)}eval_jump.c {$(VPATH)}debug.h \ {$(VPATH)}iseq.h load.$(OBJEXT): {$(VPATH)}load.c {$(VPATH)}eval_intern.h \ {$(VPATH)}util.h $(RUBY_H_INCLUDES) $(VM_CORE_H_INCLUDES) \ - {$(VPATH)}dln.h {$(VPATH)}debug.h {$(VPATH)}parse.y + {$(VPATH)}dln.h {$(VPATH)}debug.h file.$(OBJEXT): {$(VPATH)}file.c $(RUBY_H_INCLUDES) {$(VPATH)}io.h \ $(ENCODING_H_INCLUDES) {$(VPATH)}util.h {$(VPATH)}dln.h gc.$(OBJEXT): {$(VPATH)}gc.c $(RUBY_H_INCLUDES) {$(VPATH)}re.h \ {$(VPATH)}regex.h $(ENCODING_H_INCLUDES) $(VM_CORE_H_INCLUDES) \ {$(VPATH)}gc.h {$(VPATH)}io.h {$(VPATH)}eval_intern.h {$(VPATH)}util.h \ - {$(VPATH)}debug.h {$(VPATH)}parse.y + {$(VPATH)}debug.h hash.$(OBJEXT): {$(VPATH)}hash.c $(RUBY_H_INCLUDES) {$(VPATH)}util.h inits.$(OBJEXT): {$(VPATH)}inits.c $(RUBY_H_INCLUDES) io.$(OBJEXT): {$(VPATH)}io.c $(RUBY_H_INCLUDES) {$(VPATH)}io.h \ @@ -492,16 +493,16 @@ numeric.$(OBJEXT): {$(VPATH)}numeric.c $(RUBY_H_INCLUDES) \ $(ENCODING_H_INCLUDES) object.$(OBJEXT): {$(VPATH)}object.c $(RUBY_H_INCLUDES) {$(VPATH)}util.h pack.$(OBJEXT): {$(VPATH)}pack.c $(RUBY_H_INCLUDES) -parse.$(OBJEXT): {$(VPATH)}parse.c {$(VPATH)}parse.y $(RUBY_H_INCLUDES) \ +parse.$(OBJEXT): {$(VPATH)}parse.c $(RUBY_H_INCLUDES) \ {$(VPATH)}node.h $(ENCODING_H_INCLUDES) $(ID_H_INCLUDES) \ {$(VPATH)}regenc.h {$(VPATH)}regex.h {$(VPATH)}util.h {$(VPATH)}lex.c \ {$(VPATH)}keywords {$(VPATH)}id.c proc.$(OBJEXT): {$(VPATH)}proc.c {$(VPATH)}eval_intern.h \ $(RUBY_H_INCLUDES) {$(VPATH)}gc.h $(VM_CORE_H_INCLUDES) \ - {$(VPATH)}debug.h {$(VPATH)}parse.y + {$(VPATH)}debug.h process.$(OBJEXT): {$(VPATH)}process.c $(RUBY_H_INCLUDES) \ {$(VPATH)}util.h {$(VPATH)}io.h $(ENCODING_H_INCLUDES) {$(VPATH)}dln.h \ - $(VM_CORE_H_INCLUDES) {$(VPATH)}debug.h {$(VPATH)}parse.y + $(VM_CORE_H_INCLUDES) {$(VPATH)}debug.h random.$(OBJEXT): {$(VPATH)}random.c $(RUBY_H_INCLUDES) range.$(OBJEXT): {$(VPATH)}range.c $(RUBY_H_INCLUDES) \ $(ENCODING_H_INCLUDES) @@ -525,11 +526,11 @@ regsyntax.$(OBJEXT): {$(VPATH)}regsyntax.c {$(VPATH)}regint.h \ {$(VPATH)}regenc.h {$(VPATH)}oniguruma.h $(RUBY_H_INCLUDES) ruby.$(OBJEXT): {$(VPATH)}ruby.c $(RUBY_H_INCLUDES) {$(VPATH)}util.h \ $(ENCODING_H_INCLUDES) {$(VPATH)}eval_intern.h $(VM_CORE_H_INCLUDES) \ - {$(VPATH)}dln.h {$(VPATH)}debug.h {$(VPATH)}parse.y + {$(VPATH)}dln.h {$(VPATH)}debug.h safe.$(OBJEXT): {$(VPATH)}safe.c $(RUBY_H_INCLUDES) \ - $(VM_CORE_H_INCLUDES) {$(VPATH)}debug.h {$(VPATH)}parse.y + $(VM_CORE_H_INCLUDES) {$(VPATH)}debug.h signal.$(OBJEXT): {$(VPATH)}signal.c $(RUBY_H_INCLUDES) \ - $(VM_CORE_H_INCLUDES) {$(VPATH)}debug.h {$(VPATH)}parse.y + $(VM_CORE_H_INCLUDES) {$(VPATH)}debug.h sprintf.$(OBJEXT): {$(VPATH)}sprintf.c $(RUBY_H_INCLUDES) {$(VPATH)}re.h \ {$(VPATH)}regex.h {$(VPATH)}vsnprintf.c $(ENCODING_H_INCLUDES) st.$(OBJEXT): {$(VPATH)}st.c {$(VPATH)}config.h {$(VPATH)}defines.h \ @@ -542,12 +543,12 @@ string.$(OBJEXT): {$(VPATH)}string.c $(RUBY_H_INCLUDES) {$(VPATH)}re.h \ struct.$(OBJEXT): {$(VPATH)}struct.c $(RUBY_H_INCLUDES) thread.$(OBJEXT): {$(VPATH)}thread.c {$(VPATH)}eval_intern.h \ $(RUBY_H_INCLUDES) {$(VPATH)}gc.h $(VM_CORE_H_INCLUDES) \ - {$(VPATH)}debug.h {$(VPATH)}parse.y {$(VPATH)}thread_$(THREAD_MODEL).c + {$(VPATH)}debug.h {$(VPATH)}thread_$(THREAD_MODEL).c transcode.$(OBJEXT): {$(VPATH)}transcode.c $(RUBY_H_INCLUDES) \ $(ENCODING_H_INCLUDES) {$(VPATH)}transcode_data.h cont.$(OBJEXT): {$(VPATH)}cont.c $(RUBY_H_INCLUDES) \ $(VM_CORE_H_INCLUDES) {$(VPATH)}gc.h {$(VPATH)}eval_intern.h \ - {$(VPATH)}debug.h {$(VPATH)}parse.y + {$(VPATH)}debug.h time.$(OBJEXT): {$(VPATH)}time.c $(RUBY_H_INCLUDES) \ $(ENCODING_H_INCLUDES) util.$(OBJEXT): {$(VPATH)}util.c $(RUBY_H_INCLUDES) {$(VPATH)}util.h @@ -558,30 +559,28 @@ version.$(OBJEXT): {$(VPATH)}version.c $(RUBY_H_INCLUDES) \ compile.$(OBJEXT): {$(VPATH)}compile.c {$(VPATH)}iseq.h \ $(RUBY_H_INCLUDES) $(VM_CORE_H_INCLUDES) {$(VPATH)}insns.inc \ - {$(VPATH)}insns_info.inc {$(VPATH)}optinsn.inc {$(VPATH)}debug.h \ - {$(VPATH)}parse.y + {$(VPATH)}insns_info.inc {$(VPATH)}optinsn.inc {$(VPATH)}debug.h iseq.$(OBJEXT): {$(VPATH)}iseq.c {$(VPATH)}gc.h {$(VPATH)}iseq.h \ $(RUBY_H_INCLUDES) $(VM_CORE_H_INCLUDES) {$(VPATH)}insns.inc \ - {$(VPATH)}insns_info.inc {$(VPATH)}node_name.inc {$(VPATH)}debug.h \ - {$(VPATH)}parse.y + {$(VPATH)}insns_info.inc {$(VPATH)}node_name.inc {$(VPATH)}debug.h vm.$(OBJEXT): {$(VPATH)}vm.c {$(VPATH)}gc.h {$(VPATH)}iseq.h \ {$(VPATH)}eval_intern.h $(RUBY_H_INCLUDES) $(ENCODING_H_INCLUDES) \ $(VM_CORE_H_INCLUDES) {$(VPATH)}vm_method.c {$(VPATH)}vm_eval.c \ {$(VPATH)}vm_insnhelper.c {$(VPATH)}vm_insnhelper.h {$(VPATH)}vm_exec.c \ {$(VPATH)}vm_exec.h {$(VPATH)}insns.def {$(VPATH)}vmtc.inc \ - {$(VPATH)}vm.inc {$(VPATH)}insns.inc {$(VPATH)}debug.h {$(VPATH)}parse.y + {$(VPATH)}vm.inc {$(VPATH)}insns.inc {$(VPATH)}debug.h vm_dump.$(OBJEXT): {$(VPATH)}vm_dump.c $(RUBY_H_INCLUDES) \ - $(VM_CORE_H_INCLUDES) {$(VPATH)}debug.h {$(VPATH)}parse.y + $(VM_CORE_H_INCLUDES) {$(VPATH)}debug.h debug.$(OBJEXT): {$(VPATH)}debug.c $(RUBY_H_INCLUDES) \ $(ENCODING_H_INCLUDES) $(VM_CORE_H_INCLUDES) {$(VPATH)}eval_intern.h \ - {$(VPATH)}util.h {$(VPATH)}debug.h {$(VPATH)}parse.y + {$(VPATH)}util.h {$(VPATH)}debug.h id.$(OBJEXT): {$(VPATH)}id.c $(RUBY_H_INCLUDES) $(ID_H_INCLUDES) miniprelude.$(OBJEXT): {$(VPATH)}miniprelude.c $(RUBY_H_INCLUDES) \ - $(VM_CORE_H_INCLUDES) {$(VPATH)}debug.h {$(VPATH)}parse.y + $(VM_CORE_H_INCLUDES) {$(VPATH)}debug.h prelude.$(OBJEXT): {$(VPATH)}prelude.c $(RUBY_H_INCLUDES) \ - $(VM_CORE_H_INCLUDES) {$(VPATH)}debug.h {$(VPATH)}parse.y + $(VM_CORE_H_INCLUDES) {$(VPATH)}debug.h golf_prelude.$(OBJEXT): {$(VPATH)}golf_prelude.c $(RUBY_H_INCLUDES) \ - $(VM_CORE_H_INCLUDES) {$(VPATH)}debug.h {$(VPATH)}parse.y + $(VM_CORE_H_INCLUDES) {$(VPATH)}debug.h goruby.$(OBJEXT): {$(VPATH)}goruby.c {$(VPATH)}main.c $(RUBY_H_INCLUDES) \ {$(VPATH)}debug.h {$(VPATH)}node.h @@ -626,7 +625,7 @@ vmtc.inc: $(srcdir)/template/vmtc.inc.tmpl vm.inc: $(srcdir)/template/vm.inc.tmpl -srcs: {$(VPATH)}parse.c {$(VPATH)}lex.c {$(VPATH)}newline.c $(srcdir)/ext/ripper/ripper.c srcs-enc +srcs: {$(VPATH)}parse.c $(ID_H_TARGET) {$(VPATH)}lex.c {$(VPATH)}newline.c $(srcdir)/ext/ripper/ripper.c srcs-enc srcs-enc: $(ENC_MK) $(MAKE) -f $(ENC_MK) RUBY="$(MINIRUBY)" MINIRUBY="$(MINIRUBY)" $(MFLAGS) srcs @@ -646,6 +645,12 @@ transdb.h: $(PREP) srcs-enc $(MINIRUBY) $(srcdir)/enc/trans/make_transdb.rb $@.new $(srcdir)/enc/trans enc/trans $(IFCHANGE) "$@" "$@.new" +{$(VPATH)}id.h: + $(CPP) $(CPPFLAGS) -DUSE_PARSE_H $@ + +$(ID_H_TARGET): {$(VPATH)}parse.c $(srcdir)/tool/generic_erb.rb $(srcdir)/template/id.h.tmpl + $(BASERUBY) $(srcdir)/tool/generic_erb.rb --if-change --output=$(srcdir)/id.h $(srcdir)/template/id.h.tmpl --vpath=$(VPATH) parse.c + known_errors.inc: $(srcdir)/template/known_errors.inc.tmpl $(srcdir)/defs/known_errors.def $(BASERUBY) $(srcdir)/tool/generic_erb.rb $(srcdir)/template/known_errors.inc.tmpl $(srcdir)/defs/known_errors.def > $@ diff --git a/cygwin/GNUmakefile.in b/cygwin/GNUmakefile.in index 1e98a115a7..081c927575 100644 --- a/cygwin/GNUmakefile.in +++ b/cygwin/GNUmakefile.in @@ -9,7 +9,7 @@ ifeq (@target_os@,cygwin) else DLL_BASE_NAME := $(RUBY_SO_NAME) DLLWRAP += -mno-cygwin - VPATH += $(srcdir)/win32 + VPATH := $(VPATH):$(srcdir)/win32 endif ifneq ($(ENABLE_SHARED),yes) diff --git a/parse.y b/parse.y index b5743e4472..58283dceb2 100644 --- a/parse.y +++ b/parse.y @@ -19,6 +19,7 @@ #include "ruby/st.h" #include "ruby/encoding.h" #include "node.h" +#include "parse.h" #include "id.h" #include "regenc.h" #include diff --git a/id.h b/template/id.h.tmpl similarity index 51% rename from id.h rename to template/id.h.tmpl index 04cf72e976..597f2702d3 100644 --- a/id.h +++ b/template/id.h.tmpl @@ -1,3 +1,5 @@ +%# -*- c -*- +/* DO NOT EDIT THIS FILE DIRECTLY */ /********************************************************************** id.h - @@ -8,7 +10,28 @@ Copyright (C) 2007 Koichi Sasada **********************************************************************/ +<% +require 'optparse' +vpath = ["."] +input = nil +opt = OptionParser.new do |o| + o.on('-v', '--vpath=DIR') {|dirs| vpath.concat dirs.split(File::PATH_SEPARATOR)} + input, = o.order!(ARGV) +end or abort opt.opt_s +tokens = nil +vpath.find do |dir| + begin + if line = File.read(File.join(dir, input))[/^\s*enum\s+yytokentype\s*\{([^{}]*)\s*\};/m, 1] + tokens = line.scan(/\b(t(?:LAST_TOKEN|U(?:PLUS|MINUS)|POW|CMP|EQQ?|[NGL]EQ|(?:AND|OR)OP|N?MATCH|DOT\d|AREF|ASET|[LR]SHFT|LAMBDA)|id\w+)\s*=\s*(\d+),?/m) + end + rescue Errno::ENOENT + nil + else + true + end +end +%> #ifndef RUBY_ID_H #define RUBY_ID_H @@ -23,12 +46,21 @@ #define ID_JUNK 0x07 #define ID_INTERNAL ID_JUNK +#ifdef USE_PARSE_H #include "parse.h" +#endif #define symIFUNC ID2SYM(idIFUNC) #define symCFUNC ID2SYM(idCFUNC) enum ruby_method_ids { +#ifndef tLAST_TOKEN +% tokens.each do |token, value| + <%=token%> = <%=value%>, +% end +#elif <%= tokens.map {|token, value|"#{token} != #{value}"}.join(" || \\\n ") %> +#error id.h is out of date. +#endif idPLUS = '+', idMINUS = '-', idMULT = '*', @@ -62,22 +94,22 @@ enum ruby_method_ids { tBitblt, tAnswer, #endif - tLAST_ID + tLAST_ID, +#define TOKEN2ID(n) id##n = ((t##n< nul && ( - echo %dest% unchanged. + echo %1 unchanged. del %src% - goto :end + goto :nt_end ) ) -echo %dest% updated. +echo %1 updated. copy %src% %dest% > nul del %src% +:nt_end +if "%timestamp%" == "" goto :end + for %%I in ("%dest%") do set timestamp=%%~dpI\.time.%%~nxI + if not exist "%timestamp%" copy nul "%timestamp%" > nul + goto :end >> "%timestamp%" :end