2018-07-19 13:46:51 +02:00
|
|
|
module Ruby
|
|
|
|
module Normalizer
|
2019-10-03 23:36:49 +02:00
|
|
|
# Normalize ruby to sol by "flattening" structure
|
2018-07-19 13:46:51 +02:00
|
|
|
#
|
2019-08-16 13:09:56 +02:00
|
|
|
# This is a common issue for return, if and while , which all need to operate on the
|
2019-10-03 23:36:49 +02:00
|
|
|
# last value. In ruby the last value is always implicit, in sol not.
|
2018-07-19 13:46:51 +02:00
|
|
|
#
|
2019-08-16 13:09:56 +02:00
|
|
|
# A "normalized" structure is first of all not recursive, a list not a tree,
|
|
|
|
# The last expression of the list may be one of three things
|
|
|
|
# - a constant (unlikely, unless code is returning /testing a constant)
|
|
|
|
# - any variable (same)
|
|
|
|
# - a simple call (most common, but see call "normalisation" in SendStatement)
|
2018-07-19 13:46:51 +02:00
|
|
|
#
|
2019-08-16 13:09:56 +02:00
|
|
|
# We return the last expression, the one that is returned or tested on, seperately
|
|
|
|
#
|
2019-10-03 23:36:49 +02:00
|
|
|
def normalized_sol( condition )
|
|
|
|
sol_condition = condition.to_sol
|
|
|
|
return sol_condition unless( sol_condition.is_a?(Sol::Statements) )
|
|
|
|
return sol_condition.first if( sol_condition.single?)
|
|
|
|
return [sol_condition.pop , sol_condition ]
|
2018-07-19 13:46:51 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|