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

Generate token ID indexes in id.def

Separate the logic accross the tables from the template view for
id.h.
This commit is contained in:
Nobuyoshi Nakada 2022-09-08 15:25:05 +09:00
parent 7400628cb0
commit a977c66312
No known key found for this signature in database
GPG key ID: 7CD2805BFA3770C6
3 changed files with 7 additions and 9 deletions

View file

@ -194,13 +194,14 @@ predefined.split(/^/).each_with_index do |line, num|
end << token
predefined_ids[token] = name
end
index = 127
token_ops.split(/^/).each do |line|
next if /^#/ =~ line
line.sub!(/\s+#.*/, '')
id, op, token = line.split
next unless id and op
token ||= (id unless /\A\W\z/ =~ op)
token_op_ids << [id, op, token]
token_op_ids << [id, op, token, (index += 1 if token)]
end
{
"LOCAL" => local_ids,
@ -212,4 +213,5 @@ end
:preserved => preserved_ids,
:predefined => predefined_ids,
:token_op => token_op_ids,
:last_token => index,
}

View file

@ -12,7 +12,7 @@
**********************************************************************/
<%
defs = File.join(File.dirname(File.dirname(erb.filename)), "defs/id.def")
ids = eval(File.read(defs), binding, defs)
ids = eval(File.read(defs), nil, defs)
ops = ids[:token_op].uniq {|id, op, token| token && op}
%>
% ops.each do |_id, _op, token|

View file

@ -11,10 +11,8 @@
**********************************************************************/
<%
op_id_offset = 128
defs = File.join(File.dirname(File.dirname(erb.filename)), "defs/id.def")
ids = eval(File.read(defs), binding, defs)
ids = eval(File.read(defs), nil, defs)
types = ids.keys.grep(/^[A-Z]/)
%>
#ifndef RUBY_ID_H
@ -49,11 +47,9 @@ enum ruby_id_types {
#define symIFUNC ID2SYM(idIFUNC)
#define symCFUNC ID2SYM(idCFUNC)
% index = op_id_offset
% ids[:token_op].each do |_id, _op, token|
% ids[:token_op].each do |_id, _op, token, index|
% next unless token
#define RUBY_TOKEN_<%=token%> <%=index%>
% index += 1
% end
#define RUBY_TOKEN(t) RUBY_TOKEN_##t
@ -66,7 +62,7 @@ enum ruby_method_ids {
% ids[:token_op].uniq {|_, op| op}.each do |id, op, token|
id<%=id%> = <%=token ? "RUBY_TOKEN(#{token})" : "'#{op}'"%>,
% end
tPRESERVED_ID_BEGIN = <%=index-1%>,
tPRESERVED_ID_BEGIN = <%=ids[:last_token]%>,
% ids[:preserved].each do |token|
id<%=token%>,
% end