summaryrefslogtreecommitdiff
path: root/tool/transcode-tblgen.rb
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-09-03 11:07:16 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-09-03 11:07:16 +0000
commit8108417c5e4088b3b1ab6fe90a9a6d2ff9268892 (patch)
tree57b12f94c5dcaffb297ef01676148a8aff1a03ec /tool/transcode-tblgen.rb
parent2eb763857dd356d62ec46fd528e466b3fc8c2991 (diff)
* tool/transcode-tblgen.rb (ActionMap#gen_array_code): extracted from
generate_lookup_node. (ActionMap#numelt_array_code): ditto. (ActionMap#array_code_insert_at_last): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19085 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'tool/transcode-tblgen.rb')
-rw-r--r--tool/transcode-tblgen.rb61
1 files changed, 31 insertions, 30 deletions
diff --git a/tool/transcode-tblgen.rb b/tool/transcode-tblgen.rb
index 4f77da7..2404847 100644
--- a/tool/transcode-tblgen.rb
+++ b/tool/transcode-tblgen.rb
@@ -298,6 +298,26 @@ 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 = []
@@ -326,28 +346,16 @@ class ActionMap
offsets_name = "#{name}_offsets"
OffsetsMemo[offsets_key] = offsets_name
if bytes_code.empty?
- bytes_code << <<"End"
-static const unsigned char
-#{OUTPUT_PREFIX}byte_array[0] = {
-};
-End
+ bytes_code << gen_array_code("unsigned char", "#{OUTPUT_PREFIX}byte_array")
end
- size = bytes_code[/\[\d+\]/][1...-1].to_i
- bytes_code.sub!(/^(\};\n\z)/) {
+ size = numelt_array_code(bytes_code)
+ array_code_insert_at_last(bytes_code, 2+max-min+1,
"\#define #{offsets_name} #{size}\n" +
- format_offsets(min,max,offsets) + "\n" +
- $1
- }
- size += 2+max-min+1
- bytes_code.sub!(/\[\d+\]/) { "[#{size}]" }
+ format_offsets(min,max,offsets) + "\n")
end
if words_code.empty?
- words_code << <<"End"
-static const unsigned int
-#{OUTPUT_PREFIX}word_array[0] = {
-};
-End
+ words_code << gen_array_code("unsigned int", "#{OUTPUT_PREFIX}word_array")
end
if n = InfosMemo[infos]
@@ -356,26 +364,19 @@ End
infos_name = "#{name}_infos"
InfosMemo[infos] = infos_name
- size = words_code[/\[\d+\]/][1...-1].to_i
- words_code.sub!(/^(\};\n\z)/) {
+ size = numelt_array_code(words_code)
+ array_code_insert_at_last(words_code, infos.length,
"\#define #{infos_name} (sizeof(unsigned int)*#{size})\n" +
- format_infos(infos) + "\n" +
- $1
- }
- size += infos.length
- words_code.sub!(/\[\d+\]/) { "[#{size}]" }
+ format_infos(infos) + "\n")
end
- size = words_code[/\[\d+\]/][1...-1].to_i
- words_code.sub!(/^(\};\n\z)/) {
+ size = numelt_array_code(words_code)
+ array_code_insert_at_last(words_code, NUM_ELEM_BYTELOOKUP,
"\#define #{name} (sizeof(unsigned int)*#{size})\n" +
- <<"End" + "\n" + $1
+ <<"End" + "\n")
#{offsets_name},
#{infos_name},
End
- }
- size += NUM_ELEM_BYTELOOKUP
- words_code.sub!(/\[\d+\]/) { "[#{size}]" }
end
PreMemo = {}