diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-08-09 06:02:01 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-08-09 06:02:01 +0000 |
commit | 139234e1a091ac3167d3bebdfcd29b3952665334 (patch) | |
tree | c1f7be47d34829813983af23e46340bf806d4ff4 /tool | |
parent | 750cb61e65f35feb70ad855ab3353485cfd75b0c (diff) |
* transcode_data.h (rb_transcoding): add fields for restartable
transcoding.
(rb_transcoder): add max_input field.
from_unit_length field is renamed to input_unit_length.
* tool/transcode-tblgen.rb: generate max_input field.
* enc/trans/iso2022.erb.c: follow rb_transcoder change.
* enc/trans/utf_16_32.erb.c: ditto.
* transcode.c (PARTIAL_INPUT): new constant.
(transcode_char_start): new function.
(transcode_result_t): new type.
(transcode_restartable): new function.
(more_output_buffer): new function.
(transcode_loop): use transcode_restartable.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18452 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'tool')
-rw-r--r-- | tool/transcode-tblgen.rb | 35 |
1 files changed, 30 insertions, 5 deletions
diff --git a/tool/transcode-tblgen.rb b/tool/transcode-tblgen.rb index 3a20b3f0b1..119fa0d1cb 100644 --- a/tool/transcode-tblgen.rb +++ b/tool/transcode-tblgen.rb @@ -101,6 +101,22 @@ class StrSet "\#<#{self.class}: #{self.to_s}>" end + def min_length + if @pat.empty? + nil + else + @pat.map {|seq| seq.length }.min + end + end + + def max_length + if @pat.empty? + nil + else + @pat.map {|seq| seq.length }.max + end + end + def emptyable? @pat.any? {|seq| seq.empty? @@ -170,6 +186,10 @@ class ActionMap ">" end + def max_input_length + @map.keys.map {|k| k.max_length }.max + end + def empty_action @map.each {|ss, action| return action if ss.emptyable? @@ -386,6 +406,8 @@ def transcode_compile_tree(name, from, map) } am = ActionMap.parse(h) + max_input = am.max_input_length + if ValidEncoding[from] valid_encoding = StrSet.parse(ValidEncoding[from]) else @@ -394,7 +416,7 @@ def transcode_compile_tree(name, from, map) code = '' defined_name = am.generate_node(code, name, valid_encoding) - return defined_name, code + return defined_name, code, max_input end TRANSCODERS = [] @@ -411,16 +433,19 @@ def transcode_tblgen(from, to, map) tree_name = "from_#{id_from}_to_#{id_to}" end map = encode_utf8(map) - real_tree_name, tree_code = transcode_compile_tree(tree_name, from, map) + real_tree_name, tree_code, max_input = transcode_compile_tree(tree_name, from, map) transcoder_name = "rb_#{tree_name}" TRANSCODERS << transcoder_name - from_unit_length = UnitLength[from] + input_unit_length = UnitLength[from] max_output = map.map {|k,v| String === v ? v.length/2 : 1 }.max transcoder_code = <<"End" static const rb_transcoder #{transcoder_name} = { - #{c_esc from}, #{c_esc to}, &#{real_tree_name}, #{from_unit_length}, #{max_output}, - NULL, NULL, + #{c_esc from}, #{c_esc to}, &#{real_tree_name}, + #{input_unit_length}, /* input_unit_length */ + #{max_input}, /* max_input */ + #{max_output}, /* max_output */ + NULL, NULL, NULL, NULL, NULL }; End tree_code + "\n" + transcoder_code |