Loading...
Searching...
No Matches
global.f90
Go to the documentation of this file.
1!> @file
2!! @defgroup group_global Global
3!! Global configuration and shared runtime state for the fpx preprocessor.
4!!
5!! This module defines the central configuration object used throughout the
6!! entire preprocessing session. A single public instance,
7!! @link fpx_global::global global @endlink, stores all persistent settings controlling the behavior of
8!! the preprocessor.
9!!
10!! The global configuration provides:
11!!
12!! - User-defined macro definitions.
13!! - Symbols explicitly excluded via `#undef`.
14!! - Additional include search directories.
15!! - Feature switches controlling optional extensions.
16!! - Behavioural settings affecting parsing and expansion.
17!! - Runtime flags used by interactive preprocessing sessions.
18!!
19!! All fpx components access the same global state, avoiding the need to pass
20!! configuration objects through every procedure call.
21!!
22!! The design assumes the traditional single-threaded preprocessing model.
23!! If multiple preprocessing jobs are executed concurrently, each instance
24!! should maintain its own independent configuration object.
25!!
26!! @section global_features Supported configuration options
27!!
28!! The following settings are available:
29!!
30!! - `macros(:)`
31!! Collection of predefined macros available before preprocessing begins.
32!!
33!! - `undef(:)`
34!! Symbols protected from future redefinition through `#define`.
35!!
36!! - `includedir(:)`
37!! Additional directories searched by `#include`.
38!!
39!! - `expand_macros`
40!! Enables or disables macro expansion globally.
41!!
42!! - `exclude_comments`
43!! Controls whether comments are preserved in the generated output.
44!!
45!! - `implicit_continuation`
46!! Enables implicit continuation during macro expansion.
47!!
48!! - `line_break`
49!! Interprets a double backslash (`\\`) as an explicit line break.
50!!
51!! - `extra_macros`
52!! Enables non-standard predefined macros such as:
53!! - `__FILE__`
54!! - `__LINE__`
55!! - `__FUNC__`
56!! - `__TIMESTAMP__`
57!!
58!! - `interactive`
59!! Enables REPL-style interactive preprocessing.
60!!
61!! - `support_forloop`
62!! Enables support for the non-standard `#for` / `#endfor` directives.
63!!
64!! - `disable_continuation`
65!! Disables explicit Fortran continuation handling using trailing `&`.
66!!
67!! - `support_dollar_insert`
68!! Enables `${NAME}` placeholder substitution during macro expansion.
69!!
70!! @note
71!! All settings can be modified at any time before invoking
72!! `preprocess(...)`.
73!!
74!! @section global_examples Examples
75!!
76!! 1. Add custom include paths:
77!! @code{.f90}
78!! use fpx_global
79!!
80!! global%includedir = [ &
81!! string('./include'), &
82!! string('../common'), &
83!! string('/usr/local/include/fpx') ]
84!!
85!! call preprocess('main.F90')
86!! ...
87!! @endcode
88!!
89!! 2. Predefine macros:
90!! @code{.f90}
91!! use fpx_global
92!! use fpx_macro
93!!
94!! call add(global%macros, macro('DEBUG','1'))
95!! call add(global%macros, macro('MPI_VERSION','4'))
96!!
97!! call preprocess('solver.F90')
98!! ...
99!! @endcode
100!!
101!! 3. Disable macro expansion:
102!! @code{.f90}
103!! global%expand_macros = .false.
104!!
105!! call preprocess('input.F90', 'output.F90')
106!! ...
107!! @endcode
108!!
109!! 4. Enable fpx extensions:
110!! @code{.f90}
111!! global%support_forloop = .true.
112!! global%support_dollar_insert = .true.
113!! global%extra_macros = .true.
114!!
115!! call preprocess('templates.F90')
116!! ...
117!! @endcode
118!!
119!! 5. Start an interactive preprocessing session:
120!! @code
121!! global%interactive = .true.
122!!
123!! call preprocess(stdin, stdout)
124!! ...
125!! @endcode
126!!
127!! @see
128!! <a href="~/group__group__macro.html">macro</a>
129!! <a href="~/group__group__parser.html">parser</a>
130!! <a href="~/group__group__include.html">include</a>
131module fpx_global
132 use fpx_constants
133 use fpx_string
134 use fpx_macro
135
136 implicit none; private
137
138 !> Global preprocessor configuration and shared runtime state.
139 !!
140 !! This type encapsulates all user-configurable options controlling the
141 !! behaviour of the fpx preprocessor.
142 !!
143 !! A single public instance, @ref global, is provided and used throughout
144 !! the library. Applications may modify its components before starting
145 !! preprocessing to customize parsing rules, enable extensions, or
146 !! predefine symbols.
147 !!
148 !! @section global_type_examples Examples
149 !!
150 !! @code{.f90}
151 !! use fpx_global
152 !! use fpx_macro
153 !!
154 !! call add(global%macros, macro('__LFORTRAN__','1'))
155 !! global%extra_macros = .true.
156 !! global%support_forloop = .true.
157 !! ...
158 !! @endcode
159 !!
160 !! @section global_type_remarks Remarks
161 !!
162 !! - The settings remain active for the duration of the preprocessing session.
163 !! - Components may be modified at any time before calling `preprocess`.
164 !! - The global instance is intended for single-threaded use.
165 !!
166 !! @ingroup group_global
167 type, public :: global_settings
168 private
169 type(macro), allocatable, public :: macros(:) !< Predefined macros available before preprocessing begins.
170 type(string), allocatable, public :: undef(:) !< Symbols protected from future redefinition.
171 type(string), allocatable, public :: includedir(:) !< Additional directories searched by `#include`.
172 logical, public :: expand_macros = .true. !< Enable global macro expansion.
173 logical, public :: exclude_comments = .false. !< Preserve comments in the generated output.
174 logical, public :: implicit_continuation = .false. !< Enable implicit continuation during macro expansion.
175 logical, public :: line_break = .false. !< Treat `\\` as an explicit output line break.
176 logical, public :: extra_macros = .true. !< Enable non-standard predefined macros such as `__FILE__`, `__LINE__`, `__FUNC__`, and `__TIMESTAMP__`.
177 logical, public :: interactive = .false. !< Enable interactive REPL mode.
178 logical, public :: support_forloop = .true. !< Enable support for `#for` and `#endfor`.
179 logical, public :: disable_continuation = .false. !< Disable explicit continuation using trailing `&`.
180 logical, public :: support_dollar_insert = .true. !< Enable `${NAME}` placeholder substitution.
181 end type
182
183 !> Global preprocessor configuration instance.
184 !!
185 !! This singleton is automatically initialized with sensible default
186 !! values and is shared by all fpx modules during preprocessing.
187 !!
188 !! Applications typically customize this object before invoking
189 !! `preprocess(...)`.
190 !!
191 !! @ingroup group_global
192 type(global_settings), public :: global
193
194end module
type(global_settings), public global
Global preprocessor configuration instance.
Definition global.f90:192
character(:) function, allocatable, public expand_macros(line, macros, stitch, implicit_conti, dollar_insert, ctx)
Recursively expand user-defined macros.
Definition macro.f90:453
Global preprocessor configuration and shared runtime state.
Definition global.f90:167
Representation of a preprocessor macro.
Definition macro.f90:135
Represents text as a sequence of ASCII code units. The derived type wraps an allocatable character ar...
Definition string.f90:112