Line data Source code
1 : // Copyright (C) 2020-2026 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_BOUND_H
20 : #define RUST_HIR_TRAIT_BOUND_H
21 :
22 : #include "rust-hir-bound-abstract.h"
23 : #include "rust-hir-path.h"
24 : #include "rust-hir-generic-param.h"
25 :
26 : namespace Rust {
27 : namespace HIR {
28 :
29 : // A trait bound
30 : class TraitBound : public TypeParamBound
31 : {
32 : bool in_parens;
33 : BoundPolarity polarity;
34 : std::vector<LifetimeParam> for_lifetimes;
35 : TypePath type_path;
36 : location_t locus;
37 :
38 : Analysis::NodeMapping mappings;
39 :
40 : public:
41 : // Returns whether trait bound has "for" lifetimes
42 0 : bool has_for_lifetimes () const { return !for_lifetimes.empty (); }
43 :
44 1816 : TraitBound (Analysis::NodeMapping mapping, TypePath type_path,
45 : location_t locus, bool in_parens = false,
46 : BoundPolarity polarity = BoundPolarity::RegularBound,
47 : std::vector<LifetimeParam> for_lifetimes
48 : = std::vector<LifetimeParam> ())
49 1816 : : in_parens (in_parens), polarity (polarity),
50 1816 : for_lifetimes (std::move (for_lifetimes)),
51 1816 : type_path (std::move (type_path)), locus (locus), mappings (mapping)
52 1816 : {}
53 :
54 : std::string to_string () const override;
55 :
56 : std::string to_debug_string () const;
57 :
58 1817 : location_t get_locus () const override final { return locus; }
59 :
60 : void accept_vis (HIRFullVisitor &vis) override;
61 :
62 1816 : Analysis::NodeMapping get_mappings () const override final
63 : {
64 1816 : return mappings;
65 : }
66 :
67 1878 : std::vector<LifetimeParam> &get_for_lifetimes () { return for_lifetimes; }
68 0 : bool get_in_parens () { return in_parens; }
69 2210 : BoundPolarity get_polarity () { return polarity; }
70 :
71 3575 : BoundType get_bound_type () const final override { return TRAITBOUND; }
72 :
73 4367 : TypePath &get_path () { return type_path; }
74 :
75 : const TypePath &get_path () const { return type_path; }
76 :
77 : protected:
78 : /* Use covariance to implement clone function as returning this object rather
79 : * than base */
80 104 : TraitBound *clone_type_param_bound_impl () const override
81 : {
82 104 : return new TraitBound (*this);
83 : }
84 : };
85 :
86 : } // namespace HIR
87 : } // namespace Rust
88 :
89 : #endif
|