9#ifndef FORTRAN_COMMON_TYPE_KINDS_H_
10#define FORTRAN_COMMON_TYPE_KINDS_H_
12#include "Fortran-consts.h"
17#define FORTRAN_INTEGER_KINDS {1, 2, 4, 8, 16}
18#define FORTRAN_UNSIGNED_KINDS FORTRAN_INTEGER_KINDS
19#define FORTRAN_REAL_KINDS {2, 3, 4, 8, 10, 16}
20#define FORTRAN_LOGICAL_KINDS {1, 2, 4, 8}
21#define FORTRAN_CHARACTER_KINDS {1, 2, 4}
25static constexpr int IntegerKinds[] FORTRAN_INTEGER_KINDS;
26static constexpr int UnsignedKinds[] FORTRAN_UNSIGNED_KINDS;
27static constexpr int RealKinds[] FORTRAN_REAL_KINDS;
28static constexpr int LogicalKinds[] FORTRAN_LOGICAL_KINDS;
29static constexpr int CharacterKinds[] FORTRAN_CHARACTER_KINDS;
34 static inline constexpr int kinds[] FORTRAN_INTEGER_KINDS;
37 static inline constexpr int kinds[] FORTRAN_UNSIGNED_KINDS;
40 static inline constexpr int kinds[] FORTRAN_REAL_KINDS;
43 static inline constexpr int kinds[] FORTRAN_REAL_KINDS;
46 static inline constexpr int kinds[] FORTRAN_LOGICAL_KINDS;
49 static inline constexpr int kinds[] FORTRAN_CHARACTER_KINDS;
52 static inline constexpr int kinds[]{0};
55static constexpr int maxKind{16};
57template <
typename T, std::
size_t N>
58static constexpr bool IsKindInList(
const T (&kinds)[N], std::int64_t kind) {
59 for (std::size_t i{0}; i < N; ++i) {
69static constexpr bool IsValidKindOfIntrinsicType(
70 TypeCategory category, std::int64_t kind) {
72 case TypeCategory::Integer:
73 case TypeCategory::Unsigned: {
74 constexpr int kinds[] = FORTRAN_INTEGER_KINDS;
75 return IsKindInList(kinds, kind);
77 case TypeCategory::Real:
78 case TypeCategory::Complex: {
79 constexpr int kinds[] = FORTRAN_REAL_KINDS;
80 return IsKindInList(kinds, kind);
82 case TypeCategory::Character: {
83 constexpr int kinds[] = FORTRAN_CHARACTER_KINDS;
84 return IsKindInList(kinds, kind);
86 case TypeCategory::Logical: {
87 constexpr int kinds[] = FORTRAN_LOGICAL_KINDS;
88 return IsKindInList(kinds, kind);
95static constexpr int TypeSizeInBytes(TypeCategory category, std::int64_t kind) {
96 if (IsValidKindOfIntrinsicType(category, kind)) {
97 if (category == TypeCategory::Real || category == TypeCategory::Complex) {
98 int precision{PrecisionOfRealKind(kind)};
99 int bits{BitsForBinaryPrecision(precision)};
103 if (category == TypeCategory::Complex) {
Definition bit-population-count.h:20
Iterable lists of valid kinds for each TypeCategory.
Definition type-kinds.h:32