eRPC Generator (erpcgen)  Rev. 1.11.0
NXP Semiconductors
Symbol.hpp
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__SYMBOL_H_
11 #define _EMBEDDED_RPC__SYMBOL_H_
12 
13 #include "Annotation.hpp"
14 #include "AstNode.hpp"
15 #include "Token.hpp"
16 
17 #include <vector>
18 
20 // Classes
22 
23 namespace erpcgen {
24 
28 class Symbol
29 {
30 public:
35  {
36  kConstSymbol,
37  kEnumMemberSymbol,
38  kFunctionSymbol,
39  kInterfaceSymbol,
40  kProgramSymbol,
41  kStructMemberSymbol,
42  kTypenameSymbol,
43  kUnionCaseMemberSymbol
44  };
45 
53  explicit Symbol(symbol_type_t symType)
54  : m_symbolType(symType)
55  , m_name()
56  , m_location()
57  , m_annotations()
58  , m_mlComment("")
59  , m_ilComment("")
60  {
61  }
62 
71  Symbol(symbol_type_t symType, const std::string &name)
72  : m_symbolType(symType)
73  , m_name(name)
74  , m_location()
75  , m_annotations()
76  , m_mlComment("")
77  , m_ilComment("")
78  {
79  }
80 
89  Symbol(symbol_type_t symType, const Token &tok)
90  : m_symbolType(symType)
91  , m_name(tok.getStringValue())
92  , m_location(tok.getLocation())
93  , m_annotations()
94  , m_mlComment("")
95  , m_ilComment("")
96  {
97  }
98 
102  virtual ~Symbol() {}
103 
110 
116  const std::string &getName() const { return m_name; }
117 
123  void setName(const std::string &newName) { m_name = newName; }
124 
131  bool isConstSymbol() const { return (m_symbolType == kConstSymbol); }
132 
139  bool isEnumMemberSymbol() const { return (m_symbolType == kEnumMemberSymbol); }
140 
147  bool isFunctionSymbol() const { return (m_symbolType == kFunctionSymbol); }
148 
155  bool isInterfaceSymbol() const { return (m_symbolType == kInterfaceSymbol); }
156 
163  bool isProgramSymbol() const { return (m_symbolType == kProgramSymbol); }
164 
171  bool isStructMemberSymbol() const { return (m_symbolType == kStructMemberSymbol); }
172 
179  bool isDatatypeSymbol() const { return (m_symbolType == kTypenameSymbol); }
180 
187  bool isUnionCaseSymbol() const { return (m_symbolType == kUnionCaseMemberSymbol); }
188 
195 
201  void setLocation(const token_loc_t &loc) { m_location = loc; }
202 
208  int getFirstLine() const { return m_location.m_firstLine; }
209 
215  int getLastLine() const { return m_location.m_lastLine; }
216 
222  virtual std::string getDescription() const { return m_name; }
223 
229  void addAnnotation(const Annotation &a) { m_annotations.push_back(a); }
230 
236  std::string printAnnotations();
237 
246  Annotation *findAnnotation(const std::string &name, Annotation::program_lang_t lang);
247 
256  std::vector<Annotation *> getAnnotations(const std::string &name, Annotation::program_lang_t lang);
257 
263  const std::vector<Annotation> &getAnnotations() const { return m_annotations; };
264 
273  Value *getAnnValue(const std::string &annName, Annotation::program_lang_t lang);
274 
283  std::string getAnnStringValue(const std::string &annName, Annotation::program_lang_t lang);
284 
290  std::string getMlComment() { return m_mlComment; }
291 
297  void setMlComment(const std::string &comment) { m_mlComment = comment; }
298 
304  std::string getIlComment() { return m_ilComment; }
305 
311  void setIlComment(const std::string &comment) { m_ilComment = comment; }
312 
313 protected:
315  std::string m_name;
317  std::vector<Annotation> m_annotations;
318  std::string m_mlComment;
319  std::string m_ilComment;
320 };
321 
322 } // namespace erpcgen
323 
324 #endif // _EMBEDDED_RPC__SYMBOL_H_
std::string printAnnotations()
This function returns description about annotation.
Definition: Type.cpp:63
Annotation class.
Definition: Annotation.hpp:28
bool isConstSymbol() const
This function is testing symbol type.
Definition: Symbol.hpp:131
std::string getMlComment()
This function returns multiline comment for this symbol declared in IDL file.
Definition: Symbol.hpp:290
Symbol(symbol_type_t symType)
Constructor.
Definition: Symbol.hpp:53
std::string m_ilComment
Definition: Symbol.hpp:319
int getFirstLine() const
This function return first line from location of symbol.
Definition: Symbol.hpp:208
int m_lastLine
Definition: Token.hpp:29
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:110
const std::vector< Annotation > & getAnnotations() const
Return all Symbol annotations.
Definition: Symbol.hpp:263
bool isStructMemberSymbol() const
This function is testing symbol type.
Definition: Symbol.hpp:171
bool isDatatypeSymbol() const
This function is testing symbol type.
Definition: Symbol.hpp:179
std::string m_name
Definition: Symbol.hpp:315
bool isUnionCaseSymbol() const
This function is testing symbol type.
Definition: Symbol.hpp:187
Symbol(symbol_type_t symType, const Token &tok)
Constructor.
Definition: Symbol.hpp:89
int m_firstLine
Definition: Token.hpp:27
void setLocation(const token_loc_t &loc)
This function set location for symbol.
Definition: Symbol.hpp:201
Base class for all named declarations in the IDL.
Definition: Symbol.hpp:28
token_loc_t & getLocation()
This function returns location for symbol.
Definition: Symbol.hpp:194
Annotation * findAnnotation(const std::string &name, Annotation::program_lang_t lang)
Find annotation in the annotation list.
Definition: Type.cpp:83
symbol_type_t m_symbolType
Definition: Symbol.hpp:314
void setIlComment(const std::string &comment)
This function set inline comment for this symbol declared in IDL file.
Definition: Symbol.hpp:311
Abstract base class for values of arbitrary types.
Definition: Value.hpp:27
bool isInterfaceSymbol() const
This function is testing symbol type.
Definition: Symbol.hpp:155
std::vector< Annotation > m_annotations
Definition: Symbol.hpp:317
std::string getIlComment()
This function returns inline comment for this symbol declared in IDL file.
Definition: Symbol.hpp:304
token_loc_t m_location
Definition: Symbol.hpp:316
std::string m_mlComment
Definition: Symbol.hpp:318
const std::string & getName() const
This function returns symbol name.
Definition: Symbol.hpp:116
Encapsulates all information about a token.
Definition: Token.hpp:60
virtual std::string getDescription() const
This function returns description about the symbol (symbol name).
Definition: Symbol.hpp:222
int getLastLine() const
This function return last line from location of symbol.
Definition: Symbol.hpp:215
bool isProgramSymbol() const
This function is testing symbol type.
Definition: Symbol.hpp:163
symbol_type_t getSymbolType() const
This function returns symbol type.
Definition: Symbol.hpp:109
void setName(const std::string &newName)
This function set symbol name.
Definition: Symbol.hpp:123
void setMlComment(const std::string &comment)
This function set multiline comment for this symbol declared in IDL file.
Definition: Symbol.hpp:297
virtual ~Symbol()
Destructor.
Definition: Symbol.hpp:102
Token location in the source file.
Definition: Token.hpp:25
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:116
void addAnnotation(const Annotation &a)
This function add annotation to vector of symbol annotations.
Definition: Symbol.hpp:229
symbol_type_t
Supported symbol types.
Definition: Symbol.hpp:34
bool isFunctionSymbol() const
This function is testing symbol type.
Definition: Symbol.hpp:147
Definition: AstNode.hpp:26
Symbol(symbol_type_t symType, const std::string &name)
Constructor.
Definition: Symbol.hpp:71
bool isEnumMemberSymbol() const
This function is testing symbol type.
Definition: Symbol.hpp:139