Branch data Line data Source code
1 : :
2 : : // Copyright (C) 2020-2024 Free Software Foundation, Inc.
3 : :
4 : : // This file is part of GCC.
5 : :
6 : : // GCC is free software; you can redistribute it and/or modify it under
7 : : // the terms of the GNU General Public License as published by the Free
8 : : // Software Foundation; either version 3, or (at your option) any later
9 : : // version.
10 : :
11 : : // GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 : : // WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 : : // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 : : // for more details.
15 : :
16 : : // You should have received a copy of the GNU General Public License
17 : : // along with GCC; see the file COPYING3. If not see
18 : : // <http://www.gnu.org/licenses/>.
19 : :
20 : : #include "rust-hir-type.h"
21 : :
22 : : namespace Rust {
23 : : namespace HIR {
24 : :
25 : 0 : ImplTraitType::ImplTraitType (
26 : : Analysis::NodeMapping mappings,
27 : : std::vector<std::unique_ptr<TypeParamBound>> type_param_bounds,
28 : 0 : location_t locus)
29 : 0 : : Type (mappings, locus), type_param_bounds (std::move (type_param_bounds))
30 : 0 : {}
31 : :
32 : 0 : ImplTraitType::ImplTraitType (ImplTraitType const &other)
33 : 0 : : Type (other.mappings, other.locus)
34 : : {
35 : 0 : type_param_bounds.reserve (other.type_param_bounds.size ());
36 : 0 : for (const auto &e : other.type_param_bounds)
37 : 0 : type_param_bounds.push_back (e->clone_type_param_bound ());
38 : 0 : }
39 : :
40 : : ImplTraitType &
41 : 0 : ImplTraitType::operator= (ImplTraitType const &other)
42 : : {
43 : 0 : locus = other.locus;
44 : 0 : mappings = other.mappings;
45 : :
46 : 0 : type_param_bounds.reserve (other.type_param_bounds.size ());
47 : 0 : for (const auto &e : other.type_param_bounds)
48 : 0 : type_param_bounds.push_back (e->clone_type_param_bound ());
49 : :
50 : 0 : return *this;
51 : : }
52 : :
53 : 180 : TraitObjectType::TraitObjectType (
54 : : Analysis::NodeMapping mappings,
55 : : std::vector<std::unique_ptr<TypeParamBound>> type_param_bounds,
56 : 180 : location_t locus, bool is_dyn_dispatch)
57 : 180 : : Type (mappings, locus), has_dyn (is_dyn_dispatch),
58 : 180 : type_param_bounds (std::move (type_param_bounds))
59 : 180 : {}
60 : :
61 : 14 : TraitObjectType::TraitObjectType (TraitObjectType const &other)
62 : 14 : : Type (other.mappings, other.locus), has_dyn (other.has_dyn)
63 : : {
64 : 14 : type_param_bounds.reserve (other.type_param_bounds.size ());
65 : 28 : for (const auto &e : other.type_param_bounds)
66 : 14 : type_param_bounds.push_back (e->clone_type_param_bound ());
67 : 14 : }
68 : :
69 : : TraitObjectType &
70 : 0 : TraitObjectType::operator= (TraitObjectType const &other)
71 : : {
72 : 0 : mappings = other.mappings;
73 : 0 : has_dyn = other.has_dyn;
74 : 0 : locus = other.locus;
75 : 0 : type_param_bounds.reserve (other.type_param_bounds.size ());
76 : 0 : for (const auto &e : other.type_param_bounds)
77 : 0 : type_param_bounds.push_back (e->clone_type_param_bound ());
78 : :
79 : 0 : return *this;
80 : : }
81 : :
82 : 4 : ParenthesisedType::ParenthesisedType (Analysis::NodeMapping mappings,
83 : : std::unique_ptr<Type> type_inside_parens,
84 : 4 : location_t locus)
85 : : : TypeNoBounds (mappings, locus),
86 : 4 : type_in_parens (std::move (type_inside_parens))
87 : 4 : {}
88 : :
89 : 0 : ParenthesisedType::ParenthesisedType (ParenthesisedType const &other)
90 : 0 : : TypeNoBounds (other.mappings, other.locus),
91 : 0 : type_in_parens (other.type_in_parens->clone_type ())
92 : 0 : {}
93 : :
94 : : ParenthesisedType &
95 : 0 : ParenthesisedType::operator= (ParenthesisedType const &other)
96 : : {
97 : 0 : mappings = other.mappings;
98 : 0 : type_in_parens = other.type_in_parens->clone_type ();
99 : 0 : locus = other.locus;
100 : 0 : return *this;
101 : : }
102 : :
103 : : std::unique_ptr<TraitBound>
104 : 0 : ParenthesisedType::to_trait_bound (bool in_parens ATTRIBUTE_UNUSED) const
105 : : {
106 : : /* NOTE: obviously it is unknown whether the internal type is a trait bound
107 : : * due to polymorphism, so just let the internal type handle it. As
108 : : * parenthesised type, it must be in parentheses. */
109 : 0 : return type_in_parens->to_trait_bound (true);
110 : : }
111 : :
112 : 496 : TupleType::TupleType (Analysis::NodeMapping mappings,
113 : : std::vector<std::unique_ptr<Type>> elems,
114 : 496 : location_t locus)
115 : 496 : : TypeNoBounds (mappings, locus), elems (std::move (elems))
116 : 496 : {}
117 : :
118 : 48 : TupleType::TupleType (TupleType const &other)
119 : 48 : : TypeNoBounds (other.mappings, other.locus)
120 : : {
121 : 48 : mappings = other.mappings;
122 : 48 : elems.reserve (other.elems.size ());
123 : 88 : for (const auto &e : other.elems)
124 : 40 : elems.push_back (e->clone_type ());
125 : 48 : }
126 : :
127 : : TupleType &
128 : 0 : TupleType::operator= (TupleType const &other)
129 : : {
130 : 0 : locus = other.locus;
131 : :
132 : 0 : elems.reserve (other.elems.size ());
133 : 0 : for (const auto &e : other.elems)
134 : 0 : elems.push_back (e->clone_type ());
135 : :
136 : 0 : return *this;
137 : : }
138 : :
139 : 58 : NeverType::NeverType (Analysis::NodeMapping mappings, location_t locus)
140 : 58 : : TypeNoBounds (mappings, locus)
141 : 58 : {}
142 : :
143 : 5927 : RawPointerType::RawPointerType (Analysis::NodeMapping mappings, Mutability mut,
144 : 5927 : std::unique_ptr<Type> type, location_t locus)
145 : 5927 : : TypeNoBounds (mappings, locus), mut (mut), type (std::move (type))
146 : 5927 : {}
147 : :
148 : 42 : RawPointerType::RawPointerType (RawPointerType const &other)
149 : 42 : : TypeNoBounds (other.mappings, other.locus), mut (other.mut),
150 : 42 : type (other.type->clone_type ())
151 : 42 : {}
152 : :
153 : : RawPointerType &
154 : 0 : RawPointerType::operator= (RawPointerType const &other)
155 : : {
156 : 0 : mappings = other.mappings;
157 : 0 : mut = other.mut;
158 : 0 : type = other.type->clone_type ();
159 : 0 : locus = other.locus;
160 : 0 : return *this;
161 : : }
162 : :
163 : 2586 : ReferenceType::ReferenceType (Analysis::NodeMapping mappings, Mutability mut,
164 : : std::unique_ptr<Type> type_no_bounds,
165 : 2586 : location_t locus, tl::optional<Lifetime> lifetime)
166 : 2586 : : TypeNoBounds (mappings, locus), lifetime (std::move (lifetime)), mut (mut),
167 : 2586 : type (std::move (type_no_bounds))
168 : 2586 : {}
169 : :
170 : 1076 : ReferenceType::ReferenceType (ReferenceType const &other)
171 : 2152 : : TypeNoBounds (other.mappings, other.locus), lifetime (other.lifetime),
172 : 1076 : mut (other.mut), type (other.type->clone_type ())
173 : 1076 : {}
174 : :
175 : : ReferenceType &
176 : 0 : ReferenceType::operator= (ReferenceType const &other)
177 : : {
178 : 0 : mappings = other.mappings;
179 : 0 : lifetime = other.lifetime;
180 : 0 : mut = other.mut;
181 : 0 : type = other.type->clone_type ();
182 : 0 : locus = other.locus;
183 : :
184 : 0 : return *this;
185 : : }
186 : :
187 : 672 : ArrayType::ArrayType (Analysis::NodeMapping mappings,
188 : : std::unique_ptr<Type> type,
189 : 672 : std::unique_ptr<Expr> array_size, location_t locus)
190 : 672 : : TypeNoBounds (mappings, locus), elem_type (std::move (type)),
191 : 672 : size (std::move (array_size))
192 : 672 : {}
193 : :
194 : 0 : ArrayType::ArrayType (ArrayType const &other)
195 : 0 : : TypeNoBounds (other.mappings, other.locus),
196 : 0 : elem_type (other.elem_type->clone_type ()), size (other.size->clone_expr ())
197 : 0 : {}
198 : :
199 : : ArrayType &
200 : 0 : ArrayType::operator= (ArrayType const &other)
201 : : {
202 : 0 : mappings = other.mappings;
203 : 0 : elem_type = other.elem_type->clone_type ();
204 : 0 : size = other.size->clone_expr ();
205 : 0 : locus = other.locus;
206 : 0 : return *this;
207 : : }
208 : :
209 : 802 : SliceType::SliceType (Analysis::NodeMapping mappings,
210 : 802 : std::unique_ptr<Type> type, location_t locus)
211 : 802 : : TypeNoBounds (mappings, locus), elem_type (std::move (type))
212 : 802 : {}
213 : :
214 : 493 : SliceType::SliceType (SliceType const &other)
215 : 493 : : TypeNoBounds (other.mappings, other.locus),
216 : 493 : elem_type (other.elem_type->clone_type ())
217 : 493 : {}
218 : :
219 : : SliceType &
220 : 0 : SliceType::operator= (SliceType const &other)
221 : : {
222 : 0 : mappings = other.mappings;
223 : 0 : elem_type = other.elem_type->clone_type ();
224 : 0 : locus = other.locus;
225 : :
226 : 0 : return *this;
227 : : }
228 : :
229 : 199 : InferredType::InferredType (Analysis::NodeMapping mappings, location_t locus)
230 : 199 : : TypeNoBounds (mappings, locus)
231 : 199 : {}
232 : :
233 : 64 : MaybeNamedParam::MaybeNamedParam (Identifier name, ParamKind param_kind,
234 : : std::unique_ptr<Type> param_type,
235 : 64 : location_t locus)
236 : 64 : : param_type (std::move (param_type)), param_kind (param_kind),
237 : 64 : name (std::move (name)), locus (locus)
238 : 64 : {}
239 : :
240 : 0 : MaybeNamedParam::MaybeNamedParam (MaybeNamedParam const &other)
241 : 0 : : param_type (other.param_type->clone_type ()), param_kind (other.param_kind),
242 : 0 : name (other.name), locus (other.locus)
243 : 0 : {}
244 : :
245 : : MaybeNamedParam &
246 : 0 : MaybeNamedParam::operator= (MaybeNamedParam const &other)
247 : : {
248 : 0 : name = other.name;
249 : 0 : param_kind = other.param_kind;
250 : 0 : param_type = other.param_type->clone_type ();
251 : 0 : locus = other.locus;
252 : :
253 : 0 : return *this;
254 : : }
255 : :
256 : 68 : BareFunctionType::BareFunctionType (
257 : : Analysis::NodeMapping mappings, std::vector<LifetimeParam> lifetime_params,
258 : : FunctionQualifiers qualifiers, std::vector<MaybeNamedParam> named_params,
259 : 68 : bool is_variadic, std::unique_ptr<Type> type, location_t locus)
260 : 68 : : TypeNoBounds (mappings, locus), for_lifetimes (std::move (lifetime_params)),
261 : 68 : function_qualifiers (std::move (qualifiers)),
262 : 68 : params (std::move (named_params)), is_variadic (is_variadic),
263 : 68 : return_type (std::move (type))
264 : 68 : {}
265 : :
266 : 2 : BareFunctionType::BareFunctionType (BareFunctionType const &other)
267 : 2 : : TypeNoBounds (other.mappings, other.locus),
268 : 2 : for_lifetimes (other.for_lifetimes),
269 : 2 : function_qualifiers (other.function_qualifiers), params (other.params),
270 : 2 : is_variadic (other.is_variadic),
271 : 2 : return_type (other.has_return_type () ? other.return_type->clone_type ()
272 : 2 : : nullptr)
273 : 2 : {}
274 : :
275 : : BareFunctionType &
276 : 0 : BareFunctionType::operator= (BareFunctionType const &other)
277 : : {
278 : 0 : mappings = other.mappings;
279 : 0 : for_lifetimes = other.for_lifetimes;
280 : 0 : function_qualifiers = other.function_qualifiers;
281 : 0 : params = other.params;
282 : 0 : is_variadic = other.is_variadic;
283 : 0 : return_type = other.return_type->clone_type ();
284 : 0 : locus = other.locus;
285 : :
286 : 0 : return *this;
287 : : }
288 : :
289 : : } // namespace HIR
290 : : } // namespace Rust
|