mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
transform_mjit_header.rb: scan by regexp
* tool/transform_mjit_header.rb (find_decl): scan by regexp instead of char-by-char loop. return nil when finished. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62213 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
e743b36318
commit
a38b3307b6
1 changed files with 14 additions and 13 deletions
|
@ -24,24 +24,28 @@ module MJITHeader
|
||||||
# Return start..stop of last decl in CODE ending STOP
|
# Return start..stop of last decl in CODE ending STOP
|
||||||
def self.find_decl(code, stop)
|
def self.find_decl(code, stop)
|
||||||
level = 0
|
level = 0
|
||||||
stop.downto(0) do |i|
|
i = stop
|
||||||
if level == 0 && stop != i && decl_found?(code, i)
|
while i = code.rindex(/[;{}]/, i)
|
||||||
return decl_start(code, i)..stop
|
if level == 0 && stop != i && decl_found?($&, i)
|
||||||
elsif code[i] == '}'
|
return decl_start($&, i)..stop
|
||||||
|
end
|
||||||
|
case $&
|
||||||
|
when '}'
|
||||||
level += 1
|
level += 1
|
||||||
elsif code[i] == '{'
|
when '{'
|
||||||
level -= 1
|
level -= 1
|
||||||
end
|
end
|
||||||
|
i -= 1
|
||||||
end
|
end
|
||||||
0..-1
|
nil
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.decl_found?(code, i)
|
def self.decl_found?(code, i)
|
||||||
i == 0 || code[i] == ';' || code[i] == '}'
|
i == 0 || code == ';' || code == '}'
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.decl_start(code, i)
|
def self.decl_start(code, i)
|
||||||
if i == 0 && code[i] != ';' && code[i] != '}'
|
if i == 0 && code != ';' && code != '}'
|
||||||
0
|
0
|
||||||
else
|
else
|
||||||
i + 1
|
i + 1
|
||||||
|
@ -139,14 +143,11 @@ end
|
||||||
puts "\nTransforming external functions to static:"
|
puts "\nTransforming external functions to static:"
|
||||||
|
|
||||||
code = MJITHeader.separate_macro_and_code(code) # note: this does not work on MinGW
|
code = MJITHeader.separate_macro_and_code(code) # note: this does not work on MinGW
|
||||||
stop_pos = code.match(/^#/).begin(0) # See `separate_macro_and_code`. This ignores proprocessors.
|
stop_pos = -1
|
||||||
extern_names = []
|
extern_names = []
|
||||||
|
|
||||||
# This loop changes function declarations to static inline.
|
# This loop changes function declarations to static inline.
|
||||||
loop do
|
while (decl_range = MJITHeader.find_decl(code, stop_pos))
|
||||||
decl_range = MJITHeader.find_decl(code, stop_pos)
|
|
||||||
break if decl_range.end < 0
|
|
||||||
|
|
||||||
stop_pos = decl_range.begin - 1
|
stop_pos = decl_range.begin - 1
|
||||||
decl = code[decl_range]
|
decl = code[decl_range]
|
||||||
decl_name = MJITHeader.decl_name_of(decl)
|
decl_name = MJITHeader.decl_name_of(decl)
|
||||||
|
|
Loading…
Add table
Reference in a new issue