summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn Hodge <tpg@mutabah.net>2016-10-09 10:47:09 +0800
committerJohn Hodge <tpg@mutabah.net>2016-10-09 10:47:09 +0800
commit0241926381c1f069f1b1cfd8e46288e86c49f125 (patch)
treed7dbd895b823bdc14b9fd4234c67aeb5a93c9832 /src
parent967ccfbfd50e0ce0aec985bcb394e34787450f75 (diff)
downloadmrust-0241926381c1f069f1b1cfd8e46288e86c49f125.tar.gz
macro_rules - #[macro_export] handling, plan for #[macro_reexport]
Diffstat (limited to 'src')
-rw-r--r--src/expand/macro_rules.cpp8
-rw-r--r--src/hir/from_ast.cpp6
-rw-r--r--src/macro_rules/macro_rules.hpp7
3 files changed, 15 insertions, 6 deletions
diff --git a/src/expand/macro_rules.cpp b/src/expand/macro_rules.cpp
index c1d00c70..99e7680b 100644
--- a/src/expand/macro_rules.cpp
+++ b/src/expand/macro_rules.cpp
@@ -109,8 +109,12 @@ class CMacroExportHandler:
if( mac.name() != "macro_rules" ) {
ERROR(sp, E0000, "#[macro_export] is only valid on macro_rules!");
}
+ const auto& name = mac.input_ident();
- //TODO(sp, "macro_export on Item MacroInv");
+ // Tag the macro in the module for crate export
+ auto it = ::std::find_if( mod.macros().begin(), mod.macros().end(), [&](const auto& x){ return x.name == name; } );
+ ASSERT_BUG(sp, it != mod.macros().end(), "Macro '" << name << "' not defined in this module");
+ it->data->m_exported = true;
}
else {
ERROR(sp, E0000, "Use of #[macro_export] on non-macro - " << i.tag_str());
@@ -125,6 +129,8 @@ class CMacroReexportHandler:
void handle(const Span& sp, const AST::MetaItem& mi, ::AST::Crate& crate, const AST::Path& path, AST::Module& mod, AST::Item& i) const override
{
if( i.is_Crate() ) {
+ // TODO: Need to look up this crate in the crate list, then import all of the macros listed with the "export" flag set
+ // - For now, all externally loaded macros are exported (weakly) so things work...
}
else {
ERROR(sp, E0000, "Use of #[macro_reexport] on non-crate - " << i.tag_str());
diff --git a/src/hir/from_ast.cpp b/src/hir/from_ast.cpp
index 452dca5e..02aa7e02 100644
--- a/src/hir/from_ast.cpp
+++ b/src/hir/from_ast.cpp
@@ -1315,9 +1315,9 @@ public:
//}
}
for( /*const*/ auto& mac : crate.m_root_module.macros() ) {
- //if( mac.data.export ) {
- macros.insert( ::std::make_pair( mac.name, mv$(mac.data) ) );
- //}
+ if( mac.data->m_exported ) {
+ macros.insert( ::std::make_pair( mac.name, mv$(mac.data) ) );
+ }
}
auto sp = Span();
diff --git a/src/macro_rules/macro_rules.hpp b/src/macro_rules/macro_rules.hpp
index ddf11dcb..30e3e45b 100644
--- a/src/macro_rules/macro_rules.hpp
+++ b/src/macro_rules/macro_rules.hpp
@@ -135,9 +135,12 @@ class MacroRules:
public Serialisable
{
public:
- bool m_exported;
+ /// Marks if this macro should be exported from the defining crate
+ bool m_exported = false;
- ::std::string m_source_crate; // Populated on load, used for $crate
+ /// Crate that defined this macro
+ /// - Populated on deserialise if not already set
+ ::std::string m_source_crate;
/// Expansion rules
::std::vector<MacroRulesArm> m_rules;