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;
39 static constexpr int LEGACY_ERROR = 0;
40 static constexpr int ERR_UNKNOWN = 1;
41 static constexpr int ERR_UNSUPPORTED = 2;
42 static constexpr int ERR_UNEXPECTED = 3;
43 static constexpr int ERR_UNINITIALIZED = 4;
44 static constexpr int ERR_EXPECTED = 5;
45 static constexpr int ERR_NOT_FOUND = 6;
46 static constexpr int ERR_INVALID = 7;
47 static constexpr int ERR_EXPRESSION = 8;
48 static constexpr int ERR_OVERLIMIT = 9;
49 static constexpr int ERR_INSUFFICIENT = 10;
50 static constexpr int ERR_TYPE_ERROR = 11;
51 static constexpr int ERR_UNSUPPORTED_ON_TARGET = 12;
52 static constexpr int ERR_DUPLICATE = 13;
53 static constexpr int ERR_IO = 14;
54 static constexpr int ERR_UNREACHABLE = 15;
55 static constexpr int ERR_MODEL = 16;
56 static constexpr int ERR_TABLE_KEYS = 17;
57 static constexpr int ERR_RESERVED = 18;
59 static constexpr int ERR_MIN_BACKEND = 500;
60 static constexpr int ERR_MAX = 999;
64 static constexpr int LEGACY_WARNING = ERR_MAX + 1;
65 static constexpr int WARN_FAILED = 1001;
66 static constexpr int WARN_UNKNOWN = 1002;
67 static constexpr int WARN_INVALID = 1003;
68 static constexpr int WARN_UNSUPPORTED = 1004;
69 static constexpr int WARN_DEPRECATED = 1005;
70 static constexpr int WARN_UNINITIALIZED = 1006;
71 static constexpr int WARN_UNINITIALIZED_USE = 1019;
72 static constexpr int WARN_UNINITIALIZED_OUT_PARAM =
74 static constexpr int WARN_UNUSED = 1007;
75 static constexpr int WARN_MISSING = 1008;
76 static constexpr int WARN_ORDERING = 1009;
77 static constexpr int WARN_MISMATCH = 1010;
78 static constexpr int WARN_OVERFLOW = 1011;
79 static constexpr int WARN_IGNORE_PROPERTY = 1012;
80 static constexpr int WARN_TYPE_INFERENCE = 1013;
81 static constexpr int WARN_PARSER_TRANSITION = 1014;
82 static constexpr int WARN_UNREACHABLE = 1015;
83 static constexpr int WARN_SHADOWING = 1016;
84 static constexpr int WARN_IGNORE = 1017;
85 static constexpr int WARN_INVALID_HEADER = 1020;
86 static constexpr int WARN_DUPLICATE_PRIORITIES = 1021;
87 static constexpr int WARN_ENTRIES_OUT_OF_ORDER = 1022;
88 static constexpr int WARN_MULTI_HDR_EXTRACT =
90 static constexpr int WARN_EXPRESSION = 1024;
91 static constexpr int WARN_DUPLICATE = 1025;
92 static constexpr int WARN_BRANCH_HINT = 1026;
93 static constexpr int WARN_TABLE_KEYS = 1027;
95 static constexpr int WARN_MIN_BACKEND = 1500;
96 static constexpr int WARN_MAX = 2141;
100 static constexpr int INFO_INFERRED = WARN_MAX + 1;
101 static constexpr int INFO_PROGRESS = 2143;
102 static constexpr int INFO_REMOVED = 2144;
105 static constexpr int INFO_MIN_BACKEND = 3000;
106 static constexpr int INFO_MAX = 3999;
113 static ErrorCatalog instance;
123 template <MessageType type,
int errorCode>
124 bool add(
const char *name,
bool forceReplace =
false) {
125 static_assert(type != MessageType::Error ||
126 (errorCode >= ErrorType::ERR_MIN_BACKEND && errorCode <= ErrorType::ERR_MAX));
127 static_assert(type != MessageType::Warning || (errorCode >= ErrorType::WARN_MIN_BACKEND &&
128 errorCode <= ErrorType::WARN_MAX));
129 static_assert(type != MessageType::Info || (errorCode >= ErrorType::INFO_MIN_BACKEND &&
130 errorCode <= ErrorType::INFO_MAX));
131 static_assert(type != MessageType::None);
132 if (forceReplace) errorCatalog.erase(errorCode);
133 auto it = errorCatalog.emplace(errorCode, name);
141 if (errorCatalog.count(errorCode))
return errorCatalog.at(errorCode);
142 return "--unknown--"_cs;
145 bool isError(
int errorCode) {
146 return errorCode >= ErrorType::LEGACY_ERROR && errorCode <= ErrorType::ERR_MAX;
155 for (
const auto &pair : errorCatalog) {
156 if (pair.second == lookup) {
157 if (!isError(pair.first))
return false;
167 for (
const auto &pair : errorCatalog) {
168 if (pair.second == lookup)
return true;
179 static std::map<int, cstring> errorCatalog;
Definition error_catalog.h:109
static ErrorCatalog & getCatalog()
Return the singleton object.
Definition error_catalog.h:112
bool add(const char *name, bool forceReplace=false)
Definition error_catalog.h:124
bool isError(std::string_view name)
return true if the given diagnostic can only be an error; false otherwise
Definition error_catalog.h:150
cstring getName(int errorCode)
retrieve the name for errorCode
Definition error_catalog.h:138
bool diagnosticExists(std::string_view name)
return true if the given diagnostic name exists in the catalog
Definition error_catalog.h:165
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