1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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
This commit is contained in:
akr 2008-09-07 10:17:52 +00:00
parent dcdc7579c5
commit eee75cc1a6
2 changed files with 37 additions and 13 deletions

View file

@ -1,3 +1,9 @@
Sun Sep 7 19:16:38 2008 Tanaka Akira <akr@fsij.org>
* 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.
Sun Sep 7 18:28:05 2008 Tanaka Akira <akr@fsij.org>
* tool/transcode-tblgen.rb (ActionMap#generate_info): use a memo to

View file

@ -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