fix class statements to always have Statements as body

not sometimes an array, which sits badly in the tree of statements
This commit is contained in:
Torsten Ruger 2017-04-09 09:59:21 +03:00
parent a6e87491cd
commit 397eca541a
2 changed files with 24 additions and 3 deletions

View File

@ -4,7 +4,11 @@ module Vool
attr_reader :clazz attr_reader :clazz
def initialize( name , supe , body) def initialize( name , supe , body)
@name , @super_class_name , @body = name , supe , (body || []) @name , @super_class_name , @body = name , supe , body
unless( body.is_a?(ScopeStatement))
@body = ScopeStatement.new([])
@body.statements << body if body
end
end end
def collect(arr) def collect(arr)
@ -25,6 +29,7 @@ module Vool
vars.each { |var| ivar_hash[var] = :Object } vars.each { |var| ivar_hash[var] = :Object }
@clazz.set_instance_type( Parfait::Type.for_hash( @clazz , ivar_hash ) ) @clazz.set_instance_type( Parfait::Type.for_hash( @clazz , ivar_hash ) )
end end
puts "BODY is #{body.class}"
body.collect([]).each {|node| node.set_class(@clazz) } body.collect([]).each {|node| node.set_class(@clazz) }
body.create_objects body.create_objects
end end

View File

@ -1,7 +1,7 @@
require_relative "helper" require_relative "helper"
module Vool module Vool
class TestClassStatement < MiniTest::Test class TestEmptyClassStatement < MiniTest::Test
def setup def setup
input = "class Tryout < Base;end" input = "class Tryout < Base;end"
@ -21,7 +21,23 @@ module Vool
end end
def test_compile_class_body def test_compile_class_body
assert_equal [] , @lst.body assert_equal 0 , @lst.body.length
assert_equal ScopeStatement , @lst.body.class
end
end
class TestBasicClassStatement < MiniTest::Test
include CompilerHelper
def test_compile_one_method
lst = RubyCompiler.compile( in_Test("@ivar") )
assert_equal ScopeStatement , lst.body.class
assert_equal InstanceVariable , lst.body.statements.first.class
end
def test_compile_two_methods
lst = RubyCompiler.compile( in_Test("false; true;") )
assert_equal ScopeStatement , lst.body.class
assert_equal TrueStatement , lst.body.statements[1].class
end end
end end