Branch data Line data Source code
1 : : // Copyright (C) 2020-2024 Free Software Foundation, Inc.
2 : :
3 : : // This file is part of GCC.
4 : :
5 : : // GCC is free software; you can redistribute it and/or modify it under
6 : : // the terms of the GNU General Public License as published by the Free
7 : : // Software Foundation; either version 3, or (at your option) any later
8 : : // version.
9 : :
10 : : // GCC is distributed in the hope that it will be useful, but WITHOUT ANY
11 : : // WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 : : // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 : : // for more details.
14 : :
15 : : // You should have received a copy of the GNU General Public License
16 : : // along with GCC; see the file COPYING3. If not see
17 : : // <http://www.gnu.org/licenses/>.
18 : : #ifndef RUST_CFG_STRIP_H
19 : : #define RUST_CFG_STRIP_H
20 : :
21 : : #include "rust-ast-visitor.h"
22 : : #include "rust-ast.h"
23 : : #include "rust-item.h"
24 : :
25 : : namespace Rust {
26 : : // Visitor used to maybe_strip attributes.
27 : : class CfgStrip : public AST::DefaultASTVisitor
28 : : {
29 : : private:
30 : : public:
31 : : using DefaultASTVisitor::visit;
32 : :
33 : 5319 : CfgStrip () {}
34 : :
35 : : /* Run the AttrVisitor on an entire crate */
36 : : void go (AST::Crate &crate);
37 : :
38 : : void maybe_strip_struct_fields (std::vector<AST::StructField> &fields);
39 : : void maybe_strip_tuple_fields (std::vector<AST::TupleField> &fields);
40 : : void maybe_strip_function_params (
41 : : std::vector<std::unique_ptr<AST::Param>> ¶ms);
42 : : void maybe_strip_generic_args (AST::GenericArgs &args);
43 : : void maybe_strip_qualified_path_type (AST::QualifiedPathType &path_type);
44 : : void maybe_strip_closure_params (std::vector<AST::ClosureParam> ¶ms);
45 : : void maybe_strip_self_param (AST::SelfParam &self_param);
46 : : void maybe_strip_where_clause (AST::WhereClause &where_clause);
47 : :
48 : : /**
49 : : * maybe_strip a set of values, erasing them if they are marked for strip.
50 : : *
51 : : * @param values Iterable reference over values to replace or erase
52 : : */
53 : 60177 : template <typename T> void maybe_strip_pointer_allow_strip (T &values)
54 : : {
55 : 127528 : for (auto it = values.begin (); it != values.end ();)
56 : : {
57 : 67351 : auto &value = *it;
58 : :
59 : : // mark for stripping if required
60 : 67351 : value->accept_vis (*this);
61 : 67351 : if (value->is_marked_for_strip ())
62 : 25 : it = values.erase (it);
63 : : else
64 : 67326 : ++it;
65 : : }
66 : 60177 : }
67 : :
68 : : void visit (AST::Crate &crate) override;
69 : : void visit (AST::IdentifierExpr &ident_expr) override;
70 : :
71 : : void visit (AST::MacroInvocation ¯o_invoc) override;
72 : :
73 : : void visit (AST::PathInExpression &path) override;
74 : : void visit (AST::TypePathSegmentGeneric &segment) override;
75 : : void visit (AST::TypePathSegmentFunction &segment) override;
76 : : void visit (AST::QualifiedPathInExpression &path) override;
77 : : void visit (AST::QualifiedPathInType &path) override;
78 : :
79 : : void visit (AST::LiteralExpr &expr) override;
80 : : void visit (AST::BorrowExpr &expr) override;
81 : : void visit (AST::DereferenceExpr &expr) override;
82 : : void visit (AST::ErrorPropagationExpr &expr) override;
83 : : void visit (AST::NegationExpr &expr) override;
84 : : void visit (AST::ArithmeticOrLogicalExpr &expr) override;
85 : : void visit (AST::ComparisonExpr &expr) override;
86 : : void visit (AST::LazyBooleanExpr &expr) override;
87 : : void visit (AST::TypeCastExpr &expr) override;
88 : : void visit (AST::AssignmentExpr &expr) override;
89 : : void visit (AST::CompoundAssignmentExpr &expr) override;
90 : : void visit (AST::GroupedExpr &expr) override;
91 : : void visit (AST::ArrayElemsValues &elems) override;
92 : : void visit (AST::ArrayElemsCopied &elems) override;
93 : : void visit (AST::ArrayExpr &expr) override;
94 : : void visit (AST::ArrayIndexExpr &expr) override;
95 : : void visit (AST::TupleExpr &expr) override;
96 : : void visit (AST::TupleIndexExpr &expr) override;
97 : : void visit (AST::StructExprStruct &expr) override;
98 : : void visit (AST::StructExprFieldIdentifierValue &field) override;
99 : :
100 : : void visit (AST::StructExprFieldIndexValue &field) override;
101 : : void visit (AST::StructExprStructFields &expr) override;
102 : : void visit (AST::StructExprStructBase &expr) override;
103 : : void visit (AST::CallExpr &expr) override;
104 : : void visit (AST::MethodCallExpr &expr) override;
105 : : void visit (AST::FieldAccessExpr &expr) override;
106 : : void visit (AST::ClosureExprInner &expr) override;
107 : :
108 : : void visit (AST::BlockExpr &expr) override;
109 : :
110 : : void visit (AST::ClosureExprInnerTyped &expr) override;
111 : : void visit (AST::ContinueExpr &expr) override;
112 : : void visit (AST::BreakExpr &expr) override;
113 : : void visit (AST::RangeFromToExpr &expr) override;
114 : : void visit (AST::RangeFromExpr &expr) override;
115 : : void visit (AST::RangeToExpr &expr) override;
116 : : void visit (AST::RangeFromToInclExpr &expr) override;
117 : : void visit (AST::RangeToInclExpr &expr) override;
118 : : void visit (AST::ReturnExpr &expr) override;
119 : : void visit (AST::UnsafeBlockExpr &expr) override;
120 : : void visit (AST::LoopExpr &expr) override;
121 : : void visit (AST::WhileLoopExpr &expr) override;
122 : : void visit (AST::WhileLetLoopExpr &expr) override;
123 : : void visit (AST::ForLoopExpr &expr) override;
124 : : void visit (AST::IfExpr &expr) override;
125 : : void visit (AST::IfExprConseqElse &expr) override;
126 : : void visit (AST::IfLetExpr &expr) override;
127 : : void visit (AST::IfLetExprConseqElse &expr) override;
128 : : void visit (AST::MatchExpr &expr) override;
129 : : void visit (AST::AwaitExpr &expr) override;
130 : : void visit (AST::AsyncBlockExpr &expr) override;
131 : : void visit (AST::TypeParam ¶m) override;
132 : : void visit (AST::TypeBoundWhereClauseItem &item) override;
133 : : void visit (AST::Module &module) override;
134 : : void visit (AST::ExternCrate &crate) override;
135 : : void visit (AST::UseDeclaration &use_decl) override;
136 : : void visit (AST::Function &function) override;
137 : : void visit (AST::TypeAlias &type_alias) override;
138 : : void visit (AST::StructStruct &struct_item) override;
139 : : void visit (AST::TupleStruct &tuple_struct) override;
140 : : void visit (AST::EnumItem &item) override;
141 : : void visit (AST::EnumItemTuple &item) override;
142 : : void visit (AST::EnumItemStruct &item) override;
143 : : void visit (AST::EnumItemDiscriminant &item) override;
144 : : void visit (AST::Enum &enum_item) override;
145 : : void visit (AST::Union &union_item) override;
146 : : void visit (AST::ConstantItem &const_item) override;
147 : : void visit (AST::StaticItem &static_item) override;
148 : : void visit (AST::TraitItemConst &item) override;
149 : : void visit (AST::TraitItemType &item) override;
150 : : void visit (AST::Trait &trait) override;
151 : : void visit (AST::InherentImpl &impl) override;
152 : : void visit (AST::TraitImpl &impl) override;
153 : : void visit (AST::ExternalTypeItem &item) override;
154 : : void visit (AST::ExternalStaticItem &item) override;
155 : : void visit (AST::ExternBlock &block) override;
156 : :
157 : : // I don't think it would be possible to strip macros without expansion
158 : : void visit (AST::MacroRulesDefinition &rules_def) override;
159 : : void visit (AST::IdentifierPattern &pattern) override;
160 : : void visit (AST::RangePatternBoundPath &bound) override;
161 : : void visit (AST::RangePatternBoundQualPath &bound) override;
162 : : void visit (AST::ReferencePattern &pattern) override;
163 : : void visit (AST::StructPatternFieldTuplePat &field) override;
164 : : void visit (AST::StructPatternFieldIdentPat &field) override;
165 : : void visit (AST::StructPatternFieldIdent &field) override;
166 : : void visit (AST::StructPattern &pattern) override;
167 : : void visit (AST::TupleStructItemsNoRange &tuple_items) override;
168 : : void visit (AST::TupleStructItemsRange &tuple_items) override;
169 : : void visit (AST::TupleStructPattern &pattern) override;
170 : : void visit (AST::TuplePatternItemsMultiple &tuple_items) override;
171 : : void visit (AST::TuplePatternItemsRanged &tuple_items) override;
172 : : void visit (AST::GroupedPattern &pattern) override;
173 : : void visit (AST::SlicePattern &pattern) override;
174 : : void visit (AST::AltPattern &pattern) override;
175 : :
176 : : void visit (AST::LetStmt &stmt) override;
177 : : void visit (AST::ExprStmt &stmt) override;
178 : :
179 : : void visit (AST::TraitBound &bound) override;
180 : : void visit (AST::ParenthesisedType &type) override;
181 : : void visit (AST::TupleType &type) override;
182 : : void visit (AST::RawPointerType &type) override;
183 : : void visit (AST::ReferenceType &type) override;
184 : : void visit (AST::ArrayType &type) override;
185 : : void visit (AST::SliceType &type) override;
186 : : void visit (AST::BareFunctionType &type) override;
187 : : void visit (AST::SelfParam &type) override;
188 : :
189 : : template <typename T> void visit (T &item)
190 : : {
191 : : DefaultASTVisitor::visit (item);
192 : : }
193 : : };
194 : : } // namespace Rust
195 : :
196 : : #endif // RUST_CFG_STRIP_Hs
|