enforces data encapsulation in vool tree
gets rid of attraccessor
This commit is contained in:
parent
b9caad937a
commit
3fe286b5ed
@ -1,6 +1,6 @@
|
|||||||
module Vool
|
module Vool
|
||||||
class Assignment < Statement
|
class Assignment < Statement
|
||||||
attr_accessor :name , :value
|
attr_reader :name , :value
|
||||||
def initialize(name , value )
|
def initialize(name , value )
|
||||||
@name , @value = name , value
|
@name , @value = name , value
|
||||||
end
|
end
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
module Vool
|
module Vool
|
||||||
class IntegerStatement < Statement
|
class IntegerStatement < Statement
|
||||||
attr_accessor :value
|
attr_reader :value
|
||||||
def initialize(value)
|
def initialize(value)
|
||||||
@value = value
|
@value = value
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
class FloatStatement < Statement
|
class FloatStatement < Statement
|
||||||
attr_accessor :value
|
attr_reader :value
|
||||||
def initialize(value)
|
def initialize(value)
|
||||||
@value = value
|
@value = value
|
||||||
end
|
end
|
||||||
@ -22,7 +22,7 @@ module Vool
|
|||||||
class SuperStatement < Statement
|
class SuperStatement < Statement
|
||||||
end
|
end
|
||||||
class StringStatement < Statement
|
class StringStatement < Statement
|
||||||
attr_accessor :value
|
attr_reader :value
|
||||||
def initialize(value)
|
def initialize(value)
|
||||||
@value = value
|
@value = value
|
||||||
end
|
end
|
||||||
|
@ -1,11 +1,17 @@
|
|||||||
module Vool
|
module Vool
|
||||||
class IfStatement < Statement
|
class IfStatement < Statement
|
||||||
attr_accessor :condition , :if_true , :if_false
|
attr_reader :condition , :if_true , :if_false
|
||||||
|
|
||||||
def initialize( cond = nil)
|
def initialize( cond , if_true , if_false = [])
|
||||||
@condition = cond
|
@condition = cond
|
||||||
@if_true = []
|
@if_true = if_true
|
||||||
@if_false = []
|
@if_false = if_false
|
||||||
|
simplify_condition
|
||||||
|
end
|
||||||
|
|
||||||
|
def simplify_condition
|
||||||
|
return unless @condition.is_a?(ScopeStatement)
|
||||||
|
@condition = @condition.first if @condition.single?
|
||||||
end
|
end
|
||||||
|
|
||||||
def has_false?
|
def has_false?
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
module Vool
|
module Vool
|
||||||
class ReturnStatement < Statement
|
class ReturnStatement < Statement
|
||||||
attr_accessor :return_value
|
attr_reader :return_value
|
||||||
|
|
||||||
def initialize(value)
|
def initialize(value)
|
||||||
@return_value = value
|
@return_value = value
|
||||||
|
@ -137,30 +137,22 @@ module Vool
|
|||||||
|
|
||||||
def on_while statement
|
def on_while statement
|
||||||
condition , statements = *statement
|
condition , statements = *statement
|
||||||
w = WhileStatement.new( process(condition) )
|
WhileStatement.new( process(condition) , process(statements))
|
||||||
simplify_condition(w)
|
|
||||||
w.statements = process(statements)
|
|
||||||
w
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def on_if statement
|
def on_if statement
|
||||||
condition , if_true , if_false = *statement
|
condition , if_true , if_false = *statement
|
||||||
w = IfStatement.new( process(condition) )
|
if_true = process(if_true)
|
||||||
simplify_condition(w)
|
if_false = process(if_false)
|
||||||
w.if_true = process(if_true)
|
IfStatement.new( process(condition) , if_true , if_false )
|
||||||
w.if_false = process(if_false)
|
|
||||||
w
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def on_send statement
|
def on_send statement
|
||||||
kids = statement.children.dup
|
kids = statement.children.dup
|
||||||
receiver = kids.shift
|
receiver = process(kids.shift) || SelfStatement.new
|
||||||
name = kids.shift
|
name = kids.shift
|
||||||
arguments = kids
|
arguments = process_all(kids)
|
||||||
w = SendStatement.new( name )
|
SendStatement.new( name , receiver , arguments )
|
||||||
w.receiver = process(receiver) || SelfStatement.new
|
|
||||||
w.arguments = process_all(arguments)
|
|
||||||
w
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def on_and expression
|
def on_and expression
|
||||||
@ -173,18 +165,14 @@ module Vool
|
|||||||
|
|
||||||
# this is a call to super without args (z = zero arity)
|
# this is a call to super without args (z = zero arity)
|
||||||
def on_zsuper exp
|
def on_zsuper exp
|
||||||
w = SendStatement.new( nil )
|
SendStatement.new( nil , SuperStatement.new )
|
||||||
w.receiver = SuperStatement.new
|
|
||||||
w
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# this is a call to super with args and
|
# this is a call to super with args and
|
||||||
# same name as current method, which is set later
|
# same name as current method, which is set later
|
||||||
def on_super( statement )
|
def on_super( statement )
|
||||||
w = SendStatement.new( nil )
|
arguments = process_all(statement.children)
|
||||||
w.receiver = SuperStatement.new
|
SendStatement.new( nil , SuperStatement.new , arguments)
|
||||||
w.arguments = process_all(statement.children)
|
|
||||||
w
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def on_assignment statement
|
def on_assignment statement
|
||||||
@ -197,12 +185,6 @@ module Vool
|
|||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def simplify_condition( cond )
|
|
||||||
condition = cond.condition
|
|
||||||
return unless condition.is_a?(ScopeStatement)
|
|
||||||
cond.condition = condition.first if condition.single?
|
|
||||||
end
|
|
||||||
|
|
||||||
def instance_name sym
|
def instance_name sym
|
||||||
sym.to_s[1 .. -1].to_sym
|
sym.to_s[1 .. -1].to_sym
|
||||||
end
|
end
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
module Vool
|
module Vool
|
||||||
class SendStatement < Statement
|
class SendStatement < Statement
|
||||||
attr_accessor :name , :receiver , :arguments
|
attr_reader :name , :receiver , :arguments
|
||||||
def initialize(name)
|
|
||||||
@name = name
|
def initialize(name , receiver , arguments = [])
|
||||||
@arguments = []
|
@name , @receiver , @arguments = name , receiver , arguments
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
module Vool
|
module Vool
|
||||||
class Statements < Statement
|
class Statements < Statement
|
||||||
attr_accessor :statements
|
attr_reader :statements
|
||||||
def initialize(statements)
|
def initialize(statements)
|
||||||
@statements = statements
|
@statements = statements
|
||||||
end
|
end
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
module Vool
|
module Vool
|
||||||
module Named
|
module Named
|
||||||
attr_accessor :name
|
attr_reader :name
|
||||||
def initialize name
|
def initialize name
|
||||||
@name = name
|
@name = name
|
||||||
end
|
end
|
||||||
|
@ -1,9 +1,17 @@
|
|||||||
module Vool
|
module Vool
|
||||||
class WhileStatement < Statement
|
class WhileStatement < Statement
|
||||||
attr_accessor :condition , :statements
|
attr_reader :condition , :statements
|
||||||
|
|
||||||
def initialize( condition )
|
def initialize( condition , statements )
|
||||||
@condition = condition
|
@condition = condition
|
||||||
|
@statements = statements
|
||||||
|
simplify_condition
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def simplify_condition
|
||||||
|
return unless @condition.is_a?(ScopeStatement)
|
||||||
|
@condition = @condition.first if @condition.single?
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user