diff options
author | John Hodge <tpg@ucc.asn.au> | 2016-06-05 00:30:12 +0800 |
---|---|---|
committer | John Hodge <tpg@ucc.asn.au> | 2016-06-05 00:30:12 +0800 |
commit | 1f614012969b0d9052ee1bb0526afddc7e6187b6 (patch) | |
tree | c46d8d2d3815aa72c97633ebf5adaff99d68bc0a /src/resolve | |
parent | b745c5f88faf89af9a487b7cf0cfc362b73c0423 (diff) | |
download | mrust-1f614012969b0d9052ee1bb0526afddc7e6187b6.tar.gz |
Resolve - Replace `Self` when known
Diffstat (limited to 'src/resolve')
-rw-r--r-- | src/resolve/absolute.cpp | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/src/resolve/absolute.cpp b/src/resolve/absolute.cpp index 180cab0f..86d35ca7 100644 --- a/src/resolve/absolute.cpp +++ b/src/resolve/absolute.cpp @@ -68,6 +68,7 @@ struct Context if( has_self ) { assert( level == GenericSlot::Level::Top ); data.types.push_back( Named<GenericSlot> { "Self", GenericSlot { level, 0xFFFF } } ); + m_name_context.push_back( Ent::make_ConcreteSelf(nullptr) ); } if( params.ty_params().size() > 0 ) { const auto& typs = params.ty_params(); @@ -106,6 +107,25 @@ struct Context BUG(Span(), "resolve/absolute.cpp - Context::pop(TypeRef) - Mismatched pop"); } } + ::TypeRef get_self() const { + for(auto it = m_name_context.rbegin(); it != m_name_context.rend(); ++ it) + { + TU_MATCH_DEF(Ent, (*it), (e), + ( + ), + (ConcreteSelf, + if( e ) { + return e->clone(); + } + else { + return ::TypeRef("Self"); + } + ) + ) + } + + TODO(Span(), "Error when get_self called with no self"); + } void push_block() { m_block_level += 1; @@ -815,7 +835,16 @@ void Resolve_Absolute_Type(Context& context, TypeRef& type) } ), (Generic, - // TODO: Should this be bound to the relevant index, or just leave as-is? + if( e.name == "Self" ) + { + type = context.get_self(); + } + else + { + auto idx = context.lookup_local(type.span(), e.name, Context::LookupMode::Type); + // TODO: Should this be bound to the relevant index, or just leave as-is? + e.index = idx; + } ), (Path, Resolve_Absolute_Path(context, type.span(), Context::LookupMode::Type, e.path); |