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_PARTIAL_EQ_H
20 : : #define RUST_DERIVE_PARTIAL_EQ_H
21 : :
22 : : #include "rust-derive.h"
23 : : #include "rust-path.h"
24 : : #include "rust-derive-cmp-common.h"
25 : :
26 : : namespace Rust {
27 : : namespace AST {
28 : :
29 : 92 : class DerivePartialEq : DeriveVisitor
30 : : {
31 : : public:
32 : : DerivePartialEq (location_t loc);
33 : :
34 : : std::vector<std::unique_ptr<Item>> go (Item &item);
35 : :
36 : : private:
37 : : std::vector<std::unique_ptr<Item>> expanded;
38 : :
39 : : /**
40 : : * Generate both an implementation of `PartialEq` and `StructuralPartialEq`
41 : : * for the given type
42 : : */
43 : : std::vector<std::unique_ptr<Item>> partialeq_impls (
44 : : std::unique_ptr<AssociatedItem> &&eq_fn, std::string name,
45 : : const std::vector<std::unique_ptr<GenericParam>> &type_generics);
46 : :
47 : : std::unique_ptr<AssociatedItem> eq_fn (std::unique_ptr<BlockExpr> &&block,
48 : : std::string type_name);
49 : :
50 : : /**
51 : : * Build a suite of equality arithmetic expressions chained together by a
52 : : * boolean AND operator
53 : : */
54 : : std::unique_ptr<Expr>
55 : : build_eq_expression (std::vector<SelfOther> &&field_expressions);
56 : :
57 : : MatchCase match_enum_identifier (PathInExpression variant_path,
58 : : const std::unique_ptr<EnumItem> &variant);
59 : : MatchCase match_enum_tuple (PathInExpression variant_path,
60 : : const EnumItemTuple &variant);
61 : : MatchCase match_enum_struct (PathInExpression variant_path,
62 : : const EnumItemStruct &variant);
63 : :
64 : : constexpr static const char *self_discr = "#self_discr";
65 : : constexpr static const char *other_discr = "#other_discr";
66 : :
67 : : virtual void visit_struct (StructStruct &item) override;
68 : : virtual void visit_tuple (TupleStruct &item) override;
69 : : virtual void visit_enum (Enum &item) override;
70 : : virtual void visit_union (Union &item) override;
71 : : };
72 : :
73 : : } // namespace AST
74 : : } // namespace Rust
75 : :
76 : : #endif // ! RUST_DERIVE_PARTIAL_EQ_H
|