]>
Commit | Line | Data |
---|---|---|
83ffe9cd | 1 | // Copyright (C) 2021-2023 Free Software Foundation, Inc. |
c6c3db21 PH |
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-base.h" | |
23 | #include "rust-hir-type-check-type.h" | |
24 | #include "rust-hir-trait-ref.h" | |
25 | ||
26 | namespace Rust { | |
27 | namespace Resolver { | |
28 | ||
29 | class ResolveTraitItemToRef : public TypeCheckBase, | |
30 | private HIR::HIRTraitItemVisitor | |
31 | { | |
32 | public: | |
33 | static TraitItemReference | |
34 | Resolve (HIR::TraitItem &item, TyTy::BaseType *self, | |
35 | std::vector<TyTy::SubstitutionParamMapping> substitutions) | |
36 | { | |
37 | ResolveTraitItemToRef resolver (self, std::move (substitutions)); | |
38 | item.accept_vis (resolver); | |
39 | return std::move (resolver.resolved); | |
40 | } | |
41 | ||
42 | void visit (HIR::TraitItemType &type) override; | |
43 | ||
44 | void visit (HIR::TraitItemConst &cst) override; | |
45 | ||
46 | void visit (HIR::TraitItemFunc &fn) override; | |
47 | ||
48 | private: | |
49 | ResolveTraitItemToRef ( | |
50 | TyTy::BaseType *self, | |
51 | std::vector<TyTy::SubstitutionParamMapping> &&substitutions); | |
52 | ||
53 | TraitItemReference resolved; | |
54 | TyTy::BaseType *self; | |
55 | std::vector<TyTy::SubstitutionParamMapping> substitutions; | |
56 | }; | |
57 | ||
58 | class TraitResolver : public TypeCheckBase, private HIR::HIRFullVisitorBase | |
59 | { | |
60 | using HIR::HIRFullVisitorBase::visit; | |
61 | ||
62 | public: | |
63 | static TraitReference *Resolve (HIR::TypePath &path); | |
64 | ||
65 | static TraitReference *Resolve (HIR::Trait &trait); | |
66 | ||
67 | static TraitReference *Lookup (HIR::TypePath &path); | |
68 | ||
69 | private: | |
70 | TraitResolver (); | |
71 | ||
72 | TraitReference *resolve_path (HIR::TypePath &path); | |
73 | ||
74 | TraitReference *resolve_trait (HIR::Trait *trait_reference); | |
75 | ||
76 | TraitReference *lookup_path (HIR::TypePath &path); | |
77 | ||
78 | HIR::Trait *resolved_trait_reference; | |
79 | ||
80 | public: | |
81 | void visit (HIR::Trait &trait) override { resolved_trait_reference = &trait; } | |
82 | }; | |
83 | ||
84 | } // namespace Resolver | |
85 | } // namespace Rust | |
86 | ||
87 | #endif // RUST_HIR_TRAIT_RESOLVE_H |