adds super
with and without args current thinking is to fill the name of the method later as we carry no context currently, but this may change
This commit is contained in:
parent
ac7b9138ff
commit
443fd13980
@ -19,6 +19,8 @@ module Vool
|
||||
end
|
||||
class SelfStatement < Statement
|
||||
end
|
||||
class SuperStatement < Statement
|
||||
end
|
||||
class StringStatement < Statement
|
||||
attr_accessor :value
|
||||
def initialize(value)
|
||||
|
@ -161,6 +161,22 @@ module Vool
|
||||
w
|
||||
end
|
||||
|
||||
# this is a call to super without args (z = zero arity)
|
||||
def on_zsuper exp
|
||||
w = SendStatement.new( nil )
|
||||
w.receiver = SuperStatement.new
|
||||
w
|
||||
end
|
||||
|
||||
# this is a call to super with args and
|
||||
# same name as current method, which is set later
|
||||
def on_super( statement )
|
||||
w = SendStatement.new( nil )
|
||||
w.receiver = SuperStatement.new
|
||||
w.arguments = process_all(statement.children)
|
||||
w
|
||||
end
|
||||
|
||||
# def on_name statement
|
||||
# NameStatement.new(statement.children.first)
|
||||
# end
|
||||
|
@ -3,6 +3,7 @@ module Vool
|
||||
attr_accessor :name , :receiver , :arguments
|
||||
def initialize(name)
|
||||
@name = name
|
||||
@arguments = []
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -36,5 +36,28 @@ module Vool
|
||||
lst = Compiler.compile( "bar(1)")
|
||||
assert_equal 1 , lst.arguments.first.value
|
||||
end
|
||||
|
||||
def test_super0_receiver
|
||||
lst = Compiler.compile( "super")
|
||||
assert_equal SuperStatement , lst.receiver.class
|
||||
end
|
||||
def test_super0
|
||||
lst = Compiler.compile( "super")
|
||||
assert_equal SendStatement , lst.class
|
||||
end
|
||||
|
||||
def test_super_receiver
|
||||
lst = Compiler.compile( "super(1)")
|
||||
assert_equal SuperStatement , lst.receiver.class
|
||||
end
|
||||
def test_super_args
|
||||
lst = Compiler.compile( "super(1)")
|
||||
assert_equal 1 , lst.arguments.first.value
|
||||
end
|
||||
def test_super_name #is nil
|
||||
lst = Compiler.compile( "super(1)")
|
||||
assert_nil lst.name
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user