Branch data Line data Source code
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_BIR_VISITOR_H
20 : : #define RUST_BIR_VISITOR_H
21 : :
22 : : namespace Rust {
23 : : namespace BIR {
24 : :
25 : : class Statement;
26 : : class InitializerExpr;
27 : : template <unsigned N> class Operator;
28 : : class Assignment;
29 : : class BorrowExpr;
30 : : class CallExpr;
31 : :
32 : 36 : class Visitor
33 : : {
34 : : public:
35 : : virtual void visit (const Statement &stmt) = 0;
36 : : virtual void visit (const InitializerExpr &expr) = 0;
37 : : virtual void visit (const Operator<1> &expr) = 0;
38 : : virtual void visit (const Operator<2> &expr) = 0;
39 : : virtual void visit (const BorrowExpr &expr) = 0;
40 : : virtual void visit (const Assignment &expr) = 0;
41 : : virtual void visit (const CallExpr &expr) = 0;
42 : : };
43 : :
44 : 185 : class Visitable
45 : : {
46 : : public:
47 : : virtual void accept_vis (Visitor &visitor) = 0;
48 : : };
49 : :
50 : : template <typename BASE, typename T> class VisitableImpl : public BASE
51 : : {
52 : : public:
53 : : template <typename... Args>
54 : 185 : explicit VisitableImpl (Args &&... args) : BASE (std::forward<Args> (args)...)
55 : : {}
56 : :
57 : 185 : void accept_vis (Visitor &visitor) override
58 : : {
59 : 185 : visitor.visit (static_cast<T &> (*this));
60 : 185 : }
61 : : };
62 : :
63 : : } // namespace BIR
64 : : } // namespace Rust
65 : :
66 : : #endif // RUST_BIR_VISITOR_H
|