1 /**
2  * Copyright (c) 2021 - 2023 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 // 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 // NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
32 #define DECLARE_AST_NODE_CHECK_METHOD(_, __, nodeType, ___) class nodeType;
33 AST_NODE_REINTERPRET_MAPPING(DECLARE_AST_NODE_CHECK_METHOD)
34 #undef DECLARE_AST_NODE_CHECK_METHOD
35 
36 namespace visitor {
37 /**
38  * All such Visitors should override VisitClassName(Node*) for all types
39  */
40 class ASTAbstractVisitor {
41 public:
42 // NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
43 #define DECLARE_CLASSES(nodeType, className)            \
44     virtual void Visit##className(className *node) = 0; \
45     void Accept(className *node)                        \
46     {                                                   \
47         Visit##className(node);                         \
48     }
49 
50     AST_NODE_MAPPING(DECLARE_CLASSES)
51 
52 // NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
53 #define DECLARE_AST_NODE_CHECK_METHOD(nodeType1, nodeType2, baseClass, reinterpretClass) \
54     DECLARE_CLASSES(nodeType1, baseClass)
55 
56     AST_NODE_REINTERPRET_MAPPING(DECLARE_AST_NODE_CHECK_METHOD)
57 #undef DECLARE_AST_NODE_CHECK_METHOD
58 
59 #undef DECLARE_CLASSES
60 };
61 }  // namespace visitor
62 }  // namespace ark::es2panda::ir
63 
64 #endif
65