| eRPC Generator (erpcgen) Rev. 1.8.1 NXP Semiconductors

- Main Page
- Classes
- Files

- File List

AstNode.h
1 /*
2 * Copyright (c) 2014, Freescale Semiconductor, Inc.
3 * Copyright 2016 NXP
4 * All rights reserved.
5 *
6 *
7 * SPDX-License-Identifier: BSD-3-Clause
8 */
9
10 #ifndef _EMBEDDED_RPC__ASTNODE_H_
11 #define _EMBEDDED_RPC__ASTNODE_H_
12
13 #include "Token.h"
14 #include "smart_ptr.h"
15
16 #include <map>
17 #include <stack>
18 #include <string>
19 #include <typeinfo>
20 #include <vector>
21
23 // Classes
25
26 namespace erpcgen {
27
36 class AstNode
37 {
38 public:
39 typedef std::map<std::string, Value *> attribute_map_t;
41 typedef std::vector<AstNode *> child_list_t;
42 typedef child_list_t::iterator iterator;
43 typedef child_list_t::const_iterator const_iterator;
56 AstNode(const Token &token)
57 : m_token(token)
58 , m_parent(nullptr)
59 {
60 }
61
74 AstNode(Token &token, AstNode *parent)
75 : m_token(token)
76 , m_parent(parent)
77 {
78 }
79
90 AstNode(const AstNode &other);
91
103 AstNode &operator=(const AstNode &other);
104
110 virtual ~AstNode();
111
117 virtual AstNode *clone() const { return new AstNode(*this); }
118
124 virtual std::string nodeName() const { return typeid(*this).name(); }
125
127
128
135 Token &getToken() { return m_token; }
136
144 const Token &getToken() const { return m_token; }
145
151 void setToken(Token &token) { m_token = token; }
152
158 Value *getTokenValue() { return m_token.getValue(); }
159
165 std::string getTokenString() { return m_token.getValue() ? m_token.getValue()->toString() : ""; }
167
169
170
175 AstNode *getParent() const { return m_parent; }
176
182 void setParent(AstNode *newParent) { m_parent = newParent; }
184
186
187
192 size_t attributeCount() const { return m_attributes.size(); }
193
207 bool hasAttribute(const std::string &name) const;
208
222 Value *getAttribute(const std::string &name);
223
236 void setAttribute(const std::string &name, Value *node);
237
249 void removeAttribute(const std::string &name);
250
261 Value *&operator[](const std::string &name) { return m_attributes[name]; }
263
265
266
275 void appendChild(AstNode *node);
276
282 size_t childCount() const { return m_children.size(); }
283
294 AstNode *getChild(int index) const { return m_children[index]; }
295
307 size_t getIndexOfChild(AstNode *child);
308
317 size_t getIndex();
318
329 void replaceChild(AstNode *original, AstNode *replacement);
330
338 void reverseExpr();
339
352 AstNode *&operator[](int index) { return m_children[index]; }
353
366 const AstNode *operator[](int index) const { return m_children[index]; }
368
370
371 inline iterator begin() { return m_children.begin(); }
372 inline iterator end() { return m_children.end(); }
373 inline const_iterator begin() const { return m_children.begin(); }
374 inline const_iterator end() const { return m_children.end(); }
376
382 std::string getDescription() const;
383
384 protected:
385 Token m_token;
386 AstNode *m_parent;
387 attribute_map_t m_attributes;
388 child_list_t m_children;
389 };
390
394 class AstPrinter
395 {
396 public:
404 AstPrinter(AstNode *root)
405 : m_root(root)
406 , m_depth(0)
407 {
408 }
409
417 void dispatch() { dispatch(m_root, 0); }
418
428 void dispatch(AstNode *node, int childIndex = 0);
429
436 void print(AstNode *node, int childIndex = 0);
437
438 protected:
439 AstNode *m_root;
440 int m_depth;
441 std::stack<int> m_depthStack;
448 void printIndent(int indent) const;
449 };
450
451 } // namespace erpcgen
452
453 #endif // _EMBEDDED_RPC__ASTNODE_H_
erpcgen::AstNode::getChild
AstNode * getChild(int index) const
This function return child node from node children.
Definition: AstNode.h:294
erpcgen::AstNode::AstNode
AstNode(const Token &token)
This function is constructor of AstNode class.
Definition: AstNode.h:56
erpcgen::AstNode::getToken
Token & getToken()
This function returns token of this node.
Definition: AstNode.h:135
erpcgen::AstNode::getTokenString
std::string getTokenString()
This function returns string representation of this node token value.
Definition: AstNode.h:165
erpcgen::AstNode::setParent
void setParent(AstNode *newParent)
This function set parent for this node.
Definition: AstNode.h:182
erpcgen::AstNode::getAttribute
Value * getAttribute(const std::string &name)
This function return attribute from AstNode attributes.
Definition: AstNode.cpp:109
erpcgen::AstNode::operator[]
Value *& operator[](const std::string &name)
Square brackets.
Definition: AstNode.h:261
erpcgen::AstNode::removeAttribute
void removeAttribute(const std::string &name)
This function remove attribute from AstNode attributes.
Definition: AstNode.cpp:127
erpcgen::AstNode::getIndexOfChild
size_t getIndexOfChild(AstNode *child)
This function return index of searched child node.
Definition: AstNode.cpp:144
erpcgen::AstNode::setToken
void setToken(Token &token)
This function set token to this node.
Definition: AstNode.h:151
erpcgen::AstNode::m_token
Token m_token
Definition: AstNode.h:385
erpcgen::AstNode::const_iterator
child_list_t::const_iterator const_iterator
Definition: AstNode.h:43
erpcgen::AstNode::getParent
AstNode * getParent() const
This function returns pointer to parent node.
Definition: AstNode.h:175
erpcgen::AstNode::getToken
const Token & getToken() const
This function returns constant token of this node.
Definition: AstNode.h:144
erpcgen::AstNode::m_attributes
attribute_map_t m_attributes
Definition: AstNode.h:387
erpcgen::AstNode::clone
virtual AstNode * clone() const
This function returns an exact duplicate of this object.
Definition: AstNode.h:117
erpcgen::AstNode::m_children
child_list_t m_children
Definition: AstNode.h:388
erpcgen::AstNode::nodeName
virtual std::string nodeName() const
This function returns name of this node.
Definition: AstNode.h:124
erpcgen::AstNode::operator[]
const AstNode * operator[](int index) const
Square brackets.
Definition: AstNode.h:366
erpcgen::AstNode
Homogeneous AST node class.
Definition: AstNode.h:36
erpcgen::Token::getValue
Value * getValue()
This function returns token value.
Definition: Token.h:221
Value::toString
virtual std::string toString() const =0
Get Value type string representation.
erpcgen::AstNode::iterator
child_list_t::iterator iterator
Definition: AstNode.h:42
erpcgen::AstNode::getDescription
std::string getDescription() const
This function returns string description of the node.
Definition: AstNode.cpp:188
erpcgen::AstNode::attributeCount
size_t attributeCount() const
This function returns count of node attributes.
Definition: AstNode.h:192
erpcgen::AstNode::replaceChild
void replaceChild(AstNode *original, AstNode *replacement)
This function replace child in AstNode tree.
Definition: AstNode.cpp:180
Value
Abstract base class for values of arbitrary types.
Definition: Value.h:27
erpcgen::AstNode::setAttribute
void setAttribute(const std::string &name, Value *node)
This function set attribute in AstNode attributes.
Definition: AstNode.cpp:122
erpcgen::AstNode::childCount
size_t childCount() const
This function return count of children for current node.
Definition: AstNode.h:282
erpcgen::AstNode::reverseExpr
void reverseExpr()
This function replace children location in AstNode tree.
Definition: AstNode.cpp:163
erpcgen::AstNode::operator[]
AstNode *& operator[](int index)
Square brackets.
Definition: AstNode.h:352
erpcgen::AstNode::operator=
AstNode & operator=(const AstNode &other)
Assignment operator.
Definition: AstNode.cpp:52
erpcgen::AstNode::appendChild
void appendChild(AstNode *node)
This function add given node to the end of children list for current AstNode.
Definition: AstNode.cpp:135
erpcgen::AstNode::hasAttribute
bool hasAttribute(const std::string &name) const
This function find attribute in AstNode attributes.
Definition: AstNode.cpp:103
erpcgen::Token
Encapsulates all information about a token.
Definition: Token.h:60
erpcgen::AstNode::~AstNode
virtual ~AstNode()
This function is destructor of AstNode class.
Definition: AstNode.cpp:82
erpcgen::AstPrinter::m_root
AstNode * m_root
Definition: AstNode.h:439
erpcgen::AstPrinter::dispatch
void dispatch()
This function call for dispatch function.
Definition: AstNode.h:417
erpcgen::AstNode::getIndex
size_t getIndex()
This function return index of current node in parent&#39;s list of children.
Definition: AstNode.cpp:158
erpcgen::AstNode::child_list_t
std::vector< AstNode * > child_list_t
Definition: AstNode.h:41
erpcgen::AstNode::m_parent
AstNode * m_parent
Definition: AstNode.h:386
erpcgen::AstNode::getTokenValue
Value * getTokenValue()
This function returns value of token of this node.
Definition: AstNode.h:158
erpcgen::AstPrinter
Dumps an AST tree.
Definition: AstNode.h:394
erpcgen::AstNode::attribute_map_t
std::map< std::string, Value * > attribute_map_t
Definition: AstNode.h:39
erpcgen::AstPrinter::AstPrinter
AstPrinter(AstNode *root)
This function is constructor of AstPrinter class.
Definition: AstNode.h:404
erpcgen::AstPrinter::m_depth
int m_depth
Definition: AstNode.h:440
erpcgen
Definition: AstNode.h:26
erpcgen::AstNode::AstNode
AstNode(Token &token, AstNode *parent)
This function is constructor of AstNode class.
Definition: AstNode.h:74
erpcgen::AstPrinter::m_depthStack
std::stack< int > m_depthStack
Definition: AstNode.h:441