summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ast/crate.cpp13
-rw-r--r--src/ast/crate.hpp2
-rw-r--r--src/expand/mod.cpp4
3 files changed, 13 insertions, 6 deletions
diff --git a/src/ast/crate.cpp b/src/ast/crate.cpp
index fe084b54..49f9242f 100644
--- a/src/ast/crate.cpp
+++ b/src/ast/crate.cpp
@@ -50,21 +50,28 @@ void Crate::load_externs()
const auto& name = c.name;
if( check_item_cfg(it.data.attrs) )
{
- load_extern_crate( name );
+ load_extern_crate( it.data.span, name );
}
)
}
};
iterate_module(m_root_module, cb);
}
-void Crate::load_extern_crate(const ::std::string& name)
+void Crate::load_extern_crate(Span sp, const ::std::string& name)
{
- m_extern_crates.insert(::std::make_pair( name, ExternCrate { name, "output/lib"+name+".hir" } ));
+ DEBUG("Loading crate '" << name << "'");
+ // TODO: Search a list of load paths for the crate
+ ::std::string path = "output/lib"+name+".hir";
+ if( !::std::ifstream(path).good() ) {
+ ERROR(sp, E0000, "Unable to locate crate '" << name << "'");
+ }
+ m_extern_crates.insert(::std::make_pair( name, ExternCrate { name, path } ));
}
ExternCrate::ExternCrate(const ::std::string& name, const ::std::string& path):
m_name(name)
{
+ TRACE_FUNCTION_F("name=" << name << ", path='" << path << "'");
m_hir = HIR_Deserialise(path, name);
m_hir->post_load_update(name);
diff --git a/src/ast/crate.hpp b/src/ast/crate.hpp
index 4b8a42c5..146c05f6 100644
--- a/src/ast/crate.hpp
+++ b/src/ast/crate.hpp
@@ -50,7 +50,7 @@ public:
/// Load referenced crates
void load_externs();
- void load_extern_crate(const ::std::string& name);
+ void load_extern_crate(Span sp, const ::std::string& name);
};
/// Representation of an imported crate
diff --git a/src/expand/mod.cpp b/src/expand/mod.cpp
index 7f2dc06a..a3600ce5 100644
--- a/src/expand/mod.cpp
+++ b/src/expand/mod.cpp
@@ -944,7 +944,7 @@ void Expand(::AST::Crate& crate)
case ::AST::Crate::LOAD_STD:
if( crate.m_prelude_path == AST::Path() )
crate.m_prelude_path = AST::Path("std", {AST::PathNode("prelude"), AST::PathNode("v1")});
- crate.load_extern_crate("std");
+ crate.load_extern_crate(Span(), "std");
crate.m_extern_crates.at("std").with_all_macros([&](const auto& name, const auto& mac) {
crate.m_root_module.add_macro_import( name, mac );
});
@@ -953,7 +953,7 @@ void Expand(::AST::Crate& crate)
case ::AST::Crate::LOAD_CORE:
if( crate.m_prelude_path == AST::Path() )
crate.m_prelude_path = AST::Path("core", {AST::PathNode("prelude"), AST::PathNode("v1")});
- crate.load_extern_crate("core");
+ crate.load_extern_crate(Span(), "core");
crate.m_extern_crates.at("core").with_all_macros([&](const auto& name, const auto& mac) {
crate.m_root_module.add_macro_import( name, mac );
});