eRPC Generator (erpcgen)  Rev. 1.7.0
NXP Semiconductors
Symbol.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__SYMBOL_H_
37 #define _EMBEDDED_RPC__SYMBOL_H_
38 
39 #include "Annotation.h"
40 #include "AstNode.h"
41 #include "Token.h"
42 #include <vector>
43 
45 // Classes
47 
48 namespace erpcgen {
49 
53 class Symbol
54 {
55 public:
60  {
61  kConstSymbol,
62  kEnumMemberSymbol,
63  kFunctionSymbol,
64  kInterfaceSymbol,
65  kProgramSymbol,
66  kStructMemberSymbol,
67  kTypenameSymbol,
68  kUnionCaseMemberSymbol,
69 
70  kAliasTypeSymbol,
71  kArrayTypeSymbol,
72  kBuiltinTypeSymbol,
73  kEnumTypeSymbol,
74  kFunctionTypeSymbol,
75  kListTypeSymbol,
76  kStructTypeSymbol,
77  kUnionTypeSymbol
78  };
79 
88  : m_symbolType(symType)
89  , m_name()
90  , m_location()
91  , m_annotations()
92  , m_mlComment("")
93  , m_ilComment("")
94  {
95  }
96 
105  Symbol(symbol_type_t symType, const std::string &name)
106  : m_symbolType(symType)
107  , m_name(name)
108  , m_location()
109  , m_annotations()
110  , m_mlComment("")
111  , m_ilComment("")
112  {
113  }
114 
123  Symbol(symbol_type_t symType, const Token &tok)
124  : m_symbolType(symType)
125  , m_name(tok.getStringValue())
126  , m_location(tok.getLocation())
127  , m_annotations()
128  , m_mlComment("")
129  , m_ilComment("")
130  {
131  }
132 
136  virtual ~Symbol() {}
137 
144 
150  const std::string &getName() const { return m_name; }
151 
157  void setName(const std::string &newName) { m_name = newName; }
158 
165 
171  void setLocation(const token_loc_t &loc) { m_location = loc; }
172 
178  int getFirstLine() const { return m_location.m_firstLine; }
179 
185  int getLastLine() const { return m_location.m_lastLine; }
186 
192  virtual bool isBuiltin() const { return false; }
193 
199  virtual std::string getDescription() const { return m_name; }
200 
206  void addAnnotation(const Annotation &a) { m_annotations.push_back(a); }
207 
213  std::string printAnnotations();
214 
223  Annotation *findAnnotation(std::string name, Annotation::program_lang_t lang);
224 
233  std::vector<Annotation *> getAnnotations(std::string name, Annotation::program_lang_t lang);
234 
240  const std::vector<Annotation> &getAnnotations() const { return m_annotations; };
241 
250  Value *getAnnValue(const std::string annName, Annotation::program_lang_t lang);
251 
260  std::string getAnnStringValue(const std::string annName, Annotation::program_lang_t lang);
261 
267  std::string getMlComment() { return m_mlComment; }
268 
274  void setMlComment(std::string comment) { m_mlComment = comment; }
275 
281  std::string getIlComment() { return m_ilComment; }
282 
288  void setIlComment(std::string comment) { m_ilComment = comment; }
289 
290 protected:
292  std::string m_name;
294  std::vector<Annotation> m_annotations;
295  std::string m_mlComment;
296  std::string m_ilComment;
297 };
298 
299 } // namespace erpcgen
300 
301 #endif // _EMBEDDED_RPC__SYMBOL_H_
std::string printAnnotations()
This function returns description about annotation.
Definition: Type.cpp:87
Annotation class.
Definition: Annotation.h:53
std::string getMlComment()
This function returns multiline comment for this symbol declared in IDL file.
Definition: Symbol.h:267
Symbol(symbol_type_t symType)
Constructor.
Definition: Symbol.h:87
std::string m_ilComment
Definition: Symbol.h:296
int getFirstLine() const
This function return first line from location of symbol.
Definition: Symbol.h:178
virtual bool isBuiltin() const
This function return "false" value as default for identify builtin type.
Definition: Symbol.h:192
int m_lastLine
Definition: Token.h:55
Value * getAnnValue(const std::string annName, Annotation::program_lang_t lang)
This function search and returns Value object for given annotation name.
Definition: Type.cpp:134
std::string getAnnStringValue(const std::string annName, Annotation::program_lang_t lang)
This function search and returns string for given annotation name.
Definition: Type.cpp:140
const std::vector< Annotation > & getAnnotations() const
Return all Symbol annotations.
Definition: Symbol.h:240
std::string m_name
Definition: Symbol.h:292
Symbol(symbol_type_t symType, const Token &tok)
Constructor.
Definition: Symbol.h:123
int m_firstLine
Definition: Token.h:53
void setLocation(const token_loc_t &loc)
This function set location for symbol.
Definition: Symbol.h:171
Base class for all named declarations in the IDL.
Definition: Symbol.h:53
token_loc_t & getLocation()
This function returns location for symbol.
Definition: Symbol.h:164
symbol_type_t m_symbolType
Definition: Symbol.h:291
Abstract base class for values of arbitrary types.
Definition: Value.h:47
std::vector< Annotation > m_annotations
Definition: Symbol.h:294
std::string getIlComment()
This function returns inline comment for this symbol declared in IDL file.
Definition: Symbol.h:281
token_loc_t m_location
Definition: Symbol.h:293
std::string m_mlComment
Definition: Symbol.h:295
const std::string & getName() const
This function returns symbol name.
Definition: Symbol.h:150
Encapsulates all information about a token.
Definition: Token.h:86
virtual std::string getDescription() const
This function returns description about the symbol (symbol name).
Definition: Symbol.h:199
int getLastLine() const
This function return last line from location of symbol.
Definition: Symbol.h:185
void setIlComment(std::string comment)
This function set inline comment for this symbol declared in IDL file.
Definition: Symbol.h:288
symbol_type_t getSymbolType() const
This function returns symbol type.
Definition: Symbol.h:143
void setMlComment(std::string comment)
This function set multiline comment for this symbol declared in IDL file.
Definition: Symbol.h:274
void setName(const std::string &newName)
This function set symbol name.
Definition: Symbol.h:157
Annotation * findAnnotation(std::string name, Annotation::program_lang_t lang)
Find annotation in the annotation list.
Definition: Type.cpp:107
virtual ~Symbol()
Destructor.
Definition: Symbol.h:136
Token location in the source file.
Definition: Token.h:51
void addAnnotation(const Annotation &a)
This function add annotation to vector of symbol annotations.
Definition: Symbol.h:206
symbol_type_t
Supported symbol types.
Definition: Symbol.h:59
Definition: AstNode.h:51
Symbol(symbol_type_t symType, const std::string &name)
Constructor.
Definition: Symbol.h:105