FLANG

type-code.h
1 //===-- runtime/type-code.h -------------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8
9 #ifndef FORTRAN_RUNTIME_TYPE_CODE_H_
10 #define FORTRAN_RUNTIME_TYPE_CODE_H_
11
12 #include "flang/Common/Fortran.h"
13 #include "flang/ISO_Fortran_binding.h"
14
15 namespace Fortran::runtime {
16
17 using common::TypeCategory;
18
19 class TypeCode {
20 public:
21 TypeCode() {}
22 explicit TypeCode(ISO::CFI_type_t t) : raw_{t} {}
23 TypeCode(TypeCategory, int kind);
24
25 int raw() const { return raw_; }
26
27 constexpr bool IsValid() const {
28 return raw_ >= CFI_type_signed_char && raw_ <= CFI_TYPE_LAST;
29 }
30 constexpr bool IsInteger() const {
31 return raw_ >= CFI_type_signed_char && raw_ <= CFI_type_ptrdiff_t;
32 }
33 constexpr bool IsReal() const {
34 return raw_ >= CFI_type_float && raw_ <= CFI_type_long_double;
35 }
36 constexpr bool IsComplex() const {
37 return raw_ >= CFI_type_float_Complex &&
38 raw_ <= CFI_type_long_double_Complex;
39 }
40 constexpr bool IsCharacter() const {
41 return raw_ == CFI_type_char || raw_ == CFI_type_char16_t ||
42 raw_ == CFI_type_char32_t;
43 }
44 constexpr bool IsLogical() const { return raw_ == CFI_type_Bool; }
45 constexpr bool IsDerived() const { return raw_ == CFI_type_struct; }
46 constexpr bool IsIntrinsic() const { return IsValid() && !IsDerived(); }
47
48 private:
49 ISO::CFI_type_t raw_{CFI_type_other};
50 };
51 } // namespace Fortran::runtime
52 #endif // FORTRAN_RUNTIME_TYPE_CODE_H_
Fortran::runtime::TypeCode
Definition: type-code.h:19