Debian Codegraph @

gcc/rust/typecheck/rust-hir-dot-operator.h

raw
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_HIR_DOT_OPERATOR
20 #define RUST_HIR_DOT_OPERATOR
21
22 #include "rust-hir-path-probe.h"
23
24 namespace Rust {
25 namespace Resolver {
26
27 struct MethodCandidate
28 {
29 PathProbeCandidate candidate;
30 std::vector<Adjustment> adjustments;
31
32 static MethodCandidate get_error ()
33 {
34 return {PathProbeCandidate::get_error (), {}};
35 }
36
37 bool is_error () const { return candidate.is_error (); }
38
39 DefId get_defid () const { return candidate.get_defid (); }
40
41 bool operator< (const MethodCandidate &c) const
42 {
43 return get_defid () < c.get_defid ();
44 }
45 };
46
47 class MethodResolver : private TypeCheckBase, protected AutoderefCycle
48 {
49 public:
50 struct predicate_candidate
51 {
52 TyTy::TypeBoundPredicateItem lookup;
53 TyTy::FnType *fntype;
54 };
55
56 static std::set<MethodCandidate>
57 Probe (TyTy::BaseType *receiver, const HIR::PathIdentSegment &segment_name,
58 bool autoderef_flag = false);
59
60 static std::set<MethodCandidate>
61 Select (std::set<MethodCandidate> &candidates, TyTy::BaseType *receiver,
62 std::vector<TyTy::BaseType *> arguments);
63
64 static std::vector<predicate_candidate> get_predicate_items (
65 const HIR::PathIdentSegment &segment_name, const TyTy::BaseType &receiver,
66 const std::vector<TyTy::TypeBoundPredicate> &specified_bounds);
67
68 protected:
69 MethodResolver (bool autoderef_flag,
70 const HIR::PathIdentSegment &segment_name);
71
72 void try_hook (const TyTy::BaseType &r) override;
73
74 bool select (TyTy::BaseType &receiver) override;
75
76 private:
77 std::vector<Adjustment>
78 append_adjustments (const std::vector<Adjustment> &adjustments) const;
79
80 private:
81 // search
82 const HIR::PathIdentSegment &segment_name;
83 std::vector<MethodResolver::predicate_candidate> predicate_items;
84
85 // mutable fields
86 std::set<MethodCandidate> result;
87 };
88
89 } // namespace Resolver
90 } // namespace Rust
91
92 #endif // RUST_HIR_DOT_OPERATOR