Line data Source code
1 :
2 : // Copyright (C) 2020-2026 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 32 : ImplTraitType::ImplTraitType (
26 : Analysis::NodeMapping mappings,
27 : std::vector<std::unique_ptr<TypeParamBound>> type_param_bounds,
28 32 : location_t locus)
29 32 : : Type (mappings, locus), type_param_bounds (std::move (type_param_bounds))
30 32 : {}
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 167 : TraitObjectType::TraitObjectType (
54 : Analysis::NodeMapping mappings,
55 : std::vector<std::unique_ptr<TypeParamBound>> type_param_bounds,
56 167 : location_t locus, bool is_dyn_dispatch)
57 167 : : Type (mappings, locus), has_dyn (is_dyn_dispatch),
58 167 : type_param_bounds (std::move (type_param_bounds))
59 167 : {}
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 6 : ParenthesisedType::ParenthesisedType (Analysis::NodeMapping mappings,
83 : std::unique_ptr<Type> type_inside_parens,
84 6 : location_t locus)
85 : : TypeNoBounds (mappings, locus),
86 6 : type_in_parens (std::move (type_inside_parens))
87 6 : {}
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) const
105 : {
106 : /* If already in parentheses, don't convert - should stay as
107 : * ParenthesisedType */
108 0 : if (in_parens)
109 0 : return nullptr;
110 :
111 : /* NOTE: obviously it is unknown whether the internal type is a trait bound
112 : * due to polymorphism, so just let the internal type handle it. As
113 : * parenthesised type, it must be in parentheses. */
114 0 : return type_in_parens->to_trait_bound (true);
115 : }
116 :
117 453 : TupleType::TupleType (Analysis::NodeMapping mappings,
118 : std::vector<std::unique_ptr<Type>> elems,
119 453 : location_t locus)
120 453 : : TypeNoBounds (mappings, locus), elems (std::move (elems))
121 453 : {}
122 :
123 38 : TupleType::TupleType (TupleType const &other)
124 38 : : TypeNoBounds (other.mappings, other.locus)
125 : {
126 38 : mappings = other.mappings;
127 38 : elems.reserve (other.elems.size ());
128 72 : for (const auto &e : other.elems)
129 34 : elems.push_back (e->clone_type ());
130 38 : }
131 :
132 : TupleType &
133 0 : TupleType::operator= (TupleType const &other)
134 : {
135 0 : locus = other.locus;
136 :
137 0 : elems.reserve (other.elems.size ());
138 0 : for (const auto &e : other.elems)
139 0 : elems.push_back (e->clone_type ());
140 :
141 0 : return *this;
142 : }
143 :
144 47 : NeverType::NeverType (Analysis::NodeMapping mappings, location_t locus)
145 47 : : TypeNoBounds (mappings, locus)
146 47 : {}
147 :
148 6488 : RawPointerType::RawPointerType (Analysis::NodeMapping mappings, Mutability mut,
149 6488 : std::unique_ptr<Type> type, location_t locus)
150 6488 : : TypeNoBounds (mappings, locus), mut (mut), type (std::move (type))
151 6488 : {}
152 :
153 0 : RawPointerType::RawPointerType (RawPointerType const &other)
154 0 : : TypeNoBounds (other.mappings, other.locus), mut (other.mut),
155 0 : type (other.type->clone_type ())
156 0 : {}
157 :
158 : RawPointerType &
159 0 : RawPointerType::operator= (RawPointerType const &other)
160 : {
161 0 : mappings = other.mappings;
162 0 : mut = other.mut;
163 0 : type = other.type->clone_type ();
164 0 : locus = other.locus;
165 0 : return *this;
166 : }
167 :
168 4379 : ReferenceType::ReferenceType (Analysis::NodeMapping mappings, Mutability mut,
169 : std::unique_ptr<Type> type_no_bounds,
170 4379 : location_t locus, tl::optional<Lifetime> lifetime)
171 4379 : : TypeNoBounds (mappings, locus), lifetime (std::move (lifetime)), mut (mut),
172 4379 : type (std::move (type_no_bounds))
173 4379 : {}
174 :
175 672 : ReferenceType::ReferenceType (ReferenceType const &other)
176 1344 : : TypeNoBounds (other.mappings, other.locus), lifetime (other.lifetime),
177 672 : mut (other.mut), type (other.type->clone_type ())
178 672 : {}
179 :
180 : ReferenceType &
181 0 : ReferenceType::operator= (ReferenceType const &other)
182 : {
183 0 : mappings = other.mappings;
184 0 : lifetime = other.lifetime;
185 0 : mut = other.mut;
186 0 : type = other.type->clone_type ();
187 0 : locus = other.locus;
188 :
189 0 : return *this;
190 : }
191 :
192 663 : ArrayType::ArrayType (Analysis::NodeMapping mappings,
193 : std::unique_ptr<Type> type,
194 663 : std::unique_ptr<Expr> array_size, location_t locus)
195 663 : : TypeNoBounds (mappings, locus), elem_type (std::move (type)),
196 663 : size (std::move (array_size))
197 663 : {}
198 :
199 7 : ArrayType::ArrayType (ArrayType const &other)
200 7 : : TypeNoBounds (other.mappings, other.locus),
201 7 : elem_type (other.elem_type->clone_type ()), size (other.size->clone_expr ())
202 7 : {}
203 :
204 : ArrayType &
205 0 : ArrayType::operator= (ArrayType const &other)
206 : {
207 0 : mappings = other.mappings;
208 0 : elem_type = other.elem_type->clone_type ();
209 0 : size = other.size->clone_expr ();
210 0 : locus = other.locus;
211 0 : return *this;
212 : }
213 :
214 841 : SliceType::SliceType (Analysis::NodeMapping mappings,
215 841 : std::unique_ptr<Type> type, location_t locus)
216 841 : : TypeNoBounds (mappings, locus), elem_type (std::move (type))
217 841 : {}
218 :
219 503 : SliceType::SliceType (SliceType const &other)
220 503 : : TypeNoBounds (other.mappings, other.locus),
221 503 : elem_type (other.elem_type->clone_type ())
222 503 : {}
223 :
224 : SliceType &
225 0 : SliceType::operator= (SliceType const &other)
226 : {
227 0 : mappings = other.mappings;
228 0 : elem_type = other.elem_type->clone_type ();
229 0 : locus = other.locus;
230 :
231 0 : return *this;
232 : }
233 :
234 206 : InferredType::InferredType (Analysis::NodeMapping mappings, location_t locus)
235 206 : : TypeNoBounds (mappings, locus)
236 206 : {}
237 :
238 46 : MaybeNamedParam::MaybeNamedParam (Identifier name, ParamKind param_kind,
239 : std::unique_ptr<Type> param_type,
240 46 : location_t locus)
241 46 : : param_type (std::move (param_type)), param_kind (param_kind),
242 46 : name (std::move (name)), locus (locus)
243 46 : {}
244 :
245 0 : MaybeNamedParam::MaybeNamedParam (MaybeNamedParam const &other)
246 0 : : param_type (other.param_type->clone_type ()), param_kind (other.param_kind),
247 0 : name (other.name), locus (other.locus)
248 0 : {}
249 :
250 : MaybeNamedParam &
251 0 : MaybeNamedParam::operator= (MaybeNamedParam const &other)
252 : {
253 0 : name = other.name;
254 0 : param_kind = other.param_kind;
255 0 : param_type = other.param_type->clone_type ();
256 0 : locus = other.locus;
257 :
258 0 : return *this;
259 : }
260 :
261 62 : BareFunctionType::BareFunctionType (
262 : Analysis::NodeMapping mappings, std::vector<LifetimeParam> lifetime_params,
263 : FunctionQualifiers qualifiers, std::vector<MaybeNamedParam> named_params,
264 62 : bool is_variadic, std::unique_ptr<Type> type, location_t locus)
265 62 : : TypeNoBounds (mappings, locus), for_lifetimes (std::move (lifetime_params)),
266 62 : function_qualifiers (std::move (qualifiers)),
267 62 : params (std::move (named_params)), is_variadic (is_variadic),
268 62 : return_type (std::move (type))
269 62 : {}
270 :
271 13 : BareFunctionType::BareFunctionType (BareFunctionType const &other)
272 13 : : TypeNoBounds (other.mappings, other.locus),
273 13 : for_lifetimes (other.for_lifetimes),
274 13 : function_qualifiers (other.function_qualifiers), params (other.params),
275 13 : is_variadic (other.is_variadic),
276 13 : return_type (other.has_return_type () ? other.return_type->clone_type ()
277 13 : : nullptr)
278 13 : {}
279 :
280 : BareFunctionType &
281 0 : BareFunctionType::operator= (BareFunctionType const &other)
282 : {
283 0 : mappings = other.mappings;
284 0 : for_lifetimes = other.for_lifetimes;
285 0 : function_qualifiers = other.function_qualifiers;
286 0 : params = other.params;
287 0 : is_variadic = other.is_variadic;
288 0 : return_type = other.return_type->clone_type ();
289 0 : locus = other.locus;
290 :
291 0 : return *this;
292 : }
293 :
294 : } // namespace HIR
295 : } // namespace Rust
|