eRPC Generator (erpcgen)  Rev. 1.7.0
NXP Semiconductors
SymbolScope.h
1 /*
2  * The Clear BSD License
3  * Copyright (c) 2014, Freescale Semiconductor, Inc.
4  * Copyright 2016 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__SYMBOLSCOPE_H_
37 #define _EMBEDDED_RPC__SYMBOLSCOPE_H_
38 
39 #include "Symbol.h"
40 #include <map>
41 #include <string>
42 #include <vector>
43 
45 // Classes
47 
48 namespace erpcgen {
49 
54 {
55 public:
56  typedef std::map<std::string, Symbol *> symbol_map_t;
57  typedef std::vector<Symbol *> symbol_vector_t;
60  {
61  public:
62  typedef symbol_vector_t::iterator vit;
63  typedef vit::value_type value_type;
64 
65  operator value_type &() { return *m_vec; }
66  value_type &operator*() { return *m_vec; }
67  value_type &operator->() { return *m_vec; }
68 
72  typed_iterator &operator++();
73 
74  bool operator==(const typed_iterator &other) { return (m_vec == other.m_vec); }
75  bool operator!=(const typed_iterator &other) { return !(*this == other); }
76 
77  private:
78  symbol_vector_t::iterator m_vec;
79  symbol_vector_t::iterator m_endvec;
80  Symbol::symbol_type_t m_predicateType;
81 
89  typed_iterator(const vit &bv, const vit &ev, Symbol::symbol_type_t predicateType);
90 
91  friend class SymbolScope;
92  };
93 
98  : m_symbolMap()
99  , m_symbolVector()
100  , m_parent(nullptr)
101  {
102  }
103 
107  virtual ~SymbolScope() {}
108 
124  bool hasSymbol(const std::string &name, bool recursive = true);
125 
141  Symbol *getSymbol(const std::string &name, bool recursive = true);
142 
156  void addSymbol(Symbol *sym, int32_t pos = -1);
157 
170  void replaceSymbol(Symbol *oldSym, Symbol *newSym);
171 
184  int32_t getSymbolPos(Symbol *sym);
185 
192  bool hasParent() const { return m_parent != nullptr; }
193 
200 
206  void setParent(SymbolScope *parent) { m_parent = parent; }
207 
213  symbol_vector_t::iterator begin() { return m_symbolVector.begin(); }
214 
220  symbol_vector_t::iterator end() { return m_symbolVector.end(); }
221 
228 
235 
246  symbol_vector_t getSymbolsOfType(Symbol::symbol_type_t predicateType);
247 
253  symbol_vector_t getSymbolVector() { return m_symbolVector; }
254 
269  void dump();
270 
274  void clear();
275 
276 protected:
277  symbol_map_t m_symbolMap;
278  symbol_vector_t m_symbolVector;
280 };
281 
282 } // namespace erpcgen
283 
284 #endif // _EMBEDDED_RPC__SYMBOLSCOPE_H_
symbol_vector_t::iterator end()
Return end of symbol vector.
Definition: SymbolScope.h:220
void replaceSymbol(Symbol *oldSym, Symbol *newSym)
This function will replace old symbol with new symbol in the symbol scope.
Definition: Type.cpp:250
typed_iterator tend(Symbol::symbol_type_t predicateType)
Definition: Type.cpp:172
void addSymbol(Symbol *sym, int32_t pos=-1)
This function will add symbol to the symbol scope.
Definition: Type.cpp:217
virtual ~SymbolScope()
Destructor.
Definition: SymbolScope.h:107
Symbol * getSymbol(const std::string &name, bool recursive=true)
This function will return symbol.
Definition: Type.cpp:200
bool hasParent() const
Return boolean representation about existence of parent.
Definition: SymbolScope.h:192
void clear()
Erase data from m_symbolMap and m_symbolVector.
Definition: Type.cpp:288
Base class for all named declarations in the IDL.
Definition: Symbol.h:53
symbol_vector_t::iterator begin()
Return begin of symbol vector.
Definition: SymbolScope.h:213
symbol_vector_t m_symbolVector
Definition: SymbolScope.h:278
void setParent(SymbolScope *parent)
This function set parent for this object.
Definition: SymbolScope.h:206
SymbolScope()
Constructor.
Definition: SymbolScope.h:97
symbol_vector_t getSymbolsOfType(Symbol::symbol_type_t predicateType)
This function returns symbol vector with symbols.
Definition: Type.cpp:177
typed_iterator tbegin(Symbol::symbol_type_t predicateType)
Definition: Type.cpp:167
bool hasSymbol(const std::string &name, bool recursive=true)
This function returns true when name is found in symbol map.
Definition: Type.cpp:190
A scoped namespace containing symbols.
Definition: SymbolScope.h:53
std::vector< Symbol * > symbol_vector_t
Definition: SymbolScope.h:57
SymbolScope * getParent()
Return pointer to parent.
Definition: SymbolScope.h:199
Definition: SymbolScope.h:59
symbol_vector_t getSymbolVector()
This function returns symbol vector.
Definition: SymbolScope.h:253
symbol_map_t m_symbolMap
Definition: SymbolScope.h:277
int32_t getSymbolPos(Symbol *sym)
This function will return symbol position.
Definition: Type.cpp:266
void dump()
This function show debug description about the all symbols.
Definition: Type.cpp:278
SymbolScope * m_parent
Definition: SymbolScope.h:279
symbol_type_t
Supported symbol types.
Definition: Symbol.h:59
Definition: AstNode.h:51
std::map< std::string, Symbol * > symbol_map_t
Definition: SymbolScope.h:56