1 // Copyright (C) 2021-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_HIR_TRAIT_RESOLVE_H
20 #define RUST_HIR_TRAIT_RESOLVE_H
21
22 #include "rust-hir-type-check-type.h"
23
24 namespace Rust {
25 namespace Resolver {
26
27 class ResolveTraitItemToRef : public TypeCheckBase,
28 private HIR::HIRTraitItemVisitor
29 {
30 public:
31 static TraitItemReference
32 Resolve (HIR::TraitItem &item, TyTy::BaseType *self,
33 std::vector<TyTy::SubstitutionParamMapping> substitutions);
34
35 void visit (HIR::TraitItemType &type) override;
36
37 void visit (HIR::TraitItemConst &cst) override;
38
39 void visit (HIR::TraitItemFunc &fn) override;
40
41 private:
42 ResolveTraitItemToRef (
43 TyTy::BaseType *self,
44 std::vector<TyTy::SubstitutionParamMapping> &&substitutions);
45
46 TraitItemReference resolved;
47 TyTy::BaseType *self;
48 std::vector<TyTy::SubstitutionParamMapping> substitutions;
49 };
50
51 class TraitResolver : public TypeCheckBase
52 {
53 public:
54 static TraitReference *Resolve (HIR::TypePath &path);
55
56 static TraitReference *Resolve (HIR::Trait &trait);
57
58 static TraitReference *Lookup (HIR::TypePath &path);
59
60 private:
61 TraitResolver ();
62
63 TraitReference *resolve_path (HIR::TypePath &path);
64
65 TraitReference *resolve_trait (HIR::Trait *trait_reference);
66
67 TraitReference *lookup_path (HIR::TypePath &path);
68
69 bool resolve_path_to_trait (const HIR::TypePath &path,
70 HIR::Trait **resolved) const;
71 };
72
73 } // namespace Resolver
74 } // namespace Rust
75
76 #endif // RUST_HIR_TRAIT_RESOLVE_H