19#ifndef LIB_EXCEPTIONS_H_
20#define LIB_EXCEPTIONS_H_
26#include <boost/format.hpp>
28#include "lib/error_helper.h"
34constexpr char ANSI_RED[] =
"\33[31m";
35constexpr char ANSI_BLUE[] =
"\33[34m";
36constexpr char ANSI_CLR[] =
"\33[0m";
40inline bool is_cerr_redirected() {
41 static bool initialized(
false);
45 is_redir = ttyname(fileno(stderr)) ==
nullptr;
51inline const char *cerr_colorize(
const char *color) {
52 if (is_cerr_redirected()) {
59inline const char *cerr_clear_colors() {
60 if (is_cerr_redirected()) {
72 void traceCreation() {}
75 template <
typename... T>
78 boost::format fmt(format);
79 message = ::bug_helper(fmt,
"",
"",
"", std::forward<T>(args)...);
82 const char *what()
const noexcept {
return message.c_str(); }
88 template <
typename... T>
92 message =
cstring(cerr_colorize(ANSI_RED)) +
"Compiler Bug" + cerr_clear_colors() +
":\n" +
96 template <
typename... T>
97 CompilerBug(
int line,
const char *file,
const char *format, T... args)
99 message =
cstring(
"In file: ") + file +
":" + Util::toString(line) +
"\n" +
100 cerr_colorize(ANSI_RED) +
"Compiler Bug" + cerr_clear_colors() +
": " + message;
107 template <
typename... T>
110 message =
cstring(cerr_colorize(ANSI_BLUE)) +
"Not yet implemented" + cerr_clear_colors() +
114 template <
typename... T>
117 message =
cstring(
"In file: ") + file +
":" + Util::toString(line) +
"\n" +
118 cerr_colorize(ANSI_BLUE) +
"Unimplemented compiler support" +
119 cerr_clear_colors() +
": " + message;
127 template <
typename... T>
133 throw Util::CompilerBug(__LINE__, __FILE__, __VA_ARGS__); \
135#define BUG_CHECK(e, ...) \
137 if (!(e)) BUG(__VA_ARGS__); \
139#define P4C_UNIMPLEMENTED(...) \
141 throw Util::CompilerUnimplemented(__LINE__, __FILE__, __VA_ARGS__); \
147#define FATAL_ERROR(...) \
149 throw Util::CompilationError(__VA_ARGS__); \
Definition exceptions.h:125
This class indicates a bug in the compiler.
Definition exceptions.h:86
This class indicates an unimplemented feature in the compiler.
Definition exceptions.h:105
Definition exceptions.h:69