derived-type.cpp
2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//===-- runtime/derived-type.cpp ------------------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
#include "derived-type.h"
#include "descriptor.h"
#include <cstring>
namespace Fortran::runtime {
TypeParameterValue TypeParameter::GetValue(const Descriptor &descriptor) const {
if (which_ < 0) {
return value_;
} else {
return descriptor.Addendum()->LenParameterValue(which_);
}
}
bool DerivedType::IsNontrivialAnalysis() const {
if (kindParameters_ > 0 || lenParameters_ > 0 || typeBoundProcedures_ > 0) {
return true;
}
for (std::size_t j{0}; j < components_; ++j) {
if (component_[j].IsDescriptor()) {
return true;
}
if (const Descriptor * staticDescriptor{component_[j].staticDescriptor()}) {
if (const DescriptorAddendum * addendum{staticDescriptor->Addendum()}) {
if (const DerivedType * dt{addendum->derivedType()}) {
if (dt->IsNontrivial()) {
return true;
}
}
}
}
}
return false;
}
void DerivedType::Initialize(char *instance) const {
if (typeBoundProcedures_ > InitializerTBP) {
if (auto f{reinterpret_cast<void (*)(char *)>(
typeBoundProcedure_[InitializerTBP].code.host)}) {
f(instance);
}
}
#if 0 // TODO
for (std::size_t j{0}; j < components_; ++j) {
if (const Descriptor * descriptor{component_[j].GetDescriptor(instance)}) {
// invoke initialization TBP
}
}
#endif
}
void DerivedType::Destroy(char *instance, bool finalize) const {
if (finalize && typeBoundProcedures_ > FinalTBP) {
if (auto f{reinterpret_cast<void (*)(char *)>(
typeBoundProcedure_[FinalTBP].code.host)}) {
f(instance);
}
}
const char *constInstance{instance};
for (std::size_t j{0}; j < components_; ++j) {
if (Descriptor * descriptor{component_[j].GetDescriptor(instance)}) {
descriptor->Deallocate(finalize);
} else if (const Descriptor *
descriptor{component_[j].GetDescriptor(constInstance)}) {
descriptor->Destroy(component_[j].Locate<char>(instance), finalize);
}
}
}
} // namespace Fortran::runtime