2017-04-01 14:57:39 +02:00
|
|
|
module Vool
|
2017-04-08 11:11:52 +02:00
|
|
|
class ClassStatement < Statement
|
2017-04-01 14:57:39 +02:00
|
|
|
attr_reader :name, :super_class_name , :body
|
2017-04-08 11:11:52 +02:00
|
|
|
attr_reader :clazz
|
2017-04-01 14:57:39 +02:00
|
|
|
|
|
|
|
def initialize( name , supe , body)
|
2017-04-09 08:59:21 +02:00
|
|
|
@name , @super_class_name , @body = name , supe , body
|
|
|
|
unless( body.is_a?(ScopeStatement))
|
|
|
|
@body = ScopeStatement.new([])
|
|
|
|
@body.statements << body if body
|
|
|
|
end
|
2017-04-08 11:11:52 +02:00
|
|
|
end
|
|
|
|
|
2017-04-12 10:52:23 +02:00
|
|
|
# compilation to the next layer, mom
|
|
|
|
# context coming in for class is nil, also for methods, henceafter a method is passed down
|
|
|
|
def to_mom( _ )
|
2017-09-11 13:23:06 +02:00
|
|
|
methods = @body.statements.collect { |meth| meth.to_mom( nil ) }
|
2017-09-06 11:51:24 +02:00
|
|
|
Mom::Statements.new(methods)
|
2017-04-12 10:52:23 +02:00
|
|
|
end
|
|
|
|
|
2017-04-08 11:11:52 +02:00
|
|
|
def collect(arr)
|
|
|
|
@body.collect(arr)
|
|
|
|
super
|
|
|
|
end
|
|
|
|
|
|
|
|
def create_objects
|
2018-03-14 13:11:09 +01:00
|
|
|
create_class_object
|
|
|
|
body.collect([]).each {|node| node.set_class(@clazz) }
|
|
|
|
body.create_objects
|
|
|
|
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"
|
2017-04-08 18:20:11 +02:00
|
|
|
#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 )
|
2017-04-08 18:20:11 +02:00
|
|
|
vars = []
|
|
|
|
@body.collect([]).each { |node| node.add_ivar(vars) }
|
|
|
|
ivar_hash = {}
|
|
|
|
vars.each { |var| ivar_hash[var] = :Object }
|
|
|
|
@clazz.set_instance_type( Parfait::Type.for_hash( @clazz , ivar_hash ) )
|
2017-04-08 11:11:52 +02:00
|
|
|
end
|
2017-04-01 14:57:39 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|