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_RESERVED;
59 static const int ERR_MIN_BACKEND = 500;
60 static const int ERR_MAX = 999;
64 static const int LEGACY_WARNING;
65 static const int WARN_FAILED;
66 static const int WARN_UNKNOWN;
67 static const int WARN_INVALID;
68 static const int WARN_UNSUPPORTED;
69 static const int WARN_DEPRECATED;
70 static const int WARN_UNINITIALIZED;
71 static const int WARN_UNINITIALIZED_USE;
72 static const int WARN_UNINITIALIZED_OUT_PARAM;
73 static const int WARN_UNUSED;
74 static const int WARN_MISSING;
75 static const int WARN_ORDERING;
76 static const int WARN_MISMATCH;
77 static const int WARN_OVERFLOW;
78 static const int WARN_IGNORE_PROPERTY;
79 static const int WARN_TYPE_INFERENCE;
80 static const int WARN_PARSER_TRANSITION;
81 static const int WARN_UNREACHABLE;
82 static const int WARN_SHADOWING;
83 static const int WARN_IGNORE;
84 static const int WARN_INVALID_HEADER;
85 static const int WARN_DUPLICATE_PRIORITIES;
86 static const int WARN_ENTRIES_OUT_OF_ORDER;
87 static const int WARN_MULTI_HDR_EXTRACT;
88 static const int WARN_EXPRESSION;
89 static const int WARN_DUPLICATE;
90 static const int WARN_BRANCH_HINT;
92 static const int WARN_MIN_BACKEND = 1500;
93 static const int WARN_MAX = 2141;
97 static const int INFO_INFERRED;
98 static const int INFO_PROGRESS;
101 static const int INFO_MIN_BACKEND = 3000;
102 static const int INFO_MAX = 3999;
109 static ErrorCatalog instance;
119 template <MessageType type,
int errorCode>
120 bool add(
const char *name,
bool forceReplace =
false) {
121 static_assert(type != MessageType::Error ||
122 (errorCode >= ErrorType::ERR_MIN_BACKEND && errorCode <= ErrorType::ERR_MAX));
123 static_assert(type != MessageType::Warning || (errorCode >= ErrorType::WARN_MIN_BACKEND &&
124 errorCode <= ErrorType::WARN_MAX));
125 static_assert(type != MessageType::Info || (errorCode >= ErrorType::INFO_MIN_BACKEND &&
126 errorCode <= ErrorType::INFO_MAX));
127 static_assert(type != MessageType::None);
128 if (forceReplace) errorCatalog.erase(errorCode);
129 auto it = errorCatalog.emplace(errorCode, name);
120 bool add(
const char *name,
bool forceReplace =
false) {
…}
137 if (errorCatalog.count(errorCode))
return errorCatalog.at(errorCode);
138 return "--unknown--"_cs;
141 bool isError(
int errorCode) {
142 return errorCode >= ErrorType::LEGACY_ERROR && errorCode <= ErrorType::ERR_MAX;
151 for (
const auto &pair : errorCatalog) {
152 if (pair.second == lookup) {
153 if (!isError(pair.first))
return false;
167 static std::map<int, cstring> errorCatalog;
105class ErrorCatalog {
…};
Definition error_catalog.h:105
static ErrorCatalog & getCatalog()
Return the singleton object.
Definition error_catalog.h:108
bool add(const char *name, bool forceReplace=false)
Definition error_catalog.h:120
bool isError(std::string_view name)
return true if the given diagnostic can only be an error; false otherwise
Definition error_catalog.h:146
cstring getName(int errorCode)
retrieve the name for errorCode
Definition error_catalog.h:134
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