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 | |
parent | bcbabdf4ef468bc7a45732354e32b1baf5d95eee (diff) | |
download | mrust-52370f0a5abacb892b6a7bc24df9c1d232269b4c.tar.gz |
HIR Deserialise - Hackily set crate names, clean up a little
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | src/ast/crate.cpp | 18 | ||||
-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 | ||||
-rw-r--r-- | src/main.cpp | 2 |
8 files changed, 52 insertions, 22 deletions
@@ -57,7 +57,7 @@ OBJ += hir/dump.o OBJ += hir/hir.o hir/generic_params.o OBJ += hir/crate_ptr.o hir/type_ptr.o hir/expr_ptr.o OBJ += hir/type.o hir/path.o hir/expr.o hir/pattern.o -OBJ += hir/visitor.o +OBJ += hir/visitor.o hir/crate_post_load.o OBJ += hir_conv/expand_type.o hir_conv/constant_evaluation.o hir_conv/resolve_ufcs.o hir_conv/bind.o OBJ += hir_typeck/outer.o hir_typeck/common.o hir_typeck/helpers.o hir_typeck/static.o hir_typeck/impl_ref.o OBJ += hir_typeck/expr_visit.o diff --git a/src/ast/crate.cpp b/src/ast/crate.cpp index 3480de28..b9915bc8 100644 --- a/src/ast/crate.cpp +++ b/src/ast/crate.cpp @@ -6,7 +6,6 @@ #include "../expand/cfg.hpp" #include <hir/hir.hpp> // HIR::Crate #include <hir/main_bindings.hpp> // HIR_Deserialise -#include <macro_rules/macro_rules.hpp> // Used to update the crate name namespace { bool check_item_cfg(const ::AST::MetaItems& attrs) @@ -65,20 +64,11 @@ void Crate::load_extern_crate(const ::std::string& name) ExternCrate::ExternCrate(const ::std::string& name, const ::std::string& path) { - m_hir = HIR_Deserialise(path); + m_hir = HIR_Deserialise(path, name); - // TODO: Do a pass across m_hir that - // 1. Loads referenced crates - // 2. Updates all absolute paths with the crate name - // 3. Updates macros with the crate name - for(auto& mac : m_hir->m_exported_macros) - { - if( mac.second->m_source_crate == "" ) - { - mac.second->m_source_crate = name; - } - } - // 4. Sets binding pointers where required + 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/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); diff --git a/src/main.cpp b/src/main.cpp index 6d056fd4..2cd4b3e4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -35,7 +35,7 @@ void init_debug_list() g_debug_disable_map.insert( "Expand" );
g_debug_disable_map.insert( "Resolve Use" );
- g_debug_disable_map.insert( "Resolve Index" );
+ //g_debug_disable_map.insert( "Resolve Index" );
g_debug_disable_map.insert( "Resolve Absolute" );
g_debug_disable_map.insert( "HIR Lower" );
|