Full-featured conditional compilation (if / ifdef / else / endif) for the fpx preprocessor This module implements standard-conforming conditional compilation with support for:
#if with arbitrary constant expressions (using evaluate_expression)#ifdef / #ifndef and elifdef/elifndeffor testing macro existence -elifchains (multiple alternative branches) -elseas final fallbackProper nesting up toMAX_COND_DEPTHlevelsCorrect "first-match" semantics — once a branch is taken, laterelif/elseare skippedIntegration with macro expansion viais_defined()and expression evaluatorComprehensive diagnostics whenverbose = .true.`The state is maintained in a global stack (cond_stack) with cond_depth tracking nesting. The function is_active() is used throughout the preprocessor to decide whether a line should be emitted or skipped.
evaluate_expression support): Data Types | |
| type | cond_state |
| State of a single conditional block. More... | |
| integer, public cond_depth = 0 |
Current nesting depth of conditional directives (0 = outside any if)
Definition at line 103 of file conditional.f90.
| type(cond_state), dimension(max_cond_depth), public cond_stack |
Global stack of conditional states (depth-limited)
Definition at line 99 of file conditional.f90.
| subroutine, public handle_elif | ( | character(*), intent(in) | line, |
| character(*), intent(in) | filename, | ||
| integer, intent(in) | line_num, | ||
| type(macro), dimension(:), intent(in) | macros, | ||
| character(*), intent(in) | token ) |
Process elif – alternative branch after if/elif Only activates if no previous branch in the group was taken.
| [in] | line | Full source line containing the directive |
| [in] | filename | Current file (for error messages) |
| [in] | line_num | Line number (for error messages) |
| [in] | macros | Current macro table |
| [in] | token | Usually 'ELIF' |
Remarks
Definition at line 239 of file conditional.f90.
| subroutine, public handle_elifdef | ( | character(*), intent(in) | line, |
| character(*), intent(in) | filename, | ||
| integer, intent(in) | line_num, | ||
| type(macro), dimension(:), intent(in) | macros, | ||
| character(*), intent(in) | token ) |
Process elifdef – test if a macro is defined.
| [in] | line | Full source line containing the directive |
| [in] | filename | Current file (for error messages) |
| [in] | line_num | Line number (for error messages) |
| [in] | macros | Current macro table |
| [in] | token | Usually 'ELIFDEF' |
Remarks
Definition at line 275 of file conditional.f90.
| subroutine, public handle_elifndef | ( | character(*), intent(in) | line, |
| character(*), intent(in) | filename, | ||
| integer, intent(in) | line_num, | ||
| type(macro), dimension(:), intent(in) | macros, | ||
| character(*), intent(in) | token ) |
Process elifndef – test if a macro is not defined.
| [in] | line | Full source line containing the directive |
| [in] | filename | Current file (for error messages) |
| [in] | line_num | Line number (for error messages) |
| [in] | macros | Current macro table |
| [in] | token | Usually 'ELIFNDEF' |
Remarks
Definition at line 312 of file conditional.f90.
| subroutine, public handle_else | ( | character(*), intent(in) | filename, |
| integer, intent(in) | line_num ) |
Process else – final fallback branch Activates only if no previous if/elif branch was true.
| [in] | filename | Current file (for error messages) |
| [in] | line_num | Line number (for error messages) |
Remarks
Definition at line 347 of file conditional.f90.
| subroutine, public handle_endif | ( | character(*), intent(in) | filename, |
| integer, intent(in) | line_num ) |
Process endif – end of conditional block Pops the top state from the stack. Reports error on unmatched endif.
| [in] | filename | Current file (for error messages) |
| [in] | line_num | Line number (for error messages) |
Remarks
Definition at line 374 of file conditional.f90.
| subroutine, public handle_if | ( | character(*), intent(in) | line, |
| character(*), intent(in) | filename, | ||
| integer, intent(in) | line_num, | ||
| type(macro), dimension(:), intent(in) | macros, | ||
| character(*), intent(in) | token ) |
Process a if directive with constant expression evaluation Evaluates the expression after if using evaluate_expression() and pushes a new state onto the conditional stack.
| [in] | line | Full source line containing the directive |
| [in] | filename | Current file (for error messages) |
| [in] | line_num | Line number (for error messages) |
| [in] | macros | Current macro table |
| [in] | token | Usually 'IF' |
Remarks
Definition at line 134 of file conditional.f90.
| subroutine, public handle_ifdef | ( | character(*), intent(in) | line, |
| character(*), intent(in) | filename, | ||
| integer, intent(in) | line_num, | ||
| type(macro), dimension(:), intent(in) | macros, | ||
| character(*), intent(in) | token ) |
Process ifdef – test if a macro is defined.
| [in] | line | Full source line containing the directive |
| [in] | filename | Current file (for error messages) |
| [in] | line_num | Line number (for error messages) |
| [in] | macros | Current macro table |
| [in] | token | Usually 'IFDEF' |
Remarks
Definition at line 170 of file conditional.f90.
| subroutine, public handle_ifndef | ( | character(*), intent(in) | line, |
| character(*), intent(in) | filename, | ||
| integer, intent(in) | line_num, | ||
| type(macro), dimension(:), intent(in) | macros, | ||
| character(*), intent(in) | token ) |
Process ifndef – test if a macro is NOT defined.
| [in] | line | Full source line containing the directive |
| [in] | filename | Current file (for error messages) |
| [in] | line_num | Line number (for error messages) |
| [in] | macros | Current macro table |
| [in] | token | Usually 'IFNDEF' |
Remarks
Definition at line 204 of file conditional.f90.
| logical function, public is_active |
Determine if current line is inside an active conditional block.
Remarks
Definition at line 112 of file conditional.f90.