Macro management and expansion core of the fpx Fortran preprocessor.
This module implements a complete, standards-inspired macro system supporting:
The design allows safe, repeated expansion while preventing infinite recursion. All operations are container-agnostic using allocatable dynamic arrays.
This separation allows internal preprocessing routines to reuse the core expansion engine while selectively enabling predefined tokens.
Data Types | |
| interface | macro |
| Representation of a preprocessor macro. More... | |
| interface | add |
| Append macros to a macro table. More... | |
| interface | clear |
| Remove all macro definitions from a table. More... | |
| interface | get |
| Retrieve a macro by index. More... | |
| interface | insert |
| Insert a macro at a specified position. More... | |
| interface | remove |
| Remove a macro definition from a table. More... | |
| interface | size_of |
| Return the number of stored macro definitions. More... | |
| interface | preprocess_line |
| Abstract interface for line preprocessing callbacks. More... | |
| character(:) function, allocatable, public expand_all | ( | type(context), intent(in) | ctx, |
| type(macro), dimension(:), intent(inout), allocatable | macros, | ||
| logical, intent(out) | stitch, | ||
| logical, intent(in) | has_extra, | ||
| logical, intent(in) | implicit_conti, | ||
| logical, intent(in) | dollar_insert ) |
Expand a source line including predefined macros.
This routine represents the complete user-visible expansion phase.
Expansion proceeds in two steps:
Supported predefined macros include:
| [in] | ctx | Context |
| [in,out] | macros | Current macro table |
| [out] | stitch | Set to .true.true. if result ends with '&' (Fortran continuation) |
| [in] | has_extra | Has extra macros (non-standard) like FILENAME and TIMESTAMP |
| [in] | implicit_conti | If .true., implicit continuation is permitted |
| [in] | dollar_insert | If .true., the syntax ${} is supported for macro insertion |
| character(:) function, allocatable, public expand_macros | ( | character(*), intent(in) | line, |
| type(macro), dimension(:), intent(inout), allocatable | macros, | ||
| logical, intent(out) | stitch, | ||
| logical, intent(in) | implicit_conti, | ||
| logical, intent(in) | dollar_insert, | ||
| type(context), intent(in) | ctx ) |
Recursively expand user-defined macros.
Implements the core expansion engine used throughout fpx.
Supported features include:
Recursive expansion terminates automatically when cyclic dependencies are detected.
| [in] | line | Line to be expanded |
| [in,out] | macros | Current macro table |
| [out] | stitch | .true. if final line ends with '&' |
| [in] | implicit_conti | If .true., implicit continuation is permitted |
| [in] | dollar_insert | If .true., ${} macro substitution is supported |
| [in] | ctx | Context |
| logical function, public is_defined | ( | character(*), intent(in) | name, |
| type(macro), dimension(:), intent(in) | macros, | ||
| integer, intent(inout), optional | idx ) |
Determine whether a macro is currently defined.
Performs a linear search through the macro table and optionally returns the corresponding index.
| [in] | name | Macro identifier. |
| [in] | macros | Macro table. |
| [out] | idx | Position of the matching entry, if present. |