diff options
author | John Hodge <tpg@mutabah.net> | 2016-11-09 10:52:49 +0800 |
---|---|---|
committer | John Hodge <tpg@mutabah.net> | 2016-11-09 10:52:49 +0800 |
commit | b6f68fe9e76eab81942db070616b1eb1c4e61ba3 (patch) | |
tree | 925cda4e7de39755421693269df43d012fe32ab1 /src | |
parent | 59e15029d0dcf10c2cea1d13ca8c681758b2384a (diff) | |
download | mrust-b6f68fe9e76eab81942db070616b1eb1c4e61ba3.tar.gz |
HIR+Parse - Fix some ErasedTypes bugs before hitting the TODOs
Diffstat (limited to 'src')
-rw-r--r-- | src/hir/visitor.cpp | 4 | ||||
-rw-r--r-- | src/hir_typeck/outer.cpp | 49 | ||||
-rw-r--r-- | src/parse/types.cpp | 2 |
3 files changed, 15 insertions, 40 deletions
diff --git a/src/hir/visitor.cpp b/src/hir/visitor.cpp index c489e053..1882416d 100644 --- a/src/hir/visitor.cpp +++ b/src/hir/visitor.cpp @@ -306,7 +306,9 @@ void ::HIR::Visitor::visit_type(::HIR::TypeRef& ty) } ), (ErasedType, - this->visit_path(e.m_origin, ::HIR::Visitor::PathContext::TYPE); + if( e.m_origin != ::HIR::SimplePath() ) { + this->visit_path(e.m_origin, ::HIR::Visitor::PathContext::VALUE); + } for(auto& trait : e.m_traits) { this->visit_trait_path(trait); } diff --git a/src/hir_typeck/outer.cpp b/src/hir_typeck/outer.cpp index 5e436fa9..2ab0de6e 100644 --- a/src/hir_typeck/outer.cpp +++ b/src/hir_typeck/outer.cpp @@ -1,5 +1,9 @@ /* - * Check types (and evaluate constants) at the module level + * MRustC - Rust Compiler + * - By John Hodge (Mutabah/thePowersGang) + * + * hir_typeck/output.cpp + * - Typechecking at the module level (no inferrence) */ #include <hir/hir.hpp> #include <hir/visitor.hpp> @@ -9,42 +13,14 @@ namespace { const ::HIR::GenericParams& get_params_for_item(const Span& sp, const ::HIR::Crate& crate, const ::HIR::SimplePath& path, ::HIR::Visitor::PathContext pc) { - const ::HIR::Module* mod; - if( path.m_crate_name != "" ) { - ASSERT_BUG(sp, crate.m_ext_crates.count(path.m_crate_name) != 0, "Referenced crate in " << path << " not loaded"); - mod = &crate.m_ext_crates.at(path.m_crate_name)->m_root_module; - } - else { - mod = &crate.m_root_module; - } - for( unsigned int i = 0; i < path.m_components.size() - 1; i ++ ) - { - const auto& pc = path.m_components[i]; - auto it = mod->m_mod_items.find( pc ); - if( it == mod->m_mod_items.end() ) { - BUG(sp, "Couldn't find component " << i << " of " << path); - } - TU_MATCH_DEF( ::HIR::TypeItem, (it->second->ent), (e2), - ( - BUG(sp, "Node " << i << " of path " << path << " wasn't a module"); - ), - (Module, - mod = &e2; - ) - ) - } - switch( pc ) { case ::HIR::Visitor::PathContext::VALUE: { - auto it = mod->m_value_items.find( path.m_components.back() ); - if( it == mod->m_value_items.end() ) { - BUG(sp, "Couldn't find final component of " << path); - } + const auto& item = crate.get_valitem_by_path(sp, path); - TU_MATCH( ::HIR::ValueItem, (it->second->ent), (e), + TU_MATCH( ::HIR::ValueItem, (item), (e), (Import, - BUG(sp, "Value path pointed to import"); + BUG(sp, "Value path pointed to import - " << path << " = " << e.path); ), (Function, return e.m_params; @@ -54,7 +30,7 @@ namespace { ), (Static, // TODO: Return an empty set? - BUG(sp, "Attepted to get parameters for static"); + BUG(sp, "Attepted to get parameters for static " << path); ), (StructConstructor, return get_params_for_item(sp, crate, e.ty, ::HIR::Visitor::PathContext::TYPE); @@ -67,12 +43,9 @@ namespace { case ::HIR::Visitor::PathContext::TRAIT: // TODO: treat PathContext::TRAIT differently case ::HIR::Visitor::PathContext::TYPE: { - auto it = mod->m_mod_items.find( path.m_components.back() ); - if( it == mod->m_mod_items.end() ) { - BUG(sp, "Couldn't find final component of " << path); - } + const auto& item = crate.get_typeitem_by_path(sp, path); - TU_MATCH( ::HIR::TypeItem, (it->second->ent), (e), + TU_MATCH( ::HIR::TypeItem, (item), (e), (Import, BUG(sp, "Type path pointed to import - " << path); ), diff --git a/src/parse/types.cpp b/src/parse/types.cpp index 1cbcc306..4cd9d755 100644 --- a/src/parse/types.cpp +++ b/src/parse/types.cpp @@ -310,6 +310,6 @@ TypeRef Parse_Type_ErasedType(TokenStream& lex, bool allow_trait_list) if( lifetimes.size() ) DEBUG("TODO: Lifetime bounds on erased types"); - return TypeRef(lex.end_span(ps), TypeData::make_TraitObject({ {}, mv$(traits) })); + return TypeRef(lex.end_span(ps), TypeData::make_ErasedType({ {}, mv$(traits) })); } |