namespace Rust {
+/**
+ * Determines whether any cfg predicate is false and hence item with attributes
+ * should be stripped. Note that attributes must be expanded before calling.
+ */
+bool
+fails_cfg (const AST::AttrVec &attrs)
+{
+ auto &session = Session::get_instance ();
+
+ for (const auto &attr : attrs)
+ {
+ if (attr.get_path () == "cfg" && !attr.check_cfg_predicate (session))
+ return true;
+ }
+ return false;
+}
+
+/**
+ * Determines whether any cfg predicate is false and hence item with attributes
+ * should be stripped. Will expand attributes as well.
+ */
+bool
+fails_cfg_with_expand (AST::AttrVec &attrs)
+{
+ auto &session = Session::get_instance ();
+
+ // TODO: maybe have something that strips cfg attributes that evaluate true?
+ for (auto &attr : attrs)
+ {
+ if (attr.get_path () == "cfg")
+ {
+ if (!attr.is_parsed_to_meta_item ())
+ attr.parse_attr_to_meta_item ();
+
+ // DEBUG
+ if (!attr.is_parsed_to_meta_item ())
+ rust_debug ("failed to parse attr to meta item, right before "
+ "cfg predicate check");
+ else
+ rust_debug ("attr has been successfully parsed to meta item, "
+ "right before cfg predicate check");
+
+ if (!attr.check_cfg_predicate (session))
+ {
+ // DEBUG
+ rust_debug (
+ "cfg predicate failed for attribute: \033[0;31m'%s'\033[0m",
+ attr.as_string ().c_str ());
+
+ return true;
+ }
+ else
+ {
+ // DEBUG
+ rust_debug ("cfg predicate succeeded for attribute: "
+ "\033[0;31m'%s'\033[0m",
+ attr.as_string ().c_str ());
+ }
+ }
+ }
+ return false;
+}
+
+/**
+ * Expands cfg_attr attributes.
+ */
+void
+expand_cfg_attrs (AST::AttrVec &attrs)
+{
+ auto &session = Session::get_instance ();
+
+ for (std::size_t i = 0; i < attrs.size (); i++)
+ {
+ auto &attr = attrs[i];
+ if (attr.get_path () == "cfg_attr")
+ {
+ if (!attr.is_parsed_to_meta_item ())
+ attr.parse_attr_to_meta_item ();
+
+ if (attr.check_cfg_predicate (session))
+ {
+ // split off cfg_attr
+ AST::AttrVec new_attrs = attr.separate_cfg_attrs ();
+
+ // remove attr from vector
+ attrs.erase (attrs.begin () + i);
+
+ // add new attrs to vector
+ attrs.insert (attrs.begin () + i,
+ std::make_move_iterator (new_attrs.begin ()),
+ std::make_move_iterator (new_attrs.end ()));
+ }
+
+ /* do something - if feature (first token in tree) is in fact enabled,
+ * make tokens listed afterwards into attributes. i.e.: for
+ * [cfg_attr(feature = "wow", wow1, wow2)], if "wow" is true, then add
+ * attributes [wow1] and [wow2] to attribute list. This can also be
+ * recursive, so check for expanded attributes being recursive and
+ * possibly recursively call the expand_attrs? */
+ }
+ else
+ {
+ i++;
+ }
+ }
+ attrs.shrink_to_fit ();
+}
+
+void
+AttrVisitor::go (AST::Crate &crate)
+{
+ // expand crate cfg_attr attributes
+ expand_cfg_attrs (crate.inner_attrs);
+
+ if (fails_cfg_with_expand (crate.inner_attrs))
+ {
+ // basically, delete whole crate
+ crate.strip_crate ();
+ // TODO: maybe create warning here? probably not desired behaviour
+ }
+ // expand module attributes?
+}
+
// Visitor used to expand attributes.
void
AttrVisitor::expand_struct_fields (std::vector<AST::StructField> &fields)
auto &field = *it;
auto &field_attrs = field.get_outer_attrs ();
- expander.expand_cfg_attrs (field_attrs);
- if (expander.fails_cfg_with_expand (field_attrs))
+ expand_cfg_attrs (field_attrs);
+ if (fails_cfg_with_expand (field_attrs))
{
it = fields.erase (it);
continue;
auto &field = *it;
auto &field_attrs = field.get_outer_attrs ();
- expander.expand_cfg_attrs (field_attrs);
- if (expander.fails_cfg_with_expand (field_attrs))
+ expand_cfg_attrs (field_attrs);
+ if (fails_cfg_with_expand (field_attrs))
{
it = fields.erase (it);
continue;
auto ¶m = *it;
auto ¶m_attrs = param.get_outer_attrs ();
- expander.expand_cfg_attrs (param_attrs);
- if (expander.fails_cfg_with_expand (param_attrs))
+ expand_cfg_attrs (param_attrs);
+ if (fails_cfg_with_expand (param_attrs))
{
it = params.erase (it);
continue;
auto ¶m = *it;
auto ¶m_attrs = param.get_outer_attrs ();
- expander.expand_cfg_attrs (param_attrs);
- if (expander.fails_cfg_with_expand (param_attrs))
+ expand_cfg_attrs (param_attrs);
+ if (fails_cfg_with_expand (param_attrs))
{
it = params.erase (it);
continue;
AttrVisitor::visit (AST::IdentifierExpr &ident_expr)
{
// strip test based on outer attrs
- expander.expand_cfg_attrs (ident_expr.get_outer_attrs ());
- if (expander.fails_cfg_with_expand (ident_expr.get_outer_attrs ()))
+ expand_cfg_attrs (ident_expr.get_outer_attrs ());
+ if (fails_cfg_with_expand (ident_expr.get_outer_attrs ()))
{
ident_expr.mark_for_strip ();
return;
AttrVisitor::visit (AST::MacroInvocation ¯o_invoc)
{
// initial strip test based on outer attrs
- expander.expand_cfg_attrs (macro_invoc.get_outer_attrs ());
- if (expander.fails_cfg_with_expand (macro_invoc.get_outer_attrs ()))
+ expand_cfg_attrs (macro_invoc.get_outer_attrs ());
+ if (fails_cfg_with_expand (macro_invoc.get_outer_attrs ()))
{
macro_invoc.mark_for_strip ();
return;
AttrVisitor::visit (AST::PathInExpression &path)
{
// initial strip test based on outer attrs
- expander.expand_cfg_attrs (path.get_outer_attrs ());
- if (expander.fails_cfg_with_expand (path.get_outer_attrs ()))
+ expand_cfg_attrs (path.get_outer_attrs ());
+ if (fails_cfg_with_expand (path.get_outer_attrs ()))
{
path.mark_for_strip ();
return;
AttrVisitor::visit (AST::QualifiedPathInExpression &path)
{
// initial strip test based on outer attrs
- expander.expand_cfg_attrs (path.get_outer_attrs ());
- if (expander.fails_cfg_with_expand (path.get_outer_attrs ()))
+ expand_cfg_attrs (path.get_outer_attrs ());
+ if (fails_cfg_with_expand (path.get_outer_attrs ()))
{
path.mark_for_strip ();
return;
AttrVisitor::visit (AST::LiteralExpr &expr)
{
// initial strip test based on outer attrs
- expander.expand_cfg_attrs (expr.get_outer_attrs ());
- if (expander.fails_cfg_with_expand (expr.get_outer_attrs ()))
+ expand_cfg_attrs (expr.get_outer_attrs ());
+ if (fails_cfg_with_expand (expr.get_outer_attrs ()))
{
expr.mark_for_strip ();
return;
AttrVisitor::visit (AST::BorrowExpr &expr)
{
// initial strip test based on outer attrs
- expander.expand_cfg_attrs (expr.get_outer_attrs ());
- if (expander.fails_cfg_with_expand (expr.get_outer_attrs ()))
+ expand_cfg_attrs (expr.get_outer_attrs ());
+ if (fails_cfg_with_expand (expr.get_outer_attrs ()))
{
expr.mark_for_strip ();
return;
AttrVisitor::visit (AST::DereferenceExpr &expr)
{
// initial strip test based on outer attrs
- expander.expand_cfg_attrs (expr.get_outer_attrs ());
- if (expander.fails_cfg_with_expand (expr.get_outer_attrs ()))
+ expand_cfg_attrs (expr.get_outer_attrs ());
+ if (fails_cfg_with_expand (expr.get_outer_attrs ()))
{
expr.mark_for_strip ();
return;
AttrVisitor::visit (AST::ErrorPropagationExpr &expr)
{
// initial strip test based on outer attrs
- expander.expand_cfg_attrs (expr.get_outer_attrs ());
- if (expander.fails_cfg_with_expand (expr.get_outer_attrs ()))
+ expand_cfg_attrs (expr.get_outer_attrs ());
+ if (fails_cfg_with_expand (expr.get_outer_attrs ()))
{
expr.mark_for_strip ();
return;
AttrVisitor::visit (AST::NegationExpr &expr)
{
// initial strip test based on outer attrs
- expander.expand_cfg_attrs (expr.get_outer_attrs ());
- if (expander.fails_cfg_with_expand (expr.get_outer_attrs ()))
+ expand_cfg_attrs (expr.get_outer_attrs ());
+ if (fails_cfg_with_expand (expr.get_outer_attrs ()))
{
expr.mark_for_strip ();
return;
void
AttrVisitor::visit (AST::AssignmentExpr &expr)
{
- expander.expand_cfg_attrs (expr.get_outer_attrs ());
- if (expander.fails_cfg_with_expand (expr.get_outer_attrs ()))
+ expand_cfg_attrs (expr.get_outer_attrs ());
+ if (fails_cfg_with_expand (expr.get_outer_attrs ()))
{
expr.mark_for_strip ();
return;
AttrVisitor::visit (AST::GroupedExpr &expr)
{
// initial strip test based on outer attrs
- expander.expand_cfg_attrs (expr.get_outer_attrs ());
- if (expander.fails_cfg_with_expand (expr.get_outer_attrs ()))
+ expand_cfg_attrs (expr.get_outer_attrs ());
+ if (fails_cfg_with_expand (expr.get_outer_attrs ()))
{
expr.mark_for_strip ();
return;
/* strip test based on inner attrs - spec says these are inner
* attributes, not outer attributes of inner expr */
- expander.expand_cfg_attrs (expr.get_inner_attrs ());
- if (expander.fails_cfg_with_expand (expr.get_inner_attrs ()))
+ expand_cfg_attrs (expr.get_inner_attrs ());
+ if (fails_cfg_with_expand (expr.get_inner_attrs ()))
{
expr.mark_for_strip ();
return;
AttrVisitor::visit (AST::ArrayExpr &expr)
{
// initial strip test based on outer attrs
- expander.expand_cfg_attrs (expr.get_outer_attrs ());
- if (expander.fails_cfg_with_expand (expr.get_outer_attrs ()))
+ expand_cfg_attrs (expr.get_outer_attrs ());
+ if (fails_cfg_with_expand (expr.get_outer_attrs ()))
{
expr.mark_for_strip ();
return;
/* strip test based on inner attrs - spec says there are separate
* inner attributes, not just outer attributes of inner exprs */
- expander.expand_cfg_attrs (expr.get_inner_attrs ());
- if (expander.fails_cfg_with_expand (expr.get_inner_attrs ()))
+ expand_cfg_attrs (expr.get_inner_attrs ());
+ if (fails_cfg_with_expand (expr.get_inner_attrs ()))
{
expr.mark_for_strip ();
return;
* allowed, but conceptually it wouldn't make much sense, but
* having expansion code anyway. TODO */
// initial strip test based on outer attrs
- expander.expand_cfg_attrs (expr.get_outer_attrs ());
- if (expander.fails_cfg_with_expand (expr.get_outer_attrs ()))
+ expand_cfg_attrs (expr.get_outer_attrs ());
+ if (fails_cfg_with_expand (expr.get_outer_attrs ()))
{
expr.mark_for_strip ();
return;
* tuple expressions" */
// initial strip test based on outer attrs
- expander.expand_cfg_attrs (expr.get_outer_attrs ());
- if (expander.fails_cfg_with_expand (expr.get_outer_attrs ()))
+ expand_cfg_attrs (expr.get_outer_attrs ());
+ if (fails_cfg_with_expand (expr.get_outer_attrs ()))
{
expr.mark_for_strip ();
return;
/* strip test based on inner attrs - spec says these are inner
* attributes, not outer attributes of inner expr */
- expander.expand_cfg_attrs (expr.get_inner_attrs ());
- if (expander.fails_cfg_with_expand (expr.get_inner_attrs ()))
+ expand_cfg_attrs (expr.get_inner_attrs ());
+ if (fails_cfg_with_expand (expr.get_inner_attrs ()))
{
expr.mark_for_strip ();
return;
AttrVisitor::visit (AST::TupleIndexExpr &expr)
{
// initial strip test based on outer attrs
- expander.expand_cfg_attrs (expr.get_outer_attrs ());
- if (expander.fails_cfg_with_expand (expr.get_outer_attrs ()))
+ expand_cfg_attrs (expr.get_outer_attrs ());
+ if (fails_cfg_with_expand (expr.get_outer_attrs ()))
{
expr.mark_for_strip ();
return;
AttrVisitor::visit (AST::StructExprStruct &expr)
{
// initial strip test based on outer attrs
- expander.expand_cfg_attrs (expr.get_outer_attrs ());
- if (expander.fails_cfg_with_expand (expr.get_outer_attrs ()))
+ expand_cfg_attrs (expr.get_outer_attrs ());
+ if (fails_cfg_with_expand (expr.get_outer_attrs ()))
{
expr.mark_for_strip ();
return;
/* strip test based on inner attrs - spec says these are inner
* attributes, not outer attributes of inner expr */
- expander.expand_cfg_attrs (expr.get_inner_attrs ());
- if (expander.fails_cfg_with_expand (expr.get_inner_attrs ()))
+ expand_cfg_attrs (expr.get_inner_attrs ());
+ if (fails_cfg_with_expand (expr.get_inner_attrs ()))
{
expr.mark_for_strip ();
return;
AttrVisitor::visit (AST::StructExprStructFields &expr)
{
// initial strip test based on outer attrs
- expander.expand_cfg_attrs (expr.get_outer_attrs ());
- if (expander.fails_cfg_with_expand (expr.get_outer_attrs ()))
+ expand_cfg_attrs (expr.get_outer_attrs ());
+ if (fails_cfg_with_expand (expr.get_outer_attrs ()))
{
expr.mark_for_strip ();
return;
/* strip test based on inner attrs - spec says these are inner
* attributes, not outer attributes of inner expr */
- expander.expand_cfg_attrs (expr.get_inner_attrs ());
- if (expander.fails_cfg_with_expand (expr.get_inner_attrs ()))
+ expand_cfg_attrs (expr.get_inner_attrs ());
+ if (fails_cfg_with_expand (expr.get_inner_attrs ()))
{
expr.mark_for_strip ();
return;
AttrVisitor::visit (AST::StructExprStructBase &expr)
{
// initial strip test based on outer attrs
- expander.expand_cfg_attrs (expr.get_outer_attrs ());
- if (expander.fails_cfg_with_expand (expr.get_outer_attrs ()))
+ expand_cfg_attrs (expr.get_outer_attrs ());
+ if (fails_cfg_with_expand (expr.get_outer_attrs ()))
{
expr.mark_for_strip ();
return;
/* strip test based on inner attrs - spec says these are inner
* attributes, not outer attributes of inner expr */
- expander.expand_cfg_attrs (expr.get_inner_attrs ());
- if (expander.fails_cfg_with_expand (expr.get_inner_attrs ()))
+ expand_cfg_attrs (expr.get_inner_attrs ());
+ if (fails_cfg_with_expand (expr.get_inner_attrs ()))
{
expr.mark_for_strip ();
return;
AttrVisitor::visit (AST::CallExpr &expr)
{
// initial strip test based on outer attrs
- expander.expand_cfg_attrs (expr.get_outer_attrs ());
- if (expander.fails_cfg_with_expand (expr.get_outer_attrs ()))
+ expand_cfg_attrs (expr.get_outer_attrs ());
+ if (fails_cfg_with_expand (expr.get_outer_attrs ()))
{
expr.mark_for_strip ();
return;
AttrVisitor::visit (AST::MethodCallExpr &expr)
{
// initial strip test based on outer attrs
- expander.expand_cfg_attrs (expr.get_outer_attrs ());
- if (expander.fails_cfg_with_expand (expr.get_outer_attrs ()))
+ expand_cfg_attrs (expr.get_outer_attrs ());
+ if (fails_cfg_with_expand (expr.get_outer_attrs ()))
{
expr.mark_for_strip ();
return;
AttrVisitor::visit (AST::FieldAccessExpr &expr)
{
// initial strip test based on outer attrs
- expander.expand_cfg_attrs (expr.get_outer_attrs ());
- if (expander.fails_cfg_with_expand (expr.get_outer_attrs ()))
+ expand_cfg_attrs (expr.get_outer_attrs ());
+ if (fails_cfg_with_expand (expr.get_outer_attrs ()))
{
expr.mark_for_strip ();
return;
AttrVisitor::visit (AST::ClosureExprInner &expr)
{
// initial strip test based on outer attrs
- expander.expand_cfg_attrs (expr.get_outer_attrs ());
- if (expander.fails_cfg_with_expand (expr.get_outer_attrs ()))
+ expand_cfg_attrs (expr.get_outer_attrs ());
+ if (fails_cfg_with_expand (expr.get_outer_attrs ()))
{
expr.mark_for_strip ();
return;
AttrVisitor::visit (AST::BlockExpr &expr)
{
// initial strip test based on outer attrs
- expander.expand_cfg_attrs (expr.get_outer_attrs ());
- if (expander.fails_cfg_with_expand (expr.get_outer_attrs ()))
+ expand_cfg_attrs (expr.get_outer_attrs ());
+ if (fails_cfg_with_expand (expr.get_outer_attrs ()))
{
expr.mark_for_strip ();
return;
/* strip test based on inner attrs - spec says there are inner
* attributes, not just outer attributes of inner stmts */
- expander.expand_cfg_attrs (expr.get_inner_attrs ());
- if (expander.fails_cfg_with_expand (expr.get_inner_attrs ()))
+ expand_cfg_attrs (expr.get_inner_attrs ());
+ if (fails_cfg_with_expand (expr.get_inner_attrs ()))
{
expr.mark_for_strip ();
return;
std::function<std::unique_ptr<AST::Stmt> (AST::SingleASTNode)> extractor
= [] (AST::SingleASTNode node) { return node.take_stmt (); };
- expand_macro_children (MacroExpander::BLOCK, expr.get_statements (),
- extractor);
+ expand_macro_children (MacroExpander::ContextType::BLOCK,
+ expr.get_statements (), extractor);
- expander.push_context (MacroExpander::BLOCK);
+ expander.push_context (MacroExpander::ContextType::BLOCK);
// strip tail expression if exists - can actually fully remove it
if (expr.has_tail_expr ())
AttrVisitor::visit (AST::ClosureExprInnerTyped &expr)
{
// initial strip test based on outer attrs
- expander.expand_cfg_attrs (expr.get_outer_attrs ());
- if (expander.fails_cfg_with_expand (expr.get_outer_attrs ()))
+ expand_cfg_attrs (expr.get_outer_attrs ());
+ if (fails_cfg_with_expand (expr.get_outer_attrs ()))
{
expr.mark_for_strip ();
return;
AttrVisitor::visit (AST::ContinueExpr &expr)
{
// initial strip test based on outer attrs
- expander.expand_cfg_attrs (expr.get_outer_attrs ());
- if (expander.fails_cfg_with_expand (expr.get_outer_attrs ()))
+ expand_cfg_attrs (expr.get_outer_attrs ());
+ if (fails_cfg_with_expand (expr.get_outer_attrs ()))
{
expr.mark_for_strip ();
return;
AttrVisitor::visit (AST::BreakExpr &expr)
{
// initial strip test based on outer attrs
- expander.expand_cfg_attrs (expr.get_outer_attrs ());
- if (expander.fails_cfg_with_expand (expr.get_outer_attrs ()))
+ expand_cfg_attrs (expr.get_outer_attrs ());
+ if (fails_cfg_with_expand (expr.get_outer_attrs ()))
{
expr.mark_for_strip ();
return;
AttrVisitor::visit (AST::ReturnExpr &expr)
{
// initial strip test based on outer attrs
- expander.expand_cfg_attrs (expr.get_outer_attrs ());
- if (expander.fails_cfg_with_expand (expr.get_outer_attrs ()))
+ expand_cfg_attrs (expr.get_outer_attrs ());
+ if (fails_cfg_with_expand (expr.get_outer_attrs ()))
{
expr.mark_for_strip ();
return;
AttrVisitor::visit (AST::UnsafeBlockExpr &expr)
{
// initial strip test based on outer attrs
- expander.expand_cfg_attrs (expr.get_outer_attrs ());
- if (expander.fails_cfg_with_expand (expr.get_outer_attrs ()))
+ expand_cfg_attrs (expr.get_outer_attrs ());
+ if (fails_cfg_with_expand (expr.get_outer_attrs ()))
{
expr.mark_for_strip ();
return;
AttrVisitor::visit (AST::LoopExpr &expr)
{
// initial strip test based on outer attrs
- expander.expand_cfg_attrs (expr.get_outer_attrs ());
- if (expander.fails_cfg_with_expand (expr.get_outer_attrs ()))
+ expand_cfg_attrs (expr.get_outer_attrs ());
+ if (fails_cfg_with_expand (expr.get_outer_attrs ()))
{
expr.mark_for_strip ();
return;
AttrVisitor::visit (AST::WhileLoopExpr &expr)
{
// initial strip test based on outer attrs
- expander.expand_cfg_attrs (expr.get_outer_attrs ());
- if (expander.fails_cfg_with_expand (expr.get_outer_attrs ()))
+ expand_cfg_attrs (expr.get_outer_attrs ());
+ if (fails_cfg_with_expand (expr.get_outer_attrs ()))
{
expr.mark_for_strip ();
return;
AttrVisitor::visit (AST::WhileLetLoopExpr &expr)
{
// initial strip test based on outer attrs
- expander.expand_cfg_attrs (expr.get_outer_attrs ());
- if (expander.fails_cfg_with_expand (expr.get_outer_attrs ()))
+ expand_cfg_attrs (expr.get_outer_attrs ());
+ if (fails_cfg_with_expand (expr.get_outer_attrs ()))
{
expr.mark_for_strip ();
return;
AttrVisitor::visit (AST::ForLoopExpr &expr)
{
// initial strip test based on outer attrs
- expander.expand_cfg_attrs (expr.get_outer_attrs ());
- if (expander.fails_cfg_with_expand (expr.get_outer_attrs ()))
+ expand_cfg_attrs (expr.get_outer_attrs ());
+ if (fails_cfg_with_expand (expr.get_outer_attrs ()))
{
expr.mark_for_strip ();
return;
// when used as statement
// initial strip test based on outer attrs
- expander.expand_cfg_attrs (expr.get_outer_attrs ());
- if (expander.fails_cfg_with_expand (expr.get_outer_attrs ()))
+ expand_cfg_attrs (expr.get_outer_attrs ());
+ if (fails_cfg_with_expand (expr.get_outer_attrs ()))
{
expr.mark_for_strip ();
return;
AttrVisitor::visit (AST::IfExprConseqElse &expr)
{
// initial strip test based on outer attrs
- expander.expand_cfg_attrs (expr.get_outer_attrs ());
- if (expander.fails_cfg_with_expand (expr.get_outer_attrs ()))
+ expand_cfg_attrs (expr.get_outer_attrs ());
+ if (fails_cfg_with_expand (expr.get_outer_attrs ()))
{
expr.mark_for_strip ();
return;
AttrVisitor::visit (AST::IfExprConseqIf &expr)
{
// initial strip test based on outer attrs
- expander.expand_cfg_attrs (expr.get_outer_attrs ());
- if (expander.fails_cfg_with_expand (expr.get_outer_attrs ()))
+ expand_cfg_attrs (expr.get_outer_attrs ());
+ if (fails_cfg_with_expand (expr.get_outer_attrs ()))
{
expr.mark_for_strip ();
return;
AttrVisitor::visit (AST::IfExprConseqIfLet &expr)
{
// initial strip test based on outer attrs
- expander.expand_cfg_attrs (expr.get_outer_attrs ());
- if (expander.fails_cfg_with_expand (expr.get_outer_attrs ()))
+ expand_cfg_attrs (expr.get_outer_attrs ());
+ if (fails_cfg_with_expand (expr.get_outer_attrs ()))
{
expr.mark_for_strip ();
return;
AttrVisitor::visit (AST::IfLetExpr &expr)
{
// initial strip test based on outer attrs
- expander.expand_cfg_attrs (expr.get_outer_attrs ());
- if (expander.fails_cfg_with_expand (expr.get_outer_attrs ()))
+ expand_cfg_attrs (expr.get_outer_attrs ());
+ if (fails_cfg_with_expand (expr.get_outer_attrs ()))
{
expr.mark_for_strip ();
return;
AttrVisitor::visit (AST::IfLetExprConseqElse &expr)
{
// initial strip test based on outer attrs
- expander.expand_cfg_attrs (expr.get_outer_attrs ());
- if (expander.fails_cfg_with_expand (expr.get_outer_attrs ()))
+ expand_cfg_attrs (expr.get_outer_attrs ());
+ if (fails_cfg_with_expand (expr.get_outer_attrs ()))
{
expr.mark_for_strip ();
return;
AttrVisitor::visit (AST::IfLetExprConseqIf &expr)
{
// initial strip test based on outer attrs
- expander.expand_cfg_attrs (expr.get_outer_attrs ());
- if (expander.fails_cfg_with_expand (expr.get_outer_attrs ()))
+ expand_cfg_attrs (expr.get_outer_attrs ());
+ if (fails_cfg_with_expand (expr.get_outer_attrs ()))
{
expr.mark_for_strip ();
return;
AttrVisitor::visit (AST::IfLetExprConseqIfLet &expr)
{
// initial strip test based on outer attrs
- expander.expand_cfg_attrs (expr.get_outer_attrs ());
- if (expander.fails_cfg_with_expand (expr.get_outer_attrs ()))
+ expand_cfg_attrs (expr.get_outer_attrs ());
+ if (fails_cfg_with_expand (expr.get_outer_attrs ()))
{
expr.mark_for_strip ();
return;
AttrVisitor::visit (AST::MatchExpr &expr)
{
// initial strip test based on outer attrs
- expander.expand_cfg_attrs (expr.get_outer_attrs ());
- if (expander.fails_cfg_with_expand (expr.get_outer_attrs ()))
+ expand_cfg_attrs (expr.get_outer_attrs ());
+ if (fails_cfg_with_expand (expr.get_outer_attrs ()))
{
expr.mark_for_strip ();
return;
}
// inner attr strip test
- expander.expand_cfg_attrs (expr.get_inner_attrs ());
- if (expander.fails_cfg_with_expand (expr.get_inner_attrs ()))
+ expand_cfg_attrs (expr.get_inner_attrs ());
+ if (fails_cfg_with_expand (expr.get_inner_attrs ()))
{
expr.mark_for_strip ();
return;
// strip match case based on outer attributes in match arm
auto &match_arm = match_case.get_arm ();
- expander.expand_cfg_attrs (match_arm.get_outer_attrs ());
- if (expander.fails_cfg_with_expand (match_arm.get_outer_attrs ()))
+ expand_cfg_attrs (match_arm.get_outer_attrs ());
+ if (fails_cfg_with_expand (match_arm.get_outer_attrs ()))
{
// strip match case
it = match_cases.erase (it);
AttrVisitor::visit (AST::AwaitExpr &expr)
{
// initial strip test based on outer attrs
- expander.expand_cfg_attrs (expr.get_outer_attrs ());
- if (expander.fails_cfg_with_expand (expr.get_outer_attrs ()))
+ expand_cfg_attrs (expr.get_outer_attrs ());
+ if (fails_cfg_with_expand (expr.get_outer_attrs ()))
{
expr.mark_for_strip ();
return;
AttrVisitor::visit (AST::AsyncBlockExpr &expr)
{
// initial strip test based on outer attrs
- expander.expand_cfg_attrs (expr.get_outer_attrs ());
- if (expander.fails_cfg_with_expand (expr.get_outer_attrs ()))
+ expand_cfg_attrs (expr.get_outer_attrs ());
+ if (fails_cfg_with_expand (expr.get_outer_attrs ()))
{
expr.mark_for_strip ();
return;
AttrVisitor::visit (AST::Method &method)
{
// initial test based on outer attrs
- expander.expand_cfg_attrs (method.get_outer_attrs ());
- if (expander.fails_cfg_with_expand (method.get_outer_attrs ()))
+ expand_cfg_attrs (method.get_outer_attrs ());
+ if (fails_cfg_with_expand (method.get_outer_attrs ()))
{
method.mark_for_strip ();
return;
AttrVisitor::visit (AST::Module &module)
{
// strip test based on outer attrs
- expander.expand_cfg_attrs (module.get_outer_attrs ());
- if (expander.fails_cfg_with_expand (module.get_outer_attrs ()))
+ expand_cfg_attrs (module.get_outer_attrs ());
+ if (fails_cfg_with_expand (module.get_outer_attrs ()))
{
module.mark_for_strip ();
return;
if (module.get_kind () == AST::Module::ModuleKind::LOADED)
{
// strip test based on inner attrs
- expander.expand_cfg_attrs (module.get_inner_attrs ());
- if (expander.fails_cfg_with_expand (module.get_inner_attrs ()))
+ expand_cfg_attrs (module.get_inner_attrs ());
+ if (fails_cfg_with_expand (module.get_inner_attrs ()))
{
module.mark_for_strip ();
return;
AttrVisitor::visit (AST::ExternCrate &extern_crate)
{
// strip test based on outer attrs
- expander.expand_cfg_attrs (extern_crate.get_outer_attrs ());
- if (expander.fails_cfg_with_expand (extern_crate.get_outer_attrs ()))
+ expand_cfg_attrs (extern_crate.get_outer_attrs ());
+ if (fails_cfg_with_expand (extern_crate.get_outer_attrs ()))
{
extern_crate.mark_for_strip ();
return;
AttrVisitor::visit (AST::UseDeclaration &use_decl)
{
// strip test based on outer attrs
- expander.expand_cfg_attrs (use_decl.get_outer_attrs ());
- if (expander.fails_cfg_with_expand (use_decl.get_outer_attrs ()))
+ expand_cfg_attrs (use_decl.get_outer_attrs ());
+ if (fails_cfg_with_expand (use_decl.get_outer_attrs ()))
{
use_decl.mark_for_strip ();
return;
AttrVisitor::visit (AST::Function &function)
{
// initial test based on outer attrs
- expander.expand_cfg_attrs (function.get_outer_attrs ());
- if (expander.fails_cfg_with_expand (function.get_outer_attrs ()))
+ expand_cfg_attrs (function.get_outer_attrs ());
+ if (fails_cfg_with_expand (function.get_outer_attrs ()))
{
function.mark_for_strip ();
return;
AttrVisitor::visit (AST::TypeAlias &type_alias)
{
// initial test based on outer attrs
- expander.expand_cfg_attrs (type_alias.get_outer_attrs ());
- if (expander.fails_cfg_with_expand (type_alias.get_outer_attrs ()))
+ expand_cfg_attrs (type_alias.get_outer_attrs ());
+ if (fails_cfg_with_expand (type_alias.get_outer_attrs ()))
{
type_alias.mark_for_strip ();
return;
AttrVisitor::visit (AST::StructStruct &struct_item)
{
// initial test based on outer attrs
- expander.expand_cfg_attrs (struct_item.get_outer_attrs ());
- if (expander.fails_cfg_with_expand (struct_item.get_outer_attrs ()))
+ expand_cfg_attrs (struct_item.get_outer_attrs ());
+ if (fails_cfg_with_expand (struct_item.get_outer_attrs ()))
{
struct_item.mark_for_strip ();
return;
AttrVisitor::visit (AST::TupleStruct &tuple_struct)
{
// initial test based on outer attrs
- expander.expand_cfg_attrs (tuple_struct.get_outer_attrs ());
- if (expander.fails_cfg_with_expand (tuple_struct.get_outer_attrs ()))
+ expand_cfg_attrs (tuple_struct.get_outer_attrs ());
+ if (fails_cfg_with_expand (tuple_struct.get_outer_attrs ()))
{
tuple_struct.mark_for_strip ();
return;
AttrVisitor::visit (AST::EnumItem &item)
{
// initial test based on outer attrs
- expander.expand_cfg_attrs (item.get_outer_attrs ());
- if (expander.fails_cfg_with_expand (item.get_outer_attrs ()))
+ expand_cfg_attrs (item.get_outer_attrs ());
+ if (fails_cfg_with_expand (item.get_outer_attrs ()))
{
item.mark_for_strip ();
return;
AttrVisitor::visit (AST::EnumItemTuple &item)
{
// initial test based on outer attrs
- expander.expand_cfg_attrs (item.get_outer_attrs ());
- if (expander.fails_cfg_with_expand (item.get_outer_attrs ()))
+ expand_cfg_attrs (item.get_outer_attrs ());
+ if (fails_cfg_with_expand (item.get_outer_attrs ()))
{
item.mark_for_strip ();
return;
AttrVisitor::visit (AST::EnumItemStruct &item)
{
// initial test based on outer attrs
- expander.expand_cfg_attrs (item.get_outer_attrs ());
- if (expander.fails_cfg_with_expand (item.get_outer_attrs ()))
+ expand_cfg_attrs (item.get_outer_attrs ());
+ if (fails_cfg_with_expand (item.get_outer_attrs ()))
{
item.mark_for_strip ();
return;
AttrVisitor::visit (AST::EnumItemDiscriminant &item)
{
// initial test based on outer attrs
- expander.expand_cfg_attrs (item.get_outer_attrs ());
- if (expander.fails_cfg_with_expand (item.get_outer_attrs ()))
+ expand_cfg_attrs (item.get_outer_attrs ());
+ if (fails_cfg_with_expand (item.get_outer_attrs ()))
{
item.mark_for_strip ();
return;
AttrVisitor::visit (AST::Enum &enum_item)
{
// initial test based on outer attrs
- expander.expand_cfg_attrs (enum_item.get_outer_attrs ());
- if (expander.fails_cfg_with_expand (enum_item.get_outer_attrs ()))
+ expand_cfg_attrs (enum_item.get_outer_attrs ());
+ if (fails_cfg_with_expand (enum_item.get_outer_attrs ()))
{
enum_item.mark_for_strip ();
return;
AttrVisitor::visit (AST::Union &union_item)
{
// initial test based on outer attrs
- expander.expand_cfg_attrs (union_item.get_outer_attrs ());
- if (expander.fails_cfg_with_expand (union_item.get_outer_attrs ()))
+ expand_cfg_attrs (union_item.get_outer_attrs ());
+ if (fails_cfg_with_expand (union_item.get_outer_attrs ()))
{
union_item.mark_for_strip ();
return;
AttrVisitor::visit (AST::ConstantItem &const_item)
{
// initial test based on outer attrs
- expander.expand_cfg_attrs (const_item.get_outer_attrs ());
- if (expander.fails_cfg_with_expand (const_item.get_outer_attrs ()))
+ expand_cfg_attrs (const_item.get_outer_attrs ());
+ if (fails_cfg_with_expand (const_item.get_outer_attrs ()))
{
const_item.mark_for_strip ();
return;
AttrVisitor::visit (AST::StaticItem &static_item)
{
// initial test based on outer attrs
- expander.expand_cfg_attrs (static_item.get_outer_attrs ());
- if (expander.fails_cfg_with_expand (static_item.get_outer_attrs ()))
+ expand_cfg_attrs (static_item.get_outer_attrs ());
+ if (fails_cfg_with_expand (static_item.get_outer_attrs ()))
{
static_item.mark_for_strip ();
return;
AttrVisitor::visit (AST::TraitItemFunc &item)
{
// initial test based on outer attrs
- expander.expand_cfg_attrs (item.get_outer_attrs ());
- if (expander.fails_cfg_with_expand (item.get_outer_attrs ()))
+ expand_cfg_attrs (item.get_outer_attrs ());
+ if (fails_cfg_with_expand (item.get_outer_attrs ()))
{
item.mark_for_strip ();
return;
AttrVisitor::visit (AST::TraitItemMethod &item)
{
// initial test based on outer attrs
- expander.expand_cfg_attrs (item.get_outer_attrs ());
- if (expander.fails_cfg_with_expand (item.get_outer_attrs ()))
+ expand_cfg_attrs (item.get_outer_attrs ());
+ if (fails_cfg_with_expand (item.get_outer_attrs ()))
{
item.mark_for_strip ();
return;
AttrVisitor::visit (AST::TraitItemConst &item)
{
// initial test based on outer attrs
- expander.expand_cfg_attrs (item.get_outer_attrs ());
- if (expander.fails_cfg_with_expand (item.get_outer_attrs ()))
+ expand_cfg_attrs (item.get_outer_attrs ());
+ if (fails_cfg_with_expand (item.get_outer_attrs ()))
{
item.mark_for_strip ();
return;
AttrVisitor::visit (AST::TraitItemType &item)
{
// initial test based on outer attrs
- expander.expand_cfg_attrs (item.get_outer_attrs ());
- if (expander.fails_cfg_with_expand (item.get_outer_attrs ()))
+ expand_cfg_attrs (item.get_outer_attrs ());
+ if (fails_cfg_with_expand (item.get_outer_attrs ()))
{
item.mark_for_strip ();
return;
AttrVisitor::visit (AST::Trait &trait)
{
// initial strip test based on outer attrs
- expander.expand_cfg_attrs (trait.get_outer_attrs ());
- if (expander.fails_cfg_with_expand (trait.get_outer_attrs ()))
+ expand_cfg_attrs (trait.get_outer_attrs ());
+ if (fails_cfg_with_expand (trait.get_outer_attrs ()))
{
trait.mark_for_strip ();
return;
}
// strip test based on inner attrs
- expander.expand_cfg_attrs (trait.get_inner_attrs ());
- if (expander.fails_cfg_with_expand (trait.get_inner_attrs ()))
+ expand_cfg_attrs (trait.get_inner_attrs ());
+ if (fails_cfg_with_expand (trait.get_inner_attrs ()))
{
trait.mark_for_strip ();
return;
std::function<std::unique_ptr<AST::TraitItem> (AST::SingleASTNode)> extractor
= [] (AST::SingleASTNode node) { return node.take_trait_item (); };
- expand_macro_children (MacroExpander::TRAIT, trait.get_trait_items (),
- extractor);
+ expand_macro_children (MacroExpander::ContextType::TRAIT,
+ trait.get_trait_items (), extractor);
}
void
AttrVisitor::visit (AST::InherentImpl &impl)
{
// initial strip test based on outer attrs
- expander.expand_cfg_attrs (impl.get_outer_attrs ());
- if (expander.fails_cfg_with_expand (impl.get_outer_attrs ()))
+ expand_cfg_attrs (impl.get_outer_attrs ());
+ if (fails_cfg_with_expand (impl.get_outer_attrs ()))
{
impl.mark_for_strip ();
return;
}
// strip test based on inner attrs
- expander.expand_cfg_attrs (impl.get_inner_attrs ());
- if (expander.fails_cfg_with_expand (impl.get_inner_attrs ()))
+ expand_cfg_attrs (impl.get_inner_attrs ());
+ if (fails_cfg_with_expand (impl.get_inner_attrs ()))
{
impl.mark_for_strip ();
return;
std::function<std::unique_ptr<AST::InherentImplItem> (AST::SingleASTNode)>
extractor = [] (AST::SingleASTNode node) { return node.take_impl_item (); };
- expand_macro_children (MacroExpander::IMPL, impl.get_impl_items (),
- extractor);
+ expand_macro_children (MacroExpander::ContextType::IMPL,
+ impl.get_impl_items (), extractor);
}
void
AttrVisitor::visit (AST::TraitImpl &impl)
{
// initial strip test based on outer attrs
- expander.expand_cfg_attrs (impl.get_outer_attrs ());
- if (expander.fails_cfg_with_expand (impl.get_outer_attrs ()))
+ expand_cfg_attrs (impl.get_outer_attrs ());
+ if (fails_cfg_with_expand (impl.get_outer_attrs ()))
{
impl.mark_for_strip ();
return;
}
// strip test based on inner attrs
- expander.expand_cfg_attrs (impl.get_inner_attrs ());
- if (expander.fails_cfg_with_expand (impl.get_inner_attrs ()))
+ expand_cfg_attrs (impl.get_inner_attrs ());
+ if (fails_cfg_with_expand (impl.get_inner_attrs ()))
{
impl.mark_for_strip ();
return;
extractor
= [] (AST::SingleASTNode node) { return node.take_trait_impl_item (); };
- expand_macro_children (MacroExpander::TRAIT_IMPL, impl.get_impl_items (),
- extractor);
+ expand_macro_children (MacroExpander::ContextType::TRAIT_IMPL,
+ impl.get_impl_items (), extractor);
}
void
AttrVisitor::visit (AST::ExternalTypeItem &item)
{
- expander.expand_cfg_attrs (item.get_outer_attrs ());
+ expand_cfg_attrs (item.get_outer_attrs ());
- if (expander.fails_cfg_with_expand (item.get_outer_attrs ()))
+ if (fails_cfg_with_expand (item.get_outer_attrs ()))
item.mark_for_strip ();
// TODO: Can we do anything like expand a macro here?
AttrVisitor::visit (AST::ExternalStaticItem &item)
{
// strip test based on outer attrs
- expander.expand_cfg_attrs (item.get_outer_attrs ());
- if (expander.fails_cfg_with_expand (item.get_outer_attrs ()))
+ expand_cfg_attrs (item.get_outer_attrs ());
+ if (fails_cfg_with_expand (item.get_outer_attrs ()))
{
item.mark_for_strip ();
return;
AttrVisitor::visit (AST::ExternalFunctionItem &item)
{
// strip test based on outer attrs
- expander.expand_cfg_attrs (item.get_outer_attrs ());
- if (expander.fails_cfg_with_expand (item.get_outer_attrs ()))
+ expand_cfg_attrs (item.get_outer_attrs ());
+ if (fails_cfg_with_expand (item.get_outer_attrs ()))
{
item.mark_for_strip ();
return;
auto ¶m = *it;
auto ¶m_attrs = param.get_outer_attrs ();
- expander.expand_cfg_attrs (param_attrs);
- if (expander.fails_cfg_with_expand (param_attrs))
+ expand_cfg_attrs (param_attrs);
+ if (fails_cfg_with_expand (param_attrs))
{
it = params.erase (it);
continue;
AttrVisitor::visit (AST::ExternBlock &block)
{
// initial strip test based on outer attrs
- expander.expand_cfg_attrs (block.get_outer_attrs ());
- if (expander.fails_cfg_with_expand (block.get_outer_attrs ()))
+ expand_cfg_attrs (block.get_outer_attrs ());
+ if (fails_cfg_with_expand (block.get_outer_attrs ()))
{
block.mark_for_strip ();
return;
}
// strip test based on inner attrs
- expander.expand_cfg_attrs (block.get_inner_attrs ());
- if (expander.fails_cfg_with_expand (block.get_inner_attrs ()))
+ expand_cfg_attrs (block.get_inner_attrs ());
+ if (fails_cfg_with_expand (block.get_inner_attrs ()))
{
block.mark_for_strip ();
return;
extractor
= [] (AST::SingleASTNode node) { return node.take_external_item (); };
- expand_macro_children (MacroExpander::EXTERN, block.get_extern_items (),
- extractor);
+ expand_macro_children (MacroExpander::ContextType::EXTERN,
+ block.get_extern_items (), extractor);
}
// I don't think it would be possible to strip macros without expansion
AttrVisitor::visit (AST::MacroRulesDefinition &rules_def)
{
// initial strip test based on outer attrs
- expander.expand_cfg_attrs (rules_def.get_outer_attrs ());
- if (expander.fails_cfg_with_expand (rules_def.get_outer_attrs ()))
+ expand_cfg_attrs (rules_def.get_outer_attrs ());
+ if (fails_cfg_with_expand (rules_def.get_outer_attrs ()))
{
rules_def.mark_for_strip ();
return;
AttrVisitor::visit (AST::StructPatternFieldTuplePat &field)
{
// initial strip test based on outer attrs
- expander.expand_cfg_attrs (field.get_outer_attrs ());
- if (expander.fails_cfg_with_expand (field.get_outer_attrs ()))
+ expand_cfg_attrs (field.get_outer_attrs ());
+ if (fails_cfg_with_expand (field.get_outer_attrs ()))
{
field.mark_for_strip ();
return;
AttrVisitor::visit (AST::StructPatternFieldIdentPat &field)
{
// initial strip test based on outer attrs
- expander.expand_cfg_attrs (field.get_outer_attrs ());
- if (expander.fails_cfg_with_expand (field.get_outer_attrs ()))
+ expand_cfg_attrs (field.get_outer_attrs ());
+ if (fails_cfg_with_expand (field.get_outer_attrs ()))
{
field.mark_for_strip ();
return;
AttrVisitor::visit (AST::StructPatternFieldIdent &field)
{
// initial strip test based on outer attrs
- expander.expand_cfg_attrs (field.get_outer_attrs ());
- if (expander.fails_cfg_with_expand (field.get_outer_attrs ()))
+ expand_cfg_attrs (field.get_outer_attrs ());
+ if (fails_cfg_with_expand (field.get_outer_attrs ()))
{
field.mark_for_strip ();
return;
// assuming you can strip the ".." part
if (elems.has_etc ())
{
- expander.expand_cfg_attrs (elems.get_etc_outer_attrs ());
- if (expander.fails_cfg_with_expand (elems.get_etc_outer_attrs ()))
+ expand_cfg_attrs (elems.get_etc_outer_attrs ());
+ if (fails_cfg_with_expand (elems.get_etc_outer_attrs ()))
elems.strip_etc ();
}
}
AttrVisitor::visit (AST::LetStmt &stmt)
{
// initial strip test based on outer attrs
- expander.expand_cfg_attrs (stmt.get_outer_attrs ());
- if (expander.fails_cfg_with_expand (stmt.get_outer_attrs ()))
+ expand_cfg_attrs (stmt.get_outer_attrs ());
+ if (fails_cfg_with_expand (stmt.get_outer_attrs ()))
{
stmt.mark_for_strip ();
return;
auto ¶m = *it;
auto ¶m_attrs = param.get_outer_attrs ();
- expander.expand_cfg_attrs (param_attrs);
- if (expander.fails_cfg_with_expand (param_attrs))
+ expand_cfg_attrs (param_attrs);
+ if (fails_cfg_with_expand (param_attrs))
{
it = params.erase (it);
continue;