2016-12-20 19:02:52 +01:00
|
|
|
module Melon
|
|
|
|
|
2016-12-21 09:51:33 +01:00
|
|
|
class MethodCollector < TotalProcessor
|
2016-12-20 19:02:52 +01:00
|
|
|
|
|
|
|
def initialize
|
|
|
|
@methods = []
|
|
|
|
end
|
|
|
|
|
|
|
|
def collect(statement)
|
|
|
|
process statement
|
|
|
|
@methods
|
|
|
|
end
|
|
|
|
|
|
|
|
def on_def(statement)
|
|
|
|
name , args , body = *statement
|
|
|
|
args_type = make_type(args)
|
2016-12-21 10:30:35 +01:00
|
|
|
locals_type = make_locals(body)
|
|
|
|
@methods << RubyMethod.new(name , args_type , locals_type , body )
|
2016-12-20 19:02:52 +01:00
|
|
|
end
|
|
|
|
|
2016-12-21 10:30:35 +01:00
|
|
|
private
|
|
|
|
|
2016-12-20 19:02:52 +01:00
|
|
|
def make_type( statement )
|
2017-01-13 21:16:06 +01:00
|
|
|
type_hash = {}
|
2016-12-20 19:02:52 +01:00
|
|
|
statement.children.each do |arg|
|
2017-01-13 21:16:06 +01:00
|
|
|
type_hash[arg.children[0]] = :Object
|
2016-12-20 19:02:52 +01:00
|
|
|
end
|
2017-01-13 21:16:06 +01:00
|
|
|
Parfait::NamedList.type_for( type_hash )
|
2016-12-20 19:02:52 +01:00
|
|
|
end
|
|
|
|
|
2016-12-21 10:30:35 +01:00
|
|
|
def make_locals(body)
|
2017-01-13 21:16:06 +01:00
|
|
|
type_hash = LocalsCollector.new.collect(body)
|
|
|
|
Parfait::NamedList.type_for( type_hash )
|
2016-12-21 10:30:35 +01:00
|
|
|
end
|
2016-12-20 19:02:52 +01:00
|
|
|
end
|
|
|
|
end
|