Fortran Preprocessor (fpx) – compile-time loop expansion support.
This module implements the non-standard #for / #endfor directive pair used by fpx to generate repeated source code from a list of values.
Features:
During parsing, loop bodies are stored internally and emitted only when the matching #endfor is encountered. Each iteration temporarily defines the loop variable as a macro whose value is substituted into the collected body before output.
Loop variables behave like temporary macros and participate in normal macro expansion rules.
| subroutine, public add_to_loop | ( | character(*), intent(in) | line | ) |
| subroutine, public handle_endfor | ( | type(context), intent(inout) | ctx, |
| integer, intent(in) | ounit, | ||
| type(c_funptr), intent(in) | p, | ||
| type(macro), dimension(:), intent(in) | macros, | ||
| character(*), intent(in) | token ) |
Finalize a loop and emit all expanded iterations.
The collected loop body is expanded once for every value contained in the loop variable parameter list. Nested loops are handled recursively by forwarding generated lines to the enclosing loop body when present.
When the outermost loop terminates, all temporary loop state is released automatically.
| [in] | ctx | Current parsing context |
| [in] | ounit | Output unit |
| [in] | p | preprocessor function pointer |
| [in,out] | macros | Active macro table |
| [in] | token | Directive keyword (endfor) |
Remarks
| subroutine, public handle_for | ( | type(context), intent(in) | ctx, |
| type(macro), dimension(:), intent(inout), allocatable | macros, | ||
| character(*), intent(in) | token ) |
Process a #for directive and initialize a new loop context.
Parses directives of the form:
or
where MACRO_NAME expands to a bracketed list.
A temporary macro representing the loop variable is created and the iteration values are stored internally until the matching #endfor is reached.
| [in] | ctx | Current parsing context |
| [in,out] | macros | Active macro table |
| [in] | token | Directive keyword (for) |
Remarks