2018-07-19 13:46:51 +02:00
|
|
|
module Ruby
|
|
|
|
module Normalizer
|
|
|
|
# given a something, determine if it is a Name
|
|
|
|
#
|
|
|
|
# Return a Name, and a possible rest that has a hoisted part of the statement
|
|
|
|
#
|
|
|
|
# eg if( @var % 5) is not normalized
|
|
|
|
# but if(tmp_123) is with tmp_123 = @var % 5 hoisted above the if
|
|
|
|
#
|
|
|
|
# also constants count, though they may not be so useful in ifs, but returns
|
2018-07-20 08:07:09 +02:00
|
|
|
def normalize_name( condition )
|
2018-07-19 13:46:51 +02:00
|
|
|
if( condition.is_a?(ScopeStatement) and condition.single?)
|
|
|
|
condition = condition.first
|
|
|
|
end
|
2018-07-20 19:53:35 +02:00
|
|
|
return [condition] if condition.is_a?(Variable) or condition.is_a?(Constant)
|
2018-07-19 13:46:51 +02:00
|
|
|
local = "tmp_#{object_id}".to_sym
|
2018-07-20 16:51:17 +02:00
|
|
|
assign = LocalAssignment.new( local , condition)
|
|
|
|
[LocalVariable.new(local) , assign]
|
2018-07-19 13:46:51 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|