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