eRPC Generator (erpcgen)  Rev. 1.7.0
NXP Semiconductors
Token.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__TOKEN_H_
37 #define _EMBEDDED_RPC__TOKEN_H_
38 
39 #include "Value.h"
40 #include "smart_ptr.h"
41 
43 // Classes
45 
46 namespace erpcgen {
47 
52 {
55  int m_lastLine;
56  int m_lastChar;
58  token_loc_t()
59  : m_firstLine(0)
60  , m_firstChar(0)
61  , m_lastLine(0)
62  , m_lastChar(0)
63  {
64  }
65 
71  token_loc_t(const token_loc_t &other) = default;
72 
80  token_loc_t &operator=(const token_loc_t &other) = default;
81 };
82 
86 class Token
87 {
88 public:
100  Token(int token)
101  : m_token(token)
102  , m_value()
103  , m_location()
104  {
105  }
106 
120  Token(int token, Value *value)
121  : m_token(token)
122  , m_value(value)
123  , m_location()
124  {
125  }
126 
141  Token(int token, Value *value, const token_loc_t &loc)
142  : m_token(token)
143  , m_value(value)
144  , m_location(loc)
145  {
146  }
147 
160  Token(const Token &other);
161 
173  Token &operator=(const Token &other);
174 
178  ~Token() {}
179 
181 
182 
189  int getToken() const { return m_token; }
190 
198  void setToken(int tok) { m_token = tok; }
199 
207  const char *getTokenName() const;
208 
214  bool isNumberTok() const;
215 
221  bool isIdentifierTok() const;
223 
225 
226 
236  bool hasValue() const { return m_value.get() != nullptr; }
237 
247  Value *getValue() { return m_value; }
248 
258  const Value *getValue() const { return m_value; }
259 
271  void setValue(Value *val) { m_value = val; }
272 
284  const std::string &getStringValue() const;
285 
297  uint64_t getIntValue() const;
299 
301 
302 
309  const token_loc_t &getLocation() const { return m_location; }
310 
318  void setLocation(const token_loc_t &loc) { m_location = loc; }
319 
326  void setLocation(const token_loc_t &first, const token_loc_t &last);
327 
336  int getFirstLine() const { return m_location.m_firstLine; }
337 
346  int getLastLine() const { return m_location.m_lastLine; }
347 
355  bool isBinaryOp() const;
357 
358 private:
359  int m_token;
360  smart_ptr<Value> m_value;
361  token_loc_t m_location;
362 };
363 
364 } // namespace erpcgen
365 
366 #endif // _EMBEDDED_RPC__TOKEN_H_
~Token()
Destructor.
Definition: Token.h:178
Token(int token, Value *value, const token_loc_t &loc)
Constructor.
Definition: Token.h:141
void setValue(Value *val)
This function set token value.
Definition: Token.h:271
int m_lastLine
Definition: Token.h:55
Token(int token, Value *value)
Constructor.
Definition: Token.h:120
Value * getValue()
This function returns token value.
Definition: Token.h:247
int getLastLine() const
This function returns last line of token from token location (location from analyzed file)...
Definition: Token.h:346
int m_firstLine
Definition: Token.h:53
void setToken(int tok)
This function set token number.
Definition: Token.h:198
void setLocation(const token_loc_t &loc)
This function set token location (location from analyzed file).
Definition: Token.h:318
Abstract base class for values of arbitrary types.
Definition: Value.h:47
Token(int token)
Constructor.
Definition: Token.h:100
const token_loc_t & getLocation() const
This function returns token location (location from analyzed file).
Definition: Token.h:309
token_loc_t & operator=(const token_loc_t &other)=default
Default assign operator.
bool hasValue() const
This function return true/false, when token has/hasn&#39;t value.
Definition: Token.h:236
int m_lastChar
Definition: Token.h:56
Encapsulates all information about a token.
Definition: Token.h:86
const Value * getValue() const
This function returns const token value.
Definition: Token.h:258
int getToken() const
This function returns token number.
Definition: Token.h:189
int m_firstChar
Definition: Token.h:54
Token location in the source file.
Definition: Token.h:51
Definition: AstNode.h:51
int getFirstLine() const
This function returns first line of token from token location (location from analyzed file)...
Definition: Token.h:336