summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn Hodge <tpg@ucc.asn.au>2016-10-31 13:44:55 +0800
committerJohn Hodge <tpg@ucc.asn.au>2016-10-31 13:44:55 +0800
commit057faa180a825c313ed85e726bd1bfaee4e9dc64 (patch)
treee0f92bda29aa105d410a36a0ce465c1964ddbcc9 /src
parent8b945178e8fd15cccab02c621a1616daddcace16 (diff)
parent542633bbfad33d1b94921d89261bb637ba48ff47 (diff)
downloadmrust-057faa180a825c313ed85e726bd1bfaee4e9dc64.tar.gz
Merge branch 'master' of https://github.com/thepowersgang/mrustc
Diffstat (limited to 'src')
-rw-r--r--src/ast/ast.cpp4
-rw-r--r--src/ast/attrs.hpp5
-rw-r--r--src/hir/from_ast.cpp27
-rw-r--r--src/resolve/absolute.cpp13
4 files changed, 41 insertions, 8 deletions
diff --git a/src/ast/ast.cpp b/src/ast/ast.cpp
index 6e93a0d9..15b8c7d7 100644
--- a/src/ast/ast.cpp
+++ b/src/ast/ast.cpp
@@ -35,11 +35,11 @@ void MetaItems::push_back(MetaItem i)
{
m_items.push_back( ::std::move(i) );
}
-MetaItem* MetaItems::get(const char *name)
+const MetaItem* MetaItems::get(const char *name) const
{
for( auto& i : m_items ) {
if(i.name() == name) {
- i.mark_used();
+ //i.mark_used();
return &i;
}
}
diff --git a/src/ast/attrs.hpp b/src/ast/attrs.hpp
index aa892d6d..f4e6af8d 100644
--- a/src/ast/attrs.hpp
+++ b/src/ast/attrs.hpp
@@ -28,8 +28,9 @@ public:
MetaItems clone() const;
- MetaItem* get(const char *name);
- bool has(const char *name) {
+ MetaItem* get(const char *name) { return const_cast<MetaItem*>( const_cast<const MetaItems*>(this)->get(name)); }
+ const MetaItem* get(const char *name) const;
+ bool has(const char *name) const {
return get(name) != 0;
}
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) );
diff --git a/src/resolve/absolute.cpp b/src/resolve/absolute.cpp
index 76da7ed1..0d47eb21 100644
--- a/src/resolve/absolute.cpp
+++ b/src/resolve/absolute.cpp
@@ -1951,6 +1951,17 @@ void Resolve_Absolute_Struct(Context& item_context, ::AST::Struct& e)
item_context.pop( e.params() );
}
+void Resolve_Absolute_Union(Context& item_context, ::AST::Union& e)
+{
+ item_context.push( e.m_params, GenericSlot::Level::Top );
+ Resolve_Absolute_Generic(item_context, e.m_params);
+
+ for(auto& field : e.m_variants) {
+ Resolve_Absolute_Type(item_context, field.m_type);
+ }
+
+ item_context.pop( e.m_params );
+}
void Resolve_Absolute_Trait(Context& item_context, ::AST::Trait& e)
{
item_context.push( e.params(), GenericSlot::Level::Top, true );
@@ -2114,7 +2125,7 @@ void Resolve_Absolute_Mod( Context item_context, ::AST::Module& mod )
),
(Union,
DEBUG("Union - " << i.name);
- TODO(i.data.span, "Union");
+ Resolve_Absolute_Union(item_context, e);
),
(Function,
DEBUG("Function - " << i.name);