diff options
author | John Hodge <tpg@ucc.asn.au> | 2016-10-31 13:44:55 +0800 |
---|---|---|
committer | John Hodge <tpg@ucc.asn.au> | 2016-10-31 13:44:55 +0800 |
commit | 057faa180a825c313ed85e726bd1bfaee4e9dc64 (patch) | |
tree | e0f92bda29aa105d410a36a0ce465c1964ddbcc9 /src/hir/from_ast.cpp | |
parent | 8b945178e8fd15cccab02c621a1616daddcace16 (diff) | |
parent | 542633bbfad33d1b94921d89261bb637ba48ff47 (diff) | |
download | mrust-057faa180a825c313ed85e726bd1bfaee4e9dc64.tar.gz |
Merge branch 'master' of https://github.com/thepowersgang/mrustc
Diffstat (limited to 'src/hir/from_ast.cpp')
-rw-r--r-- | src/hir/from_ast.cpp | 27 |
1 files changed, 24 insertions, 3 deletions
diff --git a/src/hir/from_ast.cpp b/src/hir/from_ast.cpp index ebca4418..b600879e 100644 --- a/src/hir/from_ast.cpp +++ b/src/hir/from_ast.cpp @@ -868,9 +868,30 @@ namespace { mv$(variants) }; } -::HIR::Union LowerHIR_Union(::HIR::ItemPath path, const ::AST::Union& f) +::HIR::Union LowerHIR_Union(::HIR::ItemPath path, const ::AST::Union& f, const ::AST::MetaItems& attrs) { - TODO(Span(), "LowerHIR_Union"); + auto repr = ::HIR::Union::Repr::Rust; + + if( const auto* attr_repr = attrs.get("repr") ) + { + const auto& repr_str = attr_repr->string(); + if( repr_str == "C" ) { + repr = ::HIR::Union::Repr::C; + } + else { + // TODO: Error? + } + } + + ::HIR::Struct::Data::Data_Named variants; + for(const auto& field : f.m_variants) + variants.push_back( ::std::make_pair( field.m_name, new_visent(field.m_is_public, LowerHIR_Type(field.m_type)) ) ); + + return ::HIR::Union { + LowerHIR_GenericParams(f.m_params, nullptr), + repr, + mv$(variants) + }; } ::HIR::Trait LowerHIR_Trait(::HIR::SimplePath trait_path, const ::AST::Trait& f) { @@ -1119,7 +1140,7 @@ void _add_mod_val_item(::HIR::Module& mod, ::std::string name, bool is_pub, ::H _add_mod_ns_item( mod, item.name, item.is_pub, LowerHIR_Enum(item_path, e) ); ), (Union, - _add_mod_ns_item( mod, item.name, item.is_pub, LowerHIR_Union(item_path, e) ); + _add_mod_ns_item( mod, item.name, item.is_pub, LowerHIR_Union(item_path, e, item.data.attrs) ); ), (Trait, _add_mod_ns_item( mod, item.name, item.is_pub, LowerHIR_Trait(item_path.get_simple_path(), e) ); |