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

ruby-changes:26471

From: nobu <ko1@a...>
Date: Fri, 21 Dec 2012 16:38:27 +0900 (JST)
Subject: [ruby-changes:26471] nobu:r38522 (trunk): id.def: check duplication

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

  New Revision: 38522

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

  Log:
    id.def: check duplication
    
    * defs/id.def (KeywordError): check duplication.

  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 38521)
+++ defs/id.def	(revision 38522)
@@ -33,6 +33,12 @@ firstline, predefined = __LINE__+1, %[\ https://github.com/ruby/ruby/blob/trunk/defs/id.def#L33
   core#hash_merge_kwd
 ]
 
+class KeywordError < RuntimeError
+  def self.raise(mesg, line)
+    super(self, mesg, ["#{__FILE__}:#{line}", *caller])
+  end
+end
+
 predefined_ids = {}
 preserved_ids = []
 local_ids = []
@@ -53,6 +59,13 @@ predefined.lines.each_with_index do |lin https://github.com/ruby/ruby/blob/trunk/defs/id.def#L59
     token.sub!(/\A@/, "_I_")
     token.gsub!(/\W+/, "")
   end
+  if prev = names[name]
+    KeywordError.raise("#{name} is already registered at line #{prev+firstline}", firstline+num)
+  end
+  if prev = predefined_ids[token]
+    KeywordError.raise("#{token} is already used for #{prev} at line #{names[prev]+firstline}", firstline+num)
+  end
+  names[name] = num
   case name
   when /\A[A-Z]\w*\z/; const_ids
   when /\A(?!\d)\w+\z/; local_ids
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 38521)
+++ ChangeLog	(revision 38522)
@@ -1,4 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
-Fri Dec 21 16:38:00 2012  Nobuyoshi Nakada  <nobu@r...>
+Fri Dec 21 16:38:05 2012  Nobuyoshi Nakada  <nobu@r...>
+
+	* defs/id.def (KeywordError): check duplication.
 
 	* defs/id.def: support for other scope IDs,
 	  ID_{INSTANCE,GLOBAL,CONST,CLASS}.
Index: template/id.c.tmpl
===================================================================
--- template/id.c.tmpl	(revision 38521)
+++ template/id.c.tmpl	(revision 38522)
@@ -11,7 +11,7 @@ https://github.com/ruby/ruby/blob/trunk/template/id.c.tmpl#L11
 
 **********************************************************************/
 <%
-defs = File.join(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)
 %>
 static void
Index: template/id.h.tmpl
===================================================================
--- template/id.h.tmpl	(revision 38521)
+++ template/id.h.tmpl	(revision 38522)
@@ -21,7 +21,7 @@ token_op_ids = %w[ https://github.com/ruby/ruby/blob/trunk/template/id.h.tmpl#L21
   tCOLON2 tCOLON3
 ]
 
-defs = File.join(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)
 types = ids.keys.grep(/^[A-Z]/)
 %>

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

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