Macro definition and removal directives for the fpx preprocessor.
This module implements the #define and #undef directives used to create, update, and remove preprocessor macros during source preprocessing.
Supported macro forms include:
The parser correctly identifies matching parentheses in function-like macro signatures, allowing nested parentheses inside parameter lists. Whitespace surrounding parameters is ignored, and variadic arguments are detected automatically through the ... notation.
The module also implements #undef, allowing previously defined symbols to be removed from the active macro table. Symbols listed in globalundef are protected from redefinition and silently ignored.
All syntax errors are reported through the diagnostic framework, providing source locations and explanatory messages.
produces a diagnostic because defined is reserved for conditional expressions.
| subroutine, public handle_define | ( | type(context), intent(in) | ctx, |
| type(macro), dimension(:), intent(inout), allocatable | macros, | ||
| character(*), intent(in) | token ) |
Process a #define directive.
Parses the directive contained in the supplied context and updates the active macro table accordingly.
The routine automatically distinguishes between:
Function-like signatures are parsed using matching-parenthesis tracking, ensuring that the closing parenthesis corresponding to the opening ( is located correctly even in the presence of nested parentheses.
Existing definitions are overwritten. Symbols listed in globalundef are ignored. Attempts to define the reserved identifier defined generate an error diagnostic.
| [in] | ctx | Source context containing the complete #define directive. |
| [in,out] | macros | Active macro table updated in place. |
| [in] | token | Directive keyword, typically "define". |
Definition at line 150 of file define.f90.
| subroutine, public handle_undef | ( | type(context), intent(in) | ctx, |
| type(macro), dimension(:), intent(inout), allocatable | macros, | ||
| character(*), intent(in) | token ) |
Process a #undef directive.
Removes the specified macro from the active macro table. If the requested symbol is not currently defined, a warning diagnostic is emitted.
| [in] | ctx | Source context containing the complete #undef directive. |
| [in,out] | macros | Active macro table updated in place. |
| [in] | token | Directive keyword, typically "undef". |
Definition at line 297 of file define.f90.