diff options
author | John Hodge <tpg@mutabah.net> | 2016-03-10 10:18:59 +0800 |
---|---|---|
committer | John Hodge <tpg@mutabah.net> | 2016-03-10 10:18:59 +0800 |
commit | ce771e31b4cd157a87e7ec6531d625a895228ebf (patch) | |
tree | 25acbe58db5fc51e91724e7cfc6339aef49f620f /src/expand/mod.cpp | |
parent | 874994e677c48689036587033831af56f78797c8 (diff) | |
download | mrust-ce771e31b4cd157a87e7ec6531d625a895228ebf.tar.gz |
Expand - cfg!/#[cfg]/#[cfg_attr] hacked up
Diffstat (limited to 'src/expand/mod.cpp')
-rw-r--r-- | src/expand/mod.cpp | 30 |
1 files changed, 22 insertions, 8 deletions
diff --git a/src/expand/mod.cpp b/src/expand/mod.cpp index 33f982da..8eb6dd87 100644 --- a/src/expand/mod.cpp +++ b/src/expand/mod.cpp @@ -9,6 +9,9 @@ #include "../parse/common.hpp" // For reparse from macros #include <ast/expr.hpp> + +extern bool check_cfg(const ::AST::MetaItem& mi); + ::std::map< ::std::string, ::std::unique_ptr<ExpandDecorator> > g_decorators; ::std::map< ::std::string, ::std::unique_ptr<ExpandProcMacro> > g_macros; @@ -28,18 +31,29 @@ namespace { } } +void Expand_Attr(const ::AST::MetaItem& a, AttrStage stage, ::std::function<void(const ExpandDecorator& d,const ::AST::MetaItem& a)> f) +{ + for( auto& d : g_decorators ) { + if( d.first == a.name() ) { + DEBUG("#[" << d.first << "] " << (int)d.second->stage() << "-" << (int)stage); + if( d.second->stage() == stage ) { + f(*d.second, a); + } + } + } +} void Expand_Attrs(const ::AST::MetaItems& attrs, AttrStage stage, ::std::function<void(const ExpandDecorator& d,const ::AST::MetaItem& a)> f) { for( auto& a : attrs.m_items ) { - for( auto& d : g_decorators ) { - if( d.first == a.name() ) { - DEBUG("#[" << d.first << "] " << (int)d.second->stage() << "-" << (int)stage); - if( d.second->stage() == stage ) { - f(*d.second, a); - } + if( a.name() == "cfg_attr" ) { + if( check_cfg(a.items().m_items.at(0)) ) { + Expand_Attr(a.items().m_items.at(1), stage, f); } } + else { + Expand_Attr(a, stage, f); + } } } void Expand_Attrs(const ::AST::MetaItems& attrs, AttrStage stage, ::AST::Crate& crate, const ::AST::Path& path, ::AST::Module& mod, ::AST::Item& item) @@ -118,7 +132,7 @@ void Expand_Expr(bool is_early, ::AST::Crate& crate, LList<const AST::Module*> m void visit(::std::unique_ptr<AST::ExprNode>& cnode) { if(cnode.get()) - Expand_Attrs(cnode->attrs(), stage_pre(is_early), [&](const auto& d, const auto& a){ d.handle(a, *cnode); }); + Expand_Attrs(cnode->attrs(), stage_pre(is_early), [&](const auto& d, const auto& a){ d.handle(a, cnode); }); if(cnode.get()) { cnode->visit(*this); @@ -128,7 +142,7 @@ void Expand_Expr(bool is_early, ::AST::Crate& crate, LList<const AST::Module*> m } if(cnode.get()) - Expand_Attrs(cnode->attrs(), stage_post(is_early), [&](const auto& d, const auto& a){ d.handle(a, *cnode); }); + Expand_Attrs(cnode->attrs(), stage_post(is_early), [&](const auto& d, const auto& a){ d.handle(a, cnode); }); } void visit_nodelete(const ::AST::ExprNode& parent, ::std::unique_ptr<AST::ExprNode>& cnode) { if( cnode.get() != nullptr ) |