eRPC Generator (erpcgen)  Rev. 1.7.0
NXP Semiconductors
ParseErrors.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__PARSEERRORS_H
37 #define _EMBEDDED_RPC__PARSEERRORS_H
38 
39 #include "Logging.h"
40 #include "Token.h"
41 #include "os_config.h"
42 #include <stdexcept>
43 
45 // Definitions
47 
48 #define MAX_MESSAGE_SIZE 100
49 
51 // Classes
53 
54 namespace erpcgen {
55 
59 class erpc_error : public std::runtime_error
60 {
61 public:
67  explicit erpc_error(const std::string &__arg)
68  : std::runtime_error(__arg)
69  , m_message(__arg)
70  {
71  }
72 
73 protected:
74  std::string m_message;
75  std::string m_errName;
83  explicit erpc_error(const std::string &__arg, std::string errorName)
84  : std::runtime_error(__arg)
85  , m_message(__arg)
86  , m_errName(errorName)
87  {
88  }
89 };
90 
94 class syntax_error : public erpc_error
95 {
96 public:
102  explicit syntax_error(const std::string &__arg)
103  : erpc_error(__arg)
104  {
105  }
106 };
107 
111 class syntax_error2 : public erpc_error
112 {
113 public:
121  explicit syntax_error2(const std::string &__arg, token_loc_t loc, std::string &fileName)
122  : erpc_error(__arg, "syntax error")
123  , m_errLoc(loc)
124  , m_what(format_string("file %s:%d:%d: %s, %s", fileName.c_str(), m_errLoc.m_firstLine, m_errLoc.m_firstChar,
125  m_errName.c_str(), m_message.c_str()))
126  {
127  }
128 
136  explicit syntax_error2(const char *__arg, token_loc_t loc, std::string &fileName)
137  : erpc_error(std::string(__arg), "syntax error")
138  , m_errLoc(loc)
139  , m_what(format_string("file %s:%d:%d: %s, %s", fileName.c_str(), m_errLoc.m_firstLine, m_errLoc.m_firstChar,
140  m_errName.c_str(), m_message.c_str()))
141  {
142  }
143 
149  virtual const char *what() const NOEXCEPT NOTHROW;
150 
151 private:
152  token_loc_t m_errLoc;
153  std::string m_what;
154 };
155 
159 class lexical_error : public erpc_error
160 {
161 public:
167  explicit lexical_error(const std::string &__arg)
168  : erpc_error(__arg)
169  {
170  }
171 };
172 
177 {
178 public:
184  explicit semantic_error(const std::string &__arg)
185  : erpc_error(__arg)
186  {
187  }
188 };
189 
194 {
195 public:
201  explicit internal_error(const std::string &__arg)
202  : erpc_error(__arg)
203  {
204  }
205 };
206 
210 inline void assert_throw_internal(bool p, const std::string &&msg)
211 {
212  if (!p)
213  {
214  throw internal_error(msg);
215  }
216 }
217 
221 template <class T>
222 T *check_null(T *t)
223 {
224  if (t)
225  {
226  return t;
227  }
228  else
229  {
230  throw internal_error("unexpected null object");
231  }
232 }
233 
234 } // namespace erpcgen
235 
236 #endif // _EMBEDDED_RPC__PARSEERRORS_H
Exception class for syntax errors.
Definition: ParseErrors.h:94
syntax_error2(const std::string &__arg, token_loc_t loc, std::string &fileName)
Exception function for syntax errors.
Definition: ParseErrors.h:121
erpc_error(const std::string &__arg)
Exception function for eRPC errors.
Definition: ParseErrors.h:67
Exception class for internal errors.
Definition: ParseErrors.h:193
lexical_error(const std::string &__arg)
Exception function for lexical errors.
Definition: ParseErrors.h:167
std::string m_errName
Definition: ParseErrors.h:75
semantic_error(const std::string &__arg)
Exception function for semantic errors.
Definition: ParseErrors.h:184
STL namespace.
Exception class for lexical errors.
Definition: ParseErrors.h:159
syntax_error2(const char *__arg, token_loc_t loc, std::string &fileName)
Exception function for syntax errors.
Definition: ParseErrors.h:136
Exception class for syntax errors.
Definition: ParseErrors.h:111
erpc_error(const std::string &__arg, std::string errorName)
Exception function for eRPC errors.
Definition: ParseErrors.h:83
syntax_error(const std::string &__arg)
Exception function for syntax errors.
Definition: ParseErrors.h:102
Token location in the source file.
Definition: Token.h:51
Exception class for semantic errors.
Definition: ParseErrors.h:176
std::string m_message
Definition: ParseErrors.h:74
Definition: AstNode.h:51
internal_error(const std::string &__arg)
Exception function for internal errors.
Definition: ParseErrors.h:201
Base exception class for eRPC errors.
Definition: ParseErrors.h:59