Warning: This file is not a C or C++ file. It does not have highlighting.
1 | //===-- include/flang/Runtime/pointer.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 | // Defines APIs for Fortran runtime library support of code generated |
10 | // to manipulate and query data pointers. |
11 | |
12 | #ifndef FORTRAN_RUNTIME_POINTER_H_ |
13 | #define FORTRAN_RUNTIME_POINTER_H_ |
14 | |
15 | #include "flang/Runtime/descriptor.h" |
16 | #include "flang/Runtime/entry-names.h" |
17 | |
18 | namespace Fortran::runtime { |
19 | extern "C" { |
20 | |
21 | // Data pointer initialization for NULLIFY(), "p=>NULL()`, & for ALLOCATE(). |
22 | |
23 | // Initializes a pointer to a disassociated state for NULLIFY() or "p=>NULL()". |
24 | void RTDECL(PointerNullifyIntrinsic)( |
25 | Descriptor &, TypeCategory, int kind, int rank = 0, int corank = 0); |
26 | void RTDECL(PointerNullifyCharacter)(Descriptor &, SubscriptValue length = 0, |
27 | int kind = 1, int rank = 0, int corank = 0); |
28 | void RTDECL(PointerNullifyDerived)( |
29 | Descriptor &, const typeInfo::DerivedType &, int rank = 0, int corank = 0); |
30 | |
31 | // Explicitly sets the bounds of an initialized disassociated pointer. |
32 | // The upper cobound is ignored for the last codimension. |
33 | void RTDECL(PointerSetBounds)( |
34 | Descriptor &, int zeroBasedDim, SubscriptValue lower, SubscriptValue upper); |
35 | void RTDECL(PointerSetCoBounds)(Descriptor &, int zeroBasedCoDim, |
36 | SubscriptValue lower, SubscriptValue upper = 0); |
37 | |
38 | // Length type parameters are indexed in declaration order; i.e., 0 is the |
39 | // first length type parameter in the deepest base type. (Not for use |
40 | // with CHARACTER; see above.) |
41 | void RTDECL(PointerSetDerivedLength)(Descriptor &, int which, SubscriptValue); |
42 | |
43 | // For MOLD= allocation: acquires information from another descriptor |
44 | // to initialize a null data pointer. |
45 | void RTDECL(PointerApplyMold)( |
46 | Descriptor &, const Descriptor &mold, int rank = 0); |
47 | |
48 | // Data pointer association for "p=>TARGET" |
49 | |
50 | // Associates a scalar pointer with a simple scalar target. |
51 | void RTDECL(PointerAssociateScalar)(Descriptor &, void *); |
52 | |
53 | // Associates a pointer with a target of the same rank, possibly with new lower |
54 | // bounds, which are passed in a vector whose length must equal the rank. |
55 | void RTDECL(PointerAssociate)(Descriptor &, const Descriptor &target); |
56 | void RTDECL(PointerAssociateLowerBounds)( |
57 | Descriptor &, const Descriptor &target, const Descriptor &lowerBounds); |
58 | |
59 | // Associates a pointer with a target with bounds remapping. The target must be |
60 | // simply contiguous &/or of rank 1. The bounds constitute a [2,newRank] |
61 | // integer array whose columns are [lower bound, upper bound] on each dimension. |
62 | void RTDECL(PointerAssociateRemapping)(Descriptor &, const Descriptor &target, |
63 | const Descriptor &bounds, const char *sourceFile = nullptr, |
64 | int sourceLine = 0); |
65 | |
66 | // Data pointer allocation and deallocation |
67 | |
68 | // When an explicit type-spec appears in an ALLOCATE statement for an |
69 | // pointer with an explicit (non-deferred) length type paramater for |
70 | // a derived type or CHARACTER value, the explicit value has to match |
71 | // the length type parameter's value. This API checks that requirement. |
72 | // Returns 0 for success, or the STAT= value on failure with hasStat==true. |
73 | int RTDECL(PointerCheckLengthParameter)(Descriptor &, |
74 | int which /* 0 for CHARACTER length */, SubscriptValue other, |
75 | bool hasStat = false, const Descriptor *errMsg = nullptr, |
76 | const char *sourceFile = nullptr, int sourceLine = 0); |
77 | |
78 | // Allocates a data pointer. Its descriptor must have been initialized |
79 | // and its bounds and length type parameters set. It need not be disassociated. |
80 | // On failure, if hasStat is true, returns a nonzero error code for |
81 | // STAT= and (if present) fills in errMsg; if hasStat is false, the |
82 | // image is terminated. On success, leaves errMsg alone and returns zero. |
83 | // Successfully allocated memory is initialized if the pointer has a |
84 | // derived type, and is always initialized by PointerAllocateSource(). |
85 | // Performs all necessary coarray synchronization and validation actions. |
86 | int RTDECL(PointerAllocate)(Descriptor &, bool hasStat = false, |
87 | const Descriptor *errMsg = nullptr, const char *sourceFile = nullptr, |
88 | int sourceLine = 0); |
89 | int RTDECL(PointerAllocateSource)(Descriptor &, const Descriptor &source, |
90 | bool hasStat = false, const Descriptor *errMsg = nullptr, |
91 | const char *sourceFile = nullptr, int sourceLine = 0); |
92 | |
93 | // Deallocates a data pointer, which must have been allocated by |
94 | // PointerAllocate(), possibly copied with PointerAssociate(). |
95 | // Finalizes elements &/or components as needed. The pointer is left |
96 | // in an initialized disassociated state suitable for reallocation |
97 | // with the same bounds, cobounds, and length type parameters. |
98 | int RTDECL(PointerDeallocate)(Descriptor &, bool hasStat = false, |
99 | const Descriptor *errMsg = nullptr, const char *sourceFile = nullptr, |
100 | int sourceLine = 0); |
101 | |
102 | // Same as PointerDeallocate but also set the dynamic type as the declared type |
103 | // as mentioned in 7.3.2.3 note 7. |
104 | int RTDECL(PointerDeallocatePolymorphic)(Descriptor &, |
105 | const typeInfo::DerivedType *, bool hasStat = false, |
106 | const Descriptor *errMsg = nullptr, const char *sourceFile = nullptr, |
107 | int sourceLine = 0); |
108 | |
109 | // Association inquiries for ASSOCIATED() |
110 | |
111 | // True when the pointer is not disassociated. |
112 | bool RTDECL(PointerIsAssociated)(const Descriptor &); |
113 | |
114 | // True when the pointer is associated with a specific target. |
115 | bool RTDECL(PointerIsAssociatedWith)( |
116 | const Descriptor &, const Descriptor *target); |
117 | |
118 | } // extern "C" |
119 | } // namespace Fortran::runtime |
120 | #endif // FORTRAN_RUNTIME_POINTER_H_ |
121 |
Warning: This file is not a C or C++ file. It does not have highlighting.