Debian Codegraph @

src/utils/common.hpp

raw
1 #ifndef COMMON_HPP
2 #define COMMON_HPP
3
4 #include <cpptrace/basic.hpp>
5
6 #include "platform/platform.hpp"
7
8 #include <cstdint>
9
10 #define ESC "\033["
11 #define RESET ESC "0m"
12 #define RED ESC "31m"
13 #define GREEN ESC "32m"
14 #define YELLOW ESC "33m"
15 #define BLUE ESC "34m"
16 #define MAGENTA ESC "35m"
17 #define CYAN ESC "36m"
18
19 #if IS_GCC || IS_CLANG
20 #define NODISCARD __attribute__((warn_unused_result))
21 // #elif IS_MSVC && _MSC_VER >= 1700
22 // #define NODISCARD _Check_return_
23 #else
24 #define NODISCARD
25 #endif
26
27 // workaround a bizarre gcc bug https://godbolt.org/z/s78vnf7jv
28 // https://github.com/jeremy-rifkin/cpptrace/issues/220
29 #if defined(__GNUC__) && (__GNUC__ < 7)
30 #undef NODISCARD
31 #define NODISCARD
32 #endif
33
34 #if IS_MSVC
35 #define MSVC_CDECL __cdecl
36 #else
37 #define MSVC_CDECL
38 #endif
39
40 // support is pretty good https://godbolt.org/z/djTqv7WMY, checked in cmake during config
41 #ifdef HAS_ATTRIBUTE_PACKED
42 #define PACKED __attribute__((packed))
43 #else
44 #define PACKED
45 #endif
46
47 CPPTRACE_BEGIN_NAMESPACE
48 namespace detail {
49 inline stacktrace_frame null_frame() {
50 return {
51 0,
52 0,
53 nullable<std::uint32_t>::null(),
54 nullable<std::uint32_t>::null(),
55 "",
56 "",
57 false
58 };
59 }
60 }
61 CPPTRACE_END_NAMESPACE
62
63 #endif