Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
define_configuration.hpp
Go to the documentation of this file.
1
// Copyright 2024, Toyota Motor Corporation
2
//
3
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4
5
#ifndef INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_COMPILER_SUPPORT_PREPROCESSOR_DEFINE_CONFIGURATION_HPP_
6
#define INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_COMPILER_SUPPORT_PREPROCESSOR_DEFINE_CONFIGURATION_HPP_
7
8
// IWYU pragma: private, include "arene/base/compiler_support/preprocessor.hpp"
9
// IWYU pragma: friend "(arene/base(?!/tests)|stdlib/include/stdlib_detail)/.*"
10
11
// NOLINTBEGIN(cppcoreguidelines-macro-usage)
12
// parasoft-begin-suppress AUTOSAR-A16_0_1-d-2 "Function-like macros permitted by A16-0-1 Permit #1"
13
// parasoft-begin-suppress AUTOSAR-A16_0_1-a-2 "Function-like macros permitted by A16-0-1 Permit #1"
14
// parasoft-begin-suppress AUTOSAR-M16_0_6-a-2 "OP_SYMBOL needs to be used without parentheses in order to work
15
// correctly"
16
// parasoft-begin-suppress AUTOSAR-M16_3_1-a-2 "Token pasting ## is used to provide a configuration macro
17
// system"
18
19
/// @brief Evaluates if the given compile time configuration symbol is "on"
20
/// @param OP_SYMBOL The symbol to evaluate, unmodified.
21
/// @return true if the input symbol was defined as either @c ARENE_ON or @c ARENE_ON_BY_DEFAULT
22
/// @return false otherwise
23
/// @pre The symbol must be defined, and it must only be defined as one of @c ARENE_ON , @c ARENE_OFF ,
24
/// @c ARENE_ON_BY_DEFAULT , or @c ARENE_OFF_BY_DEFAULT else behavior is undefined.
25
/// @note This is generally not used directly in user code, prefer @c ARENE_IS_ON instead.
26
#define ARENE_IS_ON_RAW(OP_SYMBOL) ((3U OP_SYMBOL 3U) != 0U)
// NOLINT(bugprone-macro-parentheses)
27
28
/// @brief Evaluates if the given compile time configuration symbol is "on"
29
/// @param OP_SYMBOL The "query name" of symbol to evaluate. It will have @c _I_ concatenated to it before
30
/// evaluation.
31
/// @return true if the modified input symbol was defined as either @c ARENE_ON or @c ARENE_ON_BY_DEFAULT
32
/// @return false otherwise
33
/// @pre The modified symbol must be defined, and it must only be defined as one of @c ARENE_ON , @c ARENE_OFF ,
34
/// @c ARENE_ON_BY_DEFAULT , or @c ARENE_OFF_BY_DEFAULT else behavior is undefined.
35
#define ARENE_IS_ON(OP_SYMBOL) ARENE_IS_ON_RAW(OP_SYMBOL##_I_)
// NOLINT(bugprone-macro-parentheses)
36
37
/// @brief Evaluates if the given compile time configuration symbol is "off"
38
/// @param OP_SYMBOL The symbol to evaluate, unmodified.
39
/// @return true if the input symbol was defined as either @c ARENE_OFF or @c ARENE_OFF_BY_DEFAULT
40
/// @return false otherwise
41
/// @pre The symbol must be defined, and it must only be defined as one of @c ARENE_ON , @c ARENE_OFF ,
42
/// @c ARENE_ON_BY_DEFAULT , or @c ARENE_OFF_BY_DEFAULT else behavior is undefined.
43
/// @note This is generally not used directly in user code, prefer @c ARENE_IS_OFF instead.
44
#define ARENE_IS_OFF_RAW(OP_SYMBOL) ((3U OP_SYMBOL 3U) == 0U)
// NOLINT(bugprone-macro-parentheses)
45
46
/// @brief Evaluates if the given compile time configuration symbol is "off"
47
/// @param OP_SYMBOL The "query name" of symbol to evaluate. It will have @c _I_ concatenated to it before
48
/// evaluation.
49
/// @return true if the modified input symbol was defined as either @c ARENE_OFF or @c ARENE_OFF_BY_DEFAULT
50
/// @return false otherwise
51
/// @pre The modified symbol must be defined, and it must only be defined as one of @c ARENE_ON , @c ARENE_OFF ,
52
/// @c ARENE_ON_BY_DEFAULT , or @c ARENE_OFF_BY_DEFAULT else behavior is undefined.
53
#define ARENE_IS_OFF(OP_SYMBOL) ARENE_IS_OFF_RAW(OP_SYMBOL##_I_)
// NOLINT(bugprone-macro-parentheses)
54
55
/// @brief Evaluates if the given compile time configuration symbol is "on by default."
56
/// @param OP_SYMBOL The symbol to evaluate, unmodified.
57
/// @return true if the input symbol was defined as @c ARENE_ON_BY_DEFAULT.
58
/// @return false otherwise.
59
/// @pre The symbol must be defined, and it must only be defined as one of @c ARENE_ON , @c ARENE_OFF ,
60
/// @c ARENE_ON_BY_DEFAULT , or @c ARENE_OFF_BY_DEFAULT else behavior is undefined.
61
/// @note This is generally not used directly in user code, prefer @c ARENE_IS_ON_BY_DEFAULT instead.
62
#define ARENE_IS_ON_BY_DEFAULT_RAW(OP_SYMBOL) ((3U OP_SYMBOL 3U) > 3U)
// NOLINT(bugprone-macro-parentheses)
63
64
/// @brief Evaluates if the given compile time configuration symbol is "on by default."
65
/// @param OP_SYMBOL The "query name" of symbol to evaluate. It will have @c _I_ concatenated to it before
66
/// evaluation.
67
/// @return true if the modified input symbol was defined as @c ARENE_ON_BY_DEFAULT
68
/// @return false otherwise
69
/// @pre The modified symbol must be defined, and it must only be defined as one of @c ARENE_ON , @c ARENE_OFF ,
70
/// @c ARENE_ON_BY_DEFAULT , or @c ARENE_OFF_BY_DEFAULT else behavior is undefined.
71
#define ARENE_IS_ON_BY_DEFAULT(OP_SYMBOL) \
72
ARENE_IS_ON_BY_DEFAULT_RAW(OP_SYMBOL##_I_)
// NOLINT(bugprone-macro-parentheses)
73
74
/// @brief Evaluates if the given compile time configuration symbol is "off by default."
75
/// @param OP_SYMBOL The symbol to evaluate, unmodified.
76
/// @return true if the input symbol was defined as @c ARENE_OFF_BY_DEFAULT.
77
/// @return false otherwise.
78
/// @pre The symbol must be defined, and it must only be defined as one of @c ARENE_ON , @c ARENE_OFF ,
79
/// @c ARENE_ON_BY_DEFAULT , or @c ARENE_OFF_BY_DEFAULT else behavior is undefined.
80
/// @note This is generally not used directly in user code, prefer @c ARENE_IS_OFF_BY_DEFAULT instead.
81
#define ARENE_IS_OFF_BY_DEFAULT_RAW(OP_SYMBOL) \
82
((3U OP_SYMBOL 3U OP_SYMBOL 1U) == (0U - 1U))
// NOLINT(bugprone-macro-parentheses)
83
84
/// @brief Evaluates if the given compile time configuration symbol is "off by default."
85
/// @param OP_SYMBOL The "query name" of symbol to evaluate. It will have @c _I_ concatenated to it before
86
/// evaluation.
87
/// @return true if the modified input symbol was defined as @c ARENE_OFF_BY_DEFAULT
88
/// @return false otherwise
89
/// @pre The modified symbol must be defined, and it must only be defined as one of @c ARENE_ON , @c ARENE_OFF ,
90
/// @c ARENE_ON_BY_DEFAULT , or @c ARENE_OFF_BY_DEFAULT else behavior is undefined.
91
#define ARENE_IS_OFF_BY_DEFAULT(OP_SYMBOL) \
92
ARENE_IS_OFF_BY_DEFAULT_RAW(OP_SYMBOL##_I_)
// NOLINT(bugprone-macro-parentheses)
93
94
// parasoft-end-suppress AUTOSAR-A16_0_1-d-2
95
96
// parasoft-begin-suppress AUTOSAR-A16_0_1-d-2 "Macros that define special symbols to use in user configuration macros;
97
// these become the OP_SYMBOL in ARENE_IS_ON_RAW and ARENE_IS_OFF_RAW that are used to determine if the given feature is
98
// explicitly enabled or disabled either by the user, or by the implementation"
99
//
100
/// @brief A compile-time config state that specifies that the given symbol should be considered explicitly "on."
101
///
102
/// Usage:
103
/// @code{c++}
104
/// #define FOO_CONFIG_I_ ARENE_ON
105
/// @endcode
106
// NOLINTNEXTLINE(bugprone-macro-parentheses)
107
#define ARENE_ON |
108
109
/// @brief A compile-time config state that specifies that the given symbol should be considered explicitly "off."
110
///
111
/// Usage:
112
/// @code{c++}
113
/// #define FOO_CONFIG_I_ ARENE_OFF
114
/// @endcode
115
// NOLINTNEXTLINE(bugprone-macro-parentheses)
116
#define ARENE_OFF ^
117
118
/// @brief A compile-time config state that specifies that the given symbol should be considered implicitly "on."
119
///
120
/// Usage:
121
/// @code{c++}
122
/// #define FOO_CONFIG_I_ ARENE_ON_BY_DEFAULT
123
/// @endcode
124
// NOLINTNEXTLINE(bugprone-macro-parentheses)
125
#define ARENE_ON_BY_DEFAULT +
126
127
/// @brief A compile-time config state that specifies that the given symbol should be considered implicitly "off."
128
///
129
/// Usage:
130
/// @code{c++}
131
/// #define FOO_CONFIG_I_ ARENE_OFF_BY_DEFAULT
132
/// @endcode
133
// NOLINTNEXTLINE(bugprone-macro-parentheses)
134
#define ARENE_OFF_BY_DEFAULT -
135
// parasoft-end-suppress AUTOSAR-A16_0_1-d-2
136
137
// parasoft-begin-suppress AUTOSAR-A16_0_1-d-2 "Function-like macros permitted by A16-0-1 Permit #1"
138
/// @brief Rough validation that a given compile time configuration symbol has been correctly defined.
139
/// @param OP_SYMBOL The query symbol to evaluate.
140
/// @return true If one of @c ARENE_IS_ON(OP_SYMBOL) , @c ARENE_IS_OFF(OP_SYMBOL) , @c ARENE_IS_ON_BY_DEFAULT(OP_SYMBOL)
141
/// , or @c ARENE_IS_OFF_BY_DEFAULT(OP_SYMBOL) returns @c true .
142
/// @return false otherwise
143
/// @pre The symbol must be defined in such a way as to be compatible such that the @c ARENE_IS_ON and similar queries
144
/// are well formed, otherwise behavior is undefined (usually, but not always, a compiler error). This means:
145
/// 1. There is a symbol defined which is @c OP_SYMBOL_I_
146
/// 1. This symbol is defined as one of @c ARENE_ON , @c ARENE_OFF , @c ARENE_ON_BY_DEFAULT , or
147
/// @c ARENE_OFF_BY_DEFAULT
148
/// @warning This validation does _not_ magically permute the set of possible states the define could be in. It just
149
/// tries to validate that for the _current_ conditions, the symbol works with @c ARENE_IS_ON and friends. It
150
/// is up to the user to construct a test harness that would permute the define into the appropriate states to
151
/// get full coverage.
152
///
153
/// Usage:
154
/// @snippet docs/examples/compiler_support_examples.cpp arene_guarantee_internal_definition_usage_example
155
///
156
#define ARENE_GUARANTEE_INTERNAL_DEFINITION(OP_SYMBOL) \
157
(ARENE_IS_ON_RAW(
/* NOLINTNEXTLINE(bugprone-macro-parentheses)*/
\
158
OP_SYMBOL##_I_ \
159
) || \
160
ARENE_IS_OFF_RAW(
/* NOLINTNEXTLINE(bugprone-macro-parentheses)*/
\
161
OP_SYMBOL##_I_ \
162
) || \
163
ARENE_IS_ON_BY_DEFAULT_RAW(
/* NOLINTNEXTLINE(bugprone-macro-parentheses)*/
\
164
OP_SYMBOL##_I_ \
165
) || \
166
ARENE_IS_OFF_BY_DEFAULT_RAW(
/* NOLINTLINE(bugprone-macro-parentheses)*/
OP_SYMBOL##_I_))
167
168
// NOLINTEND(cppcoreguidelines-macro-usage)
169
// parasoft-end-suppress AUTOSAR-A16_0_1-d-2
170
// parasoft-end-suppress AUTOSAR-A16_0_1-a-2
171
// parasoft-end-suppress AUTOSAR-M16_0_6-a-2
172
// parasoft-end-suppress AUTOSAR-M16_3_1-a-2
173
174
#endif
// INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_COMPILER_SUPPORT_PREPROCESSOR_DEFINE_CONFIGURATION_HPP_
arene
base
compiler_support
preprocessor
define_configuration.hpp
Generated by
1.13.2