repr 0.1
Reconstructable string representations and more
Loading...
Searching...
No Matches
macro/util.h
Go to the documentation of this file.
1#pragma once
2#include <librepr/feature.h>
3#include "platform.h"
4
5#ifndef __has_attribute
6# define __has_attribute(x) (0)
7#endif
8
9#ifndef __has_builtin
10#define LIBREPR_HAS_BUILTIN(BUILTIN) (0)
11#else
12#define LIBREPR_HAS_BUILTIN(BUILTIN) __has_builtin(BUILTIN)
13#endif
14
15#ifndef __has_builtin
16# define __has_builtin(x) (0)
17#endif
18
19#ifndef __has_include
20# define __has_include(x) (0)
21#endif
22
23#ifndef __has_warning
24// GCC/Clang specific
25#define __has_warning(x) (0)
26#endif
27
28#ifdef __has_cpp_attribute
29# define REPR_HAS_CPP_ATTR(x) __has_cpp_attribute(x)
30#else
31# define REPR_HAS_CPP_ATTR(x) (0)
32#endif
33
34// Inlining macros
35#if USING(LIBREPR_COMPILER_GCC) || USING(LIBREPR_COMPILER_CLANG)
36# define LIBREPR_PROPAGATE_INLINE __attribute__(( \
37 always_inline, flatten, artificial)) inline
38# define LIBREPR_FORCE_INLINE __attribute__(( \
39 always_inline, artificial)) inline
40# define LIBREPR_NOINLINE __attribute__((noinline))
41#elif USING(LIBREPR_COMPILER_MSVC)
42# define LIBREPR_FORCE_INLINE __forceinline
43# define LIBREPR_HINT_INLINE __forceinline
44# define LIBREPR_NOINLINE __declspec(noinline)
45#endif
46
47#ifndef LIBREPR_PROPAGATE_INLINE
48# define LIBREPR_PROPAGATE_INLINE LIBREPR_FORCE_INLINE
49#endif
50
51#ifndef LIBREPR_FORCE_INLINE
52# define LIBREPR_FORCE_INLINE inline
53#endif
54
55#ifndef LIBREPR_HINT_INLINE
56# define LIBREPR_HINT_INLINE inline
57#endif
58
59#ifndef LIBREPR_NOINLINE
60# define LIBREPR_NOINLINE
61#endif
62
63#if __has_attribute(nodebug)
64# define LIBREPR_NODEBUG __attribute__((nodebug))
65#else
66# define LIBREPR_NODEBUG
67#endif
68
69#if REPR_HAS_CPP_ATTR(gnu::hot) \
70 && REPR_HAS_CPP_ATTR(gnu::cold)
71# define LIBREPR_HOT [[gnu::hot]]
72# define LIBREPR_COLD [[gnu::cold]]
73#elif defined(__GNUC__)
74# define LIBREPR_HOT __attribute__((hot))
75# define LIBREPR_COLD __attribute__((cold))
76#else
77# define LIBREPR_HOT
78# define LIBREPR_COLD
79#endif
80
81#if USING(LIBREPR_COMPILER_MSVC)
82# define LIBREPR_EMPTY_BASES __declspec(empty_bases)
83#else
84# define LIBREPR_EMPTY_BASES
85#endif
86
87#if USING(LIBREPR_COMPILER_CLANG) || USING(LIBREPR_COMPILER_MSVC)
88# define LIBREPR_RESTRICT __restrict
89#elif USING(LIBREPR_COMPILER_GCC)
90# define LIBREPR_RESTRICT __restrict__
91#else
92# define LIBREPR_RESTRICT
93#endif
94
95
96#define LIBREPR_PRAGMA(...) _Pragma(#__VA_ARGS__)
97
98// clang-format 18 introduces AllowShortCompoundRequirementOnASingleLine which
99// should fix the formatting issue with this macro. Disable clang-format for now
100// clang-format off
101#define LIBREPR_MAYBE_DO(...) \
102 if constexpr (requires { { __VA_ARGS__ }; }) { \
103 __VA_ARGS__; \
104 }
105// clang-format on