Loading...
Searching...
No Matches
fpx_macro Module Reference

Derived types and interfaces

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...
 
type  macro
 Constructor interface for macro type. More...
 
interface  remove
 Remove a macro at given index. More...
 
interface  sizeof
 Return current number of stored macros. More...
 

Functions/Subroutines

type(macro) function macro_new (name, val)
 Construct a new macro object.
 
subroutine set_default (this, name)
 Set macro name only (used internally)
 
subroutine set_with_value (this, name, value)
 Set both name and replacement value (used internally)
 
character(:) function, allocatable, public expand_all (line, macros, filepath, iline, stitch)
 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.
 
character(:) function, allocatable, public expand_macros (line, macros, stitch)
 Core recursive macro expander (handles function-like, variadic, #, ##)
 
logical function is_circular (macros, idx)
 Detect whether expanding macro at index idx would cause a cycle Builds a dependency graph from macro replacement texts and checks for circular paths. Used during expansion to avoid infinite recursion.
 
logical function, public is_defined (name, macros, idx)
 Check if a macro with given name exists in table.
 
character(:) function, allocatable tostring (any)
 Generic conversion of polymorphic value to string Used internally during macro argument stringification and debugging. Supports integers, reals, logicals, characters, and complex.
 
subroutine add_to (vec, val, n, chunk_size, finished)
 Internal helper: grow dynamic macro array in chunks for efficiency Adds a new macro to the allocatable array, growing in BUFFER_SIZE increments. Also detects direct self-references (A → A) and marks both sides as cyclic.
 
subroutine add_item (this, arg)
 Add a complete macro object to the table.
 
subroutine add_item_from_name (this, name)
 Add macro by name only (value = empty)
 
subroutine add_item_from_name_and_value (this, name, value)
 Add macro with name and replacement text.
 
subroutine add_range (this, args)
 Add multiple macros at once.
 
subroutine clear_item (this)
 Remove all macros from table.
 
type(macro) function, allocatable get_item (this, key)
 Retrieve macro by 1-based index.
 
subroutine insert_item (this, i, arg)
 Insert macro at specific position.
 
integer function size_item (this)
 Return number of defined macros.
 
subroutine remove_item (this, i)
 Remove macro at given index.
 

Variables

integer, parameter buffer_size = 256
 

Function/Subroutine Documentation

◆ add_item()

subroutine add_item ( type(macro), dimension(:), intent(inout), allocatable this,
type(macro), intent(in) arg )
private

Add a complete macro object to the table.

Definition at line 757 of file macro.f90.

◆ add_item_from_name()

subroutine add_item_from_name ( type(macro), dimension(:), intent(inout), allocatable this,
character(*), intent(in) name )
private

Add macro by name only (value = empty)

Definition at line 768 of file macro.f90.

◆ add_item_from_name_and_value()

subroutine add_item_from_name_and_value ( type(macro), dimension(:), intent(inout), allocatable this,
character(*), intent(in) name,
character(*), intent(in) value )
private

Add macro with name and replacement text.

Definition at line 779 of file macro.f90.

◆ add_range()

subroutine add_range ( type(macro), dimension(:), intent(inout), allocatable this,
type(macro), dimension(:), intent(in) args )
private

Add multiple macros at once.

Definition at line 792 of file macro.f90.

◆ add_to()

subroutine add_to ( type(macro), dimension(:), intent(inout), allocatable vec,
type(macro), intent(in) val,
integer, intent(inout) n,
integer, intent(in) chunk_size,
logical, intent(in) finished )
private

Internal helper: grow dynamic macro array in chunks for efficiency Adds a new macro to the allocatable array, growing in BUFFER_SIZE increments. Also detects direct self-references (A → A) and marks both sides as cyclic.

Definition at line 712 of file macro.f90.

◆ clear_item()

subroutine clear_item ( type(macro), dimension(:), intent(inout), allocatable this)
private

Remove all macros from table.

Definition at line 806 of file macro.f90.

◆ expand_all()

character(:) function, allocatable, public expand_all ( character(*), intent(in) line,
type(macro), dimension(:), intent(in) macros,
character(*), intent(in) filepath,
integer, intent(in) iline,
logical, intent(out) stitch )

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.

Parameters
[in]lineInput source line
[in]macrosCurrent macro table
[in]filepathCurrent source file path
[in]ilineCurrent line number
[out]stitchSet to .true.true. if result ends with '&' (Fortran continuation)
Returns
Expanded line with all macros and predefined tokens replaced

Definition at line 208 of file macro.f90.

◆ expand_macros()

character(:) function, allocatable, public expand_macros ( character(*), intent(in) line,
type(macro), dimension(:), intent(in) macros,
logical, intent(out) stitch )

Core recursive macro expander (handles function-like, variadic, #, ##)

Performs actual macro replacement with full support for:

  • Function-like macros with argument collection
  • Stringification (#param)
  • Token pasting (##)
  • Variadic macros and __VA_ARGS__, __VA_OPT__
  • Recursion with cycle detection via digraph
  • Proper handling of nested parentheses and quoted strings
Parameters
[in]lineInput line
[in]macrosCurrent macro table
[out]stitch.true. if final line ends with '&'
Returns
Line with user-defined macros expanded (predefined tokens untouched)

Definition at line 310 of file macro.f90.

◆ get_item()

type(macro) function, allocatable get_item ( type(macro), dimension(:), intent(inout) this,
integer, intent(in) key )
private

Retrieve macro by 1-based index.

Definition at line 814 of file macro.f90.

◆ insert_item()

subroutine insert_item ( type(macro), dimension(:), intent(inout), allocatable this,
integer, intent(in) i,
type(macro), intent(in) arg )
private

Insert macro at specific position.

Definition at line 828 of file macro.f90.

◆ is_circular()

logical function is_circular ( type(macro), dimension(:), intent(in) macros,
integer, intent(in) idx )
private

Detect whether expanding macro at index idx would cause a cycle Builds a dependency graph from macro replacement texts and checks for circular paths. Used during expansion to avoid infinite recursion.

Definition at line 603 of file macro.f90.

◆ is_defined()

logical function, public is_defined ( character(*), intent(in) name,
type(macro), dimension(:), intent(in) macros,
integer, intent(inout), optional idx )

Check if a macro with given name exists in table.

Parameters
[in]nameMacro name to test
[in]macrosCurrent macro table
[in,out]idxOptional: returns index (1-based) if found
Returns
.true. if macro is defined

Definition at line 662 of file macro.f90.

◆ macro_new()

type(macro) function macro_new ( character(*), intent(in) name,
character(*), intent(in), optional val )
private

Construct a new macro object.

Parameters
[in]nameMandatory macro name
[in]valOptional replacement text (default: empty)
Returns
Initialized macro object

Definition at line 163 of file macro.f90.

◆ remove_item()

subroutine remove_item ( type(macro), dimension(:), intent(inout), allocatable this,
integer, intent(in) i )
private

Remove macro at given index.

Definition at line 853 of file macro.f90.

◆ set_default()

subroutine set_default ( class(macro), intent(inout) this,
character(*), intent(in) name )
private

Set macro name only (used internally)

Definition at line 179 of file macro.f90.

◆ set_with_value()

subroutine set_with_value ( class(macro), intent(inout) this,
character(*), intent(in) name,
character(*), intent(in) value )
private

Set both name and replacement value (used internally)

Definition at line 189 of file macro.f90.

◆ size_item()

integer function size_item ( type(macro), dimension(:), intent(inout), allocatable this)
private

Return number of defined macros.

Definition at line 846 of file macro.f90.

◆ tostring()

character(:) function, allocatable tostring ( class(*), intent(in) any)
private

Generic conversion of polymorphic value to string Used internally during macro argument stringification and debugging. Supports integers, reals, logicals, characters, and complex.

Definition at line 682 of file macro.f90.

Variable Documentation

◆ buffer_size

integer, parameter buffer_size = 256
private

Definition at line 62 of file macro.f90.