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;
31static constexpr int maxKind{16};
33template <
typename T, std::
size_t N>
34static constexpr bool IsKindInList(
const T (&kinds)[N], std::int64_t kind) {
35 for (std::size_t i{0}; i < N; ++i) {
45static constexpr bool IsValidKindOfIntrinsicType(
46 TypeCategory category, std::int64_t kind) {
48 case TypeCategory::Integer:
49 case TypeCategory::Unsigned: {
50 constexpr int kinds[] = FORTRAN_INTEGER_KINDS;
51 return IsKindInList(kinds, kind);
53 case TypeCategory::Real:
54 case TypeCategory::Complex: {
55 constexpr int kinds[] = FORTRAN_REAL_KINDS;
56 return IsKindInList(kinds, kind);
58 case TypeCategory::Character: {
59 constexpr int kinds[] = FORTRAN_CHARACTER_KINDS;
60 return IsKindInList(kinds, kind);
62 case TypeCategory::Logical: {
63 constexpr int kinds[] = FORTRAN_LOGICAL_KINDS;
64 return IsKindInList(kinds, kind);
71static constexpr int TypeSizeInBytes(TypeCategory category, std::int64_t kind) {
72 if (IsValidKindOfIntrinsicType(category, kind)) {
73 if (category == TypeCategory::Real || category == TypeCategory::Complex) {
74 int precision{PrecisionOfRealKind(kind)};
75 int bits{BitsForBinaryPrecision(precision)};
79 if (category == TypeCategory::Complex) {
Definition bit-population-count.h:20