| 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 |
redefined_error (const rich_location &loc) |
| 32 |
{ |
| 33 |
rust_error_at (loc, "redefined multiple times"); |
| 34 |
} |
| 35 |
|
| 36 |
class ResolverBase : public AST::ASTVisitor |
| 37 |
{ |
| 38 |
public: |
| 39 |
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 |
|
| 114 |
void visit (AST::TypeParam &); |
| 115 |
|
| 116 |
void visit (AST::LifetimeWhereClauseItem &); |
| 117 |
void visit (AST::TypeBoundWhereClauseItem &); |
| 118 |
void visit (AST::Module &); |
| 119 |
void visit (AST::ExternCrate &); |
| 120 |
|
| 121 |
void visit (AST::UseTreeGlob &); |
| 122 |
void visit (AST::UseTreeList &); |
| 123 |
void visit (AST::UseTreeRebind &); |
| 124 |
void visit (AST::UseDeclaration &); |
| 125 |
void visit (AST::Function &); |
| 126 |
void visit (AST::TypeAlias &); |
| 127 |
void visit (AST::StructStruct &); |
| 128 |
void visit (AST::TupleStruct &); |
| 129 |
void visit (AST::EnumItem &); |
| 130 |
void visit (AST::EnumItemTuple &); |
| 131 |
void visit (AST::EnumItemStruct &); |
| 132 |
void visit (AST::EnumItemDiscriminant &); |
| 133 |
void visit (AST::Enum &); |
| 134 |
void visit (AST::Union &); |
| 135 |
void visit (AST::ConstantItem &); |
| 136 |
void visit (AST::StaticItem &); |
| 137 |
void visit (AST::TraitItemConst &); |
| 138 |
void visit (AST::TraitItemType &); |
| 139 |
void visit (AST::Trait &); |
| 140 |
void visit (AST::InherentImpl &); |
| 141 |
void visit (AST::TraitImpl &); |
| 142 |
|
| 143 |
void visit (AST::ExternalTypeItem &); |
| 144 |
void visit (AST::ExternalStaticItem &); |
| 145 |
void visit (AST::ExternBlock &); |
| 146 |
|
| 147 |
void visit (AST::MacroMatchFragment &); |
| 148 |
void visit (AST::MacroMatchRepetition &); |
| 149 |
void visit (AST::MacroMatcher &); |
| 150 |
void visit (AST::MacroRulesDefinition &); |
| 151 |
void visit (AST::MacroInvocation &); |
| 152 |
void visit (AST::MetaItemPath &); |
| 153 |
void visit (AST::MetaItemSeq &); |
| 154 |
void visit (AST::MetaWord &); |
| 155 |
void visit (AST::MetaNameValueStr &); |
| 156 |
void visit (AST::MetaListPaths &); |
| 157 |
void visit (AST::MetaListNameValueStr &); |
| 158 |
|
| 159 |
void visit (AST::LiteralPattern &); |
| 160 |
void visit (AST::IdentifierPattern &); |
| 161 |
void visit (AST::WildcardPattern &); |
| 162 |
void visit (AST::RestPattern &); |
| 163 |
|
| 164 |
void visit (AST::RangePatternBoundLiteral &); |
| 165 |
void visit (AST::RangePatternBoundPath &); |
| 166 |
void visit (AST::RangePatternBoundQualPath &); |
| 167 |
void visit (AST::RangePattern &); |
| 168 |
void visit (AST::ReferencePattern &); |
| 169 |
|
| 170 |
void visit (AST::StructPatternFieldTuplePat &); |
| 171 |
void visit (AST::StructPatternFieldIdentPat &); |
| 172 |
void visit (AST::StructPatternFieldIdent &); |
| 173 |
void visit (AST::StructPattern &); |
| 174 |
|
| 175 |
void visit (AST::TupleStructItemsNoRange &); |
| 176 |
void visit (AST::TupleStructItemsRange &); |
| 177 |
void visit (AST::TupleStructPattern &); |
| 178 |
|
| 179 |
void visit (AST::TuplePatternItemsMultiple &); |
| 180 |
void visit (AST::TuplePatternItemsRanged &); |
| 181 |
void visit (AST::TuplePattern &); |
| 182 |
void visit (AST::GroupedPattern &); |
| 183 |
void visit (AST::SlicePattern &); |
| 184 |
void visit (AST::AltPattern &); |
| 185 |
|
| 186 |
void visit (AST::EmptyStmt &); |
| 187 |
void visit (AST::LetStmt &); |
| 188 |
void visit (AST::ExprStmt &); |
| 189 |
|
| 190 |
void visit (AST::TraitBound &); |
| 191 |
void visit (AST::ImplTraitType &); |
| 192 |
void visit (AST::TraitObjectType &); |
| 193 |
void visit (AST::ParenthesisedType &); |
| 194 |
void visit (AST::ImplTraitTypeOneBound &); |
| 195 |
void visit (AST::TraitObjectTypeOneBound &); |
| 196 |
void visit (AST::TupleType &); |
| 197 |
void visit (AST::NeverType &); |
| 198 |
void visit (AST::RawPointerType &); |
| 199 |
void visit (AST::ReferenceType &); |
| 200 |
void visit (AST::ArrayType &); |
| 201 |
void visit (AST::SliceType &); |
| 202 |
void visit (AST::InferredType &); |
| 203 |
void visit (AST::BareFunctionType &); |
| 204 |
void visit (AST::FunctionParam ¶m); |
| 205 |
void visit (AST::VariadicParam ¶m); |
| 206 |
void visit (AST::SelfParam ¶m); |
| 207 |
|
| 208 |
void visit (AST::FormatArgs &fmt); |
| 209 |
|
| 210 |
protected: |
| 211 |
ResolverBase () |
| 212 |
: resolver (Resolver::get ()), mappings (Analysis::Mappings::get ()), |
| 213 |
resolved_node (UNKNOWN_NODEID) |
| 214 |
{} |
| 215 |
|
| 216 |
/** |
| 217 |
* Resolve a visibility's path through the name resolver |
| 218 |
*/ |
| 219 |
bool resolve_visibility (const AST::Visibility &vis); |
| 220 |
|
| 221 |
Resolver *resolver; |
| 222 |
Analysis::Mappings &mappings; |
| 223 |
NodeId resolved_node; |
| 224 |
}; |
| 225 |
|
| 226 |
} // namespace Resolver |
| 227 |
} // namespace Rust |
| 228 |
|
| 229 |
#endif // RUST_AST_RESOLVE_BASE_H |