From 1f37dcc2455aacd0fe797613efea712c57948835 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Tue, 18 Oct 2016 18:34:44 +0800 Subject: Expand/cfg - Support #[cfg] on crates by nuking all items --- src/expand/cfg.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src') diff --git a/src/expand/cfg.cpp b/src/expand/cfg.cpp index e4b5c49c..897c952a 100644 --- a/src/expand/cfg.cpp +++ b/src/expand/cfg.cpp @@ -6,6 +6,7 @@ #include #include "cfg.hpp" #include // Needed to clear a ExprNodeP +#include #include #include @@ -108,6 +109,15 @@ class CCfgHandler: AttrStage stage() const override { return AttrStage::Pre; } + void handle(const Span& sp, const AST::MetaItem& mi, AST::Crate& crate) const override { + DEBUG("#[cfg] crate - " << mi); + // Ignore, as #[cfg] on a crate is handled in expand/mod.cpp + if( check_cfg(sp, mi) ) { + } + else { + crate.m_root_module.items().clear(); + } + } void handle(const Span& sp, const AST::MetaItem& mi, ::AST::Crate& crate, const AST::Path& path, AST::Module& mod, AST::Item&i) const override { TRACE_FUNCTION_FR("#[cfg] item - " << mi, (i.is_None() ? "Deleted" : "")); if( check_cfg(sp, mi) ) { -- cgit v1.2.3