(root)/
gcc-13.2.0/
gcc/
rust/
resolve/
rust-ast-resolve-item.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_ITEM_H
      20  #define RUST_AST_RESOLVE_ITEM_H
      21  
      22  #include "rust-ast-full-decls.h"
      23  #include "rust-ast-resolve-base.h"
      24  #include "rust-ast-full.h"
      25  #include "rust-ast-resolve-toplevel.h"
      26  #include "rust-ast-resolve-type.h"
      27  #include "rust-ast-resolve-pattern.h"
      28  #include "rust-ast-resolve-stmt.h"
      29  #include "config.h"
      30  
      31  namespace Rust {
      32  namespace Resolver {
      33  
      34  class ResolveTraitItems : public ResolverBase
      35  {
      36    using Rust::Resolver::ResolverBase::visit;
      37  
      38  public:
      39    static void go (AST::TraitItem *item, const CanonicalPath &prefix,
      40  		  const CanonicalPath &canonical_prefix);
      41  
      42    void visit (AST::TraitItemType &type) override;
      43    void visit (AST::TraitItemFunc &func) override;
      44    void visit (AST::TraitItemMethod &func) override;
      45    void visit (AST::TraitItemConst &constant) override;
      46  
      47  private:
      48    ResolveTraitItems (const CanonicalPath &prefix,
      49  		     const CanonicalPath &canonical_prefix);
      50  
      51    const CanonicalPath &prefix;
      52    const CanonicalPath &canonical_prefix;
      53  };
      54  
      55  class ResolveItem : public ResolverBase
      56  {
      57  public:
      58    using Rust::Resolver::ResolverBase::visit;
      59  
      60    static void go (AST::Item *item, const CanonicalPath &prefix,
      61  		  const CanonicalPath &canonical_prefix);
      62  
      63    void visit (AST::TypeAlias &alias) override;
      64    void visit (AST::Module &module) override;
      65    void visit (AST::TupleStruct &struct_decl) override;
      66    void visit (AST::Enum &enum_decl) override;
      67    /* EnumItem doesn't need to be handled, no fields.  */
      68    void visit (AST::EnumItem &item) override;
      69    void visit (AST::EnumItemTuple &item) override;
      70    void visit (AST::EnumItemStruct &item) override;
      71    void visit (AST::EnumItemDiscriminant &item) override;
      72    void visit (AST::StructStruct &struct_decl) override;
      73    void visit (AST::Union &union_decl) override;
      74    void visit (AST::StaticItem &var) override;
      75    void visit (AST::ConstantItem &constant) override;
      76    void visit (AST::Function &function) override;
      77    void visit (AST::InherentImpl &impl_block) override;
      78    void visit (AST::Method &method) override;
      79    void visit (AST::TraitImpl &impl_block) override;
      80    void visit (AST::Trait &trait) override;
      81    void visit (AST::ExternBlock &extern_block) override;
      82    void visit (AST::UseDeclaration &) override;
      83  
      84  protected:
      85    void resolve_impl_item (AST::TraitImplItem *item, const CanonicalPath &prefix,
      86  			  const CanonicalPath &canonical_prefix);
      87    void resolve_impl_item (AST::InherentImplItem *item,
      88  			  const CanonicalPath &prefix,
      89  			  const CanonicalPath &canonical_prefix);
      90    void resolve_extern_item (AST::ExternalItem *item);
      91  
      92    ResolveItem (const CanonicalPath &prefix,
      93  	       const CanonicalPath &canonical_prefix);
      94  
      95    const CanonicalPath &prefix;
      96    const CanonicalPath &canonical_prefix;
      97  };
      98  
      99  class ResolveImplItems : public ResolveItem
     100  {
     101    using Rust::Resolver::ResolveItem::visit;
     102  
     103  public:
     104    static void go (AST::InherentImplItem *item, const CanonicalPath &prefix,
     105  		  const CanonicalPath &canonical_prefix);
     106    static void go (AST::TraitImplItem *item, const CanonicalPath &prefix,
     107  		  const CanonicalPath &canonical_prefix);
     108  
     109    void visit (AST::TypeAlias &alias) override;
     110  
     111  private:
     112    ResolveImplItems (const CanonicalPath &prefix,
     113  		    const CanonicalPath &canonical_prefix);
     114  };
     115  
     116  class ResolveExternItem : public ResolverBase
     117  {
     118    using Rust::Resolver::ResolverBase::visit;
     119  
     120  public:
     121    static void go (AST::ExternalItem *item, const CanonicalPath &prefix,
     122  		  const CanonicalPath &canonical_prefix);
     123  
     124    void visit (AST::ExternalFunctionItem &function) override;
     125    void visit (AST::ExternalStaticItem &item) override;
     126  
     127  private:
     128    ResolveExternItem (const CanonicalPath &prefix,
     129  		     const CanonicalPath &canonical_prefix)
     130      : ResolverBase (), prefix (prefix), canonical_prefix (canonical_prefix)
     131    {}
     132  
     133    const CanonicalPath &prefix;
     134    const CanonicalPath &canonical_prefix;
     135  };
     136  
     137  } // namespace Resolver
     138  } // namespace Rust
     139  
     140  #if CHECKING_P
     141  
     142  namespace selftest {
     143  extern void
     144  rust_simple_path_resolve_test (void);
     145  } // namespace selftest
     146  
     147  #endif // CHECKING_P
     148  
     149  #endif // RUST_AST_RESOLVE_ITEM_H