add to_s for statements

This commit is contained in:
Torsten Ruger 2018-07-03 22:18:19 +03:00
parent e099014d63
commit 2ad24ab0bb
11 changed files with 51 additions and 0 deletions

View File

@ -40,6 +40,11 @@ module Vool
block.call(self)
@value.each(&block)
end
def to_s(depth = 0)
at_depth(depth , "#{@name} = #{@value}")
end
end
class IvarAssignment < Assignment

View File

@ -52,5 +52,9 @@ module Vool
@clazz.set_instance_type( Parfait::Type.for_hash( @clazz , ivar_hash ) )
end
end
def to_s(depth = 0)
at_depth(depth , "class #{name}" , @body.to_s(depth + 1) , "end")
end
end
end

View File

@ -62,5 +62,11 @@ module Vool
@if_true != nil
end
def to_s(depth = 0)
parts = ["if (#{@condition})" , @body.to_s(depth + 1) ]
parts += ["else" , "@if_false.to_s(depth + 1)"] if(@false)
parts << "end"
at_depth(depth , *parts )
end
end
end

View File

@ -8,5 +8,9 @@ module Vool
@name , @left , @right = name , left , right
end
def to_s(depth = 0)
at_depth(depth , "#{left} #{name} #{right}")
end
end
end

View File

@ -35,6 +35,11 @@ module Vool
Parfait::NamedList.type_for( type_hash )
end
def to_s(depth = 0)
arg_str = @args.collect{|a| a.to_s}.join(', ')
at_depth(depth , "def #{name}(#{arg_str})" , @body.to_s(depth + 1) , "end")
end
private
def make_frame

View File

@ -29,5 +29,8 @@ module Vool
ret << Mom::ReturnSequence.new
end
def to_s(depth = 0)
at_depth(depth , "return #{@return_value.to_s}")
end
end
end

View File

@ -129,6 +129,11 @@ module Vool
message_setup(in_method,dynamic_call.cache_entry) << dynamic_call
end
def to_s(depth = 0)
sen = "#{receiver}.#{name}(#{@arguments.collect{|a| a.to_s}.join(', ')})"
at_depth(depth , sen)
end
private
def receiver_type_definition(in_method)
defi = @receiver.slot_definition(in_method)

View File

@ -36,6 +36,11 @@ module Vool
raise "Not implemented for #{self}"
end
def at_depth(depth , *strings)
prefix = " " * 2 * depth
strings.collect{|str| prefix + str}.join("\n")
end
end
class Expression

View File

@ -55,6 +55,10 @@ module Vool
Statements.new(@statements.collect{|s| s.normalize})
end
end
def to_s(depth = 0)
at_depth(depth , *@statements.collect{|st| st.to_s(depth)})
end
end
class ScopeStatement < Statements

View File

@ -18,6 +18,9 @@ module Vool
end
Mom::SlotDefinition.new(:message , [type , @name])
end
def to_s
name.to_s
end
end
class InstanceVariable < Expression
@ -29,6 +32,9 @@ module Vool
def add_ivar( array )
array << @name
end
def to_s
"@#{name}"
end
end
class ClassVariable < Expression

View File

@ -34,5 +34,9 @@ module Vool
@body.each(&block)
end
def to_s(depth = 0)
at_depth(depth , "while (#{@condition})" , @body.to_s(depth + 1) , "end" )
end
end
end