Loading...
Searching...
No Matches
global.f90
Go to the documentation of this file.
1!> @file
2!! @defgroup group_global Global
3!! Central global configuration and shared state for the fpx Fortran preprocessor
4!! This module defines a single global instance `global` of type `global_settings`
5!! that holds all persistent, user-configurable state used across the entire preprocessing session.
6!!
7!! - `macros(:)` : Dynamic table of all defined macros (object-like and function-like)
8!! - `undef(:)` : List of symbols explicitly undefined via `#undef`
9!! - `includedir(:)` : User-specified include search directories for `#include <...>`
10!! - `expand_macros` : Master switch to enable/disable macro expansion (default: .true.)
11!! - `exclude_comments` : When .true., strip C-style /*...*/ and Fortran ! comments from output
12!!
13!! The design uses a single public variable `global` so that all fpx modules can access
14!! and modify the same configuration without passing arguments everywhere.
15!! This is safe in single-threaded use (typical for preprocessing) and allows easy
16!! customization from driver programs or interactive sessions.
17!!
18!! @section global_examples Examples
19!!
20!! 1. Add custom include paths before preprocessing:
21!! @code{.f90}
22!!
23!! global%includedir = [ './include', '/usr/local/include/fortran', '../common' ]
24!! call preprocess('main.F90', 'main.f90')
25!! !#include <file.h> will search these directories
26!! @endcode
27!!
28!! 2. Predefine common macros (e.g. for conditional compilation):
29!! @code{.f90}
30!!
31!! call add(global%macros, macro('DEBUG', '1'))
32!! call add(global%macros, macro('MPI_VERSION', '3'))
33!! call add(global%macros, macro('USE_OPENMP', '1'))
34!!
35!! call preprocess('src/app.F90')
36!! !> Code can now use #ifdef DEBUG, #if MPI_VERSION >= 3, etc.
37!! @endcode
38!!
39!! 3. Disable macro expansion temporarily (pass-through mode):
40!! @code{.f90}
41!! global%expand_macros = .false. ! Only handle #include and conditionals
42!! call preprocess('raw_source.F90', 'clean.F90')
43!! ...
44!! @endcode
45!!
46!! 4. Strip all comments from final output:
47!! @code{.f90}
48!! global%exclude_comments = .true.
49!! call preprocess('messy.F90', 'clean_no_comments.f90')
50!! ...
51!! @endcode
52module fpx_global
53 use fpx_constants
54 use fpx_string
55 use fpx_macro
56
57 implicit none; private
58
59 !> Global preprocessor configuration and shared runtime state
60 !! All components of fpx read from and write to this single instance.
61 !! Users can safely modify its public components at any time.
62 !! <h2 class="groupheader">Examples</h2>
63 !! @code{.f90}
64 !! use fpx_global
65 !!
66 !! call add(global%macros, macro('__LFORTRAN__','1'))
67 !! call add(global%macros, macro('__VERSION__'))
68 !! call add(global%macros, macro('__LFORTRAN_MAJOR__'))
69 !! call add(global%macros, macro('__LFORTRAN_MINOR__'))
70 !! call add(global%macros, macro('__LFORTRAN_PATCHLEVEL__'))
71 !! @endcode
72 !! <h2 class="groupheader">Remarks</h2>
73 !! @par
74 !! The global settings are accessed through the global variable
75 !! @ref global
76 !! @ingroup group_global
77 type, public :: global_settings
78 private
79 type(macro), allocatable, public :: macros(:) !< List of global macros
80 type(string), allocatable, public :: undef(:) !< List of undefined macros
81 type(string), allocatable, public :: includedir(:) !< List of include directories
82 logical, public :: expand_macros = .true. !< Boolean controlling the macro expansion. The macros are expanded by default.
83 logical, public :: exlude_comments = .false. !< Boolean controlling the inclusion/exclusion of comments. The comments are kept by default.
84 logical, public :: implicit_continuation = .false. !< Boolean controlling implicit continuation line.
85 logical, public :: line_break = .false. !< Boolean controlling line break with double backslash.
86 logical, public :: extra_macros = .true. !< Boolean controlling extra non-standard macro definitions: __FILENAME__, __TIMESTAMP__ (.true. by default)).
87 logical, public :: interactive = .false. !< Boolean controlling whether the program is used in interactive mode (REPL) or not.
88 logical, public :: support_forloop = .true. !< Boolean controlling whether the program supports #for directives (.true. by default).
89 logical, public :: disable_continuation = .false. !< Boolean controlling whether the program supports explicit line continuation with &amp; (.false. by default).
90 logical, public :: support_dollar_insert = .true. !< Boolean controlling whether the program supports ${} substitution (.true. by default).
91 end type
92
93 !> @brief The single global instance used throughout fpx
94 !! Initialized automatically with sensible defaults values.
95 !! @ingroup group_global
96 type(global_settings), public :: global
97
98end module
type(global_settings), public global
The single global instance used throughout fpx Initialized automatically with sensible defaults value...
Definition global.f90:96
character(:) function, allocatable, public expand_macros(line, macros, stitch, implicit_conti, dollar_insert, ctx)
Core recursive macro expander (handles function-like, variadic, #, ##).
Definition macro.f90:344
Global preprocessor configuration and shared runtime state All components of fpx read from and write ...
Definition global.f90:77
Derived type representing a single preprocessor macro Extends string with macro-specific fields: rep...
Definition macro.f90:98
Represents text as a sequence of ASCII code units. The derived type wraps an allocatable character ar...
Definition string.f90:112