2018-03-15 06:54:14 +01:00
|
|
|
module Vool
|
|
|
|
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
|
2018-06-27 16:09:50 +02:00
|
|
|
# but if(tmp_123) is with tmp_123 = @var % 5 hoisted above the if
|
2018-03-16 15:09:35 +01:00
|
|
|
#
|
|
|
|
# also constants count, though they may not be so useful in ifs, but returns
|
2018-03-15 08:16:56 +01:00
|
|
|
def normalize_name( condition )
|
2018-03-16 14:11:17 +01:00
|
|
|
if( condition.is_a?(ScopeStatement) and condition.single?)
|
|
|
|
condition = condition.first
|
|
|
|
end
|
2018-03-16 15:09:35 +01:00
|
|
|
return [condition] if condition.is_a?(Named) or condition.is_a?(Constant)
|
2018-03-16 14:11:17 +01:00
|
|
|
condition = condition.normalize
|
2018-03-22 16:38:13 +01:00
|
|
|
local = "tmp_#{object_id}".to_sym
|
2018-03-15 08:16:56 +01:00
|
|
|
assign = Statements.new [LocalAssignment.new( local , condition)]
|
2018-03-15 06:54:14 +01:00
|
|
|
[LocalVariable.new(local) , assign]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|