From ed72ccc139fcc8bc12a4530f6baa2ac4eee76c28 Mon Sep 17 00:00:00 2001 From: Abdelrahman Said Date: Mon, 29 Dec 2025 21:41:04 +0000 Subject: [PATCH] Reformat common --- src/common/aliases/aliases.h | 22 ++--- src/common/assert/assert.h | 46 ++++----- src/common/misc/misc_utils.h | 52 +++++----- src/common/platform/platform.h | 170 ++++++++++++++++----------------- 4 files changed, 145 insertions(+), 145 deletions(-) diff --git a/src/common/aliases/aliases.h b/src/common/aliases/aliases.h index a09467a..f51bac1 100644 --- a/src/common/aliases/aliases.h +++ b/src/common/aliases/aliases.h @@ -7,20 +7,20 @@ #include #if defined(WAPP_PLATFORM_C) && WAPP_PLATFORM_C_VERSION >= WAPP_PLATFORM_C11_VERSION && !defined(WAPP_PLATFORM_APPLE) - #include + #include - #if WAPP_PLATFORM_C_VERSION >= WAPP_PLATFORM_C23_VERSION - #define c8 char8_t - #else - #define c8 uint8_t - #endif // !WAPP_PLATFORM_C23_VERSION + #if WAPP_PLATFORM_C_VERSION >= WAPP_PLATFORM_C23_VERSION + #define c8 char8_t + #else + #define c8 uint8_t + #endif // !WAPP_PLATFORM_C23_VERSION - #define c16 char16_t - #define c32 char32_t + #define c16 char16_t + #define c32 char32_t #else - #define c8 uint8_t - #define c16 uint16_t - #define c32 uint32_t + #define c8 uint8_t + #define c16 uint16_t + #define c32 uint32_t #endif // !WAPP_PLATFORM_C #define u8 uint8_t diff --git a/src/common/assert/assert.h b/src/common/assert/assert.h index 67d7dbd..9e82e4e 100644 --- a/src/common/assert/assert.h +++ b/src/common/assert/assert.h @@ -16,42 +16,42 @@ BEGIN_C_LINKAGE #define wapp_static_assert(EXPR, MSG) extern char ASSERTION_FAILED[EXPR ? 1 : -1] #ifndef WAPP_NO_RUNTIME_ASSERT - #define wapp_runtime_assert(EXPR, MSG) __wapp_runtime_assert(EXPR, MSG) + #define wapp_runtime_assert(EXPR, MSG) __wapp_runtime_assert(EXPR, MSG) #else - #define wapp_runtime_assert(EXPR, MSG) + #define wapp_runtime_assert(EXPR, MSG) #endif #ifdef WAPP_DEBUG_ASSERT - #define wapp_debug_assert(EXPR, MSG) wapp_runtime_assert(EXPR, MSG) + #define wapp_debug_assert(EXPR, MSG) wapp_runtime_assert(EXPR, MSG) #else - #define wapp_debug_assert(EXPR, MSG) + #define wapp_debug_assert(EXPR, MSG) #endif #ifdef WAPP_PLATFORM_WINDOWS -#define __wapp_runtime_assert(EXPR, MSG) do { \ - __pragma(warning(push)) \ - __pragma(warning(disable:4127)) \ - if (!(EXPR)) { \ - __pragma(warning(pop)) \ - __runtime_assert_failed(EXPR, MSG); \ - } \ +#define __wapp_runtime_assert(EXPR, MSG) do { \ + __pragma(warning(push)) \ + __pragma(warning(disable:4127)) \ + if (!(EXPR)) { \ + __pragma(warning(pop)) \ + __runtime_assert_failed(EXPR, MSG); \ + } \ } while(false) #else -#define __wapp_runtime_assert(EXPR, MSG) do { \ - if (!(EXPR)) { \ - __runtime_assert_failed(EXPR, MSG); \ - } \ +#define __wapp_runtime_assert(EXPR, MSG) do { \ + if (!(EXPR)) { \ + __runtime_assert_failed(EXPR, MSG); \ + } \ } while(false) #endif // !WAPP_PLATFORM_WINDOWS -#define __runtime_assert_failed(EXPR, MSG) do { \ - fprintf( \ - stderr, \ - "%s:%d (In function `%s`): Assertion failed (%" PRIu32 ")\nDiagnostic: %s\n\n", \ - __FILE__, __LINE__, __func__, \ - EXPR, MSG \ - ); \ - abort(); \ +#define __runtime_assert_failed(EXPR, MSG) do { \ + fprintf( \ + stderr, \ + "%s:%d (In function `%s`): Assertion failed (%" PRIu32 ")\nDiagnostic: %s\n\n", \ + __FILE__, __LINE__, __func__, \ + EXPR, MSG \ + ); \ + abort(); \ } while(false) #ifdef WAPP_PLATFORM_CPP diff --git a/src/common/misc/misc_utils.h b/src/common/misc/misc_utils.h index 482699f..ebe105f 100644 --- a/src/common/misc/misc_utils.h +++ b/src/common/misc/misc_utils.h @@ -16,35 +16,35 @@ BEGIN_C_LINKAGE #define PiB(SIZE) (((u64)SIZE) << 50) #define EiB(SIZE) (((u64)SIZE) << 60) -#define KB(SIZE) (((u64)SIZE) * 1000llu) -#define MB(SIZE) (KB(SIZE) * 1000llu) -#define GB(SIZE) (MB(SIZE) * 1000llu) -#define TB(SIZE) (GB(SIZE) * 1000llu) -#define PB(SIZE) (TB(SIZE) * 1000llu) -#define EB(SIZE) (PB(SIZE) * 1000llu) +#define KB(SIZE) (((u64)SIZE) * 1000llu) +#define MB(SIZE) (KB(SIZE) * 1000llu) +#define GB(SIZE) (MB(SIZE) * 1000llu) +#define TB(SIZE) (GB(SIZE) * 1000llu) +#define PB(SIZE) (TB(SIZE) * 1000llu) +#define EB(SIZE) (PB(SIZE) * 1000llu) #define wapp_misc_utils_padding_size(SIZE) u8 reserved_padding[sizeof(void *) - ((SIZE) % sizeof(void *))] -#define U64_RSHIFT_OR_1(X) (((u64)X) | (((u64)X) >> 1)) -#define U64_RSHIFT_OR_2(X) (((u64)X) | (((u64)X) >> 2)) -#define U64_RSHIFT_OR_4(X) (((u64)X) | (((u64)X) >> 4)) -#define U64_RSHIFT_OR_8(X) (((u64)X) | (((u64)X) >> 8)) -#define U64_RSHIFT_OR_16(X) (((u64)X) | (((u64)X) >> 16)) -#define U64_RSHIFT_OR_32(X) (((u64)X) | (((u64)X) >> 32)) -#define wapp_misc_utils_u64_round_up_pow2(X) ( \ - ( \ - U64_RSHIFT_OR_32( \ - U64_RSHIFT_OR_16( \ - U64_RSHIFT_OR_8( \ - U64_RSHIFT_OR_4( \ - U64_RSHIFT_OR_2( \ - U64_RSHIFT_OR_1(X - 1) \ - ) \ - ) \ - ) \ - ) \ - ) \ - ) + 1 \ +#define U64_RSHIFT_OR_1(X) (((u64)X) | (((u64)X) >> 1)) +#define U64_RSHIFT_OR_2(X) (((u64)X) | (((u64)X) >> 2)) +#define U64_RSHIFT_OR_4(X) (((u64)X) | (((u64)X) >> 4)) +#define U64_RSHIFT_OR_8(X) (((u64)X) | (((u64)X) >> 8)) +#define U64_RSHIFT_OR_16(X) (((u64)X) | (((u64)X) >> 16)) +#define U64_RSHIFT_OR_32(X) (((u64)X) | (((u64)X) >> 32)) +#define wapp_misc_utils_u64_round_up_pow2(X) ( \ + ( \ + U64_RSHIFT_OR_32( \ + U64_RSHIFT_OR_16( \ + U64_RSHIFT_OR_8( \ + U64_RSHIFT_OR_4( \ + U64_RSHIFT_OR_2( \ + U64_RSHIFT_OR_1(X - 1) \ + ) \ + ) \ + ) \ + ) \ + ) \ + ) + 1 \ ) #ifdef WAPP_PLATFORM_CPP diff --git a/src/common/platform/platform.h b/src/common/platform/platform.h index 9891f86..907b696 100644 --- a/src/common/platform/platform.h +++ b/src/common/platform/platform.h @@ -4,111 +4,111 @@ #define PLATFORM_H #if defined(__ANDROID__) - #define WAPP_PLATFORM_ANDROID - #define WAPP_PLATFORM_POSIX + #define WAPP_PLATFORM_ANDROID + #define WAPP_PLATFORM_POSIX #elif defined(__FreeBSD__) - #define WAPP_PLATFORM_FREE_BSD - #define WAPP_PLATFORM_BSD - #define WAPP_PLATFORM_POSIX + #define WAPP_PLATFORM_FREE_BSD + #define WAPP_PLATFORM_BSD + #define WAPP_PLATFORM_POSIX #elif defined(__NetBSD__) - #define WAPP_PLATFORM_NET_BSD - #define WAPP_PLATFORM_BSD - #define WAPP_PLATFORM_POSIX + #define WAPP_PLATFORM_NET_BSD + #define WAPP_PLATFORM_BSD + #define WAPP_PLATFORM_POSIX #elif defined(__OpenBSD__) - #define WAPP_PLATFORM_OPEN_BSD - #define WAPP_PLATFORM_BSD - #define WAPP_PLATFORM_POSIX + #define WAPP_PLATFORM_OPEN_BSD + #define WAPP_PLATFORM_BSD + #define WAPP_PLATFORM_POSIX #elif defined(__DragonFly__) - #define WAPP_PLATFORM_DRAGON_FLY - #define WAPP_PLATFORM_BSD - #define WAPP_PLATFORM_POSIX + #define WAPP_PLATFORM_DRAGON_FLY + #define WAPP_PLATFORM_BSD + #define WAPP_PLATFORM_POSIX #elif defined(__bsdi__) - #define WAPP_PLATFORM_BSD - #define WAPP_PLATFORM_POSIX + #define WAPP_PLATFORM_BSD + #define WAPP_PLATFORM_POSIX #elif defined(__linux__) || defined(linux) || defined(__linux) || defined(__gnu_linux__) - #define WAPP_PLATFORM_LINUX - #define WAPP_PLATFORM_POSIX + #define WAPP_PLATFORM_LINUX + #define WAPP_PLATFORM_POSIX #elif defined(__GNU__) || defined(__gnu_hurd__) - #define WAPP_PLATFORM_GNU - #define WAPP_PLATFORM_POSIX + #define WAPP_PLATFORM_GNU + #define WAPP_PLATFORM_POSIX #elif defined(__APPLE__) || defined(__MACH__) - #include - #if TARGET_OS_IPHONE - #define WAPP_PLATFORM_IOS - #define WAPP_PLATFORM_APPLE - #define WAPP_PLATFORM_POSIX - #elif TARGET_OS_MAC - #define WAPP_PLATFORM_MACOS - #define WAPP_PLATFORM_APPLE - #define WAPP_PLATFORM_POSIX - #else - #error "Unrecognised Apple platform" - #endif + #include + #if TARGET_OS_IPHONE + #define WAPP_PLATFORM_IOS + #define WAPP_PLATFORM_APPLE + #define WAPP_PLATFORM_POSIX + #elif TARGET_OS_MAC + #define WAPP_PLATFORM_MACOS + #define WAPP_PLATFORM_APPLE + #define WAPP_PLATFORM_POSIX + #else + #error "Unrecognised Apple platform" + #endif #elif defined(_WIN64) - #define WAPP_PLATFORM_WINDOWS64 - #define WAPP_PLATFORM_WINDOWS + #define WAPP_PLATFORM_WINDOWS64 + #define WAPP_PLATFORM_WINDOWS #elif defined(_WIN32) - #define WAPP_PLATFORM_WINDOWS32 - #define WAPP_PLATFORM_WINDOWS + #define WAPP_PLATFORM_WINDOWS32 + #define WAPP_PLATFORM_WINDOWS #elif defined(__CYGWIN__) - #define WAPP_PLATFORM_CYGWIN - #define WAPP_PLATFORM_WINDOWS + #define WAPP_PLATFORM_CYGWIN + #define WAPP_PLATFORM_WINDOWS #elif defined(__unix__) || defined(__unix) - #define WAPP_PLATFORM_UNIX - #define WAPP_PLATFORM_POSIX + #define WAPP_PLATFORM_UNIX + #define WAPP_PLATFORM_POSIX #else - #error "Unrecognised platform" + #error "Unrecognised platform" #endif #ifdef __cplusplus - #define WAPP_PLATFORM_CPP - #define WAPP_PLATFORM_CPP_VERSION __cplusplus - #define WAPP_PLATFORM_CPP98_VERSION 199711L - #define WAPP_PLATFORM_CPP11_VERSION 201103L - #define WAPP_PLATFORM_CPP14_VERSION 201402L - #define WAPP_PLATFORM_CPP17_VERSION 201703L - #define WAPP_PLATFORM_CPP20_VERSION 202002L - #define WAPP_PLATFORM_CPP23_VERSION 202302L + #define WAPP_PLATFORM_CPP + #define WAPP_PLATFORM_CPP_VERSION __cplusplus + #define WAPP_PLATFORM_CPP98_VERSION 199711L + #define WAPP_PLATFORM_CPP11_VERSION 201103L + #define WAPP_PLATFORM_CPP14_VERSION 201402L + #define WAPP_PLATFORM_CPP17_VERSION 201703L + #define WAPP_PLATFORM_CPP20_VERSION 202002L + #define WAPP_PLATFORM_CPP23_VERSION 202302L - #if WAPP_PLATFORM_CPP_VERSION == WAPP_PLATFORM_CPP98_VERSION - #define WAPP_PLATFORM_CPP98 - #elif WAPP_PLATFORM_CPP_VERSION == WAPP_PLATFORM_CPP11_VERSION - #define WAPP_PLATFORM_CPP11 - #elif WAPP_PLATFORM_CPP_VERSION == WAPP_PLATFORM_CPP14_VERSION - #define WAPP_PLATFORM_CPP14 - #elif WAPP_PLATFORM_CPP_VERSION == WAPP_PLATFORM_CPP17_VERSION - #define WAPP_PLATFORM_CPP17 - #elif WAPP_PLATFORM_CPP_VERSION == WAPP_PLATFORM_CPP20_VERSION - #define WAPP_PLATFORM_CPP20 - #elif WAPP_PLATFORM_CPP_VERSION == WAPP_PLATFORM_CPP23_VERSION - #define WAPP_PLATFORM_CPP23 - #else - #error "Unrecognised C++ version" - #endif + #if WAPP_PLATFORM_CPP_VERSION == WAPP_PLATFORM_CPP98_VERSION + #define WAPP_PLATFORM_CPP98 + #elif WAPP_PLATFORM_CPP_VERSION == WAPP_PLATFORM_CPP11_VERSION + #define WAPP_PLATFORM_CPP11 + #elif WAPP_PLATFORM_CPP_VERSION == WAPP_PLATFORM_CPP14_VERSION + #define WAPP_PLATFORM_CPP14 + #elif WAPP_PLATFORM_CPP_VERSION == WAPP_PLATFORM_CPP17_VERSION + #define WAPP_PLATFORM_CPP17 + #elif WAPP_PLATFORM_CPP_VERSION == WAPP_PLATFORM_CPP20_VERSION + #define WAPP_PLATFORM_CPP20 + #elif WAPP_PLATFORM_CPP_VERSION == WAPP_PLATFORM_CPP23_VERSION + #define WAPP_PLATFORM_CPP23 + #else + #error "Unrecognised C++ version" + #endif #else - #define WAPP_PLATFORM_C + #define WAPP_PLATFORM_C - #if defined(__STDC_VERSION__) - #define WAPP_PLATFORM_C_VERSION __STDC_VERSION__ - #define WAPP_PLATFORM_C99_VERSION 199901L - #define WAPP_PLATFORM_C11_VERSION 201112L - #define WAPP_PLATFORM_C17_VERSION 201710L - #define WAPP_PLATFORM_C23_VERSION 202311L + #if defined(__STDC_VERSION__) + #define WAPP_PLATFORM_C_VERSION __STDC_VERSION__ + #define WAPP_PLATFORM_C99_VERSION 199901L + #define WAPP_PLATFORM_C11_VERSION 201112L + #define WAPP_PLATFORM_C17_VERSION 201710L + #define WAPP_PLATFORM_C23_VERSION 202311L - #if WAPP_PLATFORM_C_VERSION == WAPP_PLATFORM_C99_VERSION - #define WAPP_PLATFORM_C99 - #elif WAPP_PLATFORM_C_VERSION == WAPP_PLATFORM_C11_VERSION - #define WAPP_PLATFORM_C11 - #elif WAPP_PLATFORM_C_VERSION == WAPP_PLATFORM_C17_VERSION - #define WAPP_PLATFORM_C17 - #elif WAPP_PLATFORM_C_VERSION == WAPP_PLATFORM_C23_VERSION - #define WAPP_PLATFORM_C23 - #else - #error "Unrecognised C version" - #endif - #else - #define WAPP_PLATFORM_C89 - #endif + #if WAPP_PLATFORM_C_VERSION == WAPP_PLATFORM_C99_VERSION + #define WAPP_PLATFORM_C99 + #elif WAPP_PLATFORM_C_VERSION == WAPP_PLATFORM_C11_VERSION + #define WAPP_PLATFORM_C11 + #elif WAPP_PLATFORM_C_VERSION == WAPP_PLATFORM_C17_VERSION + #define WAPP_PLATFORM_C17 + #elif WAPP_PLATFORM_C_VERSION == WAPP_PLATFORM_C23_VERSION + #define WAPP_PLATFORM_C23 + #else + #error "Unrecognised C version" + #endif + #else + #define WAPP_PLATFORM_C89 + #endif #endif // !__cplusplus #endif // !PLATFORM_H