Change to use enum instead of enum class for MessageLevel.
This allows us to create C interface with MessageLevel later.
diff --git a/source/diagnostic.cpp b/source/diagnostic.cpp
index 16bc33a..b92ff00 100644
--- a/source/diagnostic.cpp
+++ b/source/diagnostic.cpp
@@ -71,22 +71,22 @@
DiagnosticStream::~DiagnosticStream() {
using spvtools::MessageLevel;
if (error_ != SPV_FAILED_MATCH && consumer_ != nullptr) {
- auto level = MessageLevel::Error;
+ auto level = MessageLevel::kError;
switch (error_) {
case SPV_SUCCESS:
case SPV_REQUESTED_TERMINATION: // Essentially success.
- level = MessageLevel::Info;
+ level = MessageLevel::kInfo;
break;
case SPV_WARNING:
- level = MessageLevel::Warning;
+ level = MessageLevel::kWarning;
break;
case SPV_UNSUPPORTED:
case SPV_ERROR_INTERNAL:
case SPV_ERROR_INVALID_TABLE:
- level = MessageLevel::InternalError;
+ level = MessageLevel::kInternalError;
break;
case SPV_ERROR_OUT_OF_MEMORY:
- level = MessageLevel::Fatal;
+ level = MessageLevel::kFatal;
break;
default:
break;
diff --git a/source/message.cpp b/source/message.cpp
index 9d28c8c..efbd65c 100644
--- a/source/message.cpp
+++ b/source/message.cpp
@@ -23,22 +23,22 @@
const char* message) {
const char* level_string = nullptr;
switch (level) {
- case MessageLevel::Fatal:
+ case MessageLevel::kFatal:
level_string = "fatal";
break;
- case MessageLevel::InternalError:
+ case MessageLevel::kInternalError:
level_string = "internal error";
break;
- case MessageLevel::Error:
+ case MessageLevel::kError:
level_string = "error";
break;
- case MessageLevel::Warning:
+ case MessageLevel::kWarning:
level_string = "warning";
break;
- case MessageLevel::Info:
+ case MessageLevel::kInfo:
level_string = "info";
break;
- case MessageLevel::Debug:
+ case MessageLevel::kDebug:
level_string = "debug";
break;
}
diff --git a/source/message.h b/source/message.h
index 7af4297..9eecacf 100644
--- a/source/message.h
+++ b/source/message.h
@@ -25,15 +25,17 @@
// TODO(antiagainst): This eventually should be in the C++ interface.
// Severity levels of messages communicated to the consumer.
-enum class MessageLevel {
- Fatal, // Unrecoverable error due to environment. Will abort the program
- // immediately. E.g., out of memory.
- InternalError, // Unrecoverable error due to SPIRV-Tools internals. Will
- // abort the program immediately. E.g., unimplemented feature.
- Error, // Normal error due to user input.
- Warning, // Warning information.
- Info, // General information.
- Debug, // Debug information.
+enum MessageLevel {
+ kFatal, // Unrecoverable error due to environment.
+ // Will exit the program immediately. E.g.,
+ // out of memory.
+ kInternalError, // Unrecoverable error due to SPIRV-Tools internals.
+ // Will exit the program immediately. E.g.,
+ // unimplemented feature.
+ kError, // Normal error due to user input.
+ kWarning, // Warning information.
+ kInfo, // General information.
+ kDebug, // Debug information.
};
// Message consumer. The C strings for source and message are only alive for the
diff --git a/source/opt/log.h b/source/opt/log.h
index 8432d4a..9ad24d5 100644
--- a/source/opt/log.h
+++ b/source/opt/log.h
@@ -54,18 +54,18 @@
// Logs an error message to the consumer saying the given feature is
// unimplemented.
-#define SPIRV_UNIMPLEMENTED(consumer, feature) \
- do { \
- spvtools::Log(consumer, MessageLevel::InternalError, __FILE__, \
- {__LINE__, 0, 0}, "unimplemented: " feature); \
+#define SPIRV_UNIMPLEMENTED(consumer, feature) \
+ do { \
+ spvtools::Log(consumer, MessageLevel::kInternalError, __FILE__, \
+ {__LINE__, 0, 0}, "unimplemented: " feature); \
} while (0)
// Logs an error message to the consumer saying the code location
// should be unreachable.
-#define SPIRV_UNREACHABLE(consumer) \
- do { \
- spvtools::Log(consumer, MessageLevel::InternalError, __FILE__, \
- {__LINE__, 0, 0}, "unreachable"); \
+#define SPIRV_UNREACHABLE(consumer) \
+ do { \
+ spvtools::Log(consumer, MessageLevel::kInternalError, __FILE__, \
+ {__LINE__, 0, 0}, "unreachable"); \
} while (0)
// Helper macros for concatenating arguments.
@@ -135,31 +135,31 @@
#define SPIRV_ASSERT_1(consumer, condition) \
do { \
if (!(condition)) { \
- spvtools::Log(consumer, MessageLevel::InternalError, __FILE__, \
+ spvtools::Log(consumer, MessageLevel::kInternalError, __FILE__, \
{__LINE__, 0, 0}, "assertion failed: " #condition); \
std::exit(EXIT_FAILURE); \
} \
} while (0)
-#define SPIRV_ASSERT_2(consumer, condition, message) \
- do { \
- if (!(condition)) { \
- spvtools::Log(consumer, MessageLevel::InternalError, __FILE__, \
- {__LINE__, 0, 0}, "assertion failed: " message); \
- std::exit(EXIT_FAILURE); \
- } \
- } while (0)
-
-#define SPIRV_ASSERT_more(consumer, condition, format, ...) \
+#define SPIRV_ASSERT_2(consumer, condition, message) \
do { \
if (!(condition)) { \
- spvtools::Logf(consumer, MessageLevel::InternalError, __FILE__, \
- {__LINE__, 0, 0}, "assertion failed: " format, \
- __VA_ARGS__); \
+ spvtools::Log(consumer, MessageLevel::kInternalError, __FILE__, \
+ {__LINE__, 0, 0}, "assertion failed: " message); \
std::exit(EXIT_FAILURE); \
} \
} while (0)
+#define SPIRV_ASSERT_more(consumer, condition, format, ...) \
+ do { \
+ if (!(condition)) { \
+ spvtools::Logf(consumer, MessageLevel::kInternalError, __FILE__, \
+ {__LINE__, 0, 0}, "assertion failed: " format, \
+ __VA_ARGS__); \
+ std::exit(EXIT_FAILURE); \
+ } \
+ } while (0)
+
#define SPIRV_ASSERT_3(consumer, condition, format, ...) \
SPIRV_ASSERT_more(consumer, condition, format, __VA_ARGS__)
diff --git a/test/BinaryParse.cpp b/test/BinaryParse.cpp
index cb79461..ceb169a 100644
--- a/test/BinaryParse.cpp
+++ b/test/BinaryParse.cpp
@@ -306,7 +306,7 @@
ctx, [&invocation](spvtools::MessageLevel level, const char* source,
const spv_position_t& position, const char* message) {
++invocation;
- EXPECT_EQ(spvtools::MessageLevel::Error, level);
+ EXPECT_EQ(spvtools::MessageLevel::kError, level);
EXPECT_STREQ("input", source);
EXPECT_EQ(0u, position.line);
EXPECT_EQ(0u, position.column);
diff --git a/test/c_interface.cpp b/test/c_interface.cpp
index 0fecda1..0f8992f 100644
--- a/test/c_interface.cpp
+++ b/test/c_interface.cpp
@@ -109,7 +109,7 @@
[&invocation](MessageLevel level, const char* source,
const spv_position_t& position, const char* message) {
++invocation;
- EXPECT_EQ(MessageLevel::Error, level);
+ EXPECT_EQ(MessageLevel::kError, level);
// The error happens at scanning the begining of second line.
EXPECT_STREQ("input", source);
EXPECT_EQ(1u, position.line);
@@ -137,7 +137,7 @@
[&invocation](MessageLevel level, const char* source,
const spv_position_t& position, const char* message) {
++invocation;
- EXPECT_EQ(MessageLevel::Error, level);
+ EXPECT_EQ(MessageLevel::kError, level);
EXPECT_STREQ("input", source);
EXPECT_EQ(0u, position.line);
EXPECT_EQ(0u, position.column);
@@ -172,7 +172,7 @@
[&invocation](MessageLevel level, const char* source,
const spv_position_t& position, const char* message) {
++invocation;
- EXPECT_EQ(MessageLevel::Error, level);
+ EXPECT_EQ(MessageLevel::kError, level);
EXPECT_STREQ("input", source);
EXPECT_EQ(0u, position.line);
EXPECT_EQ(0u, position.column);
diff --git a/test/cpp_interface.cpp b/test/cpp_interface.cpp
index c24c35a..f464fcf 100644
--- a/test/cpp_interface.cpp
+++ b/test/cpp_interface.cpp
@@ -36,7 +36,7 @@
// This cannot pass validation since %1 is not defined.
t.SetMessageConsumer([](MessageLevel level, const char* source,
const spv_position_t& position, const char* message) {
- EXPECT_EQ(MessageLevel::Error, level);
+ EXPECT_EQ(MessageLevel::kError, level);
EXPECT_STREQ("input", source);
EXPECT_EQ(0u, position.line);
EXPECT_EQ(0u, position.column);
@@ -68,7 +68,7 @@
[&invocation_count](MessageLevel level, const char* source,
const spv_position_t& position, const char* message) {
++invocation_count;
- EXPECT_EQ(MessageLevel::Error, level);
+ EXPECT_EQ(MessageLevel::kError, level);
EXPECT_STREQ("input", source);
EXPECT_EQ(0u, position.line);
EXPECT_EQ(5u, position.column);
@@ -90,7 +90,7 @@
[&invocation_count](MessageLevel level, const char* source,
const spv_position_t& position, const char* message) {
++invocation_count;
- EXPECT_EQ(MessageLevel::Error, level);
+ EXPECT_EQ(MessageLevel::kError, level);
EXPECT_STREQ("input", source);
EXPECT_EQ(0u, position.line);
EXPECT_EQ(0u, position.column);
@@ -111,7 +111,7 @@
[&invocation_count](MessageLevel level, const char* source,
const spv_position_t& position, const char* message) {
++invocation_count;
- EXPECT_EQ(MessageLevel::Error, level);
+ EXPECT_EQ(MessageLevel::kError, level);
EXPECT_STREQ("input", source);
EXPECT_EQ(0u, position.line);
EXPECT_EQ(0u, position.column);
@@ -149,7 +149,7 @@
[&invocation_count](MessageLevel level, const char* source,
const spv_position_t& position, const char* message) {
++invocation_count;
- EXPECT_EQ(MessageLevel::Error, level);
+ EXPECT_EQ(MessageLevel::kError, level);
EXPECT_STREQ("input", source);
EXPECT_EQ(0u, position.line);
EXPECT_EQ(0u, position.column);
diff --git a/test/test_log.cpp b/test/test_log.cpp
index 47a0f5c..2d4cb7d 100644
--- a/test/test_log.cpp
+++ b/test/test_log.cpp
@@ -28,7 +28,7 @@
auto consumer = [&invocation](MessageLevel level, const char* source,
const spv_position_t&, const char* message) {
++invocation;
- EXPECT_EQ(MessageLevel::InternalError, level);
+ EXPECT_EQ(MessageLevel::kInternalError, level);
EXPECT_THAT(source, MatchesRegex(".*test_log.cpp$"));
EXPECT_STREQ("unimplemented: the-ultimite-feature", message);
};
@@ -42,7 +42,7 @@
auto consumer = [&invocation](MessageLevel level, const char* source,
const spv_position_t&, const char* message) {
++invocation;
- EXPECT_EQ(MessageLevel::InternalError, level);
+ EXPECT_EQ(MessageLevel::kInternalError, level);
EXPECT_THAT(source, MatchesRegex(".*test_log.cpp$"));
EXPECT_STREQ("unreachable", message);
};