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.
Data Types | |
| interface | macro |
| Derived type representing a single preprocessor macro Extends string with macro-specific fields: replacement value, parameters, variadic flag, and cyclic self-reference detection. More... | |
| interface | add |
| Add one or more macros to a dynamic table. More... | |
| interface | clear |
| Remove all macros from a table. More... | |
| interface | get |
| Retrieve a macro by index. More... | |
| interface | insert |
| Insert more macro to a dynamic table. More... | |
| interface | remove |
| Remove a macro at given index. More... | |
| interface | size_of |
| Return current number of stored macros. 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 ) |
Fully expand a line including predefined macros (FILE, LINE, etc.) First performs normal macro expansion via expand_macros(), then substitutes standard predefined tokens with current file/line/date information.
| [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 |
Remarks
| 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 ) |
Core recursive macro expander (handles function-like, variadic, #, ##).
Performs actual macro replacement with full support for:
| [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 |
Remarks
| logical function, public is_defined | ( | character(*), intent(in) | name, |
| type(macro), dimension(:), intent(in) | macros, | ||
| integer, intent(inout), optional | idx ) |