Browse Source

Replaced macros with C++17 attributes.

Бранимир Караџић 2 years ago
parent
commit
06679e1cf1
6 changed files with 20 additions and 32 deletions
  1. 0 12
      include/bx/macros.h
  2. 1 1
      include/bx/os.h
  3. 1 1
      src/filepath.cpp
  4. 5 5
      src/hash.cpp
  5. 4 4
      tests/hash_test.cpp
  6. 9 9
      tools/bin2c/bin2c.cpp

+ 0 - 12
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)

+ 1 - 1
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
 

+ 1 - 1
src/filepath.cpp

@@ -121,7 +121,7 @@ namespace bx
 
 					break;
 				}
-				BX_FALLTHROUGH;
+				[[fallthrough]];
 
 			default:
 				if ( ( rooted && slashIdx+1 != size)

+ 5 - 5
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;

+ 4 - 4
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;
 	};

+ 9 - 9
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;