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