0
0
mirror of https://github.com/yse/easy_profiler.git synced 2024-12-27 00:31:02 +08:00

#0 [Core] Added constexpr support macros and refactored extract_... functions

This commit is contained in:
Victor Zarubkin 2017-11-08 21:34:51 +03:00
parent b812e1648c
commit a0ab6a9000
2 changed files with 73 additions and 43 deletions

View File

@ -53,8 +53,6 @@
#include <cstddef>
//#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

View File

@ -136,61 +136,62 @@ namespace profiler {
//***********************************************
inline color_t extract_color() {
template <class ... TArgs>
inline EASY_CONSTEXPR_FCN color_t extract_color(TArgs...);
template <>
inline EASY_CONSTEXPR_FCN color_t extract_color<>() {
return ::profiler::colors::Default;
}
template <class ... TArgs>
inline color_t extract_color(::profiler::EasyBlockStatus, TArgs...) {
template <class T>
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_t _color) {
return _color;
}
template <class ... TArgs>
inline color_t extract_color(color_t _color, TArgs...) {
inline EASY_CONSTEXPR_FCN color_t extract_color(color_t _color, TArgs...) {
return _color;
}
template <class T, class ... TArgs>
inline color_t extract_color(T, color_t _color, TArgs...) {
return _color;
}
template <class T, class U, class ... TArgs>
inline color_t extract_color(T, U, color_t _color, TArgs...) {
return _color;
}
template <class ... TArgs>
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 <class ... TArgs>
inline EASY_CONSTEXPR_FCN EasyBlockStatus extract_enable_flag(TArgs...);
template <>
inline EASY_CONSTEXPR_FCN EasyBlockStatus extract_enable_flag<>() {
return ::profiler::ON;
}
template <class T>
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 <class ... TArgs>
inline EASY_CONSTEXPR_FCN EasyBlockStatus extract_enable_flag(EasyBlockStatus _flag, TArgs...) {
return _flag;
}
template <class T, class ... TArgs>
inline EasyBlockStatus extract_enable_flag(T, ::profiler::EasyBlockStatus _flag, TArgs...) {
return _flag;
}
template <class T, class U, class ... TArgs>
inline EasyBlockStatus extract_enable_flag(T, U, ::profiler::EasyBlockStatus _flag, TArgs...) {
return _flag;
}
template <class ... TArgs>
inline EasyBlockStatus extract_enable_flag(::profiler::EasyBlockStatus _flag, TArgs...) {
return _flag;
}
template <class ... TArgs>
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...);
}
//***********************************************