Branch data Line data Source code
1 : : // Copyright (C) 2020-2025 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 : :
19 : : #ifndef RUST_AST_RESOLVE_BASE_H
20 : : #define RUST_AST_RESOLVE_BASE_H
21 : :
22 : : #include "rust-ast-visitor.h"
23 : : #include "rust-ast.h"
24 : : #include "rust-name-resolver.h"
25 : : #include "rust-diagnostics.h"
26 : : #include "rust-location.h"
27 : :
28 : : namespace Rust {
29 : : namespace Resolver {
30 : : inline void
31 : 12 : redefined_error (const rich_location &loc)
32 : : {
33 : 12 : rust_error_at (loc, "redefined multiple times");
34 : : }
35 : :
36 : : class ResolverBase : public AST::ASTVisitor
37 : : {
38 : : public:
39 : 143861 : virtual ~ResolverBase () {}
40 : :
41 : : void visit (AST::Token &);
42 : : void visit (AST::DelimTokenTree &);
43 : : void visit (AST::AttrInputMetaItemContainer &);
44 : : void visit (AST::IdentifierExpr &);
45 : : void visit (AST::Lifetime &);
46 : : void visit (AST::LifetimeParam &);
47 : : void visit (AST::ConstGenericParam &);
48 : : void visit (AST::PathInExpression &);
49 : : void visit (AST::TypePathSegment &);
50 : : void visit (AST::TypePathSegmentGeneric &);
51 : : void visit (AST::TypePathSegmentFunction &);
52 : : void visit (AST::TypePath &);
53 : : void visit (AST::QualifiedPathInExpression &);
54 : : void visit (AST::QualifiedPathInType &);
55 : : void visit (AST::LiteralExpr &);
56 : : void visit (AST::AttrInputLiteral &);
57 : : void visit (AST::AttrInputMacro &);
58 : : void visit (AST::MetaItemLitExpr &);
59 : : void visit (AST::MetaItemPathLit &);
60 : : void visit (AST::BorrowExpr &);
61 : : void visit (AST::DereferenceExpr &);
62 : : void visit (AST::ErrorPropagationExpr &);
63 : : void visit (AST::NegationExpr &);
64 : : void visit (AST::ArithmeticOrLogicalExpr &);
65 : : void visit (AST::ComparisonExpr &);
66 : : void visit (AST::LazyBooleanExpr &);
67 : : void visit (AST::TypeCastExpr &);
68 : : void visit (AST::AssignmentExpr &);
69 : : void visit (AST::CompoundAssignmentExpr &);
70 : : void visit (AST::GroupedExpr &);
71 : : void visit (AST::ArrayElemsValues &);
72 : : void visit (AST::ArrayElemsCopied &);
73 : : void visit (AST::ArrayExpr &);
74 : : void visit (AST::ArrayIndexExpr &);
75 : : void visit (AST::TupleExpr &);
76 : : void visit (AST::TupleIndexExpr &);
77 : : void visit (AST::StructExprStruct &);
78 : : void visit (AST::StructExprFieldIdentifier &);
79 : : void visit (AST::StructExprFieldIdentifierValue &);
80 : : void visit (AST::StructExprFieldIndexValue &);
81 : : void visit (AST::StructExprStructFields &);
82 : : void visit (AST::StructExprStructBase &);
83 : : void visit (AST::CallExpr &);
84 : : void visit (AST::MethodCallExpr &);
85 : : void visit (AST::FieldAccessExpr &);
86 : : void visit (AST::ClosureExprInner &);
87 : : void visit (AST::BlockExpr &);
88 : : void visit (AST::ClosureExprInnerTyped &);
89 : : void visit (AST::ContinueExpr &);
90 : : void visit (AST::BreakExpr &);
91 : : void visit (AST::RangeFromToExpr &);
92 : : void visit (AST::RangeFromExpr &);
93 : : void visit (AST::RangeToExpr &);
94 : : void visit (AST::RangeFullExpr &);
95 : : void visit (AST::RangeFromToInclExpr &);
96 : : void visit (AST::RangeToInclExpr &);
97 : : void visit (AST::BoxExpr &);
98 : : void visit (AST::ReturnExpr &);
99 : : void visit (AST::UnsafeBlockExpr &);
100 : : void visit (AST::LoopExpr &);
101 : : void visit (AST::WhileLoopExpr &);
102 : : void visit (AST::WhileLetLoopExpr &);
103 : : void visit (AST::ForLoopExpr &);
104 : : void visit (AST::IfExpr &);
105 : : void visit (AST::IfExprConseqElse &);
106 : : void visit (AST::IfLetExpr &);
107 : : void visit (AST::IfLetExprConseqElse &);
108 : :
109 : : void visit (AST::MatchExpr &);
110 : : void visit (AST::AwaitExpr &);
111 : : void visit (AST::AsyncBlockExpr &);
112 : : void visit (AST::InlineAsm &);
113 : : void visit (AST::LlvmInlineAsm &);
114 : :
115 : : void visit (AST::TypeParam &);
116 : :
117 : : void visit (AST::LifetimeWhereClauseItem &);
118 : : void visit (AST::TypeBoundWhereClauseItem &);
119 : : void visit (AST::Module &);
120 : : void visit (AST::ExternCrate &);
121 : :
122 : : void visit (AST::UseTreeGlob &);
123 : : void visit (AST::UseTreeList &);
124 : : void visit (AST::UseTreeRebind &);
125 : : void visit (AST::UseDeclaration &);
126 : : void visit (AST::Function &);
127 : : void visit (AST::TypeAlias &);
128 : : void visit (AST::StructStruct &);
129 : : void visit (AST::TupleStruct &);
130 : : void visit (AST::EnumItem &);
131 : : void visit (AST::EnumItemTuple &);
132 : : void visit (AST::EnumItemStruct &);
133 : : void visit (AST::EnumItemDiscriminant &);
134 : : void visit (AST::Enum &);
135 : : void visit (AST::Union &);
136 : : void visit (AST::ConstantItem &);
137 : : void visit (AST::StaticItem &);
138 : : void visit (AST::TraitItemConst &);
139 : : void visit (AST::TraitItemType &);
140 : : void visit (AST::Trait &);
141 : : void visit (AST::InherentImpl &);
142 : : void visit (AST::TraitImpl &);
143 : :
144 : : void visit (AST::ExternalTypeItem &);
145 : : void visit (AST::ExternalStaticItem &);
146 : : void visit (AST::ExternBlock &);
147 : :
148 : : void visit (AST::MacroMatchFragment &);
149 : : void visit (AST::MacroMatchRepetition &);
150 : : void visit (AST::MacroMatcher &);
151 : : void visit (AST::MacroRulesDefinition &);
152 : : void visit (AST::MacroInvocation &);
153 : : void visit (AST::MetaItemPath &);
154 : : void visit (AST::MetaItemSeq &);
155 : : void visit (AST::MetaWord &);
156 : : void visit (AST::MetaNameValueStr &);
157 : : void visit (AST::MetaListPaths &);
158 : : void visit (AST::MetaListNameValueStr &);
159 : :
160 : : void visit (AST::LiteralPattern &);
161 : : void visit (AST::IdentifierPattern &);
162 : : void visit (AST::WildcardPattern &);
163 : : void visit (AST::RestPattern &);
164 : :
165 : : void visit (AST::RangePatternBoundLiteral &);
166 : : void visit (AST::RangePatternBoundPath &);
167 : : void visit (AST::RangePatternBoundQualPath &);
168 : : void visit (AST::RangePattern &);
169 : : void visit (AST::ReferencePattern &);
170 : :
171 : : void visit (AST::StructPatternFieldTuplePat &);
172 : : void visit (AST::StructPatternFieldIdentPat &);
173 : : void visit (AST::StructPatternFieldIdent &);
174 : : void visit (AST::StructPattern &);
175 : :
176 : : void visit (AST::TupleStructItemsNoRange &);
177 : : void visit (AST::TupleStructItemsRange &);
178 : : void visit (AST::TupleStructPattern &);
179 : :
180 : : void visit (AST::TuplePatternItemsMultiple &);
181 : : void visit (AST::TuplePatternItemsRanged &);
182 : : void visit (AST::TuplePattern &);
183 : : void visit (AST::GroupedPattern &);
184 : : void visit (AST::SlicePattern &);
185 : : void visit (AST::AltPattern &);
186 : :
187 : : void visit (AST::EmptyStmt &);
188 : : void visit (AST::LetStmt &);
189 : : void visit (AST::ExprStmt &);
190 : :
191 : : void visit (AST::TraitBound &);
192 : : void visit (AST::ImplTraitType &);
193 : : void visit (AST::TraitObjectType &);
194 : : void visit (AST::ParenthesisedType &);
195 : : void visit (AST::ImplTraitTypeOneBound &);
196 : : void visit (AST::TraitObjectTypeOneBound &);
197 : : void visit (AST::TupleType &);
198 : : void visit (AST::NeverType &);
199 : : void visit (AST::RawPointerType &);
200 : : void visit (AST::ReferenceType &);
201 : : void visit (AST::ArrayType &);
202 : : void visit (AST::SliceType &);
203 : : void visit (AST::InferredType &);
204 : : void visit (AST::BareFunctionType &);
205 : : void visit (AST::FunctionParam ¶m);
206 : : void visit (AST::VariadicParam ¶m);
207 : : void visit (AST::SelfParam ¶m);
208 : :
209 : : void visit (AST::FormatArgs &fmt);
210 : :
211 : : protected:
212 : 295867 : ResolverBase ()
213 : 295867 : : resolver (Resolver::get ()), mappings (Analysis::Mappings::get ()),
214 : 295867 : resolved_node (UNKNOWN_NODEID)
215 : 295867 : {}
216 : :
217 : : /**
218 : : * Resolve a visibility's path through the name resolver
219 : : */
220 : : bool resolve_visibility (const AST::Visibility &vis);
221 : :
222 : : Resolver *resolver;
223 : : Analysis::Mappings &mappings;
224 : : NodeId resolved_node;
225 : : };
226 : :
227 : : } // namespace Resolver
228 : : } // namespace Rust
229 : :
230 : : #endif // RUST_AST_RESOLVE_BASE_H
|