![]() |
Arene Base
Fundamental Utilities For Safety Critical C++
|
Working with the Preprocessor is complex and easy to get wrong, particularly while maintaining compliance with various safety critical coding standards. arene-base provides a number of facilities to facilitate working with the preprocessor in a robust, consistent manner. They serve as the basis for many of the macro-based implementations of facilities in the compiler_support subpackage.
The public header for these facilities is:
In order to facilitate build-system independent library configuration, a number of facilities are provided to standardize a mechanism for testing #define based configuration parameters. The basic idea is that a given configuration define can be in one of 4 states:
By using the appropriate configuration macros and queries described below, conditional logic can be enabled or disabled based on these define configurations. The intended pattern of usage is as follows:
FOO_SETTING.FOO_SETTING_I_.For example, the following is how the configuration stating that the current compiler should be treated as GCC, which is provided via the query name ARENE_COMPILER_GCC is defined:
The logic tree of this operation is as follows:
ARENE_COMPILER_GCC is already defined (ex: it was defined via compiler commands):ARENE_COMPILER_GCC_I_ as ARENE_ON.ARENE_COMPILER_GCC_I_ as ARENE_OFF.ARENE_COMPILER_CLANG is "off", and we detect intrinsics that suggest we're executing under gcc, define ARENE_COMPILER_GCC_I_ as ARENE_ON_BY_DEFAULT.ARENE_COMPILER_GCC_I_ as ARENE_OFF_BY_DEFAULTSee below for further explanation on how to test if a setting is on/off, and the definition of the various states a setting can be in.
The following table defines the queries for testing if a define-based configuration setting is "on" or "off":
| Query | Description |
|---|---|
ARENE_IS_ON(OP_SYMBOL) | Will be true if OP_SYMBOL, with _I_ appended to it, is defined as ARENE_ON or ARENE_ON_BY_DEFAULT |
ARENE_IS_OFF(OP_SYMBOL) | Will be true if OP_SYMBOL, with _I_ appended to it, is defined as ARENE_OFF or ARENE_OFF_BY_DEFAULT |
ARENE_IS_ON_BY_DEFAULT(OP_SYMBOL) | Will be true if OP_SYMBOL, with _I_ appended to it, is defined as ARENE_ON_BY_DEFAULT |
ARENE_IS_OFF_BY_DEFAULT(OP_SYMBOL) | Will be true if OP_SYMBOL, with _I_ appended to it, is defined as ARENE_OFF_BY_DEFAULT |
ARENE_IS_ON_RAW(OP_SYMBOL) | Same meaning as ARENE_IS_ON, but without appending _I_ to OP_SYMBOL. Should generally not be used in user code |
ARENE_IS_OFF_RAW(OP_SYMBOL) | Same meaning as ARENE_IS_ON, but without appending _I_ to OP_SYMBOL. Should generally not be used in user code |
ARENE_IS_ON_BY_DEFAULT_RAW(OP_SYMBOL) | Same meaning as ARENE_IS_ON_BY_DEFAULT, but without appending _I_ to OP_SYMBOL. Should generally not be used in user code |
ARENE_IS_OFF_BY_DEFAULT_RAW(OP_SYMBOL) | Same meaning as ARENE_IS_ON_BY_DEFAULT, but without appending _I_ to OP_SYMBOL. Should generally not be used in user code |
ARENE_GUARANTEE_INTERNAL_DEFINITION macro can be used to test that a configuration setting is validly specified.The following table defines the states a configuration define can be in:
| Sate Macro | Description |
|---|---|
ARENE_ON | The setting should be considered explicitly enabled |
ARENE_OFF | The setting should be considered explicitly disabled |
ARENE_ON_BY_DEFAULT | The setting should be considered implicitly enabled |
ARENE_OFF_BY_DEFAULT | The setting should be considered implicitly disabled |
The ARENE_GUARANTEE_INTERNAL_DEFINITION macro can be used to write unit tests that ensure a configuration parameter is validly defined:
ARENE_STRINGIZE(x) provides the necessary indirection to result in the stringification of the value of a macro argument, rather than its name, when the argument is itself a macro: