Loading...
Searching...
No Matches
diagnostics.f90
Go to the documentation of this file.
1!> @file
2!! @defgroup group_diagnostics Diagnostics
3!! Processing of #warning and #error preprocessor directives
4!! This module implements the core logic for handling messages (either as
5!! warning or errors).
6!!
7!! <h2 class="groupheader">Examples</h2>
8!!
9!! 1. Break preprocessing on error:
10!! @code{.f90}
11!! #ifdef __vax__
12!! #error "VAX not supported"
13!! #endif
14!! ...
15!! @endcode
16!!
17!! 2. Warn version mismatch:
18!! @code{.f90}
19!! #if __STDF__ > 1
20!! #warning "The version of the Fortran language is greater than 1"
21!! #endif
22!! ...
23!! @endcode
24module fpx_diagnostics
25 use, intrinsic :: iso_fortran_env, only: stdout => output_unit
26 use fpx_logging
27 use fpx_macro
28 use fpx_global
29 use fpx_string
30 use fpx_context
31
32 implicit none; private
33
34 public :: handle_error, &
36
37contains
38
39 !> Process a #error directive. It causes the preprocessor to report a
40 !! fatal error that stops the preprocessor. The string forming the rest
41 !! of the line following ‘#error’ is printed in the standard error.
42 !!
43 !! @param[in] ctx Context source line containing the #define
44 !! @param[inout] macros Current macro table (updated in-place)
45 !! @param[in] token Usually 'DEFINE' – keyword matched in lowercase
46 !!
47 !! @b Remarks
48 !! @ingroup group_diagnostics
49 subroutine handle_error(ctx, macros, token)
50 type(context), intent(in) :: ctx
51 type(macro), allocatable, intent(inout) :: macros(:)
52 character(*), intent(in) :: token
53 !private
54 integer :: pos
55
56 pos = index(lowercase(ctx%content), token) + len(token)
57 error stop trim(adjustl(ctx%content(pos + 1:)))
58 end subroutine
59
60 !> Process a #warning directive. It causes the preprocessor to report a
61 !! warning that does not stop the preprocessor. The string forming the rest
62 !! of the line following ‘#warning’ is printed in the standard output.
63 !! @param[in] ctx Context source line containing the #undef
64 !! @param[inout] macros Current macro table (updated in-place)
65 !! @param[in] token Usually 'UNDEF' – keyword matched in lowercase
66 !!
67 !! @b Remarks
68 !! @ingroup group_diagnostics
69 subroutine handle_warning(ctx, macros, token)
70 type(context), intent(in) :: ctx
71 type(macro), allocatable, intent(inout) :: macros(:)
72 character(*), intent(in) :: token
73 !private
74 integer :: pos
75
76 pos = index(lowercase(ctx%content), token) + len(token)
77 write(stdout, '(A)') trim(adjustl(ctx%content(pos + 1:)))
78 end subroutine
79end module
subroutine, public handle_error(ctx, macros, token)
Process a error directive. It causes the preprocessor to report a fatal error that stops the preproce...
subroutine, public handle_warning(ctx, macros, token)
Process a warning directive. It causes the preprocessor to report a warning that does not stop the pr...
pure character(len_trim(str)) function, public lowercase(str)
Convert string to lower case (respects contents of quotes).
Definition string.f90:640
Index operator.
Definition string.f90:178
Return the length of a string.
Definition string.f90:133
Return the trimmed string.
Definition string.f90:149
Source location and content snapshot for precise diagnostics Instances of this type are created for e...
Definition context.f90:99
Derived type representing a single preprocessor macro Extends string with macro-specific fields: rep...
Definition macro.f90:94