Plasma Engine  2.0
Loading...
Searching...
No Matches
MSVC.h
1#pragma once
2
3#if defined(_MSC_VER) && !defined(__clang__)
4
5# undef PL_COMPILER_MSVC
6# define PL_COMPILER_MSVC PL_ON
7
8# if __clang__ || __castxml__
9# undef PL_COMPILER_MSVC_CLANG
10# define PL_COMPILER_MSVC_CLANG PL_ON
11# else
12# undef PL_COMPILER_MSVC_PURE
13# define PL_COMPILER_MSVC_PURE PL_ON
14# endif
15
16# ifdef _DEBUG
17# undef PL_COMPILE_FOR_DEBUG
18# define PL_COMPILE_FOR_DEBUG PL_ON
19# endif
20
21
22// Functions marked as PL_ALWAYS_INLINE will be inlined even in Debug builds, which means you will step over them in a debugger
23# define PL_ALWAYS_INLINE __forceinline
24
25# if PL_ENABLED(PL_COMPILE_FOR_DEBUG)
26# define PL_FORCE_INLINE inline
27# else
28# define PL_FORCE_INLINE __forceinline
29# endif
30
31// workaround for MSVC compiler issue with alignment determination of dependent types
32# define PL_ALIGNMENT_OF(type) PL_COMPILE_TIME_MAX(PL_ALIGNMENT_MINIMUM, PL_COMPILE_TIME_MIN(sizeof(type), __alignof(type)))
33
34# if PL_ENABLED(PL_COMPILE_FOR_DEBUG) || (_MSC_VER >= 1929 /* broken in early VS2019 but works again in VS2022 and later 2019 versions*/)
35
36# define PL_DEBUG_BREAK \
37 { \
38 __debugbreak(); \
39 }
40
41# else
42
43# define PL_DEBUG_BREAK \
44 { \
45 /* Declared with DLL export in Assert.h */ \
46 MSVC_OutOfLine_DebugBreak(); \
47 }
48
49# endif
50
51# if PL_ENABLED(PL_COMPILER_MSVC_CLANG)
52# define PL_SOURCE_FUNCTION __PRETTY_FUNCTION__
53# else
54# define PL_SOURCE_FUNCTION __FUNCTION__
55# endif
56
57# define PL_SOURCE_LINE __LINE__
58# define PL_SOURCE_FILE __FILE__
59
60// PL_VA_NUM_ARGS() is a very nifty macro to retrieve the number of arguments handed to a variable-argument macro
61// unfortunately, VS 2010 still has this compiler bug which treats a __VA_ARGS__ argument as being one single parameter:
62// https://connect.microsoft.com/VisualStudio/feedback/details/521844/variadic-macro-treating-va-args-as-a-single-parameter-for-other-macros#details
63# if _MSC_VER >= 1400 && PL_DISABLED(PL_COMPILER_MSVC_CLANG)
64# define PL_VA_NUM_ARGS_HELPER(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, N, ...) N
65# define PL_VA_NUM_ARGS_REVERSE_SEQUENCE 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1
66# define PL_LEFT_PARENTHESIS (
67# define PL_RIGHT_PARENTHESIS )
68# define PL_VA_NUM_ARGS(...) PL_VA_NUM_ARGS_HELPER PL_LEFT_PARENTHESIS __VA_ARGS__, PL_VA_NUM_ARGS_REVERSE_SEQUENCE PL_RIGHT_PARENTHESIS
69# endif
70
71# define PL_WARNING_PUSH() __pragma(warning(push))
72# define PL_WARNING_POP() __pragma(warning(pop))
73# define PL_WARNING_DISABLE_MSVC(_x) __pragma(warning(disable \
74 : _x))
75
76# define PL_DECL_EXPORT __declspec(dllexport)
77# define PL_DECL_IMPORT __declspec(dllimport)
78# define PL_DECL_EXPORT_FRIEND __declspec(dllexport)
79# define PL_DECL_IMPORT_FRIEND __declspec(dllimport)
80
81// These use the __pragma version to control the warnings so that they can be used within other macros etc.
82# define PL_MSVC_ANALYSIS_WARNING_PUSH __pragma(warning(push))
83# define PL_MSVC_ANALYSIS_WARNING_POP __pragma(warning(pop))
84# define PL_MSVC_ANALYSIS_WARNING_DISABLE(warningNumber) __pragma(warning(disable \
85 : warningNumber))
86# define PL_MSVC_ANALYSIS_ASSUME(expression) __assume(expression)
87
88#else
89
90# define PL_WARNING_DISABLE_MSVC(_x)
91
94# define PL_MSVC_ANALYSIS_WARNING_PUSH
95# define PL_MSVC_ANALYSIS_WARNING_POP
96# define PL_MSVC_ANALYSIS_WARNING_DISABLE(warningNumber)
97# define PL_MSVC_ANALYSIS_ASSUME(expression)
98
99#endif