Debian Codegraph @

gcc/rust/hir/tree/rust-hir-bound.h

raw
1 // Copyright (C) 2020-2024 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_BOUND_H
20 #define RUST_HIR_BOUND_H
21
22 #include "rust-hir-bound-abstract.h"
23 #include "rust-common.h"
24 #include "rust-hir-path.h"
25
26 namespace Rust {
27 namespace HIR {
28
29 // Represents a lifetime (and is also a kind of type param bound)
30 class Lifetime : public TypeParamBound
31 {
32 private:
33 AST::Lifetime::LifetimeType lifetime_type;
34 std::string lifetime_name;
35 location_t locus;
36 Analysis::NodeMapping mappings;
37
38 public:
39 // Constructor
40 Lifetime (Analysis::NodeMapping mapping, AST::Lifetime::LifetimeType type,
41 std::string name, location_t locus)
42 : lifetime_type (type), lifetime_name (std::move (name)), locus (locus),
43 mappings (mapping)
44 {}
45
46 // Returns true if the lifetime is in an error state.
47 std::string as_string () const override;
48
49 void accept_vis (HIRFullVisitor &vis) override;
50
51 WARN_UNUSED_RESULT const std::string &get_name () const
52 {
53 return lifetime_name;
54 }
55
56 AST::Lifetime::LifetimeType get_lifetime_type () const
57 {
58 return lifetime_type;
59 }
60
61 location_t get_locus () const override final { return locus; }
62
63 Analysis::NodeMapping get_mappings () const override final
64 {
65 return mappings;
66 }
67
68 BoundType get_bound_type () const final override { return LIFETIME; }
69
70 protected:
71 /* Use covariance to implement clone function as returning this object rather
72 * than base */
73 Lifetime *clone_type_param_bound_impl () const override
74 {
75 return new Lifetime (*this);
76 }
77 };
78
79 } // namespace HIR
80 } // namespace Rust
81
82 #endif