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;
38 static const int LEGACY_ERROR;
39 static const int ERR_UNKNOWN;
40 static const int ERR_UNSUPPORTED;
41 static const int ERR_UNEXPECTED;
42 static const int ERR_UNINITIALIZED;
43 static const int ERR_EXPECTED;
44 static const int ERR_NOT_FOUND;
45 static const int ERR_INVALID;
46 static const int ERR_EXPRESSION;
47 static const int ERR_OVERLIMIT;
48 static const int ERR_INSUFFICIENT;
49 static const int ERR_TYPE_ERROR;
50 static const int ERR_UNSUPPORTED_ON_TARGET;
51 static const int ERR_DUPLICATE;
52 static const int ERR_IO;
53 static const int ERR_UNREACHABLE;
54 static const int ERR_MODEL;
55 static const int ERR_RESERVED;
57 static const int ERR_MIN_BACKEND = 500;
58 static const int ERR_MAX = 999;
62 static const int LEGACY_WARNING;
63 static const int WARN_FAILED;
64 static const int WARN_UNKNOWN;
65 static const int WARN_INVALID;
66 static const int WARN_UNSUPPORTED;
67 static const int WARN_DEPRECATED;
68 static const int WARN_UNINITIALIZED;
69 static const int WARN_UNINITIALIZED_USE;
70 static const int WARN_UNINITIALIZED_OUT_PARAM;
71 static const int WARN_UNUSED;
72 static const int WARN_MISSING;
73 static const int WARN_ORDERING;
74 static const int WARN_MISMATCH;
75 static const int WARN_OVERFLOW;
76 static const int WARN_IGNORE_PROPERTY;
77 static const int WARN_TYPE_INFERENCE;
78 static const int WARN_PARSER_TRANSITION;
79 static const int WARN_UNREACHABLE;
80 static const int WARN_SHADOWING;
81 static const int WARN_IGNORE;
82 static const int WARN_INVALID_HEADER;
83 static const int WARN_DUPLICATE_PRIORITIES;
84 static const int WARN_ENTRIES_OUT_OF_ORDER;
85 static const int WARN_MULTI_HDR_EXTRACT;
86 static const int WARN_EXPRESSION;
87 static const int WARN_DUPLICATE;
89 static const int WARN_MIN_BACKEND = 1500;
90 static const int WARN_MAX = 2141;
94 static const int INFO_INFERRED;
95 static const int INFO_PROGRESS;
98 static const int INFO_MIN_BACKEND = 3000;
99 static const int INFO_MAX = 3999;
116 template <MessageType type,
int errorCode>
117 bool add(
const char *name,
bool forceReplace =
false) {
118 static_assert(type != MessageType::Error ||
119 (errorCode >= ErrorType::ERR_MIN_BACKEND && errorCode <= ErrorType::ERR_MAX));
120 static_assert(type != MessageType::Warning || (errorCode >= ErrorType::WARN_MIN_BACKEND &&
121 errorCode <= ErrorType::WARN_MAX));
122 static_assert(type != MessageType::Info || (errorCode >= ErrorType::INFO_MIN_BACKEND &&
123 errorCode <= ErrorType::INFO_MAX));
124 static_assert(type != MessageType::None);
125 if (forceReplace) errorCatalog.erase(errorCode);
126 auto it = errorCatalog.emplace(errorCode, name);
134 if (errorCatalog.count(errorCode))
return errorCatalog.at(errorCode);
135 return "--unknown--"_cs;
138 bool isError(
int errorCode) {
139 return errorCode >= ErrorType::LEGACY_ERROR && errorCode <= ErrorType::ERR_MAX;
148 for (
const auto &pair : errorCatalog) {
149 if (pair.second == lookup) {
150 if (!isError(pair.first))
return false;
162 static std::map<int, cstring> errorCatalog;
Definition error_catalog.h:102
static ErrorCatalog & getCatalog()
Return the singleton object.
Definition error_catalog.h:105
bool add(const char *name, bool forceReplace=false)
Definition error_catalog.h:117
bool isError(std::string_view name)
return true if the given diagnostic can only be an error; false otherwise
Definition error_catalog.h:143
cstring getName(int errorCode)
retrieve the name for errorCode
Definition error_catalog.h:131
Definition error_catalog.h:33
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:51