eRPC Generator (erpcgen)  Rev. 1.7.0
NXP Semiconductors
AstWalker.h
1 /*
2  * The Clear BSD License
3  * Copyright (c) 2014, Freescale Semiconductor, Inc.
4  * Copyright 2016-2017 NXP
5  * All rights reserved.
6  *
7  *
8  * Redistribution and use in source and binary forms, with or without modification,
9  * are permitted (subject to the limitations in the disclaimer below) provided
10  * that the following conditions are met:
11  *
12  * o Redistributions of source code must retain the above copyright notice, this list
13  * of conditions and the following disclaimer.
14  *
15  * o Redistributions in binary form must reproduce the above copyright notice, this
16  * list of conditions and the following disclaimer in the documentation and/or
17  * other materials provided with the distribution.
18  *
19  * o Neither the name of the copyright holder nor the names of its
20  * contributors may be used to endorse or promote products derived from this
21  * software without specific prior written permission.
22  *
23  * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE.
24  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
25  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
26  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
28  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
29  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
31  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34  */
35 
36 #ifndef _EMBEDDED_RPC__ASTWALKER_H_
37 #define _EMBEDDED_RPC__ASTWALKER_H_
38 
39 #include "AstNode.h"
40 
42 // Classes
44 
45 namespace erpcgen {
46 
67 class AstWalker
68 {
69 public:
73  AstWalker() = default;
74 
82  AstWalker(std::string inputFile)
83  : m_fileName(inputFile)
84  {
85  }
86 
90  virtual ~AstWalker() = default;
91 
100  virtual void startWalk(AstNode *node);
101 
102 protected:
103  std::string m_fileName;
104  struct top_down
105  {
106  };
107  struct bottom_up
108  {
109  };
121  virtual void walk(AstNode *node);
122 
137  template <typename D>
138  void dispatch(AstNode *node);
139 
140  /*
141  * @name Top-down handlers
142  *
143  * @brief Top-down handlers types, which can be called.
144  */
146  virtual void handleRoot(AstNode *node, top_down){};
147  virtual AstNode *handleProgram(AstNode *node, top_down) { return nullptr; }
148  virtual AstNode *handleConst(AstNode *node, top_down) { return nullptr; }
149  virtual AstNode *handleChildren(AstNode *node, top_down) { return nullptr; }
150  virtual AstNode *handleType(AstNode *node, top_down) { return nullptr; }
151  virtual AstNode *handleEnum(AstNode *node, top_down) { return nullptr; }
152  virtual AstNode *handleEnumMember(AstNode *node, top_down) { return nullptr; }
153  virtual AstNode *handleStruct(AstNode *node, top_down) { return nullptr; }
154  virtual AstNode *handleStructMember(AstNode *node, top_down) { return nullptr; }
155  virtual AstNode *handleUnion(AstNode *node, top_down) { return nullptr; }
156  virtual AstNode *handleUnionCase(AstNode *node, top_down) { return nullptr; }
157  virtual AstNode *handleInterface(AstNode *node, top_down) { return nullptr; }
158  virtual AstNode *handleFunction(AstNode *node, top_down) { return nullptr; }
159  virtual AstNode *handleParam(AstNode *node, top_down) { return nullptr; }
160  virtual AstNode *handleExpr(AstNode *node, top_down) { return nullptr; }
161  virtual AstNode *handleBinaryOp(AstNode *node, top_down) { return nullptr; }
162  virtual AstNode *handleUnaryOp(AstNode *node, top_down) { return nullptr; }
163  virtual AstNode *handleAnnotation(AstNode *node, top_down) { return nullptr; }
165 
166  /*
167  * @name Bottom-up handlers
168  *
169  * @brief Bottom-up handlers types, which can be called.
170  */
172  virtual void handleRoot(AstNode *node, bottom_up){};
173  virtual AstNode *handleProgram(AstNode *node, bottom_up) { return nullptr; }
174  virtual AstNode *handleConst(AstNode *node, bottom_up) { return nullptr; }
175  virtual AstNode *handleChildren(AstNode *node, bottom_up) { return nullptr; }
176  virtual AstNode *handleType(AstNode *node, bottom_up) { return nullptr; }
177  virtual AstNode *handleEnum(AstNode *node, bottom_up) { return nullptr; }
178  virtual AstNode *handleEnumMember(AstNode *node, bottom_up) { return nullptr; }
179  virtual AstNode *handleStruct(AstNode *node, bottom_up) { return nullptr; }
180  virtual AstNode *handleStructMember(AstNode *node, bottom_up) { return nullptr; }
181  virtual AstNode *handleUnion(AstNode *node, bottom_up) { return nullptr; }
182  virtual AstNode *handleUnionCase(AstNode *node, bottom_up) { return nullptr; }
183  virtual AstNode *handleInterface(AstNode *node, bottom_up) { return nullptr; }
184  virtual AstNode *handleFunction(AstNode *node, bottom_up) { return nullptr; }
185  virtual AstNode *handleParam(AstNode *node, bottom_up) { return nullptr; }
186  virtual AstNode *handleExpr(AstNode *node, bottom_up) { return nullptr; }
187  virtual AstNode *handleBinaryOp(AstNode *node, bottom_up) { return nullptr; }
188  virtual AstNode *handleUnaryOp(AstNode *node, bottom_up) { return nullptr; }
189  virtual AstNode *handleAnnotation(AstNode *node, bottom_up) { return nullptr; }
191 };
192 
193 } // namespace erpcgen
194 
195 #endif // _EMBEDDED_RPC__ASTWALKER_H_
std::string m_fileName
Stores name of file from which AST was built.
Definition: AstWalker.h:103
AstWalker()=default
default constructor
virtual void walk(AstNode *node)
This function walk the AstNode depth-first and invoke handler methods.
Definition: AstWalker.cpp:55
virtual ~AstWalker()=default
destructor
Homogeneous AST node class.
Definition: AstNode.h:61
Performs a depth-first walk of an AST.
Definition: AstWalker.h:67
void dispatch(AstNode *node)
This function invoke the appropriate handler method for the node&#39;s token type..
Definition: AstWalker.cpp:75
Specifier type to select bottom-up handler using ADL.
Definition: AstWalker.h:107
AstWalker(std::string inputFile)
Constructor.
Definition: AstWalker.h:82
Definition: AstNode.h:51
virtual void startWalk(AstNode *node)
This function walk the AstNode depth-first and invoke handler methods.
Definition: AstWalker.cpp:46
Specifier type to select top-down handler using ADL.
Definition: AstWalker.h:104