From 06679e1cf13071375b21696305d96be76a1c8fcc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=91=D1=80=D0=B0=D0=BD=D0=B8=D0=BC=D0=B8=D1=80=20=D0=9A?= =?UTF-8?q?=D0=B0=D1=80=D0=B0=D1=9F=D0=B8=D1=9B?= Date: Sat, 2 Dec 2023 20:16:26 -0800 Subject: [PATCH] Replaced macros with C++17 attributes. --- include/bx/macros.h | 12 ------------ include/bx/os.h | 2 +- src/filepath.cpp | 2 +- src/hash.cpp | 10 +++++----- tests/hash_test.cpp | 8 ++++---- tools/bin2c/bin2c.cpp | 18 +++++++++--------- 6 files changed, 20 insertions(+), 32 deletions(-) diff --git a/include/bx/macros.h b/include/bx/macros.h index 1bca118..7d86465 100644 --- a/include/bx/macros.h +++ b/include/bx/macros.h @@ -60,22 +60,13 @@ #if BX_COMPILER_GCC || BX_COMPILER_CLANG # define BX_ASSUME(_condition) BX_MACRO_BLOCK_BEGIN if (!(_condition) ) { __builtin_unreachable(); } BX_MACRO_BLOCK_END # define BX_ALIGN_DECL(_align, _decl) _decl __attribute__( (aligned(_align) ) ) -# define BX_ALLOW_UNUSED __attribute__( (unused) ) # define BX_FORCE_INLINE inline __attribute__( (__always_inline__) ) # define BX_FUNCTION __PRETTY_FUNCTION__ # define BX_LIKELY(_x) __builtin_expect(!!(_x), 1) # define BX_UNLIKELY(_x) __builtin_expect(!!(_x), 0) # define BX_NO_INLINE __attribute__( (noinline) ) -# define BX_NO_RETURN __attribute__( (noreturn) ) # define BX_CONST_FUNC __attribute__( (pure) ) # define BX_UNREACHABLE __builtin_unreachable() - -# if BX_COMPILER_GCC >= 70000 -# define BX_FALLTHROUGH __attribute__( (fallthrough) ) -# else -# define BX_FALLTHROUGH BX_NOOP() -# endif // BX_COMPILER_GCC >= 70000 - # define BX_NO_VTABLE # define BX_PRINTF_ARGS(_format, _args) __attribute__( (format(__printf__, _format, _args) ) ) @@ -93,16 +84,13 @@ #elif BX_COMPILER_MSVC # define BX_ASSUME(_condition) __assume(_condition) # define BX_ALIGN_DECL(_align, _decl) __declspec(align(_align) ) _decl -# define BX_ALLOW_UNUSED # define BX_FORCE_INLINE __forceinline # define BX_FUNCTION __FUNCTION__ # define BX_LIKELY(_x) (_x) # define BX_UNLIKELY(_x) (_x) # define BX_NO_INLINE __declspec(noinline) -# define BX_NO_RETURN # define BX_CONST_FUNC __declspec(noalias) # define BX_UNREACHABLE __assume(false) -# define BX_FALLTHROUGH BX_NOOP() # define BX_NO_VTABLE __declspec(novtable) # define BX_PRINTF_ARGS(_format, _args) # define BX_THREAD_LOCAL __declspec(thread) diff --git a/include/bx/os.h b/include/bx/os.h index 60971ed..bffd4a2 100644 --- a/include/bx/os.h +++ b/include/bx/os.h @@ -56,7 +56,7 @@ namespace bx void* exec(const char* const* _argv); /// - BX_NO_RETURN void exit(int32_t _exitCode); + [[noreturn]] void exit(int32_t _exitCode); } // namespace bx diff --git a/src/filepath.cpp b/src/filepath.cpp index 18d827e..836e2c2 100644 --- a/src/filepath.cpp +++ b/src/filepath.cpp @@ -121,7 +121,7 @@ namespace bx break; } - BX_FALLTHROUGH; + [[fallthrough]]; default: if ( ( rooted && slashIdx+1 != size) diff --git a/src/hash.cpp b/src/hash.cpp index b45fc9a..33959e3 100644 --- a/src/hash.cpp +++ b/src/hash.cpp @@ -256,9 +256,9 @@ struct HashMurmur2APod switch (m_count) { - case 3: kk |= m_tail[2] << 16; BX_FALLTHROUGH; - case 2: kk |= m_tail[1] << 8; BX_FALLTHROUGH; - case 1: kk |= m_tail[0]; BX_FALLTHROUGH; + case 3: kk |= m_tail[2] << 16; [[fallthrough]]; + case 2: kk |= m_tail[1] << 8; [[fallthrough]]; + case 1: kk |= m_tail[0]; [[fallthrough]]; case 0: mix(kk); break; default: BX_ASSERT(false, "Bug, m_count can't be %d (expected < 4).", m_count); BX_UNREACHABLE; } @@ -318,8 +318,8 @@ struct HashMurmur3Pod switch (m_count) { - case 3: kk |= m_tail[2] << 16; BX_FALLTHROUGH; - case 2: kk |= m_tail[1] << 8; BX_FALLTHROUGH; + case 3: kk |= m_tail[2] << 16; [[fallthrough]]; + case 2: kk |= m_tail[1] << 8; [[fallthrough]]; case 1: kk |= m_tail[0]; mix1(kk); break; case 0: break; default: BX_ASSERT(false, "Bug, m_count can't be %d (expected < 4).", m_count); BX_UNREACHABLE; diff --git a/tests/hash_test.cpp b/tests/hash_test.cpp index e54d35e..41de6ef 100644 --- a/tests/hash_test.cpp +++ b/tests/hash_test.cpp @@ -126,8 +126,8 @@ uint32_t MurmurHash2A(const void * key, int len, uint32_t seed = 0) switch(len) { - case 3: t ^= data[2] << 16; BX_FALLTHROUGH; - case 2: t ^= data[1] << 8; BX_FALLTHROUGH; + case 3: t ^= data[2] << 16; [[fallthrough]]; + case 2: t ^= data[1] << 8; [[fallthrough]]; case 1: t ^= data[0]; }; @@ -229,8 +229,8 @@ uint32_t MurmurHash3_x86_32(const void * key, int len, uint32_t seed) switch(len & 3) { - case 3: k1 ^= tail[2] << 16; BX_FALLTHROUGH; - case 2: k1 ^= tail[1] << 8; BX_FALLTHROUGH; + case 3: k1 ^= tail[2] << 16; [[fallthrough]]; + case 2: k1 ^= tail[1] << 8; [[fallthrough]]; case 1: k1 ^= tail[0]; k1 *= c1; k1 = rotl32(k1,15); k1 *= c2; h1 ^= k1; }; diff --git a/tools/bin2c/bin2c.cpp b/tools/bin2c/bin2c.cpp index ef0e2fc..335b0b5 100644 --- a/tools/bin2c/bin2c.cpp +++ b/tools/bin2c/bin2c.cpp @@ -84,21 +84,21 @@ public: { switch (ch) { - case '\"': bx::write(_writer, "\\\"", &err); break; - case '\n': bx::write(_writer, "\\n\"\n\t\"", &err); break; - case '\r': bx::write(_writer, "\\r", &err); break; - case '\\': escaped = true; BX_FALLTHROUGH; - default: bx::write(_writer, ch, &err); break; + case '\"': bx::write(_writer, "\\\"", &err); break; + case '\n': bx::write(_writer, "\\n\"\n\t\"", &err); break; + case '\r': bx::write(_writer, "\\r", &err); break; + case '\\': escaped = true; [[fallthrough]]; + default: bx::write(_writer, ch, &err); break; } } else { switch (ch) { - case '\n': bx::write(_writer, "\\\"\n\t\"", &err); break; - case '\r': BX_FALLTHROUGH; - case '\t': bx::write(_writer, "\\", &err); BX_FALLTHROUGH; - default : bx::write(_writer, ch, &err); break; + case '\n': bx::write(_writer, "\\\"\n\t\"", &err); break; + case '\r': [[fallthrough]]; + case '\t': bx::write(_writer, "\\", &err); [[fallthrough]]; + default : bx::write(_writer, ch, &err); break; } escaped = false;