Skip to content

Commit d0a8e34

Browse files
committed
fix(stringification): reduce clashes,better format
This commit does the following: 1. Renames the `string_m` module and `string` function to `fortran_stringify_integer_m` and `fortran_stringify_integer`, respectively, to decrease the likelihood of name clashes with user code and to clarify the function's limited purpose. 2. Renames the `STRINGIFY` macro to `CPP_STRINGIFY_SOURCE` to more clarify the difference from `fortran_stringify_integer`. 3. Changes the `fortran_stringify_integer` string-writing format from `*` to `(i0)` for more consistent results across compilers. The results are the same for the three tested compilers: GCC (`gfortran`), NAG (`nagfor`), and LLVM (`flang-new`).
1 parent 52e14b2 commit d0a8e34

File tree

3 files changed

+15
-15
lines changed

3 files changed

+15
-15
lines changed

include/assert_macros.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,18 @@
1313

1414
! Deal with stringification issues:
1515
! https://gcc.gnu.org/legacy-ml/fortran/2009-06/msg00131.html
16-
#ifndef STRINGIFY
16+
#ifndef CPP_STRINGIFY_SOURCE
1717
# if defined(__GFORTRAN__) || defined(_CRAYFTN) || defined(NAGFOR)
18-
# define STRINGIFY(x) "x"
18+
# define CPP_STRINGIFY_SOURCE(x) "x"
1919
# else
20-
# define STRINGIFY(x) #x
20+
# define CPP_STRINGIFY_SOURCE(x) #x
2121
# endif
2222
#endif
2323

2424
#if ASSERTIONS
25-
# define call_assert(assertion) call assert_always(assertion, "call_assert(" // STRINGIFY(assertion) // ") in file " // __FILE__ // ", line " // string(__LINE__))
26-
# define call_assert_describe(assertion, description) call assert_always(assertion, description // " in file " // __FILE__ // ", line " // string(__LINE__))
27-
# define call_assert_diagnose(assertion, description, diagnostic_data) call assert_always(assertion, description // " in file " // __FILE__ // ", line " // string(__LINE__), diagnostic_data)
25+
# define call_assert(assertion) call assert_always(assertion, "call_assert(" // CPP_STRINGIFY_SOURCE(assertion) // ") in file " // __FILE__ // ", line " // fortran_stringify_integer(__LINE__))
26+
# define call_assert_describe(assertion, description) call assert_always(assertion, description // " in file " // __FILE__ // ", line " // fortran_stringify_integer(__LINE__))
27+
# define call_assert_diagnose(assertion, description, diagnostic_data) call assert_always(assertion, description // " in file " // __FILE__ // ", line " // fortran_stringify_integer(__LINE__), diagnostic_data)
2828
#else
2929
# define call_assert(assertion)
3030
# define call_assert_describe(assertion, description)
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
module string_m
1+
module fortran_stringify_integer_m
22
implicit none
33

44
contains
55

6-
pure function string(number) result(number_as_string)
6+
pure function fortran_stringify_integer(number) result(number_as_string)
77
integer, intent(in) :: number
88
integer, parameter :: max_len=128
99
character(len=max_len) :: untrimmed_string
1010
character(len=:), allocatable :: number_as_string
1111

12-
write(untrimmed_string, *) number
12+
write(untrimmed_string, '(i0)') number
1313
number_as_string = trim(adjustl(untrimmed_string))
1414
end function
1515

16-
end module string_m
16+
end module

src/assert_m.f90

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module assert_m
2-
use intrinsic_array_m
3-
use assert_subroutine_m
4-
use characterizable_m
5-
use string_m, only : string
2+
use intrinsic_array_m, only : intrinsic_array_t
3+
use assert_subroutine_m, only : assert, assert_always
4+
use characterizable_m, only : characterizable_t
5+
use fortran_stringify_integer_m, only : fortran_stringify_integer
66
implicit none
7-
end module assert_m
7+
end module

0 commit comments

Comments
 (0)