eRPC Generator (erpcgen)  Rev. 1.7.2
NXP Semiconductors
ParseErrors.h
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__PARSEERRORS_H
11 #define _EMBEDDED_RPC__PARSEERRORS_H
12 
13 #include "Logging.h"
14 #include "Token.h"
15 #include "os_config.h"
16 #include <stdexcept>
17 
19 // Definitions
21 
22 #define MAX_MESSAGE_SIZE 100
23 
25 // Classes
27 
28 namespace erpcgen {
29 
33 class erpc_error : public std::runtime_error
34 {
35 public:
41  explicit erpc_error(const std::string &__arg)
42  : std::runtime_error(__arg)
43  , m_message(__arg)
44  {
45  }
46 
47 protected:
48  std::string m_message;
49  std::string m_errName;
57  explicit erpc_error(const std::string &__arg, std::string errorName)
58  : std::runtime_error(__arg)
59  , m_message(__arg)
60  , m_errName(errorName)
61  {
62  }
63 };
64 
68 class syntax_error : public erpc_error
69 {
70 public:
76  explicit syntax_error(const std::string &__arg)
77  : erpc_error(__arg)
78  {
79  }
80 };
81 
85 class syntax_error2 : public erpc_error
86 {
87 public:
95  explicit syntax_error2(const std::string &__arg, token_loc_t loc, std::string &fileName)
96  : erpc_error(__arg, "syntax error")
97  , m_errLoc(loc)
98  , m_what(format_string("file %s:%d:%d: %s, %s", fileName.c_str(), m_errLoc.m_firstLine, m_errLoc.m_firstChar,
99  m_errName.c_str(), m_message.c_str()))
100  {
101  }
102 
110  explicit syntax_error2(const char *__arg, token_loc_t loc, std::string &fileName)
111  : erpc_error(std::string(__arg), "syntax error")
112  , m_errLoc(loc)
113  , m_what(format_string("file %s:%d:%d: %s, %s", fileName.c_str(), m_errLoc.m_firstLine, m_errLoc.m_firstChar,
114  m_errName.c_str(), m_message.c_str()))
115  {
116  }
117 
123  virtual const char *what() const NOEXCEPT NOTHROW;
124 
125 private:
126  token_loc_t m_errLoc;
127  std::string m_what;
128 };
129 
133 class lexical_error : public erpc_error
134 {
135 public:
141  explicit lexical_error(const std::string &__arg)
142  : erpc_error(__arg)
143  {
144  }
145 };
146 
151 {
152 public:
158  explicit semantic_error(const std::string &__arg)
159  : erpc_error(__arg)
160  {
161  }
162 };
163 
168 {
169 public:
175  explicit internal_error(const std::string &__arg)
176  : erpc_error(__arg)
177  {
178  }
179 };
180 
184 inline void assert_throw_internal(bool p, const std::string &&msg)
185 {
186  if (!p)
187  {
188  throw internal_error(msg);
189  }
190 }
191 
195 template <class T>
196 T *check_null(T *t)
197 {
198  if (t)
199  {
200  return t;
201  }
202  else
203  {
204  throw internal_error("unexpected null object");
205  }
206 }
207 
208 } // namespace erpcgen
209 
210 #endif // _EMBEDDED_RPC__PARSEERRORS_H
Exception class for syntax errors.
Definition: ParseErrors.h:68
syntax_error2(const std::string &__arg, token_loc_t loc, std::string &fileName)
Exception function for syntax errors.
Definition: ParseErrors.h:95
erpc_error(const std::string &__arg)
Exception function for eRPC errors.
Definition: ParseErrors.h:41
Exception class for internal errors.
Definition: ParseErrors.h:167
lexical_error(const std::string &__arg)
Exception function for lexical errors.
Definition: ParseErrors.h:141
std::string m_errName
Definition: ParseErrors.h:49
semantic_error(const std::string &__arg)
Exception function for semantic errors.
Definition: ParseErrors.h:158
STL namespace.
Exception class for lexical errors.
Definition: ParseErrors.h:133
syntax_error2(const char *__arg, token_loc_t loc, std::string &fileName)
Exception function for syntax errors.
Definition: ParseErrors.h:110
Exception class for syntax errors.
Definition: ParseErrors.h:85
erpc_error(const std::string &__arg, std::string errorName)
Exception function for eRPC errors.
Definition: ParseErrors.h:57
syntax_error(const std::string &__arg)
Exception function for syntax errors.
Definition: ParseErrors.h:76
Token location in the source file.
Definition: Token.h:25
Exception class for semantic errors.
Definition: ParseErrors.h:150
std::string m_message
Definition: ParseErrors.h:48
Definition: AstNode.h:25
internal_error(const std::string &__arg)
Exception function for internal errors.
Definition: ParseErrors.h:175
Base exception class for eRPC errors.
Definition: ParseErrors.h:33