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

ruby-changes:15113

From: akr <ko1@a...>
Date: Sat, 20 Mar 2010 19:19:14 +0900 (JST)
Subject: [ruby-changes:15113] Ruby:r26990 (trunk): * tool/transcode-tblgen.rb (ActionMap.unambiguous_action): use

akr	2010-03-20 19:18:55 +0900 (Sat, 20 Mar 2010)

  New Revision: 26990

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

  Log:
    * tool/transcode-tblgen.rb (ActionMap.unambiguous_action): use
      Array#delete.
      (ActionMap.merge2): defined.
      (ActionMap::PostMemo): removed.
      (transcode_compile_tree): use ActionMap.merge2.

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

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 26989)
+++ ChangeLog	(revision 26990)
@@ -1,3 +1,11 @@
+Sat Mar 20 19:16:42 2010  Tanaka Akira  <akr@f...>
+
+	* tool/transcode-tblgen.rb (ActionMap.unambiguous_action): use
+	  Array#delete.
+	  (ActionMap.merge2): defined.
+	  (ActionMap::PostMemo): removed.
+	  (transcode_compile_tree): use ActionMap.merge2.
+
 Sat Mar 20 13:26:09 2010  Tanaka Akira  <akr@f...>
 
 	* array.c (rb_ary_uniq_bang): the array is already unique if the
Index: tool/transcode-tblgen.rb
===================================================================
--- tool/transcode-tblgen.rb	(revision 26989)
+++ tool/transcode-tblgen.rb	(revision 26990)
@@ -179,7 +179,7 @@
     if actions.length == 1
       actions[0]
     else
-      actions = actions.find_all {|action| action != :nomap0 }
+      actions.delete(:nomap0)
       if actions.length == 1
         actions[0]
       else
@@ -225,6 +225,45 @@
     merge_rects(*mappings.map {|m| parse_to_rects(m) }, &block)
   end
 
+  def self.merge2(map1, map2, &block)
+    rects1 = parse_to_rects(map1)
+    rects2 = parse_to_rects(map2)
+
+    actions = []
+    all_rects = []
+
+    rects1.each {|rect|
+      min, max, action = rect
+      rect[2] = actions.length
+      actions << action
+      all_rects << rect
+    }
+
+    boundary = actions.length
+
+    rects2.each {|rect|
+      min, max, action = rect
+      rect[2] = actions.length
+      actions << action
+      all_rects << rect
+    }
+
+    tree = expand(all_rects) {|prefix, as0|
+      as1 = []
+      as2 = []
+      as0.each {|i|
+        if i < boundary
+          as1 << actions[i]
+        else
+          as2 << actions[i]
+        end
+      }
+      yield(prefix, as1, as2)
+    }
+
+    self.new(tree)
+  end
+
   def self.expand(rects, &block)
     #numsing = numreg = 0
     #rects.each {|min, max, action| if min == max then numsing += 1 else numreg += 1 end }
@@ -547,7 +586,6 @@
   end
 
   PreMemo = {}
-  PostMemo = {}
   NextName = "a"
 
   def generate_node(name_hint=nil)
@@ -571,16 +609,12 @@
       end
     }
 
-    if n = PostMemo[table]
-      return PreMemo[@tree] = n
-    end
-
     if !name_hint
       name_hint = "fun_" + NextName
       NextName.succ!
     end
 
-    PreMemo[@tree] = PostMemo[table] = name_hint
+    PreMemo[@tree] = name_hint
 
     generate_lookup_node(name_hint, table)
     name_hint
@@ -732,7 +766,7 @@
   }
   valid_encoding = ValidEncoding[from] if valid_encoding == nil
   if valid_encoding
-    am = ActionMap.merge(h, {valid_encoding => :undef}) {|prefix, as1, as2|
+    am = ActionMap.merge2(h, {valid_encoding => :undef}) {|prefix, as1, as2|
       a1 = as1.empty? ? nil : ActionMap.unambiguous_action(as1)
       a2 = as2.empty? ? nil : ActionMap.unambiguous_action(as2)
       if !a2

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

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