xref: /llvm-project/flang/include/flang/Runtime/derived-api.h (revision 1fcb6a9754a8db057e18f629cb90011b638901e7)
1 //===-- include/flang/Runtime/derived-api.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 // API for lowering to use for operations on derived type objects.
10 // Initialiaztion and finalization are implied for pointer and allocatable
11 // ALLOCATE()/DEALLOCATE() respectively, so these APIs should be used only for
12 // local variables.  Whole allocatable assignment should use AllocatableAssign()
13 // instead of this Assign().
14 
15 #ifndef FORTRAN_RUNTIME_DERIVED_API_H_
16 #define FORTRAN_RUNTIME_DERIVED_API_H_
17 
18 #include "flang/Runtime/entry-names.h"
19 
20 namespace Fortran::runtime {
21 class Descriptor;
22 
23 namespace typeInfo {
24 class DerivedType;
25 }
26 
27 extern "C" {
28 
29 // Initializes and allocates an object's components, if it has a derived type
30 // with any default component initialization or automatic components.
31 // The descriptor must be initialized and non-null.
32 void RTDECL(Initialize)(
33     const Descriptor &, const char *sourceFile = nullptr, int sourceLine = 0);
34 
35 // Initializes an object clone from the original object.
36 // Each allocatable member of the clone is allocated with the same bounds as
37 // in the original object, if it is also allocated in it.
38 // The descriptor must be initialized and non-null.
39 void RTDECL(InitializeClone)(const Descriptor &, const Descriptor &,
40     const char *sourceFile = nullptr, int sourceLine = 0);
41 
42 // Finalizes an object and its components.  Deallocates any
43 // allocatable/automatic components.  Does not deallocate the descriptor's
44 // storage.
45 void RTDECL(Destroy)(const Descriptor &);
46 
47 // Finalizes the object and its components.
48 void RTDECL(Finalize)(
49     const Descriptor &, const char *sourceFile = nullptr, int sourceLine = 0);
50 
51 /// Deallocates any allocatable/automatic components.
52 /// Does not deallocate the descriptor's storage.
53 /// Does not perform any finalization.
54 void RTDECL(DestroyWithoutFinalization)(const Descriptor &);
55 
56 // Intrinsic or defined assignment, with scalar expansion but not type
57 // conversion.
58 void RTDECL(Assign)(const Descriptor &, const Descriptor &,
59     const char *sourceFile = nullptr, int sourceLine = 0);
60 
61 // Perform the test of the CLASS IS type guard statement of the SELECT TYPE
62 // construct.
63 bool RTDECL(ClassIs)(const Descriptor &, const typeInfo::DerivedType &);
64 
65 // Perform the test of the SAME_TYPE_AS intrinsic.
66 bool RTDECL(SameTypeAs)(const Descriptor &, const Descriptor &);
67 
68 // Perform the test of the EXTENDS_TYPE_OF intrinsic.
69 bool RTDECL(ExtendsTypeOf)(const Descriptor &, const Descriptor &);
70 
71 } // extern "C"
72 } // namespace Fortran::runtime
73 #endif // FORTRAN_RUNTIME_DERIVED_API_H_
74