diff options
Diffstat (limited to 'src/hir')
-rw-r--r-- | src/hir/deserialise.cpp | 7 | ||||
-rw-r--r-- | src/hir/from_ast.cpp | 19 | ||||
-rw-r--r-- | src/hir/hir.hpp | 35 | ||||
-rw-r--r-- | src/hir/serialise.cpp | 5 |
4 files changed, 56 insertions, 10 deletions
diff --git a/src/hir/deserialise.cpp b/src/hir/deserialise.cpp index 5795c809..23b8fdf1 100644 --- a/src/hir/deserialise.cpp +++ b/src/hir/deserialise.cpp @@ -849,6 +849,12 @@ rv.generic = d.deserialise_vec< ::std::unique_ptr<T> >(); return rv; ) + template<> + DEF_D( ::HIR::Crate::MacroImport, + ::HIR::Crate::MacroImport rv; + rv.path = d.deserialise_simplepath(); + return rv; + ) template<> DEF_D( ::HIR::ExternLibrary, return d.deserialise_extlib(); ) ::HIR::LifetimeDef HirDeserialiser::deserialise_lifetimedef() @@ -1340,6 +1346,7 @@ rv.m_marker_impls = deserialise_pathmap< ::HIR::Crate::ImplGroup<::HIR::MarkerImpl>>(); rv.m_exported_macros = deserialise_istrumap< ::MacroRulesPtr>(); + rv.m_proc_macro_reexports = deserialise_istrumap< ::HIR::Crate::MacroImport>(); rv.m_lang_items = deserialise_strumap< ::HIR::SimplePath>(); { diff --git a/src/hir/from_ast.cpp b/src/hir/from_ast.cpp index dde40e03..e271a809 100644 --- a/src/hir/from_ast.cpp +++ b/src/hir/from_ast.cpp @@ -1395,6 +1395,9 @@ void _add_mod_ns_item(::HIR::Module& mod, RcString name, ::HIR::Publicity is_pub void _add_mod_val_item(::HIR::Module& mod, RcString name, ::HIR::Publicity is_pub, ::HIR::ValueItem ti) { mod.m_value_items.insert( ::std::make_pair( mv$(name), ::make_unique_ptr(::HIR::VisEnt< ::HIR::ValueItem> { is_pub, mv$(ti) }) ) ); } +void _add_mod_mac_item(::HIR::Module& mod, RcString name, ::HIR::Publicity is_pub, ::HIR::MacroItem ti) { + mod.m_macro_items.insert( ::std::make_pair( mv$(name), ::make_unique_ptr(::HIR::VisEnt< ::HIR::MacroItem> { is_pub, mv$(ti) }) ) ); +} ::HIR::Module LowerHIR_Module(const ::AST::Module& ast_mod, ::HIR::ItemPath path, ::std::vector< ::HIR::SimplePath> traits) { @@ -1590,6 +1593,16 @@ void _add_mod_val_item(::HIR::Module& mod, RcString name, ::HIR::Publicity is_pu } } + for( const auto& ie : ast_mod.m_macro_imports ) + { + //const auto& sp = mod_span; + if( ie.is_pub ) + { + auto mi = ::HIR::MacroItem::make_Import({ ::HIR::SimplePath(ie.path.front(), ::std::vector<RcString>(ie.path.begin()+1, ie.path.end())) }); + _add_mod_mac_item( mod, ie.name, get_pub(true), mv$(mi) ); + } + } + return mod; } @@ -1881,6 +1894,12 @@ public: { if( mac.is_pub ) { + if( !mac.macro_ptr ) { + // Add to the re-export list + auto path = ::HIR::SimplePath(mac.path.front(), ::std::vector<RcString>(mac.path.begin()+1, mac.path.end()));; + rv.m_proc_macro_reexports.insert( ::std::make_pair( mac.name, ::HIR::Crate::MacroImport { path } )); + continue ; + } // TODO: Why does this to such a move? auto v = ::std::make_pair( mac.name, MacroRulesPtr(new MacroRules( mv$(*const_cast<MacroRules*>(mac.macro_ptr)) )) ); diff --git a/src/hir/hir.hpp b/src/hir/hir.hpp index 35373b51..06c6f740 100644 --- a/src/hir/hir.hpp +++ b/src/hir/hir.hpp @@ -38,6 +38,7 @@ class Static; class ValueItem; class TypeItem; +class MacroItem; class ItemPath; @@ -382,6 +383,17 @@ public: {} }; +class ProcMacro +{ +public: + // Name of the macro + RcString name; + // Path to the handler + ::HIR::SimplePath path; + // A list of attributes to hand to the handler + ::std::vector<::std::string> attributes; +}; + class Module { public: @@ -392,6 +404,8 @@ public: ::std::unordered_map< RcString, ::std::unique_ptr<VisEnt<ValueItem>> > m_value_items; // Contains types, traits, and modules ::std::unordered_map< RcString, ::std::unique_ptr<VisEnt<TypeItem>> > m_mod_items; + // Macros! + ::std::unordered_map< RcString, ::std::unique_ptr<VisEnt<MacroItem>> > m_macro_items; ::std::vector< ::std::pair<RcString, Static> > m_inline_statics; @@ -422,6 +436,11 @@ TAGGED_UNION(ValueItem, Import, (Function, Function), (StructConstructor, struct { ::HIR::SimplePath ty; }) ); +TAGGED_UNION(MacroItem, Import, + (Import, struct { ::HIR::SimplePath path; }), + (MacroRules, MacroRulesPtr), + (ProcMacro, ProcMacro) + ); // -------------------------------------------------------------------- @@ -510,16 +529,6 @@ class ExternLibrary public: ::std::string name; }; -class ProcMacro -{ -public: - // Name of the macro - RcString name; - // Path to the handler - ::HIR::SimplePath path; - // A list of attributes to hand to the handler - ::std::vector<::std::string> attributes; -}; class Crate { public: @@ -571,6 +580,12 @@ public: /// Macros exported by this crate ::std::unordered_map< RcString, ::MacroRulesPtr > m_exported_macros; + /// Macros re-exported by this crate + struct MacroImport { + ::HIR::SimplePath path; + //bool is_proc_macro; + }; + ::std::unordered_map< RcString, MacroImport > m_proc_macro_reexports; /// Procedural macros presented ::std::vector< ::HIR::ProcMacro> m_proc_macros; diff --git a/src/hir/serialise.cpp b/src/hir/serialise.cpp index 272e176f..9acb6193 100644 --- a/src/hir/serialise.cpp +++ b/src/hir/serialise.cpp @@ -315,6 +315,10 @@ serialise_vec(ig.non_named); serialise_vec(ig.generic); } + void serialise(const ::HIR::Crate::MacroImport& e) + { + serialise(e.path); + } void serialise_crate(const ::HIR::Crate& crate) { @@ -326,6 +330,7 @@ serialise_pathmap(crate.m_marker_impls); serialise_strmap(crate.m_exported_macros); + serialise_strmap(crate.m_proc_macro_reexports); { decltype(crate.m_lang_items) lang_items_filtered; for(const auto& ent : crate.m_lang_items) |