From 2f9acf36cfd475dc48b7a46e4cdff1b284529a79 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Mon, 22 Aug 2016 20:03:11 +0800 Subject: AST+HIR - Save decoded receiver type for methods --- src/ast/ast.cpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'src/ast/ast.cpp') diff --git a/src/ast/ast.cpp b/src/ast/ast.cpp index b9394702..29ddf07f 100644 --- a/src/ast/ast.cpp +++ b/src/ast/ast.cpp @@ -302,6 +302,38 @@ Module::ItemRef Module::find_item(const ::std::string& needle, bool allow_leaves } +Function::Function(Span sp, GenericParams params, TypeRef ret_type, Arglist args): + m_span(sp), + m_params( move(params) ), + m_rettype( move(ret_type) ), + m_args( move(args) ) +{ + if( m_args.size() > 0 && m_args.front().first.binding().m_name == "self" ) { + const auto& ty = m_args.front().second; + TU_MATCH_DEF( ::TypeData, (ty.m_data), (e), + ( + // Whups! + ERROR(sp, E0000, "Invalid receiver type - " << ty); + ), + (Borrow, + if(e.is_mut) { + m_receiver = Receiver::BorrowUnique; + } + else { + m_receiver = Receiver::BorrowShared; + } + ), + // NOTE: This only applies for `self/&self/&mut self` syntax, NOT the `self: Self` syntax + (Generic, + if( e.index != 0xFFFF ) { + ERROR(sp, E0000, "Invalid receiver type - " << ty); + } + m_receiver = Receiver::Value; + ) + ) + } +} + void Trait::add_type(::std::string name, TypeRef type) { m_items.push_back( Named(mv$(name), Item::make_Type({TypeAlias(GenericParams(), mv$(type))}), true) ); } -- cgit v1.2.3