From a0ab6a9000b6c72e00b7e39ab6a5d8c209ed6edd Mon Sep 17 00:00:00 2001 From: Victor Zarubkin Date: Wed, 8 Nov 2017 21:34:51 +0300 Subject: [PATCH] #0 [Core] Added constexpr support macros and refactored extract_... functions --- .../include/easy/easy_compiler_support.h | 43 +++++++++-- .../include/easy/profiler_aux.h | 73 ++++++++++--------- 2 files changed, 73 insertions(+), 43 deletions(-) diff --git a/easy_profiler_core/include/easy/easy_compiler_support.h b/easy_profiler_core/include/easy/easy_compiler_support.h index 41b667e..3dcf26c 100644 --- a/easy_profiler_core/include/easy/easy_compiler_support.h +++ b/easy_profiler_core/include/easy/easy_compiler_support.h @@ -53,8 +53,6 @@ #include -//#define EASY_CODE_WRAP(Code) Code - #if defined(_WIN32) && !defined(EASY_PROFILER_STATIC) // Visual Studio and MinGW # ifdef _BUILD_PROFILER @@ -66,7 +64,7 @@ -#if defined (_MSC_VER) +#if defined(_MSC_VER) ////////////////////////////////////////////////////////////////////////// // Visual Studio @@ -80,19 +78,31 @@ __declspec(thread) static VarType VarName = 0;\ if (!VarName)\ VarName = VarInitializer + +// No constexpr support before Visual Studio 2015 +# define EASY_CONSTEXPR static const +# define EASY_STATIC_CONSTEXPR static const +# define EASY_CONSTEXPR_FCN # endif #define EASY_FORCE_INLINE __forceinline -#elif defined (__clang__) +#elif defined(__clang__) ////////////////////////////////////////////////////////////////////////// // Clang Compiler # if (__clang_major__ == 3 && __clang_minor__ < 3) || (__clang_major__ < 3) -// There is no support for C++11 thread_local keyword prior to clang 3.3. Use __thread instead. +// There is no support for C++11 thread_local keyword prior to Clang v3.3. Use __thread instead. # define EASY_THREAD_LOCAL __thread # endif +# if (__clang_major__ == 3 && __clang_minor__ < 1) || (__clang_major__ < 3) +// No constexpr support before Clang v3.1 +# define EASY_CONSTEXPR static const +# define EASY_STATIC_CONSTEXPR static const +# define EASY_CONSTEXPR_FCN +# endif + # if (__clang_major__ == 2 && __clang_minor__ < 9) || (__clang_major__ < 2) // There is no support for C++11 magic statics feature prior to clang 2.9. It becomes slightly harder to initialize static vars - additional "if" for each profiler block. # define EASY_LOCAL_STATIC_PTR(VarType, VarName, VarInitializer)\ @@ -100,7 +110,7 @@ if (!VarName)\ VarName = VarInitializer -// There is no support for C++11 final keyword prior to clang 2.9 +// There is no support for C++11 final keyword prior to Clang v2.9 # define EASY_FINAL # endif @@ -115,6 +125,13 @@ # define EASY_THREAD_LOCAL __thread # endif +# if (__GNUC__ == 4 && __GNUC_MINOR__ < 6) || (__GNUC__ < 4) +// No constexpr support before GCC v4.6 +# define EASY_CONSTEXPR static const +# define EASY_STATIC_CONSTEXPR static const +# define EASY_CONSTEXPR_FCN +# endif + # if (__GNUC__ == 4 && __GNUC_MINOR__ < 3) || (__GNUC__ < 4) // There is no support for C++11 magic statics feature prior to gcc 4.3. It becomes slightly harder to initialize static vars - additional "if" for each profiler block. # define EASY_LOCAL_STATIC_PTR(VarType, VarName, VarInitializer)\ @@ -130,8 +147,13 @@ #define EASY_FORCE_INLINE inline __attribute__((always_inline)) +#else +////////////////////////////////////////////////////////////////////////// +// TODO: Add other compilers support + +static_assert(false, "EasyProfiler is not configured yet for using your compiler type."); #endif -// END // TODO: Add other compilers support +// END ////////////////////////////////////////////////////////////////////////// @@ -157,6 +179,13 @@ # define EASY_FORCE_INLINE inline #endif +#ifndef EASY_CONSTEXPR +# define EASY_CONSTEXPR constexpr +# define EASY_STATIC_CONSTEXPR static constexpr +# define EASY_CONSTEXPR_FCN constexpr +# define EASY_CONSTEXPR_CPP11 +#endif + #ifndef PROFILER_API # define PROFILER_API #endif diff --git a/easy_profiler_core/include/easy/profiler_aux.h b/easy_profiler_core/include/easy/profiler_aux.h index 6807844..d8b496a 100644 --- a/easy_profiler_core/include/easy/profiler_aux.h +++ b/easy_profiler_core/include/easy/profiler_aux.h @@ -136,61 +136,62 @@ namespace profiler { //*********************************************** - inline color_t extract_color() { + template + inline EASY_CONSTEXPR_FCN color_t extract_color(TArgs...); + + template <> + inline EASY_CONSTEXPR_FCN color_t extract_color<>() { return ::profiler::colors::Default; } - template - inline color_t extract_color(::profiler::EasyBlockStatus, TArgs...) { + template + inline EASY_CONSTEXPR_FCN color_t extract_color(T) { return ::profiler::colors::Default; } + template <> + inline EASY_CONSTEXPR_FCN color_t extract_color(color_t _color) { + return _color; + } + template - inline color_t extract_color(color_t _color, TArgs...) { + inline EASY_CONSTEXPR_FCN color_t extract_color(color_t _color, TArgs...) { return _color; } template - inline color_t extract_color(T, color_t _color, TArgs...) { - return _color; - } - - template - inline color_t extract_color(T, U, color_t _color, TArgs...) { - return _color; - } - - template - inline color_t extract_color(TArgs...) { - static_assert(sizeof...(TArgs) < 2, "No profiler::color_t in arguments list for EASY_BLOCK(name, ...)!"); - return ::profiler::colors::Default; + inline EASY_CONSTEXPR_FCN color_t extract_color(T, TArgs... _args) { + return extract_color(_args...); } //*********************************************** - inline EasyBlockStatus extract_enable_flag() { + template + inline EASY_CONSTEXPR_FCN EasyBlockStatus extract_enable_flag(TArgs...); + + template <> + inline EASY_CONSTEXPR_FCN EasyBlockStatus extract_enable_flag<>() { return ::profiler::ON; } + template + inline EASY_CONSTEXPR_FCN EasyBlockStatus extract_enable_flag(T) { + return ::profiler::ON; + } + + template <> + inline EASY_CONSTEXPR_FCN EasyBlockStatus extract_enable_flag(EasyBlockStatus _flag) { + return _flag; + } + + template + inline EASY_CONSTEXPR_FCN EasyBlockStatus extract_enable_flag(EasyBlockStatus _flag, TArgs...) { + return _flag; + } + template - inline EasyBlockStatus extract_enable_flag(T, ::profiler::EasyBlockStatus _flag, TArgs...) { - return _flag; - } - - template - inline EasyBlockStatus extract_enable_flag(T, U, ::profiler::EasyBlockStatus _flag, TArgs...) { - return _flag; - } - - template - inline EasyBlockStatus extract_enable_flag(::profiler::EasyBlockStatus _flag, TArgs...) { - return _flag; - } - - template - inline EasyBlockStatus extract_enable_flag(TArgs...) { - static_assert(sizeof...(TArgs) < 2, "No EasyBlockStatus in arguments list for EASY_BLOCK(name, ...)!"); - return ::profiler::ON; + inline EASY_CONSTEXPR_FCN EasyBlockStatus extract_enable_flag(T, TArgs... _args) { + return extract_enable_flag(_args...); } //***********************************************