summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-12-21 07:38:07 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-12-21 07:38:07 +0000
commit2edcf87c1c30c29562fc52075896935ebf398367 (patch)
treeebe3d9efe134d0da8799fa2bc46b304879684526
parent298694a2fdf4451163299d61a49a15fe49ab598a (diff)
id.def: check duplication
* defs/id.def (KeywordError): check duplication. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38522 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog4
-rw-r--r--defs/id.def13
-rw-r--r--template/id.c.tmpl2
-rw-r--r--template/id.h.tmpl2
4 files changed, 18 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index b302c20..678ac3f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,6 @@
-Fri Dec 21 16:38:00 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Fri Dec 21 16:38:05 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * defs/id.def (KeywordError): check duplication.
* defs/id.def: support for other scope IDs,
ID_{INSTANCE,GLOBAL,CONST,CLASS}.
diff --git a/defs/id.def b/defs/id.def
index a9b189f..48c6334 100644
--- a/defs/id.def
+++ b/defs/id.def
@@ -33,6 +33,12 @@ firstline, predefined = __LINE__+1, %[\
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 |line, num|
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
diff --git a/template/id.c.tmpl b/template/id.c.tmpl
index 4a272a9..cac213a 100644
--- a/template/id.c.tmpl
+++ b/template/id.c.tmpl
@@ -11,7 +11,7 @@
**********************************************************************/
<%
-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
diff --git a/template/id.h.tmpl b/template/id.h.tmpl
index 8df17b3..1573247 100644
--- a/template/id.h.tmpl
+++ b/template/id.h.tmpl
@@ -21,7 +21,7 @@ token_op_ids = %w[
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]/)
%>