Debian Codegraph @

gcc/rust/hir/tree/rust-hir-generic-param.cc

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 #include "rust-hir-generic-param.h"
20
21 namespace Rust {
22 namespace HIR {
23
24 GenericParam::GenericParam (Analysis::NodeMapping mapping,
25 enum GenericKind kind)
26 : mappings (mapping), kind (kind)
27 {}
28
29 LifetimeParam::LifetimeParam (Analysis::NodeMapping mappings, Lifetime lifetime,
30 location_t locus,
31 std::vector<Lifetime> lifetime_bounds,
32 AST::AttrVec outer_attrs)
33 : GenericParam (mappings, GenericKind::LIFETIME),
34 lifetime (std::move (lifetime)),
35 lifetime_bounds (std::move (lifetime_bounds)),
36 outer_attrs (std::move (outer_attrs)), locus (locus)
37 {}
38
39 LifetimeParam::LifetimeParam (LifetimeParam const &other)
40 : GenericParam (other.mappings, GenericKind::LIFETIME),
41 lifetime (other.lifetime), lifetime_bounds (other.lifetime_bounds),
42 outer_attrs (other.outer_attrs), locus (other.locus)
43 {}
44
45 LifetimeParam &
46 LifetimeParam::operator= (LifetimeParam const &other)
47 {
48 lifetime = other.lifetime;
49 lifetime_bounds = other.lifetime_bounds;
50 outer_attrs = other.outer_attrs;
51 locus = other.locus;
52 mappings = other.mappings;
53
54 return *this;
55 }
56
57 ConstGenericParam::ConstGenericParam (std::string name,
58 std::unique_ptr<Type> type,
59 std::unique_ptr<Expr> default_expression,
60 Analysis::NodeMapping mapping,
61 location_t locus)
62 : GenericParam (mapping, GenericKind::CONST), name (std::move (name)),
63 type (std::move (type)),
64 default_expression (std::move (default_expression)), locus (locus)
65 {}
66
67 ConstGenericParam::ConstGenericParam (const ConstGenericParam &other)
68 : GenericParam (other)
69 {
70 name = other.name;
71 locus = other.locus;
72
73 if (other.type)
74 type = other.type->clone_type ();
75 if (other.default_expression)
76 default_expression = other.default_expression->clone_expr ();
77 }
78
79 std::string
80 ConstGenericParam::as_string () const
81 {
82 auto result = "ConstGenericParam: " + name + " : " + type->as_string ();
83
84 if (default_expression)
85 result += " = " + default_expression->as_string ();
86
87 return result;
88 }
89
90 void
91 ConstGenericParam::accept_vis (HIRFullVisitor &)
92 {}
93
94 } // namespace HIR
95 } // namespace Rust