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