diff options
| author | Justin M. Keyes <justinkz@gmail.com> | 2016-04-17 20:24:23 -0400 | 
|---|---|---|
| committer | Justin M. Keyes <justinkz@gmail.com> | 2016-04-17 20:24:23 -0400 | 
| commit | 007d573147bb9086c63e779b1db3938690037db8 (patch) | |
| tree | 8a0833743202d0e6be899fe65b50a47197c0e40a /src/nvim/assert.h | |
| parent | 83c683f5e15867c2e2889442860e91fd1074b4e1 (diff) | |
| parent | a64114eba017c0db3d1849186c9c54fb09308761 (diff) | |
| download | rneovim-007d573147bb9086c63e779b1db3938690037db8.tar.gz rneovim-007d573147bb9086c63e779b1db3938690037db8.tar.bz2 rneovim-007d573147bb9086c63e779b1db3938690037db8.zip  | |
Merge pull request #4131 from ZyX-I/json-functions
Add JSON support
Diffstat (limited to 'src/nvim/assert.h')
| -rw-r--r-- | src/nvim/assert.h | 101 | 
1 files changed, 70 insertions, 31 deletions
diff --git a/src/nvim/assert.h b/src/nvim/assert.h index 3a900aca65..0ce48e4766 100644 --- a/src/nvim/assert.h +++ b/src/nvim/assert.h @@ -8,17 +8,32 @@  // defined(__has_feature) && __has_feature(...). Therefore we define Clang's  // __has_feature and __has_extension macro's before referring to them.  #ifndef __has_feature -  #define __has_feature(x) 0 +# define __has_feature(x) 0  #endif  #ifndef __has_extension -  #define __has_extension __has_feature +# define __has_extension __has_feature  #endif -/// STATIC_ASSERT(condition, message) - assert at compile time if !cond +/// @def STATIC_ASSERT +/// @brief Assert at compile time if condition is not satisfied.  /// -/// example: -///  STATIC_ASSERT(sizeof(void *) == 8, "need 64-bits mode"); +/// Should be put on its own line, followed by a semicolon. +/// +/// Example: +/// +///     STATIC_ASSERT(sizeof(void *) == 8, "Expected 64-bit mode"); +/// +/// @param[in]  condition  Condition to check, should be an integer constant +///                        expression. +/// @param[in]  message  Message which will be given if check fails. + +/// @def STATIC_ASSERT_EXPR +/// @brief Like #STATIC_ASSERT, but can be used where expressions are used. +/// +/// STATIC_ASSERT_EXPR may be put in brace initializer lists. Error message +/// given in this case is not very nice with the current implementation though +/// and `message` argument is ignored.  // define STATIC_ASSERT as C11's _Static_assert whenever either C11 mode is  // detected or the compiler is known to support it. Note that Clang in C99 @@ -29,50 +44,74 @@  // clearer messages we get from _Static_assert, we suppress the warnings  // temporarily. +#define STATIC_ASSERT_PRAGMA_START +#define STATIC_ASSERT_PRAGMA_END +#define STATIC_ASSERT(...) \ +    do { \ +      STATIC_ASSERT_PRAGMA_START \ +      STATIC_ASSERT_STATEMENT(__VA_ARGS__); \ +      STATIC_ASSERT_PRAGMA_END \ +    } while (0) +  // the easiest case, when the mode is C11 (generic compiler) or Clang  // advertises explicit support for c_static_assert, meaning it won't warn.  #if __STDC_VERSION__ >= 201112L || __has_feature(c_static_assert) -  #define STATIC_ASSERT(cond, msg) _Static_assert(cond, msg) +# define STATIC_ASSERT_STATEMENT(cond, msg) _Static_assert(cond, msg)  // if we're dealing with gcc >= 4.6 in C99 mode, we can still use  // _Static_assert but we need to suppress warnings, this is pretty ugly.  #elif (!defined(__clang__) && !defined(__INTEL_COMPILER)) && \    (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) -  #define STATIC_ASSERT(cond, msg) \ -	_Pragma("GCC diagnostic push") \ -	_Pragma("GCC diagnostic ignored \"-pedantic\"") \ -	_Static_assert(cond, msg); \ -	_Pragma("GCC diagnostic pop") \ + +# define STATIC_ASSERT_STATEMENT(cond, msg) _Static_assert(cond, msg) + +# undef STATIC_ASSERT_PRAGMA_START +# define STATIC_ASSERT_PRAGMA_START \ +    _Pragma("GCC diagnostic push") \ +    _Pragma("GCC diagnostic ignored \"-pedantic\"") \ + +# undef STATIC_ASSERT_PRAGMA_END +# define STATIC_ASSERT_PRAGMA_END \ +    _Pragma("GCC diagnostic pop") \  // the same goes for clang in C99 mode, but we suppress a different warning  #elif defined(__clang__) && __has_extension(c_static_assert) -  #define STATIC_ASSERT(cond, msg) \ -	_Pragma("clang diagnostic push") \ -	_Pragma("clang diagnostic ignored \"-Wc11-extensions\"") \ -	_Static_assert(cond, msg); \ -	_Pragma("clang diagnostic pop") \ + +# define STATIC_ASSERT_STATEMENT(cond, msg) _Static_assert(cond, msg) + +# undef STATIC_ASSERT_PRAGMA_START +# define STATIC_ASSERT_PRAGMA_START \ +    _Pragma("clang diagnostic push") \ +    _Pragma("clang diagnostic ignored \"-Wc11-extensions\"") \ + +# undef STATIC_ASSERT_PRAGMA_END +# define STATIC_ASSERT_PRAGMA_END \ +    _Pragma("clang diagnostic pop") \  // TODO(aktau): verify that this works, don't have MSVC on hand.  #elif _MSC_VER >= 1600 -  #define STATIC_ASSERT(cond, msg) static_assert(cond, msg) + +# define STATIC_ASSERT_STATEMENT(cond, msg) static_assert(cond, msg)  // fallback for compilers that don't support _Static_assert or static_assert  // not as pretty but gets the job done. Credit goes to Pádraig Brady and  // contributors.  #else -  #define ASSERT_CONCAT_(a, b) a##b -  #define ASSERT_CONCAT(a, b) ASSERT_CONCAT_(a, b) -  // These can't be used after statements in c89. -  #ifdef __COUNTER__ -	#define STATIC_ASSERT(e,m) \ -	  { enum { ASSERT_CONCAT(static_assert_, __COUNTER__) = 1/(!!(e)) }; } -  #else -	// This can't be used twice on the same line so ensure if using in headers -	// that the headers are not included twice (by wrapping in #ifndef...#endif) -	// Note it doesn't cause an issue when used on same line of separate modules -	// compiled with gcc -combine -fwhole-program. -	#define STATIC_ASSERT(e,m) \ -	  { enum { ASSERT_CONCAT(assert_line_, __LINE__) = 1/(!!(e)) }; } -  #endif +# define STATIC_ASSERT_STATEMENT STATIC_ASSERT_EXPR +#endif + +#define ASSERT_CONCAT_(a, b) a##b +#define ASSERT_CONCAT(a, b) ASSERT_CONCAT_(a, b) +// These can't be used after statements in c89. +#ifdef __COUNTER__ +# define STATIC_ASSERT_EXPR(e, m) \ +    ((enum { ASSERT_CONCAT(static_assert_, __COUNTER__) = 1/(!!(e)) }) 0) +#else +// This can't be used twice on the same line so ensure if using in headers +// that the headers are not included twice (by wrapping in #ifndef...#endif) +// Note it doesn't cause an issue when used on same line of separate modules +// compiled with gcc -combine -fwhole-program. +# define STATIC_ASSERT_EXPR(e, m) \ +    ((enum { ASSERT_CONCAT(assert_line_, __LINE__) = 1/(!!(e)) }) 0)  #endif  #endif  // NVIM_ASSERT_H  | 
