9#ifndef FORTRAN_RUNTIME_TYPE_INFO_H_
10#define FORTRAN_RUNTIME_TYPE_INFO_H_
15#include "terminator.h"
16#include "flang/Common/Fortran-consts.h"
17#include "flang/Common/bit-population-count.h"
18#include "flang/Common/optional.h"
19#include "flang/Runtime/descriptor.h"
23namespace Fortran::runtime::typeInfo {
27using ProcedurePointer = void (*)();
30 ProcedurePointer proc;
36 enum class Genre : std::uint8_t {
41 RT_API_ATTRS Genre genre()
const {
return genre_; }
42 RT_API_ATTRS Fortran::common::optional<TypeParameterValue> GetValue(
46 Genre genre_{Genre::Explicit};
49 TypeParameterValue value_{0};
54 enum class Genre : std::uint8_t {
61 RT_API_ATTRS
const Descriptor &name()
const {
return name_.descriptor(); }
62 RT_API_ATTRS Genre genre()
const {
return genre_; }
63 RT_API_ATTRS TypeCategory category()
const {
64 return static_cast<TypeCategory
>(category_);
66 RT_API_ATTRS
int kind()
const {
return kind_; }
67 RT_API_ATTRS
int rank()
const {
return rank_; }
68 RT_API_ATTRS std::uint64_t offset()
const {
return offset_; }
69 RT_API_ATTRS
const Value &characterLen()
const {
return characterLen_; }
70 RT_API_ATTRS
const DerivedType *derivedType()
const {
71 return derivedType_.descriptor().OffsetElement<
const DerivedType>();
73 RT_API_ATTRS
const Value *lenValue()
const {
74 return lenValue_.descriptor().OffsetElement<
const Value>();
76 RT_API_ATTRS
const Value *bounds()
const {
77 return bounds_.descriptor().OffsetElement<
const Value>();
79 RT_API_ATTRS
const char *initialization()
const {
return initialization_; }
81 RT_API_ATTRS std::size_t GetElementByteSize(
const Descriptor &)
const;
82 RT_API_ATTRS std::size_t GetElements(
const Descriptor &)
const;
86 RT_API_ATTRS std::size_t SizeInBytes(
const Descriptor &)
const;
89 RT_API_ATTRS
void EstablishDescriptor(
94 RT_API_ATTRS
void CreatePointerDescriptor(
Descriptor &,
96 const SubscriptValue * =
nullptr)
const;
98 FILE *Dump(FILE * = stdout)
const;
102 Genre genre_{Genre::Data};
103 std::uint8_t category_;
104 std::uint8_t kind_{0};
105 std::uint8_t rank_{0};
106 std::uint64_t offset_{0};
113 const char *initialization_{
nullptr};
120 std::uint64_t offset{0};
121 ProcedurePointer procInitialization;
126 enum class Which : std::uint8_t {
128 ScalarAssignment = 1,
129 ElementalAssignment = 2,
133 WriteUnformatted = 6,
135 AssumedRankFinal = 8,
143 std::uint8_t isArgDescSet, std::uint8_t isTypeBound,
144 std::uint8_t isArgContiguousSet)
145 : which_{which}, isArgDescriptorSet_{isArgDescSet},
146 isTypeBound_{isTypeBound}, isArgContiguousSet_{isArgContiguousSet},
149 static constexpr RT_API_ATTRS Which RankFinal(
int rank) {
150 return static_cast<Which
>(
static_cast<int>(Which::ScalarFinal) + rank);
153 RT_API_ATTRS Which which()
const {
return which_; }
154 RT_API_ATTRS
bool IsArgDescriptor(
int zeroBasedArg)
const {
155 return (isArgDescriptorSet_ >> zeroBasedArg) & 1;
157 RT_API_ATTRS
bool isTypeBound()
const {
return isTypeBound_; }
158 RT_API_ATTRS
bool IsArgContiguous(
int zeroBasedArg)
const {
159 return (isArgContiguousSet_ >> zeroBasedArg) & 1;
161 template <
typename PROC> RT_API_ATTRS PROC GetProc()
const {
162 return reinterpret_cast<PROC
>(proc_);
165 FILE *Dump(FILE *)
const;
168 Which which_{Which::None};
195 std::uint8_t isArgDescriptorSet_{0};
196 std::uint8_t isTypeBound_{0};
199 std::uint8_t isArgContiguousSet_{0};
201 ProcedurePointer proc_{
nullptr};
208 RT_API_ATTRS
const Descriptor &binding()
const {
209 return binding_.descriptor();
211 RT_API_ATTRS
const Descriptor &name()
const {
return name_.descriptor(); }
212 RT_API_ATTRS std::uint64_t sizeInBytes()
const {
return sizeInBytes_; }
213 RT_API_ATTRS
const Descriptor &uninstatiated()
const {
214 return uninstantiated_.descriptor();
216 RT_API_ATTRS
const Descriptor &kindParameter()
const {
217 return kindParameter_.descriptor();
219 RT_API_ATTRS
const Descriptor &lenParameterKind()
const {
220 return lenParameterKind_.descriptor();
222 RT_API_ATTRS
const Descriptor &component()
const {
223 return component_.descriptor();
225 RT_API_ATTRS
const Descriptor &procPtr()
const {
226 return procPtr_.descriptor();
228 RT_API_ATTRS
const Descriptor &special()
const {
229 return special_.descriptor();
231 RT_API_ATTRS
bool hasParent()
const {
return hasParent_; }
232 RT_API_ATTRS
bool noInitializationNeeded()
const {
233 return noInitializationNeeded_;
235 RT_API_ATTRS
bool noDestructionNeeded()
const {
return noDestructionNeeded_; }
236 RT_API_ATTRS
bool noFinalizationNeeded()
const {
237 return noFinalizationNeeded_;
240 RT_API_ATTRS std::size_t LenParameters()
const {
241 return lenParameterKind().Elements();
244 RT_API_ATTRS
const DerivedType *GetParentType()
const;
247 RT_API_ATTRS
const Component *FindDataComponent(
248 const char *name, std::size_t nameLen)
const;
252 SpecialBinding::Which which)
const {
253 auto bitIndex{
static_cast<std::uint32_t
>(which)};
254 auto bit{std::uint32_t{1} << bitIndex};
255 if (specialBitSet_ & bit) {
259 int offset{common::BitPopulationCount(specialBitSet_ & (bit - 1))};
263 INTERNAL_CHECK(binding && binding->which() == which);
270 FILE *Dump(FILE * = stdout)
const;
282 std::uint64_t sizeInBytes_{0};
314 std::uint32_t specialBitSet_{0};
317 bool hasParent_{
false};
318 bool noInitializationNeeded_{
false};
319 bool noDestructionNeeded_{
false};
320 bool noFinalizationNeeded_{
false};
Definition: descriptor.h:138
Definition: descriptor.h:447
Definition: terminator.h:23
Definition: type-info.h:52
Definition: type-info.h:204
Definition: type-info.h:124
Definition: type-info.h:34
Definition: type-info.h:29
Definition: type-info.h:118