CompilerSysY/include/common.h
2023-05-02 17:20:35 +08:00

43 lines
1.3 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)) \
GrammarException(__FILE__, __LINE__, #cond); \
} while (0)
namespace antlrSysY {
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 std::string &what_arg) {
std::stringstream ss;
ss << filename << ":" << line << ": " << what_arg;
ss >> message;
};
virtual const char *what() const noexcept {
return message.c_str();
}
private:
std::string message;
};
} // namespace antlrSysY