diff --git a/lib/error_catalog.cpp b/lib/error_catalog.cpp index d956786dd54..5e0cb4c0ca2 100644 --- a/lib/error_catalog.cpp +++ b/lib/error_catalog.cpp @@ -38,11 +38,9 @@ const int ErrorType::ERR_IO = 14; const int ErrorType::ERR_UNREACHABLE = 15; const int ErrorType::ERR_MODEL = 16; const int ErrorType::ERR_RESERVED = 17; -// If we specialize for 1000 error types we're good! -const int ErrorType::ERR_MAX_ERRORS = 999; // ------ Warnings ----------- -const int ErrorType::LEGACY_WARNING = ERR_MAX_ERRORS + 1; +const int ErrorType::LEGACY_WARNING = ERR_MAX + 1; const int ErrorType::WARN_FAILED = 1001; const int ErrorType::WARN_UNKNOWN = 1002; const int ErrorType::WARN_INVALID = 1003; @@ -65,11 +63,10 @@ const int ErrorType::WARN_UNINITIALIZED_USE = 1019; const int ErrorType::WARN_INVALID_HEADER = 1020; const int ErrorType::WARN_DUPLICATE_PRIORITIES = 1021; const int ErrorType::WARN_ENTRIES_OUT_OF_ORDER = 1022; -const int ErrorType::WARN_MAX_WARNINGS = 2142; -// ------ Info message ----------- -const int ErrorType::INFO_INFERRED = WARN_MAX_WARNINGS + 1; -const int ErrorType::INFO_MAX_INFOS = 3999; +// ------ Info messages ----------- +const int ErrorType::INFO_INFERRED = WARN_MAX + 1; +const int ErrorType::INFO_PROGRESS = 2143; // map from errorCode to ErrorSig std::map ErrorCatalog::errorCatalog = { @@ -118,4 +115,5 @@ std::map ErrorCatalog::errorCatalog = { {ErrorType::WARN_ENTRIES_OUT_OF_ORDER, "entries_out_of_priority_order"}, // Info messages - {ErrorType::INFO_INFERRED, "inferred"}}; + {ErrorType::INFO_INFERRED, "inferred"}, + {ErrorType::INFO_PROGRESS, "progress"}}; diff --git a/lib/error_catalog.h b/lib/error_catalog.h index b98e19582fb..65ffef0e704 100644 --- a/lib/error_catalog.h +++ b/lib/error_catalog.h @@ -21,10 +21,12 @@ limitations under the License. #include #include "cstring.h" +#include "lib/error_message.h" +#include "lib/exceptions.h" + +using MessageType = ErrorMessage::MessageType; /// enumerate supported errors -/// Backends should extend this class with additional errors in the range 500-999 and -/// warnings in the range 1500-2141. /// It is a class and not an enum class because in C++11 you can't extend an enum class class ErrorType { public: @@ -48,9 +50,9 @@ class ErrorType { static const int ERR_UNREACHABLE; // unreachable parser state static const int ERR_MODEL; // something is wrong with the target model static const int ERR_RESERVED; // Reserved for target use - - // If we specialize for 1000 error types we're good! - static const int ERR_MAX_ERRORS; + // Backends should extend this class with additional errors in the range 500-999. + static const int ERR_MIN_BACKEND = 500; // first allowed backend error code + static const int ERR_MAX = 999; // last allowed error code // -------- Warnings ----------- // warnings as initially defined with a format string @@ -77,14 +79,18 @@ class ErrorType { static const int WARN_INVALID_HEADER; // access to fields of an invalid header static const int WARN_DUPLICATE_PRIORITIES; // two entries with the same priority static const int WARN_ENTRIES_OUT_OF_ORDER; // entries with priorities out of order - - static const int WARN_MAX_WARNINGS; + // Backends should extend this class with additional warnings in the range 1500-2141. + static const int WARN_MIN_BACKEND = 1500; // first allowed backend warning code + static const int WARN_MAX = 2141; // last allowed warning code // -------- Info messages ------------- // info messages as initially defined with a format string static const int INFO_INFERRED; // information inferred by compiler + static const int INFO_PROGRESS; // compilation progress - static const int INFO_MAX_INFOS; + // Backends should extend this class with additional info messages in the range 3000-3999. + static const int INFO_MIN_BACKEND = 3000; // first allowed backend info code + static const int INFO_MAX = 3999; // last allowed info code }; class ErrorCatalog { @@ -97,10 +103,19 @@ class ErrorCatalog { /// add to the catalog /// returns false if the code already exists and forceReplace was not set to true + /// @param type - error/warning/info message /// @param errorCode - integer value for the error/warning /// @param name - name for the error. Used to enable/disable all errors of that type /// @param forceReplace - override an existing error type in the catalog - bool add(int errorCode, const char *name, bool forceReplace = false) { + template + bool add(const char *name, bool forceReplace = false) { + static_assert(type != MessageType::Error || + (errorCode >= ErrorType::ERR_MIN_BACKEND && errorCode <= ErrorType::ERR_MAX)); + static_assert(type != MessageType::Warning || (errorCode >= ErrorType::WARN_MIN_BACKEND && + errorCode <= ErrorType::WARN_MAX)); + static_assert(type != MessageType::Info || (errorCode >= ErrorType::INFO_MIN_BACKEND && + errorCode <= ErrorType::INFO_MAX)); + static_assert(type != MessageType::None); if (forceReplace) errorCatalog.erase(errorCode); auto it = errorCatalog.emplace(errorCode, name); return it.second; @@ -125,7 +140,7 @@ class ErrorCatalog { bool isError(cstring name) { int code = getCode(name); if (code == -1) return false; - if (code >= ErrorType::ERR_MAX_ERRORS) return false; + if (code > ErrorType::ERR_MAX) return false; return true; }