summaryrefslogtreecommitdiff
path: root/src/ast/ast.cpp
diff options
context:
space:
mode:
authorJohn Hodge <tpg@mutabah.net>2016-08-22 20:03:11 +0800
committerJohn Hodge <tpg@mutabah.net>2016-08-22 20:03:11 +0800
commit2f9acf36cfd475dc48b7a46e4cdff1b284529a79 (patch)
tree50b25571223d37ad30430d573a6857b846941598 /src/ast/ast.cpp
parent96621f217b750115c01457d79a74f9676164b463 (diff)
downloadmrust-2f9acf36cfd475dc48b7a46e4cdff1b284529a79.tar.gz
AST+HIR - Save decoded receiver type for methods
Diffstat (limited to 'src/ast/ast.cpp')
-rw-r--r--src/ast/ast.cpp32
1 files changed, 32 insertions, 0 deletions
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<Item>(mv$(name), Item::make_Type({TypeAlias(GenericParams(), mv$(type))}), true) );
}