summaryrefslogtreecommitdiff
path: root/tool
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-03-20 10:18:55 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-03-20 10:18:55 +0000
commit750c9916e28c0f8b97e4b4c261444d822a882c6c (patch)
treed995eb9c8720a7d0ebbb76930b136c05b6ab3a0d /tool
parentb7ed43e941e838dc516be3cd03c31a2d839301ec (diff)
* tool/transcode-tblgen.rb (ActionMap.unambiguous_action): use
Array#delete. (ActionMap.merge2): defined. (ActionMap::PostMemo): removed. (transcode_compile_tree): use ActionMap.merge2. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26990 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'tool')
-rwxr-xr-xtool/transcode-tblgen.rb50
1 files changed, 42 insertions, 8 deletions
diff --git a/tool/transcode-tblgen.rb b/tool/transcode-tblgen.rb
index b9b5a4a089..ad4d56b343 100755
--- a/tool/transcode-tblgen.rb
+++ b/tool/transcode-tblgen.rb
@@ -179,7 +179,7 @@ class ActionMap
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 @@ class ActionMap
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
end
PreMemo = {}
- PostMemo = {}
NextName = "a"
def generate_node(name_hint=nil)
@@ -571,16 +609,12 @@ End
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 @@ def transcode_compile_tree(name, from, map, valid_encoding=nil)
}
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