* defs/id.def: support for other scope IDs,
  ID_{INSTANCE,GLOBAL,CONST,CLASS}.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38521 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2012-12-21 07:38:03 +00:00
Родитель e8794bf215
Коммит 298694a2fd
4 изменённых файлов: 47 добавлений и 16 удалений

Просмотреть файл

@ -1,3 +1,8 @@
Fri Dec 21 16:38:00 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
* defs/id.def: support for other scope IDs,
ID_{INSTANCE,GLOBAL,CONST,CLASS}.
Fri Dec 21 14:45:00 2012 Zachary Scott <zachary@zacharyscott.net>
* lib/irb.rb, lib/irb/*: Documentation for IRB

Просмотреть файл

@ -1,5 +1,5 @@
# -*- ruby -*-
predefined = %[\
# -*- mode: ruby; coding: us-ascii -*-
firstline, predefined = __LINE__+1, %[\
intern
method_missing MethodMissing
length
@ -35,16 +35,40 @@ predefined = %[\
predefined_ids = {}
preserved_ids = []
attr_ids = []
predefined.each_line do |line|
local_ids = []
instance_ids = []
global_ids = []
const_ids = []
class_ids = []
names = {}
predefined.lines.each_with_index do |line, num|
next if /^#/ =~ line or (name, token = line.split; !name)
token ||= name
if /#/ =~ token
token = "_#{token.gsub(/\W+/, '_')}"
else
token = token.sub(/\?/, 'P').sub(/\A[a-z]/) {$&.upcase}
token.sub!(/\A\$/, "_G_")
token.sub!(/\A@@/, "_C_")
token.sub!(/\A@/, "_I_")
token.gsub!(/\W+/, "")
end
(/\A(?!\d)\w+\z/ =~ name ? attr_ids : preserved_ids) << token
case name
when /\A[A-Z]\w*\z/; const_ids
when /\A(?!\d)\w+\z/; local_ids
when /\A\$(?:\d+|(?!\d)\w+)\z/; global_ids
when /\A@@(?!\d)\w+\z/; class_ids
when /\A@(?!\d)\w+\z/; instance_ids
else preserved_ids
end << token
predefined_ids[token] = name
end
{
"LOCAL" => local_ids,
"INSTANCE" => instance_ids,
"GLOBAL" => global_ids,
"CONST" => const_ids,
"CLASS" => class_ids,
:preserved => preserved_ids,
:predefined => predefined_ids,
}

Просмотреть файл

@ -11,9 +11,8 @@
**********************************************************************/
<%
predefined_ids = nil
defs = File.join(File.dirname(erb.filename), "../defs/id.def")
eval(File.read(defs), binding, defs)
ids = eval(File.read(defs), binding, defs)
%>
static void
Init_id(void)
@ -22,7 +21,7 @@ Init_id(void)
#define rb_intern(str) rb_intern_const(str)
rb_encoding *enc = rb_usascii_encoding();
% predefined_ids.each_pair do |token, name|
% ids[:predefined].each do |token, name|
REGISTER_SYMID(id<%=token%>, "<%=name%>");
% end
}

Просмотреть файл

@ -21,10 +21,9 @@ token_op_ids = %w[
tCOLON2 tCOLON3
]
preserved_ids = nil
attr_ids = nil
defs = File.join(File.dirname(erb.filename), "../defs/id.def")
eval(File.read(defs), binding, defs)
ids = eval(File.read(defs), binding, defs)
types = ids.keys.grep(/^[A-Z]/)
%>
#ifndef RUBY_ID_H
#define RUBY_ID_H
@ -75,16 +74,20 @@ enum ruby_method_ids {
idAREF = RUBY_TOKEN(AREF),
idASET = RUBY_TOKEN(ASET),
tPRESERVED_ID_BEGIN = <%=op_id_offset + token_op_ids.size - 1%>,
% preserved_ids.each do |token|
% ids[:preserved].each do |token|
id<%=token%>,
% end
tPRESERVED_ID_END,
% attr_ids.each do |token|
% ids.values_at(*types).flatten.each do |token|
t<%=token%>,
% end
#define TOKEN2ID(n) id##n = ((t##n<<ID_SCOPE_SHIFT)|ID_LOCAL)
% attr_ids.each do |token|
TOKEN2ID(<%=token%>),
% types.each do |type|
% types = ids[type] or next
% types.empty? and next
#define TOKEN2<%=type%>ID(n) id##n = ((t##n<<ID_SCOPE_SHIFT)|ID_<%=type%>)
% types.each do |token|
TOKEN2<%=type%>ID(<%=token%>),
% end
% end
tLAST_OP_ID = tPRESERVED_ID_END-1,
idLAST_OP_ID = tLAST_OP_ID >> ID_SCOPE_SHIFT