Debian Codegraph @

gcc/rust/expand/rust-derive-clone.h

raw
1 // Copyright (C) 2020-2025 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_DERIVE_CLONE_H
20 #define RUST_DERIVE_CLONE_H
21
22 #include "rust-derive.h"
23
24 namespace Rust {
25 namespace AST {
26
27 class DeriveClone : DeriveVisitor
28 {
29 public:
30 DeriveClone (location_t loc);
31
32 std::unique_ptr<AST::Item> go (Item &item);
33
34 private:
35 std::unique_ptr<Item> expanded;
36
37 /**
38 * Create a call to "clone". For now, this creates a call to
39 * `Clone::clone`, but should ultimately call into
40 * `::core::clone::Clone::clone`
41 *
42 * Clone::clone(<to_clone>)
43 */
44 std::unique_ptr<Expr> clone_call (std::unique_ptr<Expr> &&to_clone);
45
46 /**
47 * Create the actual "clone" function of the implementation, so
48 *
49 * fn clone(&self) -> Self { <clone_expr> }
50 *
51 */
52 std::unique_ptr<AssociatedItem> clone_fn (std::unique_ptr<Expr> &&clone_expr);
53
54 /**
55 * Create the Clone trait implementation for a type
56 *
57 * impl Clone for <type> {
58 * <clone_fn>
59 * }
60 *
61 */
62 std::unique_ptr<Item>
63 clone_impl (std::unique_ptr<AssociatedItem> &&clone_fn, std::string name,
64 const std::vector<std::unique_ptr<GenericParam>> &type_generics);
65
66 /**
67 * Get the path to use for matching and creating a variant when matching on an
68 * enum. E.g. for the `Option` enum, with the `None` variant, this will create
69 * a path `Option::None`
70 */
71 PathInExpression variant_match_path (Enum &item, const Identifier &variant);
72
73 /**
74 * Implementation of clone for all possible variants of an enum
75 */
76 MatchCase clone_enum_identifier (PathInExpression variant_path,
77 const std::unique_ptr<EnumItem> &variant);
78 MatchCase clone_enum_tuple (PathInExpression variant_path,
79 const EnumItemTuple &variant);
80 MatchCase clone_enum_struct (PathInExpression variant_path,
81 const EnumItemStruct &variant);
82
83 virtual void visit_struct (StructStruct &item);
84 virtual void visit_tuple (TupleStruct &item);
85 virtual void visit_enum (Enum &item);
86 virtual void visit_union (Union &item);
87 };
88
89 } // namespace AST
90 } // namespace Rust
91
92 #endif // ! RUST_DERIVE_CLONE_H