[前][次][番号順一覧][スレッド一覧]

ruby-changes:24813

From: nobu <ko1@a...>
Date: Fri, 31 Aug 2012 14:31:35 +0900 (JST)
Subject: [ruby-changes:24813] nobu:r36864 (trunk): id.h: independent from parse.h

nobu	2012-08-31 14:31:20 +0900 (Fri, 31 Aug 2012)

  New Revision: 36864

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=36864

  Log:
    id.h: independent from parse.h
    
    * template/id.h.tmpl, tool/id2token.rb: make id.h independent from
      parse.h, and make parse.c dependent on it instead.

  Added files:
    trunk/tool/id2token.rb
  Modified files:
    trunk/ChangeLog
    trunk/common.mk
    trunk/ext/ripper/depend
    trunk/parse.y
    trunk/template/id.h.tmpl

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 36863)
+++ ChangeLog	(revision 36864)
@@ -1,3 +1,8 @@
+Fri Aug 31 14:31:17 2012  Nobuyoshi Nakada  <nobu@r...>
+
+	* template/id.h.tmpl, tool/id2token.rb: make id.h independent from
+	  parse.h, and make parse.c dependent on it instead.
+
 Fri Aug 31 14:27:39 2012  Nobuyoshi Nakada  <nobu@r...>
 
 	* lib/mkmf.rb (create_makefile): fix race conditions at install-ext.
Index: common.mk
===================================================================
--- common.mk	(revision 36863)
+++ common.mk	(revision 36864)
@@ -27,7 +27,6 @@
 PLATFORM_D    = ./$(PLATFORM_DIR)/.time
 RDOCOUT       = $(EXTOUT)/rdoc
 CAPIOUT       = doc/capi
-ID_H_TARGET   = ./.id.h.time
 
 DMYEXT	      = dmyext.$(OBJEXT)
 NORMALMAINOBJ = main.$(OBJEXT)
@@ -105,7 +104,7 @@
 		$(COMMONOBJS)
 
 OBJS          = $(EXPORTOBJS) prelude.$(OBJEXT)
-ALLOBJS       = $(ID_H_TARGET) $(NORMALMAINOBJ) $(MINIOBJS) $(COMMONOBJS) $(DMYEXT)
+ALLOBJS       = $(NORMALMAINOBJ) $(MINIOBJS) $(COMMONOBJS) $(DMYEXT)
 
 GOLFOBJS      = goruby.$(OBJEXT) golf_prelude.$(OBJEXT)
 
@@ -561,22 +560,19 @@
 
 PHONY:
 
-{$(VPATH)}parse.c: {$(VPATH)}parse.y $(srcdir)/tool/ytab.sed
+{$(VPATH)}parse.c: {$(VPATH)}parse.y $(srcdir)/tool/ytab.sed {$(VPATH)}id.h
 {$(VPATH)}parse.h: {$(VPATH)}parse.c
 
 {$(srcdir)}.y.c:
 	$(ECHO) generating $@
-	$(Q)$(YACC) -d $(YFLAGS) -o y.tab.c $(SRC_FILE)
-	$(Q)sed -f $(srcdir)/tool/ytab.sed -e "/^#/s!y\.tab\.c!$@!" y.tab.c > $@.new
+	$(Q)$(BASERUBY) $(srcdir)/tool/id2token.rb --vpath=$(VPATH) id.h $(SRC_FILE) > parse.tmp.y
+	$(Q)$(YACC) -d $(YFLAGS) -o y.tab.c parse.tmp.y
+	$(Q)$(RM) parse.tmp.y
+	$(Q)sed -f $(srcdir)/tool/ytab.sed -e "/^#/s!parse\.tmp\.[iy]!parse.y!" -e "/^#/s!y\.tab\.c!$@!" y.tab.c > $@.new
 	$(Q)$(MV) $@.new $@
+	$(Q)sed -e "/^#line.*y\.tab\.h/d;/^#line.*parse.*\.y/d" y.tab.h > $(@:.c=.h)
 	$(Q)$(RM) y.tab.c y.tab.h
 
-{$(srcdir)}.y.h:
-	$(ECHO) generating $@
-	$(Q)$(YACC) -d $(YFLAGS) -o y.tab.c $(SRC_FILE)
-	$(Q)sed -e "/^#line.*y\.tab\.h/d;/^#line.*parse\.y/d" y.tab.h > $(@:.c=.h)
-	$(Q)$(RM) y.tab.c y.tab.h
-
 acosh.$(OBJEXT): {$(VPATH)}acosh.c
 alloca.$(OBJEXT): {$(VPATH)}alloca.c {$(VPATH)}config.h
 crypt.$(OBJEXT): {$(VPATH)}crypt.c
@@ -847,15 +843,14 @@
 	$(Q) $(MAKE) -f $(ENC_MK) RUBY="$(MINIRUBY)" MINIRUBY="$(MINIRUBY)" $(MFLAGS) srcs
 
 incs: $(INSNS) {$(VPATH)}node_name.inc {$(VPATH)}encdb.h {$(VPATH)}transdb.h {$(VPATH)}known_errors.inc \
-      $(srcdir)/revision.h $(REVISION_H) enc/unicode/name2ctype.h $(ID_H_TARGET)
+      $(srcdir)/revision.h $(REVISION_H) enc/unicode/name2ctype.h {$(VPATH)}id.h
 
 insns: $(INSNS)
 
-$(ID_H_INCLUDES) $(ID_H_TARGET): {$(VPATH)}parse.h $(srcdir)/tool/generic_erb.rb $(srcdir)/template/id.h.tmpl
-	$(ECHO) generating id.h
-	$(Q) $(BASERUBY) $(srcdir)/tool/generic_erb.rb --if-change --output=id.h \
-		--vpath=$(VPATH) --timestamp \
-		$(srcdir)/template/id.h.tmpl parse.h
+{$(VPATH)}id.h: $(srcdir)/tool/generic_erb.rb $(srcdir)/template/id.h.tmpl
+	$(ECHO) generating $@
+	$(Q) $(BASERUBY) $(srcdir)/tool/generic_erb.rb --output=$@ \
+		$(srcdir)/template/$@.tmpl
 
 node_name.inc: {$(VPATH)}node.h
 	$(ECHO) generating $@
@@ -904,7 +899,7 @@
 $(srcdir)/ext/ripper/ripper.c: parse.y
 	$(ECHO) generating $@
 	$(Q) $(CHDIR) $(@D) && $(exec) $(MAKE) -f depend $(MFLAGS) \
-		Q=$(Q) ECHO=$(ECHO) top_srcdir=../.. srcdir=. RUBY="$(BASERUBY)"
+		Q=$(Q) ECHO=$(ECHO) top_srcdir=../.. srcdir=. VPATH=../.. RUBY="$(BASERUBY)"
 
 $(srcdir)/ext/json/parser/parser.c: $(srcdir)/ext/json/parser/parser.rl
 	$(ECHO) generating $@
Index: parse.y
===================================================================
--- parse.y	(revision 36863)
+++ parse.y	(revision 36864)
@@ -744,25 +744,25 @@
 %type <val> program reswords then do dot_or_colon
 %*/
 %token END_OF_INPUT 0	"end-of-input"
-%token tUPLUS		"unary+"
-%token tUMINUS		"unary-"
-%token tPOW		"**"
-%token tCMP		"<=>"
-%token tEQ		"=="
-%token tEQQ		"==="
-%token tNEQ		"!="
-%token tGEQ		">="
-%token tLEQ		"<="
+%token tUPLUS		RUBY_TOKEN(UPLUS)  "unary+"
+%token tUMINUS		RUBY_TOKEN(UMINUS) "unary-"
+%token tPOW		RUBY_TOKEN(POW)    "**"
+%token tCMP		RUBY_TOKEN(CMP)    "<=>"
+%token tEQ		RUBY_TOKEN(EQ)     "=="
+%token tEQQ		RUBY_TOKEN(EQQ)    "==="
+%token tNEQ		RUBY_TOKEN(NEQ)    "!="
+%token tGEQ		RUBY_TOKEN(GEQ)    ">="
+%token tLEQ		RUBY_TOKEN(LEQ)    "<="
 %token tANDOP		"&&"
 %token tOROP		"||"
-%token tMATCH		"=~"
-%token tNMATCH		"!~"
-%token tDOT2		".."
-%token tDOT3		"..."
-%token tAREF		"[]"
-%token tASET		"[]="
-%token tLSHFT		"<<"
-%token tRSHFT		">>"
+%token tMATCH		RUBY_TOKEN(MATCH)  "=~"
+%token tNMATCH		RUBY_TOKEN(NMATCH) "!~"
+%token tDOT2		RUBY_TOKEN(DOT2)   ".."
+%token tDOT3		RUBY_TOKEN(DOT3)   "..."
+%token tAREF		RUBY_TOKEN(AREF)   "[]"
+%token tASET		RUBY_TOKEN(ASET)   "[]="
+%token tLSHFT		RUBY_TOKEN(LSHFT)  "<<"
+%token tRSHFT		RUBY_TOKEN(RSHFT)  ">>"
 %token tCOLON2		"::"
 %token tCOLON3		":: at EXPR_BEG"
 %token <id> tOP_ASGN	/* +=, -=  etc. */
@@ -9918,8 +9918,8 @@
     st_table *ivar2_id;
     st_table *id_ivar2;
 #endif
-    VALUE op_sym[tLAST_TOKEN];
-} global_symbols = {tLAST_ID};
+    VALUE op_sym[tLAST_OP_ID];
+} global_symbols = {tLAST_TOKEN};
 
 static const struct st_hash_type symhash = {
     rb_str_hash_cmp,
@@ -9977,7 +9977,7 @@
 {
     rb_mark_tbl(global_symbols.id_str);
     rb_gc_mark_locations(global_symbols.op_sym,
-			 global_symbols.op_sym + tLAST_TOKEN);
+			 global_symbols.op_sym + numberof(global_symbols.op_sym));
 }
 #endif /* !RIPPER */
 
@@ -10264,7 +10264,7 @@
 	if (m[last] == '=') {
 	    /* attribute assignment */
 	    id = rb_intern3(name, last, enc);
-	    if (id > tLAST_TOKEN && !is_attrset_id(id)) {
+	    if (id > tLAST_OP_ID && !is_attrset_id(id)) {
 		enc = rb_enc_get(rb_id2str(id));
 		id = rb_id_attrset(id);
 		goto id_register;
Index: ext/ripper/depend
===================================================================
--- ext/ripper/depend	(revision 36863)
+++ ext/ripper/depend	(revision 36864)
@@ -25,7 +25,9 @@
 
 ripper.y: $(srcdir)/tools/preproc.rb $(top_srcdir)/parse.y
 	$(ECHO) extracting $@ from $(top_srcdir)/parse.y
-	$(Q) $(RUBY) $(srcdir)/tools/preproc.rb $(top_srcdir)/parse.y --output=$@
+	$(Q) $(RUBY) $(top_srcdir)/tool/id2token.rb --vpath=$(VPATH) id.h $(top_srcdir)/parse.y > ripper.tmp.y
+	$(Q) $(RUBY) $(srcdir)/tools/preproc.rb ripper.tmp.y --output=$@
+	$(Q) $(RM) ripper.tmp.y
 
 check: $(GEN) $(SRC1) $(SRC2)
 	$(ECHO) checking $(SRC1) and $(SRC2)
Index: tool/id2token.rb
===================================================================
--- tool/id2token.rb	(revision 0)
+++ tool/id2token.rb	(revision 36864)
@@ -0,0 +1,29 @@
+#! /usr/bin/ruby -p
+BEGIN {
+  require 'optparse'
+  vpath = ["."]
+  header = nil
+
+  opt = OptionParser.new do |o|
+    o.on('-v', '--vpath=DIR') {|dirs| vpath.concat dirs.split(File::PATH_SEPARATOR)}
+    header = o.order!(ARGV).shift
+  end or abort opt.opt_s
+
+  TOKENS = {}
+  vpath.find do |dir|
+    begin
+      h = File.read(File.join(dir, header))
+    rescue Errno::ENOENT
+      nil
+    else
+      h.scan(/^#define\s+RUBY_TOKEN_(\w+)\s+(\d+)/) do |token, id|
+        TOKENS[token] = id
+      end
+      true
+    end
+  end or abort "#{header} not found in #{vpath.inspect}"
+
+  TOKENS_RE = /\bRUBY_TOKEN\((#{TOKENS.keys.join('|')})\)\s*(?=\s)/
+}
+
+$_.gsub!(TOKENS_RE) {TOKENS[$1]} if /^%token/ =~ $_

Property changes on: tool/id2token.rb
___________________________________________________________________
Added: svn:eol-style
   + LF
Added: svn:executable
   + *

Index: template/id.h.tmpl
===================================================================
--- template/id.h.tmpl	(revision 36863)
+++ template/id.h.tmpl	(revision 36864)
@@ -13,15 +13,8 @@
 <%
 require 'optparse'
 
-input = ARGV.shift or abort opt.opt_s
+op_id_offset = 128
 
-tokens = nil
-vpath.open(input) do |f|
-  if line = f.read[/^\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
-end
-
 method_ids = %w[
   Intern
   MethodMissing
@@ -39,6 +32,12 @@
   Answer
 ]
 
+token_op_ids = %w[
+  tDOT2 tDOT3 tUPLUS tUMINUS tPOW tDSTAR tCMP tLSHFT tRSHFT
+  tLEQ tGEQ tEQ tEQQ tNEQ tMATCH tNMATCH tAREF tASET
+  tCOLON2 tCOLON3
+]
+
 preserved_ids = %w[
   NULL
   Respond_to
@@ -70,74 +69,54 @@
 #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)
 
-#if !defined tLAST_TOKEN && defined YYTOKENTYPE
-#define tLAST_TOKEN tLAST_TOKEN
-#endif
+% token_op_ids.each_with_index do |token, index|
+#define RUBY_TOKEN_<%=token[/\At(.+)\z/, 1]%> <%=op_id_offset + index%>
+% end
+#define RUBY_TOKEN(t) RUBY_TOKEN_##t
 
 enum ruby_method_ids {
-#ifndef tLAST_TOKEN
-% tokens.each do |token, value|
-    <%=token%> = <%=value%>,
-% end
-#endif
-    idDot2 = tDOT2,
-    idDot3 = tDOT3,
-    idUPlus = tUPLUS,
-    idUMinus = tUMINUS,
-    idPow = tPOW,
-    idCmp = tCMP,
+    idDot2 = RUBY_TOKEN(DOT2),
+    idDot3 = RUBY_TOKEN(DOT3),
+    idUPlus = RUBY_TOKEN(UPLUS),
+    idUMinus = RUBY_TOKEN(UMINUS),
+    idPow = RUBY_TOKEN(POW),
+    idCmp = RUBY_TOKEN(CMP),
     idPLUS = '+',
     idMINUS = '-',
     idMULT = '*',
     idDIV = '/',
     idMOD = '%',
     idLT = '<',
-    idLTLT = tLSHFT,
-    idLE = tLEQ,
+    idLTLT = RUBY_TOKEN(LSHFT),
+    idLE = RUBY_TOKEN(LEQ),
     idGT = '>',
-    idGE = tGEQ,
-    idEq = tEQ,
-    idEqq = tEQQ,
-    idNeq = tNEQ,
+    idGE = RUBY_TOKEN(GEQ),
+    idEq = RUBY_TOKEN(EQ),
+    idEqq = RUBY_TOKEN(EQQ),
+    idNeq = RUBY_TOKEN(NEQ),
     idNot = '!',
     idBackquote = '`',
-    idEqTilde = tMATCH,
-    idNeqTilde = tNMATCH,
-    idAREF = tAREF,
-    idASET = tASET,
-    tPRESERVED_ID_BEGIN = tLAST_TOKEN-1,
+    idEqTilde = RUBY_TOKEN(MATCH),
+    idNeqTilde = RUBY_TOKEN(NMATCH),
+    idAREF = RUBY_TOKEN(AREF),
+    idASET = RUBY_TOKEN(ASET),
+    tPRESERVED_ID_BEGIN = <%=op_id_offset + token_op_ids.size - 1%>,
 % preserved_ids.each do |token|
     id<%=token%>,
 % end
     tPRESERVED_ID_END,
-    tLAST_OP_ID = tPRESERVED_ID_END-1,
-    idLAST_OP_ID = tLAST_OP_ID >> ID_SCOPE_SHIFT,
 % method_ids.each do |token|
     t<%=token%>,
 % end
-    tLAST_ID,
 #define TOKEN2ID(n) id##n = ((t##n<<ID_SCOPE_SHIFT)|ID_LOCAL)
 % method_ids.each do |token|
     TOKEN2ID(<%=token%>),
 % end
-    TOKEN2ID(LAST_ID)
+    tLAST_OP_ID = tPRESERVED_ID_END-1,
+    idLAST_OP_ID = tLAST_OP_ID >> ID_SCOPE_SHIFT
 };
 
-#ifdef tLAST_TOKEN
-struct ruby_method_ids_check {
-#define ruby_method_id_check_for(name, value) \
-    int checking_for_##name[name == (value) ? 1 : -1]
-% tokens.map do |token, value|
-ruby_method_id_check_for(<%=token%>, <%=value%>);
-% end
-};
-#endif
-
 #endif /* RUBY_ID_H */

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]