8#ifndef LIB_ERROR_CATALOG_H_
9#define LIB_ERROR_CATALOG_H_
15#include "lib/error_message.h"
16#include "lib/exceptions.h"
20using MessageType = ErrorMessage::MessageType;
30 static constexpr int LEGACY_ERROR = 0;
31 static constexpr int ERR_UNKNOWN = 1;
32 static constexpr int ERR_UNSUPPORTED = 2;
33 static constexpr int ERR_UNEXPECTED = 3;
34 static constexpr int ERR_UNINITIALIZED = 4;
35 static constexpr int ERR_EXPECTED = 5;
36 static constexpr int ERR_NOT_FOUND = 6;
37 static constexpr int ERR_INVALID = 7;
38 static constexpr int ERR_EXPRESSION = 8;
39 static constexpr int ERR_OVERLIMIT = 9;
40 static constexpr int ERR_INSUFFICIENT = 10;
41 static constexpr int ERR_TYPE_ERROR = 11;
42 static constexpr int ERR_UNSUPPORTED_ON_TARGET = 12;
43 static constexpr int ERR_DUPLICATE = 13;
44 static constexpr int ERR_IO = 14;
45 static constexpr int ERR_UNREACHABLE = 15;
46 static constexpr int ERR_MODEL = 16;
47 static constexpr int ERR_TABLE_KEYS = 17;
48 static constexpr int ERR_RESERVED = 18;
50 static constexpr int ERR_MIN_BACKEND = 500;
51 static constexpr int ERR_MAX = 999;
55 static constexpr int LEGACY_WARNING = ERR_MAX + 1;
56 static constexpr int WARN_FAILED = 1001;
57 static constexpr int WARN_UNKNOWN = 1002;
58 static constexpr int WARN_INVALID = 1003;
59 static constexpr int WARN_UNSUPPORTED = 1004;
60 static constexpr int WARN_DEPRECATED = 1005;
61 static constexpr int WARN_UNINITIALIZED = 1006;
62 static constexpr int WARN_UNINITIALIZED_USE = 1019;
63 static constexpr int WARN_UNINITIALIZED_OUT_PARAM =
65 static constexpr int WARN_UNUSED = 1007;
66 static constexpr int WARN_MISSING = 1008;
67 static constexpr int WARN_ORDERING = 1009;
68 static constexpr int WARN_MISMATCH = 1010;
69 static constexpr int WARN_OVERFLOW = 1011;
70 static constexpr int WARN_IGNORE_PROPERTY = 1012;
71 static constexpr int WARN_TYPE_INFERENCE = 1013;
72 static constexpr int WARN_PARSER_TRANSITION = 1014;
73 static constexpr int WARN_UNREACHABLE = 1015;
74 static constexpr int WARN_SHADOWING = 1016;
75 static constexpr int WARN_IGNORE = 1017;
76 static constexpr int WARN_INVALID_HEADER = 1020;
77 static constexpr int WARN_DUPLICATE_PRIORITIES = 1021;
78 static constexpr int WARN_ENTRIES_OUT_OF_ORDER = 1022;
79 static constexpr int WARN_MULTI_HDR_EXTRACT =
81 static constexpr int WARN_EXPRESSION = 1024;
82 static constexpr int WARN_DUPLICATE = 1025;
83 static constexpr int WARN_BRANCH_HINT = 1026;
84 static constexpr int WARN_TABLE_KEYS = 1027;
86 static constexpr int WARN_MIN_BACKEND = 1500;
87 static constexpr int WARN_MAX = 2141;
91 static constexpr int INFO_INFERRED = WARN_MAX + 1;
92 static constexpr int INFO_PROGRESS = 2143;
93 static constexpr int INFO_REMOVED = 2144;
96 static constexpr int INFO_MIN_BACKEND = 3000;
97 static constexpr int INFO_MAX = 3999;
104 static ErrorCatalog instance;
114 template <MessageType type,
int errorCode>
115 bool add(
const char *name,
bool forceReplace =
false) {
116 static_assert(type != MessageType::Error ||
117 (errorCode >= ErrorType::ERR_MIN_BACKEND && errorCode <= ErrorType::ERR_MAX));
118 static_assert(type != MessageType::Warning || (errorCode >= ErrorType::WARN_MIN_BACKEND &&
119 errorCode <= ErrorType::WARN_MAX));
120 static_assert(type != MessageType::Info || (errorCode >= ErrorType::INFO_MIN_BACKEND &&
121 errorCode <= ErrorType::INFO_MAX));
122 static_assert(type != MessageType::None);
123 if (forceReplace) errorCatalog.erase(errorCode);
124 auto it = errorCatalog.emplace(errorCode, name);
132 if (errorCatalog.count(errorCode))
return errorCatalog.at(errorCode);
133 return "--unknown--"_cs;
136 bool isError(
int errorCode) {
137 return errorCode >= ErrorType::LEGACY_ERROR && errorCode <= ErrorType::ERR_MAX;
146 for (
const auto &pair : errorCatalog) {
147 if (pair.second == lookup) {
148 if (!isError(pair.first))
return false;
158 for (
const auto &pair : errorCatalog) {
159 if (pair.second == lookup)
return true;
170 static std::map<int, cstring> errorCatalog;
Definition error_catalog.h:100
static ErrorCatalog & getCatalog()
Return the singleton object.
Definition error_catalog.h:103
bool add(const char *name, bool forceReplace=false)
Definition error_catalog.h:115
bool isError(std::string_view name)
return true if the given diagnostic can only be an error; false otherwise
Definition error_catalog.h:141
cstring getName(int errorCode)
retrieve the name for errorCode
Definition error_catalog.h:129
bool diagnosticExists(std::string_view name)
return true if the given diagnostic name exists in the catalog
Definition error_catalog.h:156
Definition error_reporter.h:40
Definition error_catalog.h:26
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:13
void error(const char *format, Args &&...args)
Report an error with the given message.
Definition lib/error.h:58