summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-09-03 11:36:04 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-09-03 11:36:04 +0000
commit9233dc9bf4072a20f67c25df5ce181f614edccd7 (patch)
treedf162435c874cbceefe45608243cff1848b2f911
parent4406629bd6f5841db014f9ec5aed860239182e05 (diff)
* tool/transcode-tblgen.rb (ArrayCode): new class.
(ActionMap#gen_array_code): moved to ArrayCode. (ActionMap#numelt_array_code): ditto. (ActionMap#array_code_insert_at_last): ditto. (TRANSCODE_GENERATED_BYTES_CODE): use ArrayCode. (TRANSCODE_GENERATED_WORDS_CODE): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19087 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog9
-rw-r--r--tool/transcode-tblgen.rb74
2 files changed, 46 insertions, 37 deletions
diff --git a/ChangeLog b/ChangeLog
index 4e6ffe8045..2589dc8f2f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+Wed Sep 3 20:34:10 2008 Tanaka Akira <akr@fsij.org>
+
+ * tool/transcode-tblgen.rb (ArrayCode): new class.
+ (ActionMap#gen_array_code): moved to ArrayCode.
+ (ActionMap#numelt_array_code): ditto.
+ (ActionMap#array_code_insert_at_last): ditto.
+ (TRANSCODE_GENERATED_BYTES_CODE): use ArrayCode.
+ (TRANSCODE_GENERATED_WORDS_CODE): ditto.
+
Wed Sep 3 20:08:35 2008 Tanaka Akira <akr@fsij.org>
* enc/trans/japanese.trans: new file.
diff --git a/tool/transcode-tblgen.rb b/tool/transcode-tblgen.rb
index 2404847aca..9738205022 100644
--- a/tool/transcode-tblgen.rb
+++ b/tool/transcode-tblgen.rb
@@ -155,6 +155,32 @@ class StrSet
end
end
+class ArrayCode
+ def initialize(type, name)
+ @code = <<"End"
+static const #{type}
+#{name}[0] = {
+};
+End
+ end
+
+ def length
+ @code[/\[\d+\]/][1...-1].to_i
+ end
+
+ def insert_at_last(num, str)
+ newnum = self.length + num
+ @code.sub!(/^(\};\n\z)/) {
+ str + $1
+ }
+ @code.sub!(/\[\d+\]/) { "[#{newnum}]" }
+ end
+
+ def to_s
+ @code.dup
+ end
+end
+
class ActionMap
def self.parse(hash)
h = {}
@@ -298,26 +324,6 @@ class ActionMap
code
end
- def gen_array_code(type, name)
- <<"End"
-static const #{type}
-#{name}[0] = {
-};
-End
- end
-
- def numelt_array_code(code)
- code[/\[\d+\]/][1...-1].to_i
- end
-
- def array_code_insert_at_last(code, num, str)
- newnum = numelt_array_code(code) + num
- code.sub!(/^(\};\n\z)/) {
- str + $1
- }
- code.sub!(/\[\d+\]/) { "[#{newnum}]" }
- end
-
def generate_lookup_node(bytes_code, words_code, name, table)
offsets = []
infos = []
@@ -345,33 +351,26 @@ End
else
offsets_name = "#{name}_offsets"
OffsetsMemo[offsets_key] = offsets_name
- if bytes_code.empty?
- bytes_code << gen_array_code("unsigned char", "#{OUTPUT_PREFIX}byte_array")
- end
- size = numelt_array_code(bytes_code)
- array_code_insert_at_last(bytes_code, 2+max-min+1,
+ size = bytes_code.length
+ bytes_code.insert_at_last(2+max-min+1,
"\#define #{offsets_name} #{size}\n" +
format_offsets(min,max,offsets) + "\n")
end
- if words_code.empty?
- words_code << gen_array_code("unsigned int", "#{OUTPUT_PREFIX}word_array")
- end
-
if n = InfosMemo[infos]
infos_name = n
else
infos_name = "#{name}_infos"
InfosMemo[infos] = infos_name
- size = numelt_array_code(words_code)
- array_code_insert_at_last(words_code, infos.length,
+ size = words_code.length
+ words_code.insert_at_last(infos.length,
"\#define #{infos_name} (sizeof(unsigned int)*#{size})\n" +
format_infos(infos) + "\n")
end
- size = numelt_array_code(words_code)
- array_code_insert_at_last(words_code, NUM_ELEM_BYTELOOKUP,
+ size = words_code.length
+ words_code.insert_at_last(NUM_ELEM_BYTELOOKUP,
"\#define #{name} (sizeof(unsigned int)*#{size})\n" +
<<"End" + "\n")
#{offsets_name},
@@ -563,8 +562,6 @@ def transcode_compile_tree(name, from, map)
end
TRANSCODERS = []
-TRANSCODE_GENERATED_BYTES_CODE = ''
-TRANSCODE_GENERATED_WORDS_CODE = ''
TRANSCODE_GENERATED_TRANSCODER_CODE = ''
def transcode_tblgen(from, to, map)
@@ -608,8 +605,8 @@ def transcode_generate_node(am, name_hint=nil)
end
def transcode_generated_code
- TRANSCODE_GENERATED_BYTES_CODE +
- TRANSCODE_GENERATED_WORDS_CODE +
+ TRANSCODE_GENERATED_BYTES_CODE.to_s +
+ TRANSCODE_GENERATED_WORDS_CODE.to_s +
"\#define TRANSCODE_TABLE_INFO #{OUTPUT_PREFIX}byte_array, #{OUTPUT_PREFIX}word_array, sizeof(unsigned int)\n" +
TRANSCODE_GENERATED_TRANSCODER_CODE
end
@@ -722,6 +719,9 @@ OUTPUT_PREFIX = output_filename ? File.basename(output_filename)[/\A[A-Za-z0-9_]
OUTPUT_PREFIX.sub!(/\A_+/, '')
OUTPUT_PREFIX.sub!(/_*\z/, '_')
+TRANSCODE_GENERATED_BYTES_CODE = ArrayCode.new("unsigned char", "#{OUTPUT_PREFIX}byte_array")
+TRANSCODE_GENERATED_WORDS_CODE = ArrayCode.new("unsigned int", "#{OUTPUT_PREFIX}word_array")
+
arg = ARGV.shift
$srcdir = File.dirname(arg)
$:.unshift $srcdir unless $:.include? $srcdir