1 /**
2 * Copyright (c) 2021 - 2025 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 "util/es2pandaMacros.h"
21 #include <tuple>
22
23 namespace ark::es2panda::ir {
24 // CC-OFFNXT(G.PRE.02,G.PRE.09) name part
25 // NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
26 #define DECLARE_CLASSES(nodeType, className) class className;
27
28 AST_NODE_MAPPING(DECLARE_CLASSES)
29
30 #undef DECLARE_CLASSES
31 // CC-OFFNXT(G.PRE.02,G.PRE.09) name part
32 // NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
33 #define DECLARE_AST_NODE_CHECK_METHOD(_, __, nodeType, ___) class nodeType;
AST_NODE_REINTERPRET_MAPPING(DECLARE_AST_NODE_CHECK_METHOD)34 AST_NODE_REINTERPRET_MAPPING(DECLARE_AST_NODE_CHECK_METHOD)
35 #undef DECLARE_AST_NODE_CHECK_METHOD
36
37 namespace visitor {
38 /**
39 * All such Visitors should override VisitClassName(Node*) for all types
40 */
41 class ASTAbstractVisitor {
42 public:
43 // NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
44 #define DECLARE_CLASSES(nodeType, className) \
45 virtual void Visit##className(className *node) = 0; \
46 void Accept(className *node) \
47 { \
48 Visit##className(node); \
49 }
50
51 AST_NODE_MAPPING(DECLARE_CLASSES)
52
53 // NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
54 #define DECLARE_AST_NODE_CHECK_METHOD(nodeType1, nodeType2, baseClass, reinterpretClass) \
55 DECLARE_CLASSES(nodeType1, baseClass)
56
57 AST_NODE_REINTERPRET_MAPPING(DECLARE_AST_NODE_CHECK_METHOD)
58 #undef DECLARE_AST_NODE_CHECK_METHOD
59
60 #undef DECLARE_CLASSES
61 };
62 } // namespace visitor
63 } // namespace ark::es2panda::ir
64
65 #endif
66