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 maxKind{16};
27template <
typename T, std::
size_t N>
28static constexpr bool IsKindInList(
const T (&kinds)[N], std::int64_t kind) {
29 for (std::size_t i{0}; i < N; ++i) {
39static constexpr bool IsValidKindOfIntrinsicType(
40 TypeCategory category, std::int64_t kind) {
42 case TypeCategory::Integer:
43 case TypeCategory::Unsigned: {
44 constexpr int kinds[] = FORTRAN_INTEGER_KINDS;
45 return IsKindInList(kinds, kind);
47 case TypeCategory::Real:
48 case TypeCategory::Complex: {
49 constexpr int kinds[] = FORTRAN_REAL_KINDS;
50 return IsKindInList(kinds, kind);
52 case TypeCategory::Character: {
53 constexpr int kinds[] = FORTRAN_CHARACTER_KINDS;
54 return IsKindInList(kinds, kind);
56 case TypeCategory::Logical: {
57 constexpr int kinds[] = FORTRAN_LOGICAL_KINDS;
58 return IsKindInList(kinds, kind);
65static constexpr int TypeSizeInBytes(TypeCategory category, std::int64_t kind) {
66 if (IsValidKindOfIntrinsicType(category, kind)) {
67 if (category == TypeCategory::Real || category == TypeCategory::Complex) {
68 int precision{PrecisionOfRealKind(kind)};
69 int bits{BitsForBinaryPrecision(precision)};
73 if (category == TypeCategory::Complex) {
Definition bit-population-count.h:20