summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Hodge <tpg@mutabah.net>2016-10-08 15:29:59 +0800
committerJohn Hodge <tpg@mutabah.net>2016-10-08 15:29:59 +0800
commitb0dff9731a56ca33d0d6326d402af6d4c54963ec (patch)
treec5432b021a7b17452e967c3fd04b73bb55c4940b
parent391d72b800942aeb55ba77952915a81b2731e970 (diff)
downloadmrust-b0dff9731a56ca33d0d6326d402af6d4c54963ec.tar.gz
HIR+AST - Store/Load/Use extern crate list from loaded crates
-rw-r--r--src/ast/crate.cpp14
-rw-r--r--src/hir/deserialise.cpp9
-rw-r--r--src/hir/serialise.cpp4
-rw-r--r--src/resolve/index.cpp1
4 files changed, 25 insertions, 3 deletions
diff --git a/src/ast/crate.cpp b/src/ast/crate.cpp
index 5f27e02f..c05b2e29 100644
--- a/src/ast/crate.cpp
+++ b/src/ast/crate.cpp
@@ -99,7 +99,17 @@ void Crate::load_extern_crate(Span sp, const ::std::string& name)
if( !::std::ifstream(path).good() ) {
ERROR(sp, E0000, "Unable to locate crate '" << name << "'");
}
- m_extern_crates.insert(::std::make_pair( name, ExternCrate { name, path } ));
+ auto res = m_extern_crates.insert(::std::make_pair( name, ExternCrate { name, path } ));
+ auto crate_ext_list = mv$( res.first->second.m_hir->m_ext_crates );
+
+ // Load referenced crates
+ for( const auto& ext : crate_ext_list )
+ {
+ if( m_extern_crates.count(ext.first) == 0 )
+ {
+ this->load_extern_crate(sp, ext.first);
+ }
+ }
}
ExternCrate::ExternCrate(const ::std::string& name, const ::std::string& path):
@@ -109,8 +119,6 @@ ExternCrate::ExternCrate(const ::std::string& name, const ::std::string& path):
m_hir = HIR_Deserialise(path, name);
m_hir->post_load_update(name);
-
- // TODO: Load referenced crates
}
void ExternCrate::with_all_macros(::std::function<void(const ::std::string& , const MacroRules&)> cb) const
diff --git a/src/hir/deserialise.cpp b/src/hir/deserialise.cpp
index fa34ce85..9fc7d23c 100644
--- a/src/hir/deserialise.cpp
+++ b/src/hir/deserialise.cpp
@@ -1042,6 +1042,15 @@ namespace {
rv.m_exported_macros = deserialise_strumap< ::MacroRulesPtr>();
rv.m_lang_items = deserialise_strumap< ::HIR::SimplePath>();
+ {
+ size_t n = read_count();
+ for(size_t i = 0; i < n; i ++)
+ {
+ auto ext_crate_name = read_string();
+ rv.m_ext_crates.insert( ::std::make_pair(ext_crate_name, ::HIR::CratePtr{}) );
+ }
+ }
+
return rv;
}
}
diff --git a/src/hir/serialise.cpp b/src/hir/serialise.cpp
index 8aece163..7c112b23 100644
--- a/src/hir/serialise.cpp
+++ b/src/hir/serialise.cpp
@@ -319,6 +319,10 @@ namespace {
serialise_strmap(crate.m_exported_macros);
serialise_strmap(crate.m_lang_items);
+
+ write_count(crate.m_ext_crates.size());
+ for(const auto& ext : crate.m_ext_crates)
+ write_string(ext.first);
}
void serialise_module(const ::HIR::Module& mod)
{
diff --git a/src/resolve/index.cpp b/src/resolve/index.cpp
index a9751de3..089edd66 100644
--- a/src/resolve/index.cpp
+++ b/src/resolve/index.cpp
@@ -304,6 +304,7 @@ void Resolve_Index_Module_Wildcard__glob_in_hir_mod(const Span& sp, const AST::C
const auto& spath = ve.ent.as_Import();
p = hir_to_ast( spath );
+ ASSERT_BUG(sp, crate.m_extern_crates.count(spath.m_crate_name) == 1, "Crate " << spath.m_crate_name << " is not loaded");
const auto* hmod = &crate.m_extern_crates.at(spath.m_crate_name).m_hir->m_root_module;
for(unsigned int i = 0; i < spath.m_components.size()-1; i ++) {
const auto& it = hmod->m_mod_items.at( spath.m_components[i] );