#include "rust-cfg-strip.h"
#include "rust-ast-full.h"
+#include "rust-ast-visitor.h"
#include "rust-session-manager.h"
#include "rust-attribute-values.h"
void
CfgStrip::go (AST::Crate &crate)
+{
+ visit (crate);
+}
+
+void
+CfgStrip::visit (AST::Crate &crate)
{
// expand crate cfg_attr attributes
expand_cfg_attrs (crate.inner_attrs);
auto &items = crate.items;
+ AST::DefaultASTVisitor::visit (crate);
for (auto it = items.begin (); it != items.end ();)
{
auto &item = *it;
- item->accept_vis (*this);
-
if (item->is_marked_for_strip ())
it = items.erase (it);
else
it++;
}
-
// expand module attributes?
}
maybe_strip_where_clause (decl.get_where_clause ());
}
-void
-CfgStrip::visit (AST::Token &)
-{
- // shouldn't require?
-}
-void
-CfgStrip::visit (AST::DelimTokenTree &)
-{
- // shouldn't require?
-}
-void
-CfgStrip::visit (AST::AttrInputMetaItemContainer &)
-{
- // shouldn't require?
-}
void
CfgStrip::visit (AST::IdentifierExpr &ident_expr)
{
// strip test based on outer attrs
+ AST::DefaultASTVisitor::visit (ident_expr);
expand_cfg_attrs (ident_expr.get_outer_attrs ());
if (fails_cfg_with_expand (ident_expr.get_outer_attrs ()))
{
return;
}
}
-void
-CfgStrip::visit (AST::Lifetime &)
-{
- // shouldn't require?
-}
-void
-CfgStrip::visit (AST::LifetimeParam &)
-{
- // supposedly does not require - cfg does nothing
-}
-void
-CfgStrip::visit (AST::ConstGenericParam &)
-{
- // likewise
-}
void
CfgStrip::visit (AST::MacroInvocation ¯o_invoc)
maybe_strip_generic_args (segment.get_generic_args ());
}
}
-void
-CfgStrip::visit (AST::TypePathSegment &)
-{
- // shouldn't require
-}
+
void
CfgStrip::visit (AST::TypePathSegmentGeneric &segment)
{
void
CfgStrip::visit (AST::TypePathSegmentFunction &segment)
{
+ AST::DefaultASTVisitor::visit (segment);
auto &type_path_function = segment.get_type_path_function ();
for (auto &type : type_path_function.get_params ())
{
- type->accept_vis (*this);
if (type->is_marked_for_strip ())
rust_error_at (type->get_locus (),
"cannot strip type in this position");
if (type_path_function.has_return_type ())
{
auto &return_type = type_path_function.get_return_type ();
- return_type->accept_vis (*this);
if (return_type->is_marked_for_strip ())
rust_error_at (return_type->get_locus (),
"cannot strip type in this position");
}
}
-void
-CfgStrip::visit (AST::TypePath &path)
-{
- // this shouldn't strip any segments, but can strip inside them
- for (auto &segment : path.get_segments ())
- segment->accept_vis (*this);
-}
+
void
CfgStrip::visit (AST::QualifiedPathInExpression &path)
{
// initial strip test based on outer attrs
+ AST::DefaultASTVisitor::visit (path);
+
expand_cfg_attrs (path.get_outer_attrs ());
if (fails_cfg_with_expand (path.get_outer_attrs ()))
{
maybe_strip_generic_args (segment.get_generic_args ());
}
}
+
void
CfgStrip::visit (AST::QualifiedPathInType &path)
{
maybe_strip_qualified_path_type (path.get_qualified_path_type ());
// this shouldn't strip any segments, but can strip inside them
- for (auto &segment : path.get_segments ())
- segment->accept_vis (*this);
+ AST::DefaultASTVisitor::visit (path);
}
void
return;
}
}
-void
-CfgStrip::visit (AST::AttrInputLiteral &)
-{
- // shouldn't require?
-}
-void
-CfgStrip::visit (AST::AttrInputMacro &)
-{
- // shouldn't require?
-}
-void
-CfgStrip::visit (AST::MetaItemLitExpr &)
-{
- // shouldn't require?
-}
-void
-CfgStrip::visit (AST::MetaItemPathLit &)
-{
- // shouldn't require?
-}
+
void
CfgStrip::visit (AST::BorrowExpr &expr)
{
+ AST::DefaultASTVisitor::visit (expr);
// initial strip test based on outer attrs
expand_cfg_attrs (expr.get_outer_attrs ());
if (fails_cfg_with_expand (expr.get_outer_attrs ()))
* allowed to have external attributes in this position so can't be
* stripped. */
auto &borrowed_expr = expr.get_borrowed_expr ();
- borrowed_expr->accept_vis (*this);
if (borrowed_expr->is_marked_for_strip ())
rust_error_at (borrowed_expr->get_locus (),
"cannot strip expression in this position - outer "
void
CfgStrip::visit (AST::ErrorPropagationExpr &expr)
{
+ AST::DefaultASTVisitor::visit (expr);
+
// initial strip test based on outer attrs
expand_cfg_attrs (expr.get_outer_attrs ());
if (fails_cfg_with_expand (expr.get_outer_attrs ()))
* allowed to have external attributes in this position so can't be
* stripped. */
auto &propagating_expr = expr.get_propagating_expr ();
- propagating_expr->accept_vis (*this);
if (propagating_expr->is_marked_for_strip ())
rust_error_at (propagating_expr->get_locus (),
"cannot strip expression in this position - outer "
void
CfgStrip::visit (AST::NegationExpr &expr)
{
+ AST::DefaultASTVisitor::visit (expr);
// initial strip test based on outer attrs
expand_cfg_attrs (expr.get_outer_attrs ());
if (fails_cfg_with_expand (expr.get_outer_attrs ()))
* allowed to have external attributes in this position so can't be
* stripped. */
auto &negated_expr = expr.get_negated_expr ();
- negated_expr->accept_vis (*this);
if (negated_expr->is_marked_for_strip ())
rust_error_at (negated_expr->get_locus (),
"cannot strip expression in this position - outer "
void
CfgStrip::visit (AST::ArithmeticOrLogicalExpr &expr)
{
+ AST::DefaultASTVisitor::visit (expr);
/* outer attributes never allowed before these. while cannot strip
* two direct descendant expressions, can strip ones below that */
- /* should have no possibility for outer attrs as would be parsed
- * with outer expr */
- auto &l_expr = expr.get_left_expr ();
- l_expr->accept_vis (*this);
-
- /* should syntactically not have outer attributes, though this may
- * not have worked in practice */
- auto &r_expr = expr.get_right_expr ();
- r_expr->accept_vis (*this);
-
// ensure that they are not marked for strip
if (expr.get_left_expr ()->is_marked_for_strip ())
rust_error_at (expr.get_left_expr ()->get_locus (),
"cannot strip expression in this position - outer "
"attributes not allowed");
}
+
void
CfgStrip::visit (AST::ComparisonExpr &expr)
{
/* outer attributes never allowed before these. while cannot strip
* two direct descendant expressions, can strip ones below that */
-
- /* should have no possibility for outer attrs as would be parsed
- * with outer expr */
- auto &l_expr = expr.get_left_expr ();
- l_expr->accept_vis (*this);
-
- /* should syntactically not have outer attributes, though this may
- * not have worked in practice */
- auto &r_expr = expr.get_right_expr ();
- r_expr->accept_vis (*this);
+ AST::DefaultASTVisitor::visit (expr);
// ensure that they are not marked for strip
if (expr.get_left_expr ()->is_marked_for_strip ())
"cannot strip expression in this position - outer "
"attributes not allowed");
}
+
void
CfgStrip::visit (AST::LazyBooleanExpr &expr)
{
/* outer attributes never allowed before these. while cannot strip
* two direct descendant expressions, can strip ones below that */
-
- /* should have no possibility for outer attrs as would be parsed
- * with outer expr */
- auto &l_expr = expr.get_left_expr ();
- l_expr->accept_vis (*this);
-
- /* should syntactically not have outer attributes, though this may
- * not have worked in practice */
- auto &r_expr = expr.get_right_expr ();
- r_expr->accept_vis (*this);
+ AST::DefaultASTVisitor::visit (expr);
// ensure that they are not marked for strip
if (expr.get_left_expr ()->is_marked_for_strip ())
"cannot strip expression in this position - outer "
"attributes not allowed");
}
+
void
CfgStrip::visit (AST::TypeCastExpr &expr)
{
/* outer attributes never allowed before these. while cannot strip
* direct descendant expression, can strip ones below that */
+ AST::DefaultASTVisitor::visit (expr);
auto &casted_expr = expr.get_casted_expr ();
- /* should have no possibility for outer attrs as would be parsed
- * with outer expr */
- casted_expr->accept_vis (*this);
-
// ensure that they are not marked for strip
if (casted_expr->is_marked_for_strip ())
rust_error_at (casted_expr->get_locus (),
// TODO: strip sub-types of type
auto &type = expr.get_type_to_cast_to ();
- type->accept_vis (*this);
if (type->is_marked_for_strip ())
rust_error_at (type->get_locus (), "cannot strip type in this position");
}
expr.mark_for_strip ();
return;
}
-
- /* should have no possibility for outer attrs as would be parsed
- * with outer expr */
- auto &l_expr = expr.get_left_expr ();
- l_expr->accept_vis (*this);
-
- /* should syntactically not have outer attributes, though this may
- * not have worked in practice */
- auto &r_expr = expr.get_right_expr ();
- r_expr->accept_vis (*this);
+ AST::DefaultASTVisitor::visit (expr);
// ensure that they are not marked for strip
if (expr.get_left_expr ()->is_marked_for_strip ())
{
/* outer attributes never allowed before these. while cannot strip
* two direct descendant expressions, can strip ones below that */
-
- /* should have no possibility for outer attrs as would be parsed
- * with outer expr */
- auto &l_expr = expr.get_left_expr ();
- l_expr->accept_vis (*this);
-
- /* should syntactically not have outer attributes, though this may
- * not have worked in practice */
- auto &r_expr = expr.get_right_expr ();
- r_expr->accept_vis (*this);
+ AST::DefaultASTVisitor::visit (expr);
// ensure that they are not marked for strip
if (expr.get_left_expr ()->is_marked_for_strip ())
/* strip any internal sub-expressions - expression itself isn't
* allowed to have external attributes in this position so can't be
* stripped. */
+ AST::DefaultASTVisitor::visit (expr);
+
auto &inner_expr = expr.get_expr_in_parens ();
- inner_expr->accept_vis (*this);
if (inner_expr->is_marked_for_strip ())
rust_error_at (inner_expr->get_locus (),
"cannot strip expression in this position - outer "
* expressions" according to spec. on the other hand, it would not
* make conceptual sense to be able to remove either expression. As
* such, not implementing. TODO clear up the ambiguity here */
+ AST::DefaultASTVisitor::visit (elems);
// only intend stripping for internal sub-expressions
auto &copied_expr = elems.get_elem_to_copy ();
- copied_expr->accept_vis (*this);
if (copied_expr->is_marked_for_strip ())
rust_error_at (copied_expr->get_locus (),
"cannot strip expression in this position - outer "
/* assuming you can't strip away the ArrayElems type, but can strip
* internal expressions and whatever */
- expr.get_array_elems ()->accept_vis (*this);
+ AST::DefaultASTVisitor::visit (expr);
}
+
void
CfgStrip::visit (AST::ArrayIndexExpr &expr)
{
/* strip any internal sub-expressions - expression itself isn't
* allowed to have external attributes in this position so can't be
* stripped. */
- auto &array_expr = expr.get_array_expr ();
- array_expr->accept_vis (*this);
+ AST::DefaultASTVisitor::visit (expr);
+
+ const auto &array_expr = expr.get_array_expr ();
if (array_expr->is_marked_for_strip ())
rust_error_at (array_expr->get_locus (),
"cannot strip expression in this position - outer "
"attributes not allowed");
- auto &index_expr = expr.get_index_expr ();
- index_expr->accept_vis (*this);
+ const auto &index_expr = expr.get_index_expr ();
if (index_expr->is_marked_for_strip ())
rust_error_at (index_expr->get_locus (),
"cannot strip expression in this position - outer "
return;
}
+ AST::DefaultASTVisitor::visit (expr);
/* wouldn't strip this directly (as outer attrs should be
* associated with this level), but any sub-expressions would be
* stripped. Thus, no need to erase when strip check called. */
auto &tuple_expr = expr.get_tuple_expr ();
- tuple_expr->accept_vis (*this);
if (tuple_expr->is_marked_for_strip ())
rust_error_at (tuple_expr->get_locus (),
"cannot strip expression in this position - outer "
"attributes not allowed");
}
+
void
CfgStrip::visit (AST::StructExprStruct &expr)
{
rust_error_at (struct_name.get_locus (),
"cannot strip path in this position");
}
-void
-CfgStrip::visit (AST::StructExprFieldIdentifier &)
-{
- // as no attrs (at moment, at least), no stripping possible
-}
+
void
CfgStrip::visit (AST::StructExprFieldIdentifierValue &field)
{
/* as no attrs possible (at moment, at least), only sub-expression
* stripping is possible */
+ AST::DefaultASTVisitor::visit (field);
+
auto &value = field.get_value ();
- value->accept_vis (*this);
if (value->is_marked_for_strip ())
rust_error_at (value->get_locus (),
"cannot strip expression in this position - outer "
{
/* as no attrs possible (at moment, at least), only sub-expression
* stripping is possible */
+ AST::DefaultASTVisitor::visit (field);
+
auto &value = field.get_value ();
- value->accept_vis (*this);
if (value->is_marked_for_strip ())
rust_error_at (value->get_locus (),
"cannot strip expression in this position - outer "
* stripped at top level of struct fields, but I wouldn't think
* that they would be, so operating under the assumption that only
* sub-expressions can be stripped. */
- for (auto &field : expr.get_fields ())
- {
- field->accept_vis (*this);
- // shouldn't strip in this
- }
+ AST::DefaultASTVisitor::visit (expr);
/* struct base presumably can't be stripped, as the '..' is before
* the expression. as such, can only strip sub-expressions. */
"attributes not allowed");
}
}
+
void
CfgStrip::visit (AST::StructExprStructBase &expr)
{
/* should not be outer attrs on "function" expression - outer attrs
* should be associated with call expr as a whole. only sub-expr
* expansion is possible. */
+ AST::DefaultASTVisitor::visit (expr);
+
auto &function = expr.get_function_expr ();
- function->accept_vis (*this);
if (function->is_marked_for_strip ())
rust_error_at (function->get_locus (),
"cannot strip expression in this position - outer "
/* should not be outer attrs on "receiver" expression - outer attrs
* should be associated with call expr as a whole. only sub-expr
* expansion is possible. */
+ AST::DefaultASTVisitor::visit (expr);
+
auto &receiver = expr.get_receiver_expr ();
- receiver->accept_vis (*this);
if (receiver->is_marked_for_strip ())
rust_error_at (receiver->get_locus (),
"cannot strip expression in this position - outer "
/* should not be outer attrs on "receiver" expression - outer attrs
* should be associated with field expr as a whole. only sub-expr
* expansion is possible. */
+ AST::DefaultASTVisitor::visit (expr);
+
auto &receiver = expr.get_receiver_expr ();
- receiver->accept_vis (*this);
if (receiver->is_marked_for_strip ())
rust_error_at (receiver->get_locus (),
"cannot strip expression in this position - outer "
* allowed by spec */
maybe_strip_closure_params (expr.get_params ());
+ AST::DefaultASTVisitor::visit (expr);
+
// can't strip expression itself, but can strip sub-expressions
auto &definition_expr = expr.get_definition_expr ();
- definition_expr->accept_vis (*this);
if (definition_expr->is_marked_for_strip ())
rust_error_at (definition_expr->get_locus (),
"cannot strip expression in this position - outer "
maybe_strip_pointer_allow_strip (expr.get_statements ());
+ AST::DefaultASTVisitor::visit (expr);
+
// strip tail expression if exists - can actually fully remove it
if (expr.has_tail_expr ())
{
auto &tail_expr = expr.get_tail_expr ();
- tail_expr->accept_vis (*this);
-
if (tail_expr->is_marked_for_strip ())
expr.strip_tail_expr ();
}
* allowed by spec */
maybe_strip_closure_params (expr.get_params ());
+ AST::DefaultASTVisitor::visit (expr);
+
// can't strip return type, but can strip sub-types
auto &type = expr.get_return_type ();
- type->accept_vis (*this);
if (type->is_marked_for_strip ())
rust_error_at (type->get_locus (), "cannot strip type in this position");
expr.mark_for_strip ();
return;
}
+ AST::DefaultASTVisitor::visit (expr);
/* spec does not say that you can have outer attributes on
* expression, so assuming you can't. stripping for sub-expressions
{
auto &break_expr = expr.get_break_expr ();
- break_expr->accept_vis (*this);
-
if (break_expr->is_marked_for_strip ())
rust_error_at (break_expr->get_locus (),
"cannot strip expression in this position - outer "
{
/* outer attributes never allowed before these. while cannot strip
* two direct descendant expressions, can strip ones below that */
-
- /* should have no possibility for outer attrs as would be parsed
- * with outer expr */
- expr.get_from_expr ()->accept_vis (*this);
- /* should syntactically not have outer attributes, though this may
- * not have worked in practice */
- expr.get_to_expr ()->accept_vis (*this);
+ AST::DefaultASTVisitor::visit (expr);
// ensure that they are not marked for strip
if (expr.get_from_expr ()->is_marked_for_strip ())
/* outer attributes never allowed before these. while cannot strip
* direct descendant expression, can strip ones below that */
+ AST::DefaultASTVisitor::visit (expr);
/* should have no possibility for outer attrs as would be parsed
* with outer expr */
auto &from_expr = expr.get_from_expr ();
-
- from_expr->accept_vis (*this);
-
if (from_expr->is_marked_for_strip ())
rust_error_at (from_expr->get_locus (),
"cannot strip expression in this position - outer "
/* outer attributes never allowed before these. while cannot strip
* direct descendant expression, can strip ones below that */
+ AST::DefaultASTVisitor::visit (expr);
/* should syntactically not have outer attributes, though this may
* not have worked in practice */
auto &to_expr = expr.get_to_expr ();
-
- to_expr->accept_vis (*this);
-
if (to_expr->is_marked_for_strip ())
rust_error_at (to_expr->get_locus (),
"cannot strip expression in this position - outer "
"attributes not allowed");
}
-void
-CfgStrip::visit (AST::RangeFullExpr &)
-{
- // outer attributes never allowed before these, so no stripping
-}
+
void
CfgStrip::visit (AST::RangeFromToInclExpr &expr)
{
/* outer attributes never allowed before these. while cannot strip
* two direct descendant expressions, can strip ones below that */
- /* should have no possibility for outer attrs as would be parsed
- * with outer expr */
- expr.get_from_expr ()->accept_vis (*this);
- /* should syntactically not have outer attributes, though this may
- * not have worked in practice */
- expr.get_to_expr ()->accept_vis (*this);
+ AST::DefaultASTVisitor::visit (expr);
// ensure that they are not marked for strip
if (expr.get_from_expr ()->is_marked_for_strip ())
/* outer attributes never allowed before these. while cannot strip
* direct descendant expression, can strip ones below that */
+ AST::DefaultASTVisitor::visit (expr);
/* should syntactically not have outer attributes, though this may
* not have worked in practice */
auto &to_expr = expr.get_to_expr ();
-
- to_expr->accept_vis (*this);
-
if (to_expr->is_marked_for_strip ())
rust_error_at (to_expr->get_locus (),
"cannot strip expression in this position - outer "
return;
}
+ AST::DefaultASTVisitor::visit (expr);
+
/* spec does not say that you can have outer attributes on
* expression, so assuming you can't. stripping for sub-expressions
* is the only thing that can be done */
if (expr.has_returned_expr ())
{
auto &returned_expr = expr.get_returned_expr ();
-
- returned_expr->accept_vis (*this);
-
if (returned_expr->is_marked_for_strip ())
rust_error_at (returned_expr->get_locus (),
"cannot strip expression in this position - outer "
return;
}
+ AST::DefaultASTVisitor::visit (expr);
+
// can't strip block itself, but can strip sub-expressions
auto &block_expr = expr.get_block_expr ();
- block_expr->accept_vis (*this);
if (block_expr->is_marked_for_strip ())
rust_error_at (block_expr->get_locus (),
"cannot strip block expression in this position - outer "
return;
}
+ AST::DefaultASTVisitor::visit (expr);
+
// can't strip block itself, but can strip sub-expressions
auto &loop_block = expr.get_loop_block ();
- loop_block->accept_vis (*this);
if (loop_block->is_marked_for_strip ())
rust_error_at (loop_block->get_locus (),
"cannot strip block expression in this position - outer "
return;
}
+ AST::DefaultASTVisitor::visit (expr);
// can't strip predicate expr itself, but can strip sub-expressions
auto &predicate_expr = expr.get_predicate_expr ();
- predicate_expr->accept_vis (*this);
if (predicate_expr->is_marked_for_strip ())
rust_error_at (predicate_expr->get_locus (),
"cannot strip expression in this position - outer "
// can't strip block itself, but can strip sub-expressions
auto &loop_block = expr.get_loop_block ();
- loop_block->accept_vis (*this);
if (loop_block->is_marked_for_strip ())
rust_error_at (loop_block->get_locus (),
"cannot strip block expression in this position - outer "
return;
}
+ AST::DefaultASTVisitor::visit (expr);
+
for (auto &pattern : expr.get_patterns ())
- {
- pattern->accept_vis (*this);
- if (pattern->is_marked_for_strip ())
- rust_error_at (pattern->get_locus (),
- "cannot strip pattern in this position");
- }
+ if (pattern->is_marked_for_strip ())
+ rust_error_at (pattern->get_locus (),
+ "cannot strip pattern in this position");
// can't strip scrutinee expr itself, but can strip sub-expressions
auto &scrutinee_expr = expr.get_scrutinee_expr ();
- scrutinee_expr->accept_vis (*this);
if (scrutinee_expr->is_marked_for_strip ())
rust_error_at (scrutinee_expr->get_locus (),
"cannot strip expression in this position - outer "
// can't strip block itself, but can strip sub-expressions
auto &loop_block = expr.get_loop_block ();
- loop_block->accept_vis (*this);
if (loop_block->is_marked_for_strip ())
rust_error_at (loop_block->get_locus (),
"cannot strip block expression in this position - outer "
return;
}
+ AST::DefaultASTVisitor::visit (expr);
// strip sub-patterns of pattern
auto &pattern = expr.get_pattern ();
- pattern->accept_vis (*this);
if (pattern->is_marked_for_strip ())
rust_error_at (pattern->get_locus (),
"cannot strip pattern in this position");
// can't strip scrutinee expr itself, but can strip sub-expressions
auto &iterator_expr = expr.get_iterator_expr ();
- iterator_expr->accept_vis (*this);
if (iterator_expr->is_marked_for_strip ())
rust_error_at (iterator_expr->get_locus (),
"cannot strip expression in this position - outer "
// can't strip block itself, but can strip sub-expressions
auto &loop_block = expr.get_loop_block ();
- loop_block->accept_vis (*this);
if (loop_block->is_marked_for_strip ())
rust_error_at (loop_block->get_locus (),
"cannot strip block expression in this position - outer "
return;
}
+ AST::DefaultASTVisitor::visit (expr);
+
// can't strip condition expr itself, but can strip sub-expressions
auto &condition_expr = expr.get_condition_expr ();
- condition_expr->accept_vis (*this);
if (condition_expr->is_marked_for_strip ())
rust_error_at (condition_expr->get_locus (),
"cannot strip expression in this position - outer "
// can't strip if block itself, but can strip sub-expressions
auto &if_block = expr.get_if_block ();
- if_block->accept_vis (*this);
if (if_block->is_marked_for_strip ())
rust_error_at (if_block->get_locus (),
"cannot strip block expression in this position - outer "
"attributes not allowed");
}
+
void
CfgStrip::visit (AST::IfExprConseqElse &expr)
{
return;
}
+ AST::DefaultASTVisitor::visit (expr);
+
// can't strip condition expr itself, but can strip sub-expressions
auto &condition_expr = expr.get_condition_expr ();
- condition_expr->accept_vis (*this);
if (condition_expr->is_marked_for_strip ())
rust_error_at (condition_expr->get_locus (),
"cannot strip expression in this position - outer "
// can't strip if block itself, but can strip sub-expressions
auto &if_block = expr.get_if_block ();
- if_block->accept_vis (*this);
if (if_block->is_marked_for_strip ())
rust_error_at (if_block->get_locus (),
"cannot strip block expression in this position - outer "
// can't strip else block itself, but can strip sub-expressions
auto &else_block = expr.get_else_block ();
- else_block->accept_vis (*this);
if (else_block->is_marked_for_strip ())
rust_error_at (else_block->get_locus (),
"cannot strip block expression in this position - outer "
"attributes not allowed");
}
+
void
CfgStrip::visit (AST::IfLetExpr &expr)
{
return;
}
+ AST::DefaultASTVisitor::visit (expr);
+
for (auto &pattern : expr.get_patterns ())
- {
- pattern->accept_vis (*this);
- if (pattern->is_marked_for_strip ())
- rust_error_at (pattern->get_locus (),
- "cannot strip pattern in this position");
- }
+ if (pattern->is_marked_for_strip ())
+ rust_error_at (pattern->get_locus (),
+ "cannot strip pattern in this position");
// can't strip value expr itself, but can strip sub-expressions
auto &value_expr = expr.get_value_expr ();
- value_expr->accept_vis (*this);
if (value_expr->is_marked_for_strip ())
rust_error_at (value_expr->get_locus (),
"cannot strip expression in this position - outer "
// can't strip if block itself, but can strip sub-expressions
auto &if_block = expr.get_if_block ();
- if_block->accept_vis (*this);
if (if_block->is_marked_for_strip ())
rust_error_at (if_block->get_locus (),
"cannot strip block expression in this position - outer "
return;
}
+ AST::DefaultASTVisitor::visit (expr);
+
for (auto &pattern : expr.get_patterns ())
- {
- pattern->accept_vis (*this);
- if (pattern->is_marked_for_strip ())
- rust_error_at (pattern->get_locus (),
- "cannot strip pattern in this position");
- }
+ if (pattern->is_marked_for_strip ())
+ rust_error_at (pattern->get_locus (),
+ "cannot strip pattern in this position");
// can't strip value expr itself, but can strip sub-expressions
auto &value_expr = expr.get_value_expr ();
- value_expr->accept_vis (*this);
if (value_expr->is_marked_for_strip ())
rust_error_at (value_expr->get_locus (),
"cannot strip expression in this position - outer "
// can't strip if block itself, but can strip sub-expressions
auto &if_block = expr.get_if_block ();
- if_block->accept_vis (*this);
if (if_block->is_marked_for_strip ())
rust_error_at (if_block->get_locus (),
"cannot strip block expression in this position - outer "
// can't strip else block itself, but can strip sub-expressions
auto &else_block = expr.get_else_block ();
- else_block->accept_vis (*this);
if (else_block->is_marked_for_strip ())
rust_error_at (else_block->get_locus (),
"cannot strip block expression in this position - outer "
return;
}
+ AST::DefaultASTVisitor::visit (expr);
+
// can't strip scrutinee expr itself, but can strip sub-expressions
auto &scrutinee_expr = expr.get_scrutinee_expr ();
- scrutinee_expr->accept_vis (*this);
if (scrutinee_expr->is_marked_for_strip ())
rust_error_at (scrutinee_expr->get_locus (),
"cannot strip expression in this position - outer "
}
for (auto &pattern : match_arm.get_patterns ())
- {
- pattern->accept_vis (*this);
- if (pattern->is_marked_for_strip ())
- rust_error_at (pattern->get_locus (),
- "cannot strip pattern in this position");
- }
+ if (pattern->is_marked_for_strip ())
+ rust_error_at (pattern->get_locus (),
+ "cannot strip pattern in this position");
/* assuming that guard expression cannot be stripped as
* strictly speaking you would have to strip the whole guard to
if (match_arm.has_match_arm_guard ())
{
auto &guard_expr = match_arm.get_guard_expr ();
- guard_expr->accept_vis (*this);
if (guard_expr->is_marked_for_strip ())
rust_error_at (guard_expr->get_locus (),
"cannot strip expression in this position - outer "
// strip sub-expressions from match cases
auto &case_expr = match_case.get_expr ();
- case_expr->accept_vis (*this);
if (case_expr->is_marked_for_strip ())
rust_error_at (case_expr->get_locus (),
"cannot strip expression in this position - outer "
++it;
}
}
+
void
CfgStrip::visit (AST::AwaitExpr &expr)
{
"cannot strip expression in this position - outer "
"attributes not allowed");
}
+
void
CfgStrip::visit (AST::AsyncBlockExpr &expr)
{
return;
}
+ AST::DefaultASTVisitor::visit (expr);
+
// can't strip block itself, but can strip sub-expressions
auto &block_expr = expr.get_block_expr ();
- block_expr->accept_vis (*this);
if (block_expr->is_marked_for_strip ())
rust_error_at (block_expr->get_locus (),
"cannot strip block expression in this position - outer "
{
// outer attributes don't actually do anything, so ignore them
- if (param.has_type_param_bounds ())
- {
- // don't strip directly, only components of bounds
- for (auto &bound : param.get_type_param_bounds ())
- bound->accept_vis (*this);
- }
+ AST::DefaultASTVisitor::visit (param);
- if (param.has_type ())
- {
- auto &type = param.get_type ();
- type->accept_vis (*this);
-
- if (type->is_marked_for_strip ())
- rust_error_at (type->get_locus (),
- "cannot strip type in this position");
- }
-}
-void
-CfgStrip::visit (AST::LifetimeWhereClauseItem &)
-{
- // shouldn't require
+ if (param.has_type () && param.get_type ()->is_marked_for_strip ())
+ rust_error_at (param.get_type ()->get_locus (),
+ "cannot strip type in this position");
}
+
void
CfgStrip::visit (AST::TypeBoundWhereClauseItem &item)
{
// for lifetimes shouldn't require
+ AST::DefaultASTVisitor::visit (item);
auto &type = item.get_type ();
- type->accept_vis (*this);
-
if (type->is_marked_for_strip ())
rust_error_at (type->get_locus (), "cannot strip type in this position");
-
- // don't strip directly, only components of bounds
- for (auto &bound : item.get_type_param_bounds ())
- bound->accept_vis (*this);
}
+
void
CfgStrip::visit (AST::Module &module)
{
// strip items if required
maybe_strip_pointer_allow_strip (module.get_items ());
}
+
void
CfgStrip::visit (AST::ExternCrate &extern_crate)
{
extern_crate.get_locus ());
}
}
-void
-CfgStrip::visit (AST::UseTreeGlob &)
-{
- // shouldn't require?
-}
-void
-CfgStrip::visit (AST::UseTreeList &)
-{
- // shouldn't require?
-}
-void
-CfgStrip::visit (AST::UseTreeRebind &)
-{
- // shouldn't require?
-}
+
void
CfgStrip::visit (AST::UseDeclaration &use_decl)
{
return;
}
}
+
void
CfgStrip::visit (AST::Function &function)
{
return;
}
- // just expand sub-stuff - can't actually strip generic params themselves
- for (auto ¶m : function.get_generic_params ())
- param->accept_vis (*this);
+ AST::DefaultASTVisitor::visit (function);
/* strip function parameters if required - this is specifically
* allowed by spec */
if (function.has_return_type ())
{
auto &return_type = function.get_return_type ();
- return_type->accept_vis (*this);
-
if (return_type->is_marked_for_strip ())
rust_error_at (return_type->get_locus (),
"cannot strip type in this position");
}
- if (function.has_where_clause ())
- maybe_strip_where_clause (function.get_where_clause ());
-
/* body should always exist - if error state, should have returned
* before now */
// can't strip block itself, but can strip sub-expressions
if (function.has_body ())
{
- auto &block_expr = function.get_definition ().value ();
- block_expr->accept_vis (*this);
- if (block_expr->is_marked_for_strip ())
- rust_error_at (block_expr->get_locus (),
+ auto &block_expr = function.get_definition ();
+ if (block_expr.value ()->is_marked_for_strip ())
+ rust_error_at (block_expr.value ()->get_locus (),
"cannot strip block expression in this position - outer "
"attributes not allowed");
}
return;
}
- // just expand sub-stuff - can't actually strip generic params themselves
- for (auto ¶m : type_alias.get_generic_params ())
- param->accept_vis (*this);
-
- if (type_alias.has_where_clause ())
- maybe_strip_where_clause (type_alias.get_where_clause ());
+ AST::DefaultASTVisitor::visit (type_alias);
auto &type = type_alias.get_type_aliased ();
- type->accept_vis (*this);
if (type->is_marked_for_strip ())
rust_error_at (type->get_locus (), "cannot strip type in this position");
}
+
void
CfgStrip::visit (AST::StructStruct &struct_item)
{
return;
}
- // just expand sub-stuff - can't actually strip generic params themselves
- for (auto ¶m : struct_item.get_generic_params ())
- param->accept_vis (*this);
-
- if (struct_item.has_where_clause ())
- maybe_strip_where_clause (struct_item.get_where_clause ());
+ AST::DefaultASTVisitor::visit (struct_item);
}
void
CfgStrip::visit (AST::TupleStruct &tuple_struct)
return;
}
- // just expand sub-stuff - can't actually strip generic params themselves
- for (auto ¶m : tuple_struct.get_generic_params ())
- param->accept_vis (*this);
+ AST::DefaultASTVisitor::visit (tuple_struct);
/* strip struct fields if required - this is presumably
* allowed by spec */
maybe_strip_tuple_fields (tuple_struct.get_fields ());
-
- if (tuple_struct.has_where_clause ())
- maybe_strip_where_clause (tuple_struct.get_where_clause ());
}
void
CfgStrip::visit (AST::EnumItem &item)
return;
}
}
+
void
CfgStrip::visit (AST::EnumItemTuple &item)
{
* allowed by spec */
maybe_strip_tuple_fields (item.get_tuple_fields ());
}
+
void
CfgStrip::visit (AST::EnumItemStruct &item)
{
* allowed by spec */
maybe_strip_struct_fields (item.get_struct_fields ());
}
+
void
CfgStrip::visit (AST::EnumItemDiscriminant &item)
{
return;
}
+ AST::DefaultASTVisitor::visit (item);
/* strip any internal sub-expressions - expression itself isn't
* allowed to have external attributes in this position so can't be
* stripped. */
auto &expr = item.get_expr ();
- expr->accept_vis (*this);
if (expr->is_marked_for_strip ())
rust_error_at (expr->get_locus (),
"cannot strip expression in this position - outer "
return;
}
- // just expand sub-stuff - can't actually strip generic params themselves
- for (auto ¶m : enum_item.get_generic_params ())
- param->accept_vis (*this);
-
- if (enum_item.has_where_clause ())
- maybe_strip_where_clause (enum_item.get_where_clause ());
+ AST::DefaultASTVisitor::visit (enum_item);
/* strip enum fields if required - this is presumably
* allowed by spec */
return;
}
- // just expand sub-stuff - can't actually strip generic params themselves
- for (auto ¶m : union_item.get_generic_params ())
- param->accept_vis (*this);
-
- if (union_item.has_where_clause ())
- maybe_strip_where_clause (union_item.get_where_clause ());
+ AST::DefaultASTVisitor::visit (union_item);
/* strip union fields if required - this is presumably
* allowed by spec */
return;
}
+ AST::DefaultASTVisitor::visit (const_item);
+
// strip any sub-types
auto &type = const_item.get_type ();
- type->accept_vis (*this);
-
if (type->is_marked_for_strip ())
rust_error_at (type->get_locus (), "cannot strip type in this position");
if (const_item.has_expr ())
{
auto &expr = const_item.get_expr ();
- expr->accept_vis (*this);
if (expr->is_marked_for_strip ())
rust_error_at (expr->get_locus (),
"cannot strip expression in this position - outer "
return;
}
+ AST::DefaultASTVisitor::visit (static_item);
+
// strip any sub-types
auto &type = static_item.get_type ();
- type->accept_vis (*this);
if (type->is_marked_for_strip ())
rust_error_at (type->get_locus (), "cannot strip type in this position");
* allowed to have external attributes in this position so can't be
* stripped. */
auto &expr = static_item.get_expr ();
- expr->accept_vis (*this);
if (expr->is_marked_for_strip ())
rust_error_at (expr->get_locus (),
"cannot strip expression in this position - outer "
maybe_strip_trait_function_decl (item.get_trait_function_decl ());
+ AST::DefaultASTVisitor::visit (item);
+
if (item.has_definition ())
{
/* strip any internal sub-expressions - expression itself isn't
* allowed to have external attributes in this position so can't be
* stripped. */
auto &block = item.get_definition ();
- block->accept_vis (*this);
if (block->is_marked_for_strip ())
rust_error_at (block->get_locus (),
"cannot strip block expression in this "
"position - outer attributes not allowed");
}
}
+
void
CfgStrip::visit (AST::TraitItemMethod &item)
{
maybe_strip_trait_method_decl (item.get_trait_method_decl ());
+ AST::DefaultASTVisitor::visit (item);
+
if (item.has_definition ())
{
/* strip any internal sub-expressions - expression itself isn't
* allowed to have external attributes in this position so can't be
* stripped. */
auto &block = item.get_definition ();
- block->accept_vis (*this);
if (block->is_marked_for_strip ())
rust_error_at (block->get_locus (),
"cannot strip block expression in this "
"position - outer attributes not allowed");
}
}
+
void
CfgStrip::visit (AST::TraitItemConst &item)
{
return;
}
+ AST::DefaultASTVisitor::visit (item);
+
// strip any sub-types
auto &type = item.get_type ();
- type->accept_vis (*this);
if (type->is_marked_for_strip ())
rust_error_at (type->get_locus (), "cannot strip type in this position");
if (item.has_expression ())
{
auto &expr = item.get_expr ();
- expr->accept_vis (*this);
if (expr->is_marked_for_strip ())
rust_error_at (expr->get_locus (),
"cannot strip expression in this position - outer "
"attributes not allowed");
}
}
+
void
CfgStrip::visit (AST::TraitItemType &item)
{
return;
}
- if (item.has_type_param_bounds ())
- {
- // don't strip directly, only components of bounds
- for (auto &bound : item.get_type_param_bounds ())
- bound->accept_vis (*this);
- }
+ AST::DefaultASTVisitor::visit (item);
}
+
void
CfgStrip::visit (AST::Trait &trait)
{
return;
}
- // just expand sub-stuff - can't actually strip generic params themselves
- for (auto ¶m : trait.get_generic_params ())
- param->accept_vis (*this);
-
- if (trait.has_type_param_bounds ())
- {
- // don't strip directly, only components of bounds
- for (auto &bound : trait.get_type_param_bounds ())
- bound->accept_vis (*this);
- }
-
- if (trait.has_where_clause ())
- maybe_strip_where_clause (trait.get_where_clause ());
+ AST::DefaultASTVisitor::visit (trait);
maybe_strip_pointer_allow_strip (trait.get_trait_items ());
}
+
void
CfgStrip::visit (AST::InherentImpl &impl)
{
return;
}
- // just expand sub-stuff - can't actually strip generic params themselves
- for (auto ¶m : impl.get_generic_params ())
- param->accept_vis (*this);
+ AST::DefaultASTVisitor::visit (impl);
auto &type = impl.get_type ();
- type->accept_vis (*this);
if (type->is_marked_for_strip ())
rust_error_at (type->get_locus (), "cannot strip type in this position");
- if (impl.has_where_clause ())
- maybe_strip_where_clause (impl.get_where_clause ());
-
maybe_strip_pointer_allow_strip (impl.get_impl_items ());
}
+
void
CfgStrip::visit (AST::TraitImpl &impl)
{
return;
}
- // just expand sub-stuff - can't actually strip generic params themselves
- for (auto ¶m : impl.get_generic_params ())
- param->accept_vis (*this);
+ AST::DefaultASTVisitor::visit (impl);
auto &type = impl.get_type ();
- type->accept_vis (*this);
-
if (type->is_marked_for_strip ())
rust_error_at (type->get_locus (), "cannot strip type in this position");
rust_error_at (trait_path.get_locus (),
"cannot strip typepath in this position");
- if (impl.has_where_clause ())
- maybe_strip_where_clause (impl.get_where_clause ());
-
maybe_strip_pointer_allow_strip (impl.get_impl_items ());
}
return;
}
- auto &type = item.get_type ();
- type->accept_vis (*this);
+ AST::DefaultASTVisitor::visit (item);
+ auto &type = item.get_type ();
if (type->is_marked_for_strip ())
rust_error_at (type->get_locus (), "cannot strip type in this position");
}
return;
}
- // just expand sub-stuff - can't actually strip generic params themselves
- for (auto ¶m : item.get_generic_params ())
- param->accept_vis (*this);
+ AST::DefaultASTVisitor::visit (item);
/* strip function parameters if required - this is specifically
* allowed by spec */
if (!param.is_variadic ())
{
auto &type = param.get_type ();
- param.get_type ()->accept_vis (*this);
-
if (type->is_marked_for_strip ())
rust_error_at (type->get_locus (),
"cannot strip type in this position");
if (item.has_return_type ())
{
auto &return_type = item.get_return_type ();
- return_type->accept_vis (*this);
if (return_type->is_marked_for_strip ())
rust_error_at (return_type->get_locus (),
"cannot strip type in this position");
}
-
- if (item.has_where_clause ())
- maybe_strip_where_clause (item.get_where_clause ());
}
void
maybe_strip_pointer_allow_strip (block.get_extern_items ());
}
-// I don't think it would be possible to strip macros without expansion
-void
-CfgStrip::visit (AST::MacroMatchFragment &)
-{}
-void
-CfgStrip::visit (AST::MacroMatchRepetition &)
-{}
-void
-CfgStrip::visit (AST::MacroMatcher &)
-{}
void
CfgStrip::visit (AST::MacroRulesDefinition &rules_def)
{
}
}
-void
-CfgStrip::visit (AST::MetaItemPath &)
-{}
-void
-CfgStrip::visit (AST::MetaItemSeq &)
-{}
-void
-CfgStrip::visit (AST::MetaWord &)
-{}
-void
-CfgStrip::visit (AST::MetaNameValueStr &)
-{}
-void
-CfgStrip::visit (AST::MetaListPaths &)
-{}
-void
-CfgStrip::visit (AST::MetaListNameValueStr &)
-{}
-
-void
-CfgStrip::visit (AST::LiteralPattern &)
-{
- // not possible
-}
void
CfgStrip::visit (AST::IdentifierPattern &pattern)
{
if (!pattern.has_pattern_to_bind ())
return;
+ AST::DefaultASTVisitor::visit (pattern);
+
auto &sub_pattern = pattern.get_pattern_to_bind ();
- sub_pattern->accept_vis (*this);
if (sub_pattern->is_marked_for_strip ())
rust_error_at (sub_pattern->get_locus (),
"cannot strip pattern in this position");
}
-void
-CfgStrip::visit (AST::WildcardPattern &)
-{
- // not possible
-}
-void
-CfgStrip::visit (AST::RestPattern &)
-{
- // not possible
-}
-void
-CfgStrip::visit (AST::RangePatternBoundLiteral &)
-{
- // not possible
-}
+
void
CfgStrip::visit (AST::RangePatternBoundPath &bound)
{
if (path.is_marked_for_strip ())
rust_error_at (path.get_locus (), "cannot strip path in this position");
}
+
void
CfgStrip::visit (AST::RangePatternBoundQualPath &bound)
{
if (path.is_marked_for_strip ())
rust_error_at (path.get_locus (), "cannot strip path in this position");
}
-void
-CfgStrip::visit (AST::RangePattern &pattern)
-{
- // should have no capability to strip lower or upper bounds, only expand
- pattern.get_lower_bound ()->accept_vis (*this);
- pattern.get_upper_bound ()->accept_vis (*this);
-}
+
void
CfgStrip::visit (AST::ReferencePattern &pattern)
{
+ AST::DefaultASTVisitor::visit (pattern);
+
auto &sub_pattern = pattern.get_referenced_pattern ();
- sub_pattern->accept_vis (*this);
if (sub_pattern->is_marked_for_strip ())
rust_error_at (sub_pattern->get_locus (),
"cannot strip pattern in this position");
return;
}
+ AST::DefaultASTVisitor::visit (field);
+
// strip sub-patterns (can't strip top-level pattern)
auto &sub_pattern = field.get_index_pattern ();
- sub_pattern->accept_vis (*this);
if (sub_pattern->is_marked_for_strip ())
rust_error_at (sub_pattern->get_locus (),
"cannot strip pattern in this position");
}
+
void
CfgStrip::visit (AST::StructPatternFieldIdentPat &field)
{
return;
}
+ AST::DefaultASTVisitor::visit (field);
// strip sub-patterns (can't strip top-level pattern)
auto &sub_pattern = field.get_ident_pattern ();
- sub_pattern->accept_vis (*this);
if (sub_pattern->is_marked_for_strip ())
rust_error_at (sub_pattern->get_locus (),
"cannot strip pattern in this position");
return;
}
}
+
void
CfgStrip::visit (AST::StructPattern &pattern)
{
elems.strip_etc ();
}
}
+
void
CfgStrip::visit (AST::TupleStructItemsNoRange &tuple_items)
{
+ AST::DefaultASTVisitor::visit (tuple_items);
// can't strip individual patterns, only sub-patterns
for (auto &pattern : tuple_items.get_patterns ())
{
- pattern->accept_vis (*this);
-
if (pattern->is_marked_for_strip ())
rust_error_at (pattern->get_locus (),
"cannot strip pattern in this position");
void
CfgStrip::visit (AST::TupleStructItemsRange &tuple_items)
{
+ AST::DefaultASTVisitor::visit (tuple_items);
// can't strip individual patterns, only sub-patterns
for (auto &lower_pattern : tuple_items.get_lower_patterns ())
{
- lower_pattern->accept_vis (*this);
-
if (lower_pattern->is_marked_for_strip ())
rust_error_at (lower_pattern->get_locus (),
"cannot strip pattern in this position");
}
for (auto &upper_pattern : tuple_items.get_upper_patterns ())
{
- upper_pattern->accept_vis (*this);
-
if (upper_pattern->is_marked_for_strip ())
rust_error_at (upper_pattern->get_locus (),
"cannot strip pattern in this position");
// TODO: quit stripping now? or keep going?
}
}
+
void
CfgStrip::visit (AST::TupleStructPattern &pattern)
{
if (path.is_marked_for_strip ())
rust_error_at (path.get_locus (), "cannot strip path in this position");
- if (pattern.has_items ())
- pattern.get_items ()->accept_vis (*this);
+ AST::DefaultASTVisitor::visit (pattern);
}
+
void
CfgStrip::visit (AST::TuplePatternItemsMultiple &tuple_items)
{
+ AST::DefaultASTVisitor::visit (tuple_items);
+
// can't strip individual patterns, only sub-patterns
for (auto &pattern : tuple_items.get_patterns ())
{
- pattern->accept_vis (*this);
-
if (pattern->is_marked_for_strip ())
rust_error_at (pattern->get_locus (),
"cannot strip pattern in this position");
// TODO: quit stripping now? or keep going?
}
}
+
void
CfgStrip::visit (AST::TuplePatternItemsRanged &tuple_items)
{
+ AST::DefaultASTVisitor::visit (tuple_items);
+
// can't strip individual patterns, only sub-patterns
for (auto &lower_pattern : tuple_items.get_lower_patterns ())
{
- lower_pattern->accept_vis (*this);
-
if (lower_pattern->is_marked_for_strip ())
rust_error_at (lower_pattern->get_locus (),
"cannot strip pattern in this position");
}
for (auto &upper_pattern : tuple_items.get_upper_patterns ())
{
- upper_pattern->accept_vis (*this);
-
if (upper_pattern->is_marked_for_strip ())
rust_error_at (upper_pattern->get_locus (),
"cannot strip pattern in this position");
// TODO: quit stripping now? or keep going?
}
}
-void
-CfgStrip::visit (AST::TuplePattern &pattern)
-{
- if (pattern.has_tuple_pattern_items ())
- pattern.get_items ()->accept_vis (*this);
-}
+
void
CfgStrip::visit (AST::GroupedPattern &pattern)
{
+ AST::DefaultASTVisitor::visit (pattern);
// can't strip inner pattern, only sub-patterns
auto &pattern_in_parens = pattern.get_pattern_in_parens ();
- pattern_in_parens->accept_vis (*this);
-
if (pattern_in_parens->is_marked_for_strip ())
rust_error_at (pattern_in_parens->get_locus (),
"cannot strip pattern in this position");
}
+
void
CfgStrip::visit (AST::SlicePattern &pattern)
{
+ AST::DefaultASTVisitor::visit (pattern);
// can't strip individual patterns, only sub-patterns
for (auto &item : pattern.get_items ())
{
- item->accept_vis (*this);
-
if (item->is_marked_for_strip ())
rust_error_at (item->get_locus (),
"cannot strip pattern in this position");
// TODO: quit stripping now? or keep going?
}
}
+
void
CfgStrip::visit (AST::AltPattern &pattern)
{
+ AST::DefaultASTVisitor::visit (pattern);
// can't strip individual patterns, only sub-patterns
for (auto &alt : pattern.get_alts ())
{
- alt->accept_vis (*this);
-
if (alt->is_marked_for_strip ())
rust_error_at (alt->get_locus (),
"cannot strip pattern in this position");
}
}
-void
-CfgStrip::visit (AST::EmptyStmt &)
-{
- // assuming no outer attributes, so nothing can happen
-}
void
CfgStrip::visit (AST::LetStmt &stmt)
{
return;
}
+ AST::DefaultASTVisitor::visit (stmt);
// can't strip pattern, but call for sub-patterns
auto &pattern = stmt.get_pattern ();
- pattern->accept_vis (*this);
if (pattern->is_marked_for_strip ())
rust_error_at (pattern->get_locus (),
"cannot strip pattern in this position");
if (stmt.has_type ())
{
auto &type = stmt.get_type ();
- type->accept_vis (*this);
if (type->is_marked_for_strip ())
rust_error_at (type->get_locus (),
if (stmt.has_init_expr ())
{
auto &init_expr = stmt.get_init_expr ();
- init_expr->accept_vis (*this);
if (init_expr->is_marked_for_strip ())
rust_error_at (init_expr->get_locus (),
"attributes not allowed");
}
}
+
void
CfgStrip::visit (AST::ExprStmt &stmt)
{
if (stmt.is_marked_for_strip ())
return;
+ AST::DefaultASTVisitor::visit (stmt);
// strip if expr is to be stripped
auto &expr = stmt.get_expr ();
- expr->accept_vis (*this);
if (expr->is_marked_for_strip ())
{
stmt.mark_for_strip ();
rust_error_at (path.get_locus (),
"cannot strip type path in this position");
}
-void
-CfgStrip::visit (AST::ImplTraitType &type)
-{
- // don't strip directly, only components of bounds
- for (auto &bound : type.get_type_param_bounds ())
- bound->accept_vis (*this);
-}
-void
-CfgStrip::visit (AST::TraitObjectType &type)
-{
- // don't strip directly, only components of bounds
- for (auto &bound : type.get_type_param_bounds ())
- bound->accept_vis (*this);
-}
+
void
CfgStrip::visit (AST::ParenthesisedType &type)
{
+ AST::DefaultASTVisitor::visit (type);
// expand but don't strip inner type
auto &inner_type = type.get_type_in_parens ();
- inner_type->accept_vis (*this);
if (inner_type->is_marked_for_strip ())
rust_error_at (inner_type->get_locus (),
"cannot strip type in this position");
}
-void
-CfgStrip::visit (AST::ImplTraitTypeOneBound &type)
-{
- // no stripping possible
- visit (type.get_trait_bound ());
-}
-void
-CfgStrip::visit (AST::TraitObjectTypeOneBound &type)
-{
- // no stripping possible
- visit (type.get_trait_bound ());
-}
+
void
CfgStrip::visit (AST::TupleType &type)
{
+ AST::DefaultASTVisitor::visit (type);
// TODO: assuming that types can't be stripped as types don't have outer
// attributes
for (auto &elem_type : type.get_elems ())
{
- elem_type->accept_vis (*this);
if (elem_type->is_marked_for_strip ())
rust_error_at (elem_type->get_locus (),
"cannot strip type in this position");
}
}
-void
-CfgStrip::visit (AST::NeverType &)
-{
- // no stripping possible
-}
+
void
CfgStrip::visit (AST::RawPointerType &type)
{
+ AST::DefaultASTVisitor::visit (type);
// expand but don't strip type pointed to
auto &pointed_type = type.get_type_pointed_to ();
- pointed_type->accept_vis (*this);
if (pointed_type->is_marked_for_strip ())
rust_error_at (pointed_type->get_locus (),
"cannot strip type in this position");
}
+
void
CfgStrip::visit (AST::ReferenceType &type)
{
+ AST::DefaultASTVisitor::visit (type);
// expand but don't strip type referenced
auto &referenced_type = type.get_type_referenced ();
- referenced_type->accept_vis (*this);
if (referenced_type->is_marked_for_strip ())
rust_error_at (referenced_type->get_locus (),
"cannot strip type in this position");
}
+
void
CfgStrip::visit (AST::ArrayType &type)
{
+ AST::DefaultASTVisitor::visit (type);
// expand but don't strip type referenced
auto &base_type = type.get_elem_type ();
- base_type->accept_vis (*this);
if (base_type->is_marked_for_strip ())
rust_error_at (base_type->get_locus (),
"cannot strip type in this position");
// same for expression
auto &size_expr = type.get_size_expr ();
- size_expr->accept_vis (*this);
if (size_expr->is_marked_for_strip ())
rust_error_at (size_expr->get_locus (),
"cannot strip expression in this position");
void
CfgStrip::visit (AST::SliceType &type)
{
+ AST::DefaultASTVisitor::visit (type);
// expand but don't strip elem type
auto &elem_type = type.get_elem_type ();
- elem_type->accept_vis (*this);
if (elem_type->is_marked_for_strip ())
rust_error_at (elem_type->get_locus (),
"cannot strip type in this position");
}
-void
-CfgStrip::visit (AST::InferredType &)
-{
- // none possible
-}
+
void
CfgStrip::visit (AST::BareFunctionType &type)
{
// seem to be no generics
+ AST::DefaultASTVisitor::visit (type);
// presumably function params can be stripped
auto ¶ms = type.get_function_params ();
}
auto &type = param.get_type ();
- type->accept_vis (*this);
-
if (type->is_marked_for_strip ())
rust_error_at (type->get_locus (),
"cannot strip type in this position");
// In that case, we need to handle AST::TypeNoBounds on top of just
// AST::Types
auto &return_type = type.get_return_type ();
- return_type->accept_vis (*this);
if (return_type->is_marked_for_strip ())
rust_error_at (return_type->get_locus (),
"cannot strip type in this position");
// no where clause, apparently
}
-void
-CfgStrip::visit (AST::VariadicParam &type)
-{}
-
-void
-CfgStrip::visit (AST::FunctionParam &type)
-{}
-
void
CfgStrip::visit (AST::SelfParam ¶m)
{
+ AST::DefaultASTVisitor::visit (param);
+
if (param.has_type ())
{
auto &type = param.get_type ();
- type->accept_vis (*this);
-
if (type->is_marked_for_strip ())
rust_error_at (type->get_locus (),
"cannot strip type in this position");