Debian Codegraph @

gcc/rust/hir/tree/rust-hir-type-abstract.h

raw
1 // Copyright (C) 2020-2024 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_HIR_TYPE_ABSTRACT_H
20 #define RUST_HIR_TYPE_ABSTRACT_H
21
22 #include "rust-hir-node.h"
23 #include "rust-hir-visitable.h"
24 #include "rust-system.h"
25 #include "rust-hir-map.h"
26
27 namespace Rust {
28 namespace HIR {
29
30 class TraitBound;
31
32 // Base class for types as represented in HIR - abstract
33 class Type : public Node, public FullVisitable
34 {
35 public:
36 using FullVisitable::accept_vis;
37 // Unique pointer custom clone function
38 std::unique_ptr<Type> clone_type () const
39 {
40 return std::unique_ptr<Type> (clone_type_impl ());
41 }
42
43 // virtual destructor
44 virtual ~Type () {}
45
46 BaseKind get_hir_kind () override final { return TYPE; }
47
48 virtual std::string as_string () const = 0;
49
50 /* HACK: convert to trait bound. Virtual method overriden by classes that
51 * enable this. */
52 virtual std::unique_ptr<TraitBound>
53 to_trait_bound (bool in_parens ATTRIBUTE_UNUSED) const;
54 /* as pointer, shouldn't require definition beforehand, only forward
55 * declaration. */
56
57 virtual void accept_vis (HIRTypeVisitor &vis) = 0;
58
59 virtual const Analysis::NodeMapping &get_mappings () const
60 {
61 return mappings;
62 }
63 virtual location_t get_locus () const { return locus; }
64
65 protected:
66 Type (Analysis::NodeMapping mappings, location_t locus)
67 : mappings (mappings), locus (locus)
68 {}
69
70 // Clone function implementation as pure virtual method
71 virtual Type *clone_type_impl () const = 0;
72
73 Analysis::NodeMapping mappings;
74 location_t locus;
75 };
76
77 } // namespace HIR
78 } // namespace Rust
79
80 #endif