summaryrefslogtreecommitdiff
path: root/template
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-11-05 04:04:00 (GMT)
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-11-05 04:04:00 (GMT)
commit72b785e07210c7419802caa3595fc03d84df2c3a (patch)
tree618b9df3d58a48193bba18ccbc56819b41c900b4 /template
parentfcd15352327bb7d6c8db952e8c3fb3ce7412cca1 (diff)
id.def: token_ops
* defs/id.def (token_ops): gather associations between IDs, operators, and parser tokens. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52458 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'template')
-rw-r--r--template/id.c.tmpl16
-rw-r--r--template/id.h.tmpl48
2 files changed, 25 insertions, 39 deletions
diff --git a/template/id.c.tmpl b/template/id.c.tmpl
index cac213a..477a76b 100644
--- a/template/id.c.tmpl
+++ b/template/id.c.tmpl
@@ -13,7 +13,23 @@
<%
defs = File.join(File.dirname(File.dirname(erb.filename)), "defs/id.def")
ids = eval(File.read(defs), binding, defs)
+ops = ids[:token_op].uniq {|id, op, token| token && op}
%>
+% ops.each do |_id, _op, token|
+% next unless token
+#define t<%=token%> RUBY_TOKEN(<%=token%>)
+% end
+
+static const struct {
+ unsigned short token;
+ const char name[3], term;
+} op_tbl[] = {
+% ops.each do |_id, op, token|
+% next unless token
+ {t<%=token%>, "<%=op%>"},
+% end
+};
+
static void
Init_id(void)
{
diff --git a/template/id.h.tmpl b/template/id.h.tmpl
index 5e7f117..0db35c1 100644
--- a/template/id.h.tmpl
+++ b/template/id.h.tmpl
@@ -15,12 +15,6 @@ require 'optparse'
op_id_offset = 128
-token_op_ids = %w[
- tDOT2 tDOT3 tUPLUS tUMINUS tPOW tDSTAR tCMP tLSHFT tRSHFT
- tLEQ tGEQ tEQ tEQQ tNEQ tMATCH tNMATCH tAREF tASET
- tCOLON2 tCOLON3 tANDOP tOROP tDOTQ
-]
-
defs = File.join(File.dirname(File.dirname(erb.filename)), "defs/id.def")
ids = eval(File.read(defs), binding, defs)
types = ids.keys.grep(/^[A-Z]/)
@@ -57,43 +51,19 @@ enum ruby_id_types {
#define symIFUNC ID2SYM(idIFUNC)
#define symCFUNC ID2SYM(idCFUNC)
-% token_op_ids.each_with_index do |token, index|
-#define RUBY_TOKEN_<%=token[/\At(.+)\z/, 1]%> <%=op_id_offset + index%>
+% index = op_id_offset
+% ids[:token_op].each do |_id, _op, token|
+% next unless token
+#define RUBY_TOKEN_<%=token%> <%=index%>
+% index += 1
% end
#define RUBY_TOKEN(t) RUBY_TOKEN_##t
enum ruby_method_ids {
- 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 = RUBY_TOKEN(LSHFT),
- idLE = RUBY_TOKEN(LEQ),
- idGT = '>',
- idGTGT = RUBY_TOKEN(RSHFT),
- idGE = RUBY_TOKEN(GEQ),
- idEq = RUBY_TOKEN(EQ),
- idEqq = RUBY_TOKEN(EQQ),
- idNeq = RUBY_TOKEN(NEQ),
- idNot = '!',
- idBackquote = '`',
- idEqTilde = RUBY_TOKEN(MATCH),
- idNeqTilde = RUBY_TOKEN(NMATCH),
- idAREF = RUBY_TOKEN(AREF),
- idASET = RUBY_TOKEN(ASET),
- idCOLON2 = RUBY_TOKEN(COLON2),
- idANDOP = RUBY_TOKEN(ANDOP),
- idOROP = RUBY_TOKEN(OROP),
- idDOTQ = RUBY_TOKEN(DOTQ),
- tPRESERVED_ID_BEGIN = <%=op_id_offset + token_op_ids.size - 1%>,
+% ids[:token_op].uniq {|_, op| op}.each do |id, op, token|
+ id<%=id%> = <%=token ? "RUBY_TOKEN(#{token})" : "'#{op}'"%>,
+% end
+ tPRESERVED_ID_BEGIN = <%=index-1%>,
% ids[:preserved].each do |token|
id<%=token%>,
% end