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