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 end << token
predefined_ids[token] = name predefined_ids[token] = name
end end
index = 127
token_ops.split(/^/).each do |line| token_ops.split(/^/).each do |line|
next if /^#/ =~ line next if /^#/ =~ line
line.sub!(/\s+#.*/, '') line.sub!(/\s+#.*/, '')
id, op, token = line.split id, op, token = line.split
next unless id and op next unless id and op
token ||= (id unless /\A\W\z/ =~ 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 end
{ {
"LOCAL" => local_ids, "LOCAL" => local_ids,
@ -212,4 +213,5 @@ end
:preserved => preserved_ids, :preserved => preserved_ids,
:predefined => predefined_ids, :predefined => predefined_ids,
:token_op => token_op_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") 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 = ids[:token_op].uniq {|id, op, token| token && op}
%> %>
% ops.each do |_id, _op, token| % 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") 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]/) types = ids.keys.grep(/^[A-Z]/)
%> %>
#ifndef RUBY_ID_H #ifndef RUBY_ID_H
@ -49,11 +47,9 @@ enum ruby_id_types {
#define symIFUNC ID2SYM(idIFUNC) #define symIFUNC ID2SYM(idIFUNC)
#define symCFUNC ID2SYM(idCFUNC) #define symCFUNC ID2SYM(idCFUNC)
% index = op_id_offset % ids[:token_op].each do |_id, _op, token, index|
% ids[:token_op].each do |_id, _op, token|
% next unless token % next unless token
#define RUBY_TOKEN_<%=token%> <%=index%> #define RUBY_TOKEN_<%=token%> <%=index%>
% index += 1
% end % end
#define RUBY_TOKEN(t) RUBY_TOKEN_##t #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| % ids[:token_op].uniq {|_, op| op}.each do |id, op, token|
id<%=id%> = <%=token ? "RUBY_TOKEN(#{token})" : "'#{op}'"%>, id<%=id%> = <%=token ? "RUBY_TOKEN(#{token})" : "'#{op}'"%>,
% end % end
tPRESERVED_ID_BEGIN = <%=index-1%>, tPRESERVED_ID_BEGIN = <%=ids[:last_token]%>,
% ids[:preserved].each do |token| % ids[:preserved].each do |token|
id<%=token%>, id<%=token%>,
% end % end