Skip to content

Commit 9929cdb

Browse files
authored
Add separate logical kind parameters (#424)
1 parent b3c3102 commit 9929cdb

File tree

8 files changed

+91
-19
lines changed

8 files changed

+91
-19
lines changed

doc/specs/index.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ This is and index/directory of the specifications (specs) for each new module/fe
1515
- [bitsets](./stdlib_bitsets.html) - Bitset data types and procedures
1616
- [error](./stdlib_error.html) - Catching and handling errors
1717
- [IO](./stdlib_io.html) - Input/output helper & convenience
18+
- [kinds](./stdlib_kinds.html) - Kind parameters
1819
- [linalg](./stdlib_linalg.html) - Linear Algebra
1920
- [logger](./stdlib_logger.html) - Runtime logging system
2021
- [optval](./stdlib_optval.html) - Fallback value for optional arguments
@@ -25,10 +26,6 @@ This is and index/directory of the specifications (specs) for each new module/fe
2526
- [string\_type](./stdlib_string_type.html) - Basic string support
2627
- [strings](./stdlib_strings.html) - String handling and manipulation routines
2728

28-
## Missing specs
29-
30-
- [kinds](https://github.com/fortran-lang/stdlib/blob/master/src/stdlib_kinds.f90)
31-
3229
## Released/Stable Features & Modules
3330

3431
- (None yet)

doc/specs/stdlib_kinds.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
---
2+
title: kinds
3+
---
4+
5+
# The `stdlib_kinds` module
6+
7+
[TOC]
8+
9+
## Introduction
10+
11+
The `stdlib_kinds` module provides kind parameters for the Fortran intrinsic data types,
12+
*integer*, *logical*, *real*, and *complex*.
13+
14+
15+
## Constants provided by `stdlib_kinds`
16+
17+
### `sp`
18+
19+
Alias for intrinsic named constant `real32` imported from `iso_fortran_env`.
20+
21+
22+
### `dp`
23+
24+
Alias for intrinsic named constant `real64` imported from `iso_fortran_env`.
25+
26+
27+
### `qp`
28+
29+
Alias for intrinsic named constant `real128` imported from `iso_fortran_env`.
30+
31+
32+
### `int8`
33+
34+
Reexported intrinsic named constant `int8` from `iso_fortran_env`.
35+
36+
37+
### `int16`
38+
39+
Reexported intrinsic named constant `int16` from `iso_fortran_env`.
40+
41+
42+
### `int32`
43+
44+
Reexported intrinsic named constant `int32` from `iso_fortran_env`.
45+
46+
47+
### `int64`
48+
49+
Reexported intrinsic named constant `int64` from `iso_fortran_env`.
50+
51+
52+
### `lk`
53+
54+
Kind parameter of the default logical data type.
55+
56+
57+
### `c_bool`
58+
59+
Reexported intrinsic named constant `c_bool` from `iso_c_binding`.

src/common.fypp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@
2727
#! Collected (kind, type) tuples for integer types
2828
#:set INT_KINDS_TYPES = list(zip(INT_KINDS, INT_TYPES))
2929

30+
#! Logical kinds to be considered during templating
31+
#:set LOG_KINDS = ["lk", "c_bool"]
32+
33+
#! Logical types to be considered during templating
34+
#:set LOG_TYPES = ["logical({})".format(k) for k in LOG_KINDS]
35+
36+
#! Collected (kind, type) tuples for logical types
37+
#:set LOG_KINDS_TYPES = list(zip(LOG_KINDS, LOG_TYPES))
38+
3039
#! Derived type string_type
3140
#:set STRING_KINDS = ["string_type"]
3241

src/stdlib_ascii.fypp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
!>
66
!> The specification of this module is available [here](../page/specs/stdlib_ascii.html).
77
module stdlib_ascii
8-
use stdlib_kinds, only : int8, int16, int32, int64
8+
use stdlib_kinds, only : int8, int16, int32, int64, lk, c_bool
99

1010
implicit none
1111
private
@@ -28,6 +28,8 @@ module stdlib_ascii
2828
interface to_string
2929
#:for kind in INT_KINDS
3030
module procedure :: to_string_integer_${kind}$
31+
#:endfor
32+
#:for kind in LOG_KINDS
3133
module procedure :: to_string_logical_${kind}$
3234
#:endfor
3335
end interface to_string
@@ -396,7 +398,7 @@ contains
396398
end function to_string_integer_${kind}$
397399
#:endfor
398400

399-
#:for kind in INT_KINDS
401+
#:for kind in LOG_KINDS
400402
!> Represent an logical of kind ${kind}$ as character sequence
401403
pure function to_string_logical_${kind}$(val) result(string)
402404
integer, parameter :: ik = ${kind}$

src/stdlib_kinds.f90

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@ module stdlib_kinds
22
!! version: experimental
33
use iso_fortran_env, only: sp=>real32, dp=>real64, qp=>real128
44
use iso_fortran_env, only: int8, int16, int32, int64
5+
use iso_c_binding, only: c_bool
56
! If we decide later to use iso_c_binding instead of iso_fortran_env:
67
!use iso_c_binding, only: sp=>c_float, dp=>c_double, qp=>c_float128
78
!use iso_c_binding, only: int8=>c_int8_t, int16=>c_int16_t, int32=>c_int32_t, int64=>c_int64_t
89
implicit none
910
private
10-
public sp, dp, qp, int8, int16, int32, int64
11+
public sp, dp, qp, int8, int16, int32, int64, lk, c_bool
12+
13+
integer, parameter :: lk = kind(.true.)
1114
end module stdlib_kinds

src/stdlib_string_type.fypp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
module stdlib_string_type
1616
use stdlib_ascii, only: to_lower_ => to_lower, to_upper_ => to_upper, &
1717
& to_title_ => to_title, to_sentence_ => to_sentence, reverse_ => reverse, to_string
18-
use stdlib_kinds, only : int8, int16, int32, int64
18+
use stdlib_kinds, only : int8, int16, int32, int64, lk, c_bool
1919
implicit none
2020
private
2121

@@ -47,6 +47,8 @@ module stdlib_string_type
4747
module procedure :: new_string
4848
#:for kind in INT_KINDS
4949
module procedure :: new_string_from_integer_${kind}$
50+
#:endfor
51+
#:for kind in LOG_KINDS
5052
module procedure :: new_string_from_logical_${kind}$
5153
#:endfor
5254
end interface string_type
@@ -373,7 +375,7 @@ contains
373375
end function new_string_from_integer_${kind}$
374376
#:endfor
375377

376-
#:for kind in INT_KINDS
378+
#:for kind in LOG_KINDS
377379
!> Constructor for new string instances from a logical of kind ${kind}$.
378380
elemental function new_string_from_logical_${kind}$(val) result(new)
379381
logical(${kind}$), intent(in) :: val

src/tests/ascii/test_ascii.f90

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ program test_ascii
88
is_control, is_punctuation, is_graphical, is_printable, is_ascii, &
99
to_lower, to_upper, to_title, to_sentence, reverse, LF, TAB, NUL, DEL, &
1010
to_string
11-
use stdlib_kinds, only : int8, int16, int32, int64
11+
use stdlib_kinds, only : int8, int16, int32, int64, lk, c_bool
1212

1313
implicit none
1414

@@ -676,11 +676,11 @@ subroutine test_to_string
676676
write(flc, '(g0)') .false.
677677
call check(to_string(.false.) == trim(flc))
678678

679-
write(flc, '(g0)') .true._int8
680-
call check(to_string(.true._int8) == trim(flc))
679+
write(flc, '(g0)') .true._c_bool
680+
call check(to_string(.true._c_bool) == trim(flc))
681681

682-
write(flc, '(g0)') .false._int64
683-
call check(to_string(.false._int64) == trim(flc))
682+
write(flc, '(g0)') .false._lk
683+
call check(to_string(.false._lk) == trim(flc))
684684
end subroutine test_to_string
685685

686686
end program test_ascii

src/tests/string/test_string_assignment.f90

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
! SPDX-Identifier: MIT
22
module test_string_assignment
33
use stdlib_error, only : check
4-
use stdlib_kinds, only : int8, int16, int32, int64
4+
use stdlib_kinds, only : int8, int16, int32, int64, lk, c_bool
55
use stdlib_string_type, only : string_type, assignment(=), operator(==), len
66
implicit none
77

@@ -52,11 +52,11 @@ subroutine test_char_value
5252
write(flc, '(g0)') .false.
5353
call check(string_type(.false.) == trim(flc))
5454

55-
write(flc, '(g0)') .false._int8
56-
call check(string_type(.false._int8) == trim(flc))
55+
write(flc, '(g0)') .false._c_bool
56+
call check(string_type(.false._c_bool) == trim(flc))
5757

58-
write(flc, '(g0)') .true._int64
59-
call check(string_type(.true._int64) == trim(flc))
58+
write(flc, '(g0)') .true._lk
59+
call check(string_type(.true._lk) == trim(flc))
6060
end subroutine test_char_value
6161

6262
end module test_string_assignment

0 commit comments

Comments
 (0)