[前][次][番号順一覧][スレッド一覧]

ruby-changes:26470

From: nobu <ko1@a...>
Date: Fri, 21 Dec 2012 16:38:13 +0900 (JST)
Subject: [ruby-changes:26470] nobu:r38521 (trunk): id.def: other scope ID

nobu	2012-12-21 16:38:03 +0900 (Fri, 21 Dec 2012)

  New Revision: 38521

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=38521

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

  Modified files:
    trunk/ChangeLog
    trunk/defs/id.def
    trunk/template/id.c.tmpl
    trunk/template/id.h.tmpl

Index: defs/id.def
===================================================================
--- defs/id.def	(revision 38520)
+++ defs/id.def	(revision 38521)
@@ -1,5 +1,5 @@ https://github.com/ruby/ruby/blob/trunk/defs/id.def#L1
-# -*- ruby -*-
-predefined = %[\
+# -*- mode: ruby; coding: us-ascii -*-
+firstline, predefined = __LINE__+1, %[\
   intern
   method_missing                                        MethodMissing
   length
@@ -35,16 +35,40 @@ predefined = %[\ https://github.com/ruby/ruby/blob/trunk/defs/id.def#L35
 
 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,
+}
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 38520)
+++ ChangeLog	(revision 38521)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Fri Dec 21 16:38:00 2012  Nobuyoshi Nakada  <nobu@r...>
+
+	* defs/id.def: support for other scope IDs,
+	  ID_{INSTANCE,GLOBAL,CONST,CLASS}.
+
 Fri Dec 21 14:45:00 2012  Zachary Scott  <zachary@z...>
 
 	* lib/irb.rb, lib/irb/*: Documentation for IRB
Index: template/id.c.tmpl
===================================================================
--- template/id.c.tmpl	(revision 38520)
+++ template/id.c.tmpl	(revision 38521)
@@ -11,9 +11,8 @@ https://github.com/ruby/ruby/blob/trunk/template/id.c.tmpl#L11
 
 **********************************************************************/
 <%
-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) https://github.com/ruby/ruby/blob/trunk/template/id.c.tmpl#L21
 #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
 }
Index: template/id.h.tmpl
===================================================================
--- template/id.h.tmpl	(revision 38520)
+++ template/id.h.tmpl	(revision 38521)
@@ -21,10 +21,9 @@ token_op_ids = %w[ https://github.com/ruby/ruby/blob/trunk/template/id.h.tmpl#L21
   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 { https://github.com/ruby/ruby/blob/trunk/template/id.h.tmpl#L74
     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

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]