1 /**
2 * Copyright (c) 2021 - 2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #ifndef ES2PANDA_COMPILER_CORE_AST_VISITOR_H
17 #define ES2PANDA_COMPILER_CORE_AST_VISITOR_H
18
19 #include <ir/astNodeMapping.h>
20 #include "macros.h"
21
22 #include <tuple>
23
24 namespace ark::es2panda::ir {
25 // CC-OFFNXT(G.PRE.02,G.PRE.09) name part
26 // NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
27 #define DECLARE_CLASSES(nodeType, className) class className;
28
29 AST_NODE_MAPPING(DECLARE_CLASSES)
30
31 #undef DECLARE_CLASSES
32 // CC-OFFNXT(G.PRE.02,G.PRE.09) name part
33 // NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
34 #define DECLARE_AST_NODE_CHECK_METHOD(_, __, nodeType, ___) class nodeType;
AST_NODE_REINTERPRET_MAPPING(DECLARE_AST_NODE_CHECK_METHOD)35 AST_NODE_REINTERPRET_MAPPING(DECLARE_AST_NODE_CHECK_METHOD)
36 #undef DECLARE_AST_NODE_CHECK_METHOD
37
38 namespace visitor {
39 /**
40 * All such Visitors should override VisitClassName(Node*) for all types
41 */
42 class ASTAbstractVisitor {
43 public:
44 // NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
45 #define DECLARE_CLASSES(nodeType, className) \
46 virtual void Visit##className(className *node) = 0; \
47 void Accept(className *node) \
48 { \
49 Visit##className(node); \
50 }
51
52 AST_NODE_MAPPING(DECLARE_CLASSES)
53
54 // NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
55 #define DECLARE_AST_NODE_CHECK_METHOD(nodeType1, nodeType2, baseClass, reinterpretClass) \
56 DECLARE_CLASSES(nodeType1, baseClass)
57
58 AST_NODE_REINTERPRET_MAPPING(DECLARE_AST_NODE_CHECK_METHOD)
59 #undef DECLARE_AST_NODE_CHECK_METHOD
60
61 #undef DECLARE_CLASSES
62 };
63 } // namespace visitor
64 } // namespace ark::es2panda::ir
65
66 #endif
67