Branch data Line data Source code
1 : : // Copyright (C) 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_EQ_H
20 : : #define RUST_DERIVE_EQ_H
21 : :
22 : : #include "rust-derive.h"
23 : :
24 : : namespace Rust {
25 : : namespace AST {
26 : :
27 : : // FIXME: Need to figure out structuraleq marker trait
28 : :
29 : 2 : class DeriveEq : DeriveVisitor
30 : : {
31 : : public:
32 : : DeriveEq (location_t loc);
33 : :
34 : : std::vector<std::unique_ptr<AST::Item>> go (Item &item);
35 : :
36 : : private:
37 : : std::vector<std::unique_ptr<Item>> expanded;
38 : :
39 : : /**
40 : : * Create the actual `assert_receiver_is_total_eq` function of the
41 : : * implementation, which asserts that every type contained within our targeted
42 : : * type also implements `Eq`.
43 : : */
44 : : std::unique_ptr<AssociatedItem>
45 : : assert_receiver_is_total_eq_fn (std::vector<std::unique_ptr<Type>> &&types);
46 : :
47 : : /**
48 : : * Create the Eq trait implementation for a type
49 : : *
50 : : * impl Eq for <type> {
51 : : * <assert_receiver_is_total_eq>
52 : : * }
53 : : *
54 : : */
55 : : std::vector<std::unique_ptr<Item>>
56 : : eq_impls (std::unique_ptr<AssociatedItem> &&fn, std::string name,
57 : : const std::vector<std::unique_ptr<GenericParam>> &type_generics);
58 : :
59 : : /**
60 : : * Generate the following structure definition
61 : : *
62 : : * struct AssertParamIsEq<T: Eq + ?Sized> { _t: PhantomData<T> }
63 : : */
64 : : std::unique_ptr<Stmt> assert_param_is_eq ();
65 : :
66 : : /**
67 : : * Generate a let statement to assert a type implements `Eq`
68 : : *
69 : : * let _: AssertParamIsEq<type>;
70 : : */
71 : : std::unique_ptr<Stmt> assert_type_is_eq (std::unique_ptr<Type> &&type);
72 : :
73 : : virtual void visit_struct (StructStruct &item);
74 : : virtual void visit_tuple (TupleStruct &item);
75 : : virtual void visit_enum (Enum &item);
76 : : virtual void visit_union (Union &item);
77 : : };
78 : :
79 : : } // namespace AST
80 : : } // namespace Rust
81 : :
82 : : #endif // ! RUST_DERIVE_EQ_H
|