9#ifndef FORTRAN_RUNTIME_TYPE_CODE_H_
10#define FORTRAN_RUNTIME_TYPE_CODE_H_
12#include "flang/Common/Fortran-consts.h"
13#include "flang/Common/optional.h"
14#include "flang/ISO_Fortran_binding_wrapper.h"
17namespace Fortran::runtime {
19using common::TypeCategory;
24 explicit RT_API_ATTRS
TypeCode(ISO::CFI_type_t t) : raw_{t} {}
25 RT_API_ATTRS
TypeCode(TypeCategory,
int kind);
27 RT_API_ATTRS
int raw()
const {
return raw_; }
29 constexpr RT_API_ATTRS
bool IsValid()
const {
30 return raw_ >= CFI_type_signed_char && raw_ <= CFI_TYPE_LAST;
32 constexpr RT_API_ATTRS
bool IsInteger()
const {
33 return raw_ >= CFI_type_signed_char && raw_ <= CFI_type_ptrdiff_t;
35 constexpr RT_API_ATTRS
bool IsReal()
const {
36 return raw_ >= CFI_type_half_float && raw_ <= CFI_type_float128;
38 constexpr RT_API_ATTRS
bool IsComplex()
const {
39 return raw_ >= CFI_type_half_float_Complex &&
40 raw_ <= CFI_type_float128_Complex;
42 constexpr RT_API_ATTRS
bool IsCharacter()
const {
43 return raw_ == CFI_type_char || raw_ == CFI_type_char16_t ||
44 raw_ == CFI_type_char32_t;
46 constexpr RT_API_ATTRS
bool IsLogical()
const {
47 return raw_ == CFI_type_Bool ||
48 (raw_ >= CFI_type_int_least8_t && raw_ <= CFI_type_int_least64_t);
50 constexpr RT_API_ATTRS
bool IsDerived()
const {
51 return raw_ == CFI_type_struct;
53 constexpr RT_API_ATTRS
bool IsIntrinsic()
const {
54 return IsValid() && !IsDerived();
57 RT_API_ATTRS Fortran::common::optional<std::pair<TypeCategory, int>>
58 GetCategoryAndKind()
const;
60 RT_API_ATTRS
bool operator==(
TypeCode that)
const {
61 if (raw_ == that.raw_) {
67 auto thisCK{GetCategoryAndKind()};
68 auto thatCK{that.GetCategoryAndKind()};
69 return thisCK && thatCK && *thisCK == *thatCK;
72 RT_API_ATTRS
bool operator!=(
TypeCode that)
const {
return !(*
this == that); }
75 ISO::CFI_type_t raw_{CFI_type_other};
Definition: type-code.h:21