summaryrefslogtreecommitdiff
path: root/src/hir/from_ast.cpp
diff options
context:
space:
mode:
authorJohn Hodge <tpg@mutabah.net>2016-07-02 21:44:14 +0800
committerJohn Hodge <tpg@mutabah.net>2016-07-02 21:44:14 +0800
commita7233bc617922aefee408fa282ade1bffdde59fe (patch)
tree3575a4923945a15e0d42edeba385429f68f671b9 /src/hir/from_ast.cpp
parentfa7d318700dc91c35bcbab09e24164a7f41ed5ad (diff)
downloadmrust-a7233bc617922aefee408fa282ade1bffdde59fe.tar.gz
HIR Typecheck - Unified Struct/Enum data structures, CS coming along
Diffstat (limited to 'src/hir/from_ast.cpp')
-rw-r--r--src/hir/from_ast.cpp18
1 files changed, 13 insertions, 5 deletions
diff --git a/src/hir/from_ast.cpp b/src/hir/from_ast.cpp
index 8a9d25fc..5003e1f9 100644
--- a/src/hir/from_ast.cpp
+++ b/src/hir/from_ast.cpp
@@ -653,6 +653,14 @@ const ::HIR::SimplePath path_Sized = ::HIR::SimplePath("", {"marker", "Sized"});
};
}
+
+namespace {
+ template<typename T>
+ ::HIR::VisEnt<T> new_visent(bool pub, T v) {
+ return ::HIR::VisEnt<T> { pub, mv$(v) };
+ }
+}
+
::HIR::Struct LowerHIR_Struct(const ::AST::Struct& ent)
{
::HIR::Struct::Data data;
@@ -674,7 +682,7 @@ const ::HIR::SimplePath path_Sized = ::HIR::SimplePath("", {"marker", "Sized"});
(Struct,
::HIR::Struct::Data::Data_Named fields;
for(const auto& field : e.ents)
- fields.push_back( ::std::make_pair( field.m_name, ::HIR::VisEnt< ::HIR::TypeRef> { field.m_is_public, LowerHIR_Type(field.m_type) } ) );
+ fields.push_back( ::std::make_pair( field.m_name, new_visent(field.m_is_public, LowerHIR_Type(field.m_type)) ) );
data = ::HIR::Struct::Data::make_Named( mv$(fields) );
)
)
@@ -702,16 +710,16 @@ const ::HIR::SimplePath path_Sized = ::HIR::SimplePath("", {"marker", "Sized"});
variants.push_back( ::std::make_pair(var.m_name, ::HIR::Enum::Variant::make_Unit({})) );
}
else {
- ::std::vector< ::HIR::TypeRef> types;
+ ::HIR::Enum::Variant::Data_Tuple types;
for(const auto& st : e.m_sub_types)
- types.push_back( LowerHIR_Type(st) );
+ types.push_back( new_visent(true, LowerHIR_Type(st)) );
variants.push_back( ::std::make_pair(var.m_name, ::HIR::Enum::Variant::make_Tuple(mv$(types))) );
}
),
(Struct,
- ::std::vector< ::std::pair< ::std::string, ::HIR::TypeRef> > ents;
+ ::HIR::Enum::Variant::Data_Struct ents;
for( const auto& ent : e.m_fields )
- ents.push_back( ::std::make_pair( ent.m_name, LowerHIR_Type(ent.m_type) ) );
+ ents.push_back( ::std::make_pair( ent.m_name, new_visent(true, LowerHIR_Type(ent.m_type)) ) );
variants.push_back( ::std::make_pair(var.m_name, ::HIR::Enum::Variant::make_Struct(mv$(ents))) );
)
)