1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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
This commit is contained in:
akr 2008-09-03 11:07:16 +00:00
parent 2eb763857d
commit 8108417c5e
2 changed files with 38 additions and 30 deletions

View file

@ -1,3 +1,10 @@
Wed Sep 3 20:04:33 2008 Tanaka Akira <akr@fsij.org>
* 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.
Wed Sep 3 20:01:01 2008 Tanaka Akira <akr@fsij.org>
* parse.y (parser_encoding_name): defined.

View file

@ -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 = {}