diff options
author | John Hodge <tpg@mutabah.net> | 2016-09-03 14:11:40 +0800 |
---|---|---|
committer | John Hodge <tpg@mutabah.net> | 2016-09-03 14:11:40 +0800 |
commit | c9442608f88bb841660aa9358b42f3fc9729c72f (patch) | |
tree | faecc8464db161fed70882cad90d8bc867d5178a /src | |
parent | 5b8ec18a7c2e85d4e0f8ebbbe24d816d0caa4a76 (diff) | |
download | mrust-c9442608f88bb841660aa9358b42f3fc9729c72f.tar.gz |
Resolve - More populated bindings
Diffstat (limited to 'src')
-rw-r--r-- | src/hir/from_ast_expr.cpp | 49 | ||||
-rw-r--r-- | src/resolve/absolute.cpp | 34 |
2 files changed, 65 insertions, 18 deletions
diff --git a/src/hir/from_ast_expr.cpp b/src/hir/from_ast_expr.cpp index 415ff978..5e3908aa 100644 --- a/src/hir/from_ast_expr.cpp +++ b/src/hir/from_ast_expr.cpp @@ -563,16 +563,32 @@ struct LowerHIR_ExprNode_Visitor: m_rv.reset( new ::HIR::ExprNode_PathValue( v.span(), mv$(p), ::HIR::ExprNode_PathValue::UNKNOWN ) ); ), (Struct, - assert( e.struct_ ); + ASSERT_BUG(v.span(), e.struct_ || e.hir, "PathValue bound to a struct but pointer not set - " << v.m_path); // Check the form and emit a PathValue if not a unit - if( e.struct_->m_data.is_Struct() ) { - ERROR(v.span(), E0000, "Named value referring to a struct that isn't tuple-like or unit-like - " << v.m_path); - } - else if( e.struct_->m_data.as_Tuple().ents.size() > 0 ) { - m_rv.reset( new ::HIR::ExprNode_PathValue( v.span(), LowerHIR_Path(Span(v.get_pos()), v.m_path), ::HIR::ExprNode_PathValue::STRUCT_CONSTR ) ); + if( e.struct_ ) + { + if( e.struct_->m_data.is_Struct() ) { + ERROR(v.span(), E0000, "Named value referring to a struct that isn't tuple-like or unit-like - " << v.m_path); + } + else if( e.struct_->m_data.as_Tuple().ents.size() > 0 ) { + m_rv.reset( new ::HIR::ExprNode_PathValue( v.span(), LowerHIR_Path(Span(v.get_pos()), v.m_path), ::HIR::ExprNode_PathValue::STRUCT_CONSTR ) ); + } + else { + m_rv.reset( new ::HIR::ExprNode_UnitVariant( v.span(), LowerHIR_GenericPath(Span(v.get_pos()), v.m_path), true ) ); + } } - else { - m_rv.reset( new ::HIR::ExprNode_UnitVariant( v.span(), LowerHIR_GenericPath(Span(v.get_pos()), v.m_path), true ) ); + else + { + const auto& str = *e.hir; + if( str.m_data.is_Unit() ) { + m_rv.reset( new ::HIR::ExprNode_UnitVariant( v.span(), LowerHIR_GenericPath(Span(v.get_pos()), v.m_path), true ) ); + } + else if( str.m_data.is_Tuple() ) { + m_rv.reset( new ::HIR::ExprNode_PathValue( v.span(), LowerHIR_Path(Span(v.get_pos()), v.m_path), ::HIR::ExprNode_PathValue::STRUCT_CONSTR ) ); + } + else { + ERROR(v.span(), E0000, "Named value referring to a struct that isn't tuple-like or unit-like - " << v.m_path); + } } ), (EnumVar, @@ -582,11 +598,22 @@ struct LowerHIR_ExprNode_Visitor: m_rv.reset( new ::HIR::ExprNode_PathValue( v.span(), LowerHIR_Path(Span(v.get_pos()), v.m_path), ::HIR::ExprNode_PathValue::FUNCTION ) ); ), (Static, - assert( e.static_ ); - if( e.static_->s_class() != ::AST::Static::CONST ) { + if( e.static_ ) + { + if( e.static_->s_class() != ::AST::Static::CONST ) { + m_rv.reset( new ::HIR::ExprNode_PathValue( v.span(), LowerHIR_Path(Span(v.get_pos()), v.m_path), ::HIR::ExprNode_PathValue::STATIC ) ); + } + else { + m_rv.reset( new ::HIR::ExprNode_PathValue( v.span(), LowerHIR_Path(Span(v.get_pos()), v.m_path), ::HIR::ExprNode_PathValue::CONSTANT ) ); + } + } + else if( e.hir ) + { m_rv.reset( new ::HIR::ExprNode_PathValue( v.span(), LowerHIR_Path(Span(v.get_pos()), v.m_path), ::HIR::ExprNode_PathValue::STATIC ) ); } - else { + // HACK: If the HIR pointer is nullptr, then it refers to a `const + else + { m_rv.reset( new ::HIR::ExprNode_PathValue( v.span(), LowerHIR_Path(Span(v.get_pos()), v.m_path), ::HIR::ExprNode_PathValue::CONSTANT ) ); } ) diff --git a/src/resolve/absolute.cpp b/src/resolve/absolute.cpp index 7106e572..bb30befc 100644 --- a/src/resolve/absolute.cpp +++ b/src/resolve/absolute.cpp @@ -354,11 +354,6 @@ struct Context } AST::Path lookup_opt(const ::std::string& name, LookupMode mode) const { - // TODO: Quirk with primitive types: - // - `usize::is_power_of_two` (associated function - liballoc/heap.rs) - // - `str::from_utf8_unchecked` (free function - libcore/fmt/mod.rs) - // A workaround would be to accept the path here and search the located module for the next entry and fall back on referring to the type otherwise. - for(auto it = m_name_context.rbegin(); it != m_name_context.rend(); ++ it) { TU_MATCH(Ent, (*it), (e), @@ -752,7 +747,7 @@ namespace { ::AST::Path new_path; const auto& next_node = path_abs.nodes[i+1]; - // TODO: If the named item can't be found in the trait, fall back to it being a type binding + // If the named item can't be found in the trait, fall back to it being a type binding // - What if this item is from a nested trait? bool found = false; switch( i+1 < path_abs.nodes.size() ? Context::LookupMode::Namespace : mode ) @@ -907,7 +902,32 @@ namespace { Resolve_Absolute_Path_BindAbsolute__hir_from_import(context, sp, true, path, v->second->ent.as_Import()); return ; } - // TODO: Set binding + TU_MATCH_DEF(::HIR::ValueItem, (v->second->ent), (e), + ( + // TODO: Handle other values types + TODO(sp, "Bind item type " << v->second->ent.tag_str()); + ), + (Function, + path.bind( ::AST::PathBinding::make_Function({nullptr/*, &e*/}) ); + ), + (StructConstructor, + auto ty_path = e.ty; + ty_path.m_crate_name = ""; + path.bind( ::AST::PathBinding::make_Struct({nullptr, &crate.m_hir->get_struct_by_path(sp, ty_path)}) ); + ), + (StructConstant, + auto ty_path = e.ty; + ty_path.m_crate_name = ""; + path.bind( ::AST::PathBinding::make_Struct({nullptr, &crate.m_hir->get_struct_by_path(sp, ty_path)}) ); + ), + (Static, + path.bind( ::AST::PathBinding::make_Static({nullptr, &e}) ); + ), + (Constant, + // Bind + path.bind( ::AST::PathBinding::make_Static({nullptr, nullptr}) ); + ) + ) path = split_into_crate(sp, mv$(path), start, crate.m_name); return ; } |