Branch data Line data Source code
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_PATTERN_ABSTRACT_H
20 : : #define RUST_HIR_PATTERN_ABSTRACT_H
21 : :
22 : : #include "rust-hir-visitable.h"
23 : : #include "rust-hir-visitor.h"
24 : : #include "rust-hir-node.h"
25 : : #include "rust-system.h"
26 : :
27 : : namespace Rust {
28 : : namespace HIR {
29 : :
30 : : // Pattern base HIR node
31 : 81883 : class Pattern : public Node, virtual public FullVisitable
32 : : {
33 : : public:
34 : : using FullVisitable::accept_vis;
35 : :
36 : : enum PatternType
37 : : {
38 : : PATH,
39 : : LITERAL,
40 : : IDENTIFIER,
41 : : WILDCARD,
42 : : RANGE,
43 : : REFERENCE,
44 : : STRUCT,
45 : : TUPLE_STRUCT,
46 : : TUPLE,
47 : : GROUPED,
48 : : SLICE,
49 : : ALT
50 : : };
51 : :
52 : 0 : BaseKind get_hir_kind () override final { return PATTERN; }
53 : :
54 : : // Unique pointer custom clone function
55 : 31058 : std::unique_ptr<Pattern> clone_pattern () const
56 : : {
57 : 31058 : return std::unique_ptr<Pattern> (clone_pattern_impl ());
58 : : }
59 : :
60 : : // possible virtual methods: is_refutable()
61 : :
62 : : virtual ~Pattern () {}
63 : :
64 : : virtual std::string as_string () const = 0;
65 : :
66 : : virtual void accept_vis (HIRPatternVisitor &vis) = 0;
67 : :
68 : : virtual const Analysis::NodeMapping &get_mappings () const = 0;
69 : :
70 : : virtual location_t get_locus () const = 0;
71 : :
72 : : virtual PatternType get_pattern_type () const = 0;
73 : :
74 : : protected:
75 : : // Clone pattern implementation as pure virtual method
76 : : virtual Pattern *clone_pattern_impl () const = 0;
77 : : };
78 : :
79 : : } // namespace HIR
80 : : } // namespace Rust
81 : :
82 : : #endif
|