eRPC Generator (erpcgen)  Rev. 1.7.0
NXP Semiconductors
Annotation.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__ANNOTATION_H_
37 #define _EMBEDDED_RPC__ANNOTATION_H_
38 
39 #include "AstNode.h"
40 #include "Token.h"
41 #include "Value.h"
42 #include <string>
43 
45 // Classes
47 
48 namespace erpcgen {
49 
54 {
55 public:
56  enum program_lang_t
57  {
58  kAll,
59  kC,
60  kPython
61  };
62 
72  Annotation(const Token &token, Value *val, program_lang_t lang)
73  : m_name(token.getStringValue())
74  , m_value(val)
75  , m_location(token.getLocation())
76  , m_lang(lang)
77  {
78  }
79 
87  Annotation(const Token &token)
88  : m_name(token.getStringValue())
89  , m_value(nullptr)
90  , m_location(token.getLocation())
91  , m_lang(kAll)
92  {
93  }
94 
103  : m_name(a.m_name)
104  , m_value(a.m_value)
105  , m_location(a.m_location)
106  , m_lang(a.m_lang)
107  {
108  }
109 
115  std::string getName() const { return m_name; }
116 
122  bool hasValue() { return nullptr != m_value; }
123 
132 
138  program_lang_t getLang() const { return m_lang; }
139 
145  std::string toString() { return m_name + " = " + m_value->toString(); }
146 
152  token_loc_t &getLocation() { return m_location; }
153 
154 private:
155  std::string m_name;
156  Value *m_value;
157  token_loc_t m_location;
158  program_lang_t m_lang;
159 };
160 
161 } // namespace erpcgen
162 
163 #endif // _EMBEDDED_RPC__ANNOTATION_H_
Annotation(const Token &token, Value *val, program_lang_t lang)
Constructor.
Definition: Annotation.h:72
Annotation class.
Definition: Annotation.h:53
Annotation(const Annotation &a)
Constructor.
Definition: Annotation.h:102
std::string toString()
This function returns toString representation.
Definition: Annotation.h:145
virtual std::string toString() const =0
Get Value type string representation.
bool hasValue()
Checks to see if value instance member is null.
Definition: Annotation.h:122
Abstract base class for values of arbitrary types.
Definition: Value.h:47
program_lang_t getLang() const
This function returns programming language type for which is annotation intended. ...
Definition: Annotation.h:138
Encapsulates all information about a token.
Definition: Token.h:86
std::string getName() const
This function returns annotation name.
Definition: Annotation.h:115
token_loc_t & getLocation()
This function returns location for symbol.
Definition: Annotation.h:152
Token location in the source file.
Definition: Token.h:51
Annotation(const Token &token)
Constructor.
Definition: Annotation.h:87
Value * getValueObject()
This function returns annotation value.
Definition: Type.cpp:74
Definition: AstNode.h:51