2019-12-21 04:52:07 +08:00
|
|
|
//===-- runtime/type-code.h -------------------------------------*- C++ -*-===//
|
2018-08-01 07:46:30 +08:00
|
|
|
//
|
2019-12-21 04:52:07 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2018-08-01 07:46:30 +08:00
|
|
|
//
|
2020-01-11 04:12:03 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2018-08-01 07:46:30 +08:00
|
|
|
|
|
|
|
#ifndef FORTRAN_RUNTIME_TYPE_CODE_H_
|
|
|
|
#define FORTRAN_RUNTIME_TYPE_CODE_H_
|
|
|
|
|
2020-02-25 23:11:52 +08:00
|
|
|
#include "flang/Common/Fortran.h"
|
2020-02-14 06:41:56 +08:00
|
|
|
#include "flang/ISO_Fortran_binding.h"
|
2020-08-07 08:30:01 +08:00
|
|
|
#include <optional>
|
|
|
|
#include <utility>
|
2018-08-01 07:46:30 +08:00
|
|
|
|
|
|
|
namespace Fortran::runtime {
|
|
|
|
|
2018-08-02 00:45:59 +08:00
|
|
|
using common::TypeCategory;
|
|
|
|
|
2018-08-01 07:46:30 +08:00
|
|
|
class TypeCode {
|
|
|
|
public:
|
|
|
|
TypeCode() {}
|
|
|
|
explicit TypeCode(ISO::CFI_type_t t) : raw_{t} {}
|
[flang] More Fortran runtime support for CHARACTER operations
Summary:
- Remove C++ library dependence from lock.h
- Implement LEN_TRIM, REPEAT, ADJUSTL, ADJUSTR, MAX/MIN
intrinsic functions for CHARACTER
Reviewers: tskeith, PeteSteinfeld, sscalpone, schweitz, DavidTruby
Reviewed By: PeteSteinfeld
Subscribers: llvm-commits, flang-commits
Tags: #flang, #llvm
Differential Revision: https://reviews.llvm.org/D82054
2020-06-18 04:17:24 +08:00
|
|
|
TypeCode(TypeCategory, int kind);
|
2018-08-01 07:46:30 +08:00
|
|
|
|
|
|
|
int raw() const { return raw_; }
|
|
|
|
|
|
|
|
constexpr bool IsValid() const {
|
[flang] More Fortran runtime support for CHARACTER operations
Summary:
- Remove C++ library dependence from lock.h
- Implement LEN_TRIM, REPEAT, ADJUSTL, ADJUSTR, MAX/MIN
intrinsic functions for CHARACTER
Reviewers: tskeith, PeteSteinfeld, sscalpone, schweitz, DavidTruby
Reviewed By: PeteSteinfeld
Subscribers: llvm-commits, flang-commits
Tags: #flang, #llvm
Differential Revision: https://reviews.llvm.org/D82054
2020-06-18 04:17:24 +08:00
|
|
|
return raw_ >= CFI_type_signed_char && raw_ <= CFI_TYPE_LAST;
|
2018-08-01 07:46:30 +08:00
|
|
|
}
|
|
|
|
constexpr bool IsInteger() const {
|
|
|
|
return raw_ >= CFI_type_signed_char && raw_ <= CFI_type_ptrdiff_t;
|
|
|
|
}
|
|
|
|
constexpr bool IsReal() const {
|
|
|
|
return raw_ >= CFI_type_float && raw_ <= CFI_type_long_double;
|
|
|
|
}
|
|
|
|
constexpr bool IsComplex() const {
|
|
|
|
return raw_ >= CFI_type_float_Complex &&
|
|
|
|
raw_ <= CFI_type_long_double_Complex;
|
|
|
|
}
|
[flang] More Fortran runtime support for CHARACTER operations
Summary:
- Remove C++ library dependence from lock.h
- Implement LEN_TRIM, REPEAT, ADJUSTL, ADJUSTR, MAX/MIN
intrinsic functions for CHARACTER
Reviewers: tskeith, PeteSteinfeld, sscalpone, schweitz, DavidTruby
Reviewed By: PeteSteinfeld
Subscribers: llvm-commits, flang-commits
Tags: #flang, #llvm
Differential Revision: https://reviews.llvm.org/D82054
2020-06-18 04:17:24 +08:00
|
|
|
constexpr bool IsCharacter() const {
|
|
|
|
return raw_ == CFI_type_char || raw_ == CFI_type_char16_t ||
|
|
|
|
raw_ == CFI_type_char32_t;
|
|
|
|
}
|
2020-08-07 08:30:01 +08:00
|
|
|
constexpr bool IsLogical() const {
|
|
|
|
return raw_ == CFI_type_Bool ||
|
2021-04-13 01:10:38 +08:00
|
|
|
(raw_ >= CFI_type_int_least8_t && raw_ <= CFI_type_int_least64_t);
|
2020-08-07 08:30:01 +08:00
|
|
|
}
|
2018-08-01 07:46:30 +08:00
|
|
|
constexpr bool IsDerived() const { return raw_ == CFI_type_struct; }
|
|
|
|
constexpr bool IsIntrinsic() const { return IsValid() && !IsDerived(); }
|
|
|
|
|
2020-08-07 08:30:01 +08:00
|
|
|
std::optional<std::pair<TypeCategory, int>> GetCategoryAndKind() const;
|
|
|
|
|
2020-11-11 07:13:02 +08:00
|
|
|
bool operator==(const TypeCode &that) const { return raw_ == that.raw_; }
|
|
|
|
bool operator!=(const TypeCode &that) const { return raw_ != that.raw_; }
|
|
|
|
|
2018-08-01 07:46:30 +08:00
|
|
|
private:
|
|
|
|
ISO::CFI_type_t raw_{CFI_type_other};
|
|
|
|
};
|
2020-03-29 12:00:16 +08:00
|
|
|
} // namespace Fortran::runtime
|
|
|
|
#endif // FORTRAN_RUNTIME_TYPE_CODE_H_
|