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

ruby-changes:7695

From: akr <ko1@a...>
Date: Sun, 7 Sep 2008 19:18:45 +0900 (JST)
Subject: [ruby-changes:7695] Ruby:r19216 (trunk): * tool/transcode-tblgen.rb (ActionMap#str_name): new method to

akr	2008-09-07 19:17:52 +0900 (Sun, 07 Sep 2008)

  New Revision: 19216

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

  Log:
    * 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.

  Modified files:
    trunk/ChangeLog
    trunk/tool/transcode-tblgen.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 19215)
+++ ChangeLog	(revision 19216)
@@ -1,3 +1,9 @@
+Sun Sep  7 19:16:38 2008  Tanaka Akira  <akr@f...>
+
+	* 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@f...>
 
 	* tool/transcode-tblgen.rb (ActionMap#generate_info): use a memo to
Index: tool/transcode-tblgen.rb
===================================================================
--- tool/transcode-tblgen.rb	(revision 19215)
+++ tool/transcode-tblgen.rb	(revision 19216)
@@ -277,8 +277,38 @@
     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 @@
     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

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

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