diff options
author | John Hodge <tpg@mutabah.net> | 2016-10-30 18:34:38 +0800 |
---|---|---|
committer | John Hodge <tpg@mutabah.net> | 2016-10-30 18:34:38 +0800 |
commit | e87f3ee6f2c8bbbfd1e18285528dfa305479b2ee (patch) | |
tree | 186e4c51de05194188a62d75e0e44e1a6007a0e2 /src/hir/from_ast.cpp | |
parent | 649f9f98efe3f1b138c34f3762a5feba9dde457c (diff) | |
download | mrust-e87f3ee6f2c8bbbfd1e18285528dfa305479b2ee.tar.gz |
HIR+Resolve - Refactor handling of enum variant imports
Diffstat (limited to 'src/hir/from_ast.cpp')
-rw-r--r-- | src/hir/from_ast.cpp | 31 |
1 files changed, 24 insertions, 7 deletions
diff --git a/src/hir/from_ast.cpp b/src/hir/from_ast.cpp index b0185596..a3957d2b 100644 --- a/src/hir/from_ast.cpp +++ b/src/hir/from_ast.cpp @@ -1096,7 +1096,7 @@ void _add_mod_val_item(::HIR::Module& mod, ::std::string name, bool is_pub, ::H (Crate, // All 'extern crate' items should be normalised into a list in the crate root // - If public, add a namespace import here referring to the root of the imported crate - _add_mod_ns_item( mod, item.name, item.is_pub, ::HIR::TypeItem::make_Import( ::HIR::SimplePath(e.name, {}) ) ); + _add_mod_ns_item( mod, item.name, item.is_pub, ::HIR::TypeItem::make_Import({ ::HIR::SimplePath(e.name, {}), false, 0} ) ); ), (Type, _add_mod_ns_item( mod, item.name, item.is_pub, ::HIR::TypeItem::make_TypeAlias( LowerHIR_TypeAlias(e) ) ); @@ -1141,17 +1141,34 @@ void _add_mod_val_item(::HIR::Module& mod, ::std::string name, bool is_pub, ::H for( const auto& ie : ast_mod.m_namespace_items ) { if( ie.second.is_import ) { - _add_mod_ns_item(mod, ie.first, ie.second.is_pub, ::HIR::TypeItem::make_Import({ - LowerHIR_SimplePath( Span(), ie.second.path ) - }) ); + auto hir_path = LowerHIR_SimplePath( Span(), ie.second.path ); + ::HIR::TypeItem ti; + TU_MATCH_DEF( ::AST::PathBinding, (ie.second.path.binding()), (pb), + ( + ti = ::HIR::TypeItem::make_Import({ mv$(hir_path), false, 0 }); + ), + (EnumVar, + ti = ::HIR::TypeItem::make_Import({ mv$(hir_path), true, pb.idx }); + ) + ) + _add_mod_ns_item(mod, ie.first, ie.second.is_pub, mv$(ti)); } } for( const auto& ie : ast_mod.m_value_items ) { if( ie.second.is_import ) { - _add_mod_val_item(mod, ie.first, ie.second.is_pub, ::HIR::ValueItem::make_Import({ - LowerHIR_SimplePath( Span(), ie.second.path ) - }) ); + auto hir_path = LowerHIR_SimplePath( Span(), ie.second.path ); + ::HIR::ValueItem vi; + + TU_MATCH_DEF( ::AST::PathBinding, (ie.second.path.binding()), (pb), + ( + vi = ::HIR::ValueItem::make_Import({ mv$(hir_path), false, 0 }); + ), + (EnumVar, + vi = ::HIR::ValueItem::make_Import({ mv$(hir_path), true, pb.idx }); + ) + ) + _add_mod_val_item(mod, ie.first, ie.second.is_pub, mv$(vi)); } } |