rubyx/lib/vool/statements/class_statement.rb

48 lines
1.3 KiB
Ruby
Raw Normal View History

module Vool
2017-04-08 11:11:52 +02:00
class ClassStatement < Statement
attr_reader :name, :super_class_name , :body
2017-04-08 11:11:52 +02:00
attr_reader :clazz
def initialize( name , supe , body)
@name , @super_class_name , @body = name , supe , body
2017-04-08 11:11:52 +02:00
end
def normalize
ClassStatement.new(@name , @super_class_name, @body&.normalize )
end
2018-03-16 06:02:11 +01:00
# there is no mom equivalent for a class, this should never be called
def to_mom( _ )
raise "should not be called (call create_objects)"
end
def each(&block)
block.call(self)
@body.each(&block) if @body
2017-04-08 11:11:52 +02:00
end
def create_objects
create_class_object
mom = nil #return mom for test purpose
self.each {|node| mom = node.create_objects(@clazz) if node.is_a?(MethodStatement) }
mom
end
def create_class_object
2017-04-08 11:11:52 +02:00
@clazz = Parfait.object_space.get_class_by_name(@name )
if(@clazz)
#FIXME super class check with "sup"
#existing class, don't overwrite type (parfait only?)
else
2017-04-08 11:11:52 +02:00
@clazz = Parfait.object_space.create_class(@name , @super_class_name )
ivar_hash = {}
self.each do |node|
next unless node.is_a?(InstanceVariable) or node.is_a?(IvarAssignment)
ivar_hash[node.name] = :Object
end
@clazz.set_instance_type( Parfait::Type.for_hash( @clazz , ivar_hash ) )
2017-04-08 11:11:52 +02:00
end
end
end
end