summaryrefslogtreecommitdiff
path: root/tool
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-09-07 10:17:52 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-09-07 10:17:52 +0000
commiteee75cc1a67c4360ed762f3c01df2ebe074d8d4d (patch)
treee65d09b182fd7e89275bbe1d2862a9680b6a8e99 /tool
parentdcdc7579c5e9bf5596e19f52e30d1f2bcd67610b (diff)
* tool/transcode-tblgen.rb (ActionMap#str_name): new method to
generate a name base on string content. (ActionMap#gen_str): extracted from generate_info and use str_name. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19216 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'tool')
-rw-r--r--tool/transcode-tblgen.rb44
1 files changed, 31 insertions, 13 deletions
diff --git a/tool/transcode-tblgen.rb b/tool/transcode-tblgen.rb
index 33368db2e9d..b9301e5c5cb 100644
--- a/tool/transcode-tblgen.rb
+++ b/tool/transcode-tblgen.rb
@@ -277,8 +277,38 @@ class ActionMap
code
end
+ UsedName = {}
+
StrMemo = {}
+ def str_name(bytes)
+ size = @bytes_code.length
+ rawbytes = [bytes].pack("H*")
+
+ n = nil
+ if !n && !(suf = rawbytes.gsub(/[^A-Za-z0-9_]/, '')).empty? && !UsedName[nn = "str1_" + suf] then n = nn end
+ if !n && !UsedName[nn = "str1_" + bytes] then n = nn end
+ n ||= "str1s_#{size}"
+
+ StrMemo[bytes] = n
+ UsedName[n] = true
+ n
+ end
+
+ def gen_str(bytes)
+ if n = StrMemo[bytes]
+ n
+ else
+ len = bytes.length/2
+ size = @bytes_code.length
+ n = str_name(bytes)
+ @bytes_code.insert_at_last(1 + len,
+ "\#define #{n} makeSTR1(#{size})\n" +
+ " #{len}," + bytes.gsub(/../, ' 0x\&,') + "\n")
+ n
+ end
+ end
+
def generate_info(info)
case info
when :nomap
@@ -304,19 +334,7 @@ class ActionMap
when /\A(f[0-7])([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])\z/i
"o4(0x#$1,0x#$2,0x#$3,0x#$4)"
when /\A([0-9a-f][0-9a-f]){0,255}\z/i
- bytes = info.upcase
- if n = StrMemo[bytes]
- n
- else
- len = info.length/2
- size = @bytes_code.length
- @bytes_code.insert_at_last(1 + len,
- "\#define str1_#{size} makeSTR1(#{size})\n" +
- " #{len}," + info.gsub(/../, ' 0x\&,') + "\n")
- n = "str1_#{size}"
- StrMemo[bytes] = n
- n
- end
+ gen_str(info.upcase)
when /\A\/\*BYTE_LOOKUP\*\// # pointer to BYTE_LOOKUP structure
$'.to_s
else