50 lines
2.0 KiB
C++
50 lines
2.0 KiB
C++
#pragma once
|
|
#include "3rdparty/easylogging++.h"
|
|
#include <any>
|
|
#include <exception>
|
|
#include <optional>
|
|
#include <sstream>
|
|
#include <string>
|
|
|
|
#define panic(message) \
|
|
do { \
|
|
throw GrammarException(__FILE__, __LINE__, (message)); \
|
|
} while (0)
|
|
|
|
#define sysy_assert(cond) \
|
|
do { \
|
|
if (!(cond)) throw GrammarException(__FILE__, __LINE__, #cond); \
|
|
} while (0)
|
|
|
|
#define DEF_PTR_T(type) \
|
|
class type; \
|
|
typedef std::shared_ptr<type> type##Ptr_t
|
|
|
|
namespace antlrSysY {
|
|
|
|
template <typename T>
|
|
std::ostream &operator<<(typename std::enable_if<std::is_enum<T>::value, std::ostream>::type &stream, const T &e) {
|
|
return stream << static_cast<typename std::underlying_type<T>::type>(e);
|
|
}
|
|
|
|
class GrammarException : public std::exception {
|
|
public:
|
|
GrammarException() : message("Unknown Grammar Exception") {}
|
|
GrammarException(const std::string &what_arg) : message(what_arg){};
|
|
GrammarException(const char *what_arg) : message(what_arg){};
|
|
GrammarException(const char *filename, int line, const char *what_arg) {
|
|
std::ostringstream ss;
|
|
ss << filename << ":" << line << ": "
|
|
<< "\x1b[031m" << what_arg << "\x1b[0m";
|
|
message = ss.str();
|
|
};
|
|
|
|
virtual const char *what() const noexcept {
|
|
return message.c_str();
|
|
}
|
|
|
|
private:
|
|
std::string message;
|
|
};
|
|
|
|
} // namespace antlrSysY
|