diff options
| author | John Hodge <tpg@mutabah.net> | 2016-08-29 16:47:26 +0800 |
|---|---|---|
| committer | John Hodge <tpg@mutabah.net> | 2016-08-29 16:47:26 +0800 |
| commit | 52370f0a5abacb892b6a7bc24df9c1d232269b4c (patch) | |
| tree | 7ac34fed7ad08a0cd9617ac18877d0b3d661ab82 /src/hir | |
| parent | bcbabdf4ef468bc7a45732354e32b1baf5d95eee (diff) | |
| download | mrust-52370f0a5abacb892b6a7bc24df9c1d232269b4c.tar.gz | |
HIR Deserialise - Hackily set crate names, clean up a little
Diffstat (limited to 'src/hir')
| -rw-r--r-- | src/hir/crate_post_load.cpp | 26 | ||||
| -rw-r--r-- | src/hir/deserialise.cpp | 15 | ||||
| -rw-r--r-- | src/hir/from_ast.cpp | 5 | ||||
| -rw-r--r-- | src/hir/hir.hpp | 4 | ||||
| -rw-r--r-- | src/hir/main_bindings.hpp | 2 |
5 files changed, 46 insertions, 6 deletions
diff --git a/src/hir/crate_post_load.cpp b/src/hir/crate_post_load.cpp new file mode 100644 index 00000000..81c5b029 --- /dev/null +++ b/src/hir/crate_post_load.cpp @@ -0,0 +1,26 @@ +/* + * MRustC - Rust Compiler + * - By John Hodge (Mutabah/thePowersGang) + * + * hir/crate_post_load.cpp + * - Updates the crate after deserialising + */ +#include <hir/hir.hpp> +#include <macro_rules/macro_rules.hpp> // Used to update the crate name + + +void HIR::Crate::post_load_update(const ::std::string& name) +{ + // TODO: Do a pass across m_hir that + // 1. Updates all absolute paths with the crate name + // 2. Sets binding pointers where required + // 3. Updates macros with the crate name + for(auto& mac : m_exported_macros) + { + if( mac.second->m_source_crate == "" ) + { + mac.second->m_source_crate = name; + } + } +} + diff --git a/src/hir/deserialise.cpp b/src/hir/deserialise.cpp index 40a98154..e0b12f92 100644 --- a/src/hir/deserialise.cpp +++ b/src/hir/deserialise.cpp @@ -20,10 +20,11 @@ namespace { class HirDeserialiser { - + const ::std::string& m_crate_name; ::std::istream& m_is; public: - HirDeserialiser(::std::istream& is): + HirDeserialiser(const ::std::string& crate_name, ::std::istream& is): + m_crate_name( crate_name ), m_is(is) {} @@ -731,8 +732,12 @@ namespace { ::HIR::SimplePath HirDeserialiser::deserialise_simplepath() { TRACE_FUNCTION; + // HACK! If the read crate name is empty, replace it with the name we're loaded with + auto crate_name = read_string(); + if( crate_name == "" ) + crate_name = m_crate_name; return ::HIR::SimplePath { - read_string(), + mv$(crate_name), deserialise_vec< ::std::string>() }; } @@ -1039,10 +1044,10 @@ namespace { } } -::HIR::CratePtr HIR_Deserialise(const ::std::string& filename) +::HIR::CratePtr HIR_Deserialise(const ::std::string& filename, const ::std::string& loaded_name) { ::std::ifstream in(filename); - HirDeserialiser s { in }; + HirDeserialiser s { loaded_name, in }; try { diff --git a/src/hir/from_ast.cpp b/src/hir/from_ast.cpp index df43678c..73187ba8 100644 --- a/src/hir/from_ast.cpp +++ b/src/hir/from_ast.cpp @@ -1236,6 +1236,11 @@ public: { rv.m_lang_items.insert( ::std::make_pair(lang_item_path.first, LowerHIR_SimplePath(sp, lang_item_path.second)) ); } + // TODO: Populate m_lang_items from loaded crates too + for(auto& ext_crate : crate.m_extern_crates) + { + TODO(sp, "Transfer extern crate - " << ext_crate.first); + } // Set all pointers in the HIR to the correct (now fixed) locations IndexVisitor(rv).visit_crate( rv ); diff --git a/src/hir/hir.hpp b/src/hir/hir.hpp index c7c59f48..44f44356 100644 --- a/src/hir/hir.hpp +++ b/src/hir/hir.hpp @@ -315,6 +315,10 @@ public: /// Language items avaliable through this crate (includes ones from loaded externs) ::std::unordered_map< ::std::string, ::HIR::SimplePath> m_lang_items; + /// Method called to populate runtime state after deserialisation + /// See hir/crate_post_load.cpp + void post_load_update(const ::std::string& loaded_name); + const ::HIR::SimplePath& get_lang_item_path(const Span& sp, const char* name) const; const ::HIR::TypeItem& get_typeitem_by_path(const Span& sp, const ::HIR::SimplePath& path) const; diff --git a/src/hir/main_bindings.hpp b/src/hir/main_bindings.hpp index 89896df0..622d8e2e 100644 --- a/src/hir/main_bindings.hpp +++ b/src/hir/main_bindings.hpp @@ -18,4 +18,4 @@ namespace AST { extern void HIR_Dump(::std::ostream& sink, const ::HIR::Crate& crate); extern ::HIR::CratePtr LowerHIR_FromAST(::AST::Crate crate); extern void HIR_Serialise(const ::std::string& filename, const ::HIR::Crate& crate); -extern ::HIR::CratePtr HIR_Deserialise(const ::std::string& filename); +extern ::HIR::CratePtr HIR_Deserialise(const ::std::string& filename, const ::std::string& loaded_name); |
