17#ifndef LIB_ERROR_CATALOG_H_
18#define LIB_ERROR_CATALOG_H_
24#include "lib/error_message.h"
25#include "lib/exceptions.h"
29using MessageType = ErrorMessage::MessageType;
40 static const int LEGACY_ERROR;
41 static const int ERR_UNKNOWN;
42 static const int ERR_UNSUPPORTED;
43 static const int ERR_UNEXPECTED;
44 static const int ERR_UNINITIALIZED;
45 static const int ERR_EXPECTED;
46 static const int ERR_NOT_FOUND;
47 static const int ERR_INVALID;
48 static const int ERR_EXPRESSION;
49 static const int ERR_OVERLIMIT;
50 static const int ERR_INSUFFICIENT;
51 static const int ERR_TYPE_ERROR;
52 static const int ERR_UNSUPPORTED_ON_TARGET;
53 static const int ERR_DUPLICATE;
54 static const int ERR_IO;
55 static const int ERR_UNREACHABLE;
56 static const int ERR_MODEL;
57 static const int ERR_TABLE_KEYS;
58 static const int ERR_RESERVED;
60 static const int ERR_MIN_BACKEND = 500;
61 static const int ERR_MAX = 999;
65 static const int LEGACY_WARNING;
66 static const int WARN_FAILED;
67 static const int WARN_UNKNOWN;
68 static const int WARN_INVALID;
69 static const int WARN_UNSUPPORTED;
70 static const int WARN_DEPRECATED;
71 static const int WARN_UNINITIALIZED;
72 static const int WARN_UNINITIALIZED_USE;
73 static const int WARN_UNINITIALIZED_OUT_PARAM;
74 static const int WARN_UNUSED;
75 static const int WARN_MISSING;
76 static const int WARN_ORDERING;
77 static const int WARN_MISMATCH;
78 static const int WARN_OVERFLOW;
79 static const int WARN_IGNORE_PROPERTY;
80 static const int WARN_TYPE_INFERENCE;
81 static const int WARN_PARSER_TRANSITION;
82 static const int WARN_UNREACHABLE;
83 static const int WARN_SHADOWING;
84 static const int WARN_IGNORE;
85 static const int WARN_INVALID_HEADER;
86 static const int WARN_DUPLICATE_PRIORITIES;
87 static const int WARN_ENTRIES_OUT_OF_ORDER;
88 static const int WARN_MULTI_HDR_EXTRACT;
89 static const int WARN_EXPRESSION;
90 static const int WARN_DUPLICATE;
91 static const int WARN_BRANCH_HINT;
92 static const int WARN_TABLE_KEYS;
94 static const int WARN_MIN_BACKEND = 1500;
95 static const int WARN_MAX = 2141;
99 static const int INFO_INFERRED;
100 static const int INFO_PROGRESS;
101 static const int INFO_REMOVED;
104 static const int INFO_MIN_BACKEND = 3000;
105 static const int INFO_MAX = 3999;
112 static ErrorCatalog instance;
122 template <MessageType type,
int errorCode>
123 bool add(
const char *name,
bool forceReplace =
false) {
124 static_assert(type != MessageType::Error ||
125 (errorCode >= ErrorType::ERR_MIN_BACKEND && errorCode <= ErrorType::ERR_MAX));
126 static_assert(type != MessageType::Warning || (errorCode >= ErrorType::WARN_MIN_BACKEND &&
127 errorCode <= ErrorType::WARN_MAX));
128 static_assert(type != MessageType::Info || (errorCode >= ErrorType::INFO_MIN_BACKEND &&
129 errorCode <= ErrorType::INFO_MAX));
130 static_assert(type != MessageType::None);
131 if (forceReplace) errorCatalog.erase(errorCode);
132 auto it = errorCatalog.emplace(errorCode, name);
140 if (errorCatalog.count(errorCode))
return errorCatalog.at(errorCode);
141 return "--unknown--"_cs;
144 bool isError(
int errorCode) {
145 return errorCode >= ErrorType::LEGACY_ERROR && errorCode <= ErrorType::ERR_MAX;
154 for (
const auto &pair : errorCatalog) {
155 if (pair.second == lookup) {
156 if (!isError(pair.first))
return false;
170 static std::map<int, cstring> errorCatalog;
Definition error_catalog.h:108
static ErrorCatalog & getCatalog()
Return the singleton object.
Definition error_catalog.h:111
bool add(const char *name, bool forceReplace=false)
Definition error_catalog.h:123
bool isError(std::string_view name)
return true if the given diagnostic can only be an error; false otherwise
Definition error_catalog.h:149
cstring getName(int errorCode)
retrieve the name for errorCode
Definition error_catalog.h:137
Definition error_reporter.h:49
Definition error_catalog.h:35
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:24
void error(const char *format, Args &&...args)
Report an error with the given message.
Definition lib/error.h:58