summaryrefslogtreecommitdiff
path: root/template
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-08-31 05:31:20 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-08-31 05:31:20 +0000
commit470c941ce5bd1800fc24f271c6234cee096fd592 (patch)
tree124a826f07c07015f08bc835b057200570f91671 /template
parent2e42f37a020ce9c94f7d41e69b3e3ffec43a54ce (diff)
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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36864 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'template')
-rw-r--r--template/id.h.tmpl81
1 files changed, 30 insertions, 51 deletions
diff --git a/template/id.h.tmpl b/template/id.h.tmpl
index 3279064..0e54e76 100644
--- a/template/id.h.tmpl
+++ b/template/id.h.tmpl
@@ -13,14 +13,7 @@
<%
require 'optparse'
-input = ARGV.shift or abort opt.opt_s
-
-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
+op_id_offset = 128
method_ids = %w[
Intern
@@ -39,6 +32,12 @@ method_ids = %w[
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 @@ preserved_ids = %w[
#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)
-};
-
-#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
+ tLAST_OP_ID = tPRESERVED_ID_END-1,
+ idLAST_OP_ID = tLAST_OP_ID >> ID_SCOPE_SHIFT
};
-#endif
#endif /* RUBY_ID_H */