summaryrefslogtreecommitdiff
path: root/src/hir
diff options
context:
space:
mode:
authorJohn Hodge <tpg@ucc.asn.au>2017-07-16 13:27:31 +0800
committerJohn Hodge <tpg@ucc.asn.au>2017-07-16 13:27:31 +0800
commit97567dbbd8c3f8719dbb9e32c6d0f3a155246508 (patch)
tree3268a7f2bcadd013199883b7bbc2f26b9c385643 /src/hir
parent9d1a660045de5a3cc37315c78a3a75999fef9b9a (diff)
downloadmrust-97567dbbd8c3f8719dbb9e32c6d0f3a155246508.tar.gz
All - Upgrade to rustc 1.19.0 beta (2017-07-08)
Diffstat (limited to 'src/hir')
-rw-r--r--src/hir/from_ast.cpp88
-rw-r--r--src/hir/from_ast_expr.cpp47
2 files changed, 89 insertions, 46 deletions
diff --git a/src/hir/from_ast.cpp b/src/hir/from_ast.cpp
index e0429aca..96cd4725 100644
--- a/src/hir/from_ast.cpp
+++ b/src/hir/from_ast.cpp
@@ -894,7 +894,10 @@ namespace {
if( const auto* attr_repr = attrs.get("repr") )
{
- const auto& repr_str = attr_repr->string();
+ ASSERT_BUG(Span(), attr_repr->has_sub_items(), "#[repr] attribute malformed, " << *attr_repr);
+ ASSERT_BUG(Span(), attr_repr->items().size() == 1, "#[repr] attribute malformed, " << *attr_repr);
+ ASSERT_BUG(Span(), attr_repr->items()[0].has_noarg(), "#[repr] attribute malformed, " << *attr_repr);
+ const auto& repr_str = attr_repr->items()[0].name();
if( repr_str == "C" ) {
repr = ::HIR::Union::Repr::C;
}
@@ -1607,6 +1610,89 @@ public:
// Set all pointers in the HIR to the correct (now fixed) locations
IndexVisitor(rv).visit_crate( rv );
+ // TODO: If the current crate is libcore, store the paths to various non-lang ops items
+ if( crate.m_crate_name == "core" )
+ {
+ struct H {
+ static ::HIR::SimplePath resolve_path(const ::HIR::Crate& crate, bool is_value, ::std::initializer_list<const char*> n)
+ {
+ ::HIR::SimplePath cur_path("", {});
+
+ const ::HIR::Module* mod = &crate.m_root_module;
+ assert(n.begin() != n.end());
+ for(auto it = n.begin(); it != n.end()-1; ++it)
+ {
+ auto it2 = mod->m_mod_items.find(*it);
+ if( it2 == mod->m_mod_items.end() )
+ return ::HIR::SimplePath();
+ const auto& e = it2->second;
+ if(const auto* ip = e->ent.opt_Import())
+ {
+ // TODO: Handle module aliases?
+ (void)ip;
+ return ::HIR::SimplePath();
+ }
+ else if(const auto* ep = e->ent.opt_Module() )
+ {
+ cur_path.m_components.push_back(*it);
+ mod = ep;
+ }
+ else
+ {
+ // Incorrect item type
+ return ::HIR::SimplePath();
+ }
+ }
+
+ auto last = *(n.end()-1);
+ if( is_value )
+ {
+ throw "";
+ }
+ else
+ {
+ auto it2 = mod->m_mod_items.find(last);
+ if( it2 == mod->m_mod_items.end() )
+ return ::HIR::SimplePath();
+
+ // Found: Either return the current path, or return this alias.
+ if(const auto* ip = it2->second->ent.opt_Import())
+ {
+ if(ip->is_variant)
+ return ::HIR::SimplePath();
+ return ip->path;
+ }
+ else
+ {
+ cur_path.m_components.push_back(last);
+ return cur_path;
+ }
+ }
+ }
+ };
+ // TODO: Check for existing defintions of lang items
+ if( rv.m_lang_items.count("boxed_trait") == 0 )
+ {
+ rv.m_lang_items.insert(::std::make_pair( ::std::string("boxed_trait"), H::resolve_path(rv, false, {"ops", "Boxed"}) ));
+ }
+ if( rv.m_lang_items.count("placer_trait") == 0 )
+ {
+ rv.m_lang_items.insert(::std::make_pair( ::std::string("placer_trait"), H::resolve_path(rv, false, {"ops", "Placer"}) ));
+ }
+ if( rv.m_lang_items.count("place_trait") == 0 )
+ {
+ rv.m_lang_items.insert(::std::make_pair( ::std::string("place_trait"), H::resolve_path(rv, false, {"ops", "Place"}) ));
+ }
+ if( rv.m_lang_items.count("box_place_trait") == 0 )
+ {
+ rv.m_lang_items.insert(::std::make_pair( ::std::string("box_place_trait"), H::resolve_path(rv, false, {"ops", "BoxPlace"}) ));
+ }
+ if( rv.m_lang_items.count("in_place_trait") == 0 )
+ {
+ rv.m_lang_items.insert(::std::make_pair( ::std::string("in_place_trait"), H::resolve_path(rv, false, {"ops", "InPlace"}) ));
+ }
+ }
+
g_crate_ptr = nullptr;
return ::HIR::CratePtr( mv$(rv) );
}
diff --git a/src/hir/from_ast_expr.cpp b/src/hir/from_ast_expr.cpp
index 296bdce1..4a82867f 100644
--- a/src/hir/from_ast_expr.cpp
+++ b/src/hir/from_ast_expr.cpp
@@ -118,53 +118,10 @@ struct LowerHIR_ExprNode_Visitor:
switch(v.m_type)
{
case ::AST::ExprNode_BinOp::RANGE: {
- // NOTE: Not language items
- auto path_Range = ::HIR::GenericPath( ::HIR::SimplePath(g_core_crate, {"ops", "Range"}) );
- auto path_RangeFrom = ::HIR::GenericPath( ::HIR::SimplePath(g_core_crate, {"ops", "RangeFrom"}) );
- auto path_RangeTo = ::HIR::GenericPath( ::HIR::SimplePath(g_core_crate, {"ops", "RangeTo"}) );
- auto path_RangeFull = ::HIR::GenericPath( ::HIR::SimplePath(g_core_crate, {"ops", "RangeFull"}) );
-
- ::HIR::ExprNode_StructLiteral::t_values values;
- if( v.m_left )
- values.push_back( ::std::make_pair( ::std::string("start"), LowerHIR_ExprNode_Inner( *v.m_left ) ) );
- if( v.m_right )
- values.push_back( ::std::make_pair( ::std::string("end") , LowerHIR_ExprNode_Inner( *v.m_right ) ) );
-
- if( v.m_left ) {
- if( v.m_right ) {
- m_rv.reset( new ::HIR::ExprNode_StructLiteral(v.span(), mv$(path_Range), true, nullptr, mv$(values)) );
- }
- else {
- m_rv.reset( new ::HIR::ExprNode_StructLiteral(v.span(), mv$(path_RangeFrom), true, nullptr, mv$(values)) );
- }
- }
- else {
- if( v.m_right ) {
- m_rv.reset( new ::HIR::ExprNode_StructLiteral(v.span(), mv$(path_RangeTo), true, nullptr, mv$(values)) );
- }
- else {
- m_rv.reset( new ::HIR::ExprNode_UnitVariant(v.span(), mv$(path_RangeFull), true) );
- }
- }
+ BUG(v.span(), "Unexpected RANGE binop");
break; }
case ::AST::ExprNode_BinOp::RANGE_INC: {
- // NOTE: Not language items
- auto path_RangeInclusive_NonEmpty = ::HIR::GenericPath( ::HIR::SimplePath(g_core_crate, {"ops", "RangeInclusive", "NonEmpty"}) );
- auto path_RangeToInclusive = ::HIR::GenericPath( ::HIR::SimplePath(g_core_crate, {"ops", "RangeToInclusive"}) );
-
- if( v.m_left )
- {
- ::HIR::ExprNode_StructLiteral::t_values values;
- values.push_back( ::std::make_pair( ::std::string("start"), LowerHIR_ExprNode_Inner( *v.m_left ) ) );
- values.push_back( ::std::make_pair( ::std::string("end") , LowerHIR_ExprNode_Inner( *v.m_right ) ) );
- m_rv.reset( new ::HIR::ExprNode_StructLiteral(v.span(), mv$(path_RangeInclusive_NonEmpty), false, nullptr, mv$(values)) );
- }
- else
- {
- ::HIR::ExprNode_StructLiteral::t_values values;
- values.push_back( ::std::make_pair( ::std::string("end") , LowerHIR_ExprNode_Inner( *v.m_right ) ) );
- m_rv.reset( new ::HIR::ExprNode_StructLiteral(v.span(), mv$(path_RangeToInclusive), true, nullptr, mv$(values)) );
- }
+ BUG(v.span(), "Unexpected RANGE_INC binop");
break; }
case ::AST::ExprNode_BinOp::PLACE_IN:
TODO(v.span(), "Desugar placement syntax");