summaryrefslogtreecommitdiff
path: root/src/resolve/index.cpp
diff options
context:
space:
mode:
authorJohn Hodge <tpg@ucc.asn.au>2017-11-01 20:46:36 +0800
committerJohn Hodge <tpg@ucc.asn.au>2017-11-01 20:46:36 +0800
commitcb271f8ea98d1a5c65a5e636a0e73a85710027b4 (patch)
tree9694427c074c0e0d581cde6e01b6167016e0f844 /src/resolve/index.cpp
parent8306f43ccdf0414b48891aa5eb04d8901899c052 (diff)
downloadmrust-cb271f8ea98d1a5c65a5e636a0e73a85710027b4.tar.gz
HIR - Refactor enums to only embed a single field (and give variants types)
Diffstat (limited to 'src/resolve/index.cpp')
-rw-r--r--src/resolve/index.cpp39
1 files changed, 28 insertions, 11 deletions
diff --git a/src/resolve/index.cpp b/src/resolve/index.cpp
index 2f4ece59..458aed5e 100644
--- a/src/resolve/index.cpp
+++ b/src/resolve/index.cpp
@@ -223,8 +223,8 @@ void Resolve_Index_Module_Base(const AST::Crate& crate, AST::Module& mod)
is_struct = e.enum_->variants().at(e.idx).m_data.is_Struct();
}
else {
- ASSERT_BUG(sp, e.idx < e.hir->m_variants.size(), "Variant out of range for " << i_data.path);
- is_struct = e.hir->m_variants.at(e.idx).second.is_Struct();
+ //ASSERT_BUG(sp, e.idx < e.hir->m_variants.size(), "Variant out of range for " << i_data.path);
+ is_struct = TU_TEST1(e.hir->m_data, Data, .at(e.idx).is_struct);
}
if( is_struct )
_add_item_type(sp, mod, i.name, i.is_pub, i_data.path, !allow_collide);
@@ -457,19 +457,36 @@ void Resolve_Index_Module_Wildcard__use_stmt(AST::Crate& crate, AST::Module& dst
{
DEBUG("Glob enum " << i_data.path << " (HIR)");
unsigned int idx = 0;
- for( const auto& ev : e.hir->m_variants )
+ if( e.hir->m_data.is_Value() )
{
- ::AST::Path p = i_data.path + ev.first;
- p.bind( ::AST::PathBinding::make_EnumVar({nullptr, idx, e.hir}) );
+ const auto* de = e.hir->m_data.opt_Value();
+ for(const auto& ev : de->variants)
+ {
+ ::AST::Path p = i_data.path + ev.name;
+ p.bind( ::AST::PathBinding::make_EnumVar({nullptr, idx, e.hir}) );
- if( ev.second.is_Struct() ) {
- _add_item_type ( sp, dst_mod, ev.first, is_pub, mv$(p), false );
- }
- else {
- _add_item_value( sp, dst_mod, ev.first, is_pub, mv$(p), false );
+ _add_item_value( sp, dst_mod, ev.name, is_pub, mv$(p), false );
+
+ idx += 1;
}
+ }
+ else
+ {
+ const auto* de = &e.hir->m_data.as_Data();
+ for(const auto& ev : *de)
+ {
+ ::AST::Path p = i_data.path + ev.name;
+ p.bind( ::AST::PathBinding::make_EnumVar({nullptr, idx, e.hir}) );
- idx += 1;
+ if( ev.is_struct ) {
+ _add_item_type ( sp, dst_mod, ev.name, is_pub, mv$(p), false );
+ }
+ else {
+ _add_item_value( sp, dst_mod, ev.name, is_pub, mv$(p), false );
+ }
+
+ idx += 1;
+ }
}
}
)