|
| 1 | +#pragma once |
| 2 | + |
| 3 | +// FRT or SWIFT_SHARED_REFERENCE type |
| 4 | +struct FRTStruct { |
| 5 | + // Friend function declarations |
| 6 | + friend FRTStruct * returnInstanceOfFRTStruct(int v); |
| 7 | + friend FRTStruct * returnInstanceOfFRTStructWithAttrReturnsRetained(int v); |
| 8 | + friend FRTStruct * returnInstanceOfFRTStructWithAttrReturnsUnretained(int v); |
| 9 | +} \ |
| 10 | + __attribute__((swift_attr("import_reference"))) \ |
| 11 | + __attribute__((swift_attr("retain:retainFRTStruct"))) \ |
| 12 | + __attribute__((swift_attr("release:releaseFRTStruct"))); |
| 13 | + |
| 14 | +// Retain function for the FRT or SWIFT_SHARED_REFERENCE type FRTStruct |
| 15 | +void retainFRTStruct(FRTStruct * _Nonnull b) { |
| 16 | +} |
| 17 | + |
| 18 | +// Release function for the FRT or SWIFT_SHARED_REFERENCE type FRTStruct |
| 19 | +void releaseFRTStruct(FRTStruct * _Nonnull b) { |
| 20 | +} |
| 21 | + |
| 22 | +// Friend function definition |
| 23 | + FRTStruct * returnInstanceOfFRTStruct() { |
| 24 | + return new FRTStruct; |
| 25 | +} |
| 26 | + |
| 27 | +// Friend function definition |
| 28 | + FRTStruct * returnInstanceOfFRTStructWithAttrReturnsRetained() __attribute__((swift_attr("returns_retained"))) { |
| 29 | + return new FRTStruct; |
| 30 | +} |
| 31 | + |
| 32 | +// Friend function definition |
| 33 | + FRTStruct * returnInstanceOfFRTStructWithAttrReturnsUnretained() __attribute__((swift_attr("returns_unretained"))) { |
| 34 | + return new FRTStruct; |
| 35 | +} |
| 36 | + |
| 37 | +// Global/free C++ functions returning FRT without any attributes |
| 38 | +FRTStruct* _Nonnull global_function_returning_FRT(); |
| 39 | +FRTStruct* _Nonnull global_function_returning_copy(); |
| 40 | +FRTStruct* _Nonnull global_function_returning_create(); |
| 41 | +FRTStruct* _Nonnull global_function_returning_init(); |
| 42 | +FRTStruct* _Nonnull global_function_returning_clone(); |
| 43 | + |
| 44 | +// Global/free C++ functions returning FRT with attribute swift_attr("returns_retained") or SWIFT_RETURNS_RETAINED |
| 45 | +FRTStruct* _Nonnull global_function_returning_FRT_with_attr_returns_retained() __attribute__((swift_attr("returns_retained"))); |
| 46 | +FRTStruct* _Nonnull global_function_returning_copy_with_attr_returns_retained() __attribute__((swift_attr("returns_retained"))); |
| 47 | +FRTStruct* _Nonnull global_function_returning_create_with_attr_returns_retained() __attribute__((swift_attr("returns_retained"))); |
| 48 | +FRTStruct* _Nonnull global_function_returning_init_with_attr_returns_retained() __attribute__((swift_attr("returns_retained"))); |
| 49 | +FRTStruct* _Nonnull global_function_returning_clone_with_attr_returns_retained() __attribute__((swift_attr("returns_retained"))); |
| 50 | + |
| 51 | +// Global/free C++ functions returning FRT with attribute swift_attr("returns_unretained") or SWIFT_RETURNS_UNRETAINED |
| 52 | +FRTStruct* _Nonnull global_function_returning_FRT_with_attr_returns_unretained() __attribute__((swift_attr("returns_unretained"))); |
| 53 | +FRTStruct* _Nonnull global_function_returning_copy_with_attr_returns_unretained() __attribute__((swift_attr("returns_unretained"))); |
| 54 | +FRTStruct* _Nonnull global_function_returning_create_with_attr_returns_unretained() __attribute__((swift_attr("returns_unretained"))); |
| 55 | +FRTStruct* _Nonnull global_function_returning_init_with_attr_returns_unretained() __attribute__((swift_attr("returns_unretained"))); |
| 56 | +FRTStruct* _Nonnull global_function_returning_clone_with_attr_returns_unretained() __attribute__((swift_attr("returns_unretained"))); |
| 57 | + |
| 58 | +// Static Global/free functions returning FRT |
| 59 | +static FRTStruct* _Nonnull global_static_function_returning_FRT(); |
| 60 | +static FRTStruct* _Nonnull global_static_function_returning_FRT_with_attr_returns_retained() __attribute__((swift_attr("returns_retained"))); |
| 61 | +static FRTStruct* _Nonnull global_static_function_returning_FRT_with_attr_returns_unretained() __attribute__((swift_attr("returns_unretained"))); |
| 62 | +static FRTStruct* _Nonnull global_static_function_returning_copy(); |
| 63 | +static FRTStruct* _Nonnull global_static_function_returning_create(); |
| 64 | +static FRTStruct* _Nonnull global_static_function_returning_copy_with_attr_returns_retained() __attribute__((swift_attr("returns_retained"))); |
| 65 | +static FRTStruct* _Nonnull global_static_function_returning_copy_with_attr_returns_unretained() __attribute__((swift_attr("returns_unretained"))); |
| 66 | + |
| 67 | +// Global/free functions returning FRT without _Nonnull |
| 68 | +FRTStruct* global_function_returning_FRT_wihout_Nonnull(); |
| 69 | +FRTStruct* global_function_returning_FRT_with_attr_returns_retained_wihout_Nonnull() __attribute__((swift_attr("returns_retained"))); |
| 70 | +FRTStruct* global_function_returning_FRT_with_attr_returns_unretained_wihout_Nonnull() __attribute__((swift_attr("returns_unretained"))); |
| 71 | +FRTStruct* global_function_returning_copy_wihout_Nonnull(); |
| 72 | +FRTStruct* global_function_returning_create_wihout_Nonnull(); |
| 73 | +FRTStruct* global_function_returning_copy_with_attr_returns_retained_wihout_Nonnull() __attribute__((swift_attr("returns_retained"))); |
| 74 | +FRTStruct* global_function_returning_copy_with_attr_returns_unretained_wihout_Nonnull() __attribute__((swift_attr("returns_unretained"))); |
| 75 | + |
| 76 | +// Struct having static methods returning FRT without any attributes |
| 77 | +struct StructWithStaticMethodsReturningFRTWithoutAttributes { |
| 78 | + static FRTStruct* _Nonnull StaticMethodReturningFRT(); |
| 79 | + static FRTStruct* _Nonnull StaticMethodReturningFRT_copy(); |
| 80 | + static FRTStruct* _Nonnull StaticMethodReturningFRT_create(); |
| 81 | + static FRTStruct* _Nonnull StaticMethodReturningFRT_init(); |
| 82 | + static FRTStruct* _Nonnull StaticMethodReturningFRT_clone(); |
| 83 | +}; |
| 84 | + |
| 85 | +// Struct having static methods returning FRT with attribute swift_attr("returns_retained") or SWIFT_RETURNS_RETAINED |
| 86 | +struct StructWithStaticMethodsReturningFRTWithAttributeReturnsRetained { |
| 87 | + static FRTStruct* _Nonnull StaticMethodReturningFRT() __attribute__((swift_attr("returns_retained"))); |
| 88 | + static FRTStruct* _Nonnull StaticMethodReturningFRT_copy() __attribute__((swift_attr("returns_retained"))); |
| 89 | + static FRTStruct* _Nonnull StaticMethodReturningFRT_create() __attribute__((swift_attr("returns_retained"))); |
| 90 | + static FRTStruct* _Nonnull StaticMethodReturningFRT_init() __attribute__((swift_attr("returns_retained"))); |
| 91 | + static FRTStruct* _Nonnull StaticMethodReturningFRT_clone() __attribute__((swift_attr("returns_retained"))); |
| 92 | +}; |
| 93 | + |
| 94 | +// Struct having static methods returning FRT with attribute swift_attr("returns_unretained") or SWIFT_RETURNS_UNRETAINED |
| 95 | +struct StructWithStaticMethodsReturningFRTWithAttributeReturnsUnretained { |
| 96 | + static FRTStruct* _Nonnull StaticMethodReturningFRT() __attribute__((swift_attr("returns_unretained"))); |
| 97 | + static FRTStruct* _Nonnull StaticMethodReturningFRT_copy() __attribute__((swift_attr("returns_unretained"))); |
| 98 | + static FRTStruct* _Nonnull StaticMethodReturningFRT_create() __attribute__((swift_attr("returns_unretained"))); |
| 99 | + static FRTStruct* _Nonnull StaticMethodReturningFRT_init() __attribute__((swift_attr("returns_unretained"))); |
| 100 | + static FRTStruct* _Nonnull StaticMethodReturningFRT_clone() __attribute__((swift_attr("returns_unretained"))); |
| 101 | +}; |
| 102 | + |
| 103 | +// Global/free C++ functions returning FRT with both attributes swift_attr("returns_unretained") and swift_attr("returns_retained") |
| 104 | +FRTStruct* _Nonnull global_function_returning_FRT_with_both_attrs_returns_retained_returns_unretained() __attribute__((swift_attr("returns_retained"))) __attribute__((swift_attr("returns_unretained"))); |
| 105 | + |
| 106 | +// Struct having static method returning FRT with both attributes swift_attr("returns_unretained") and swift_attr("returns_retained") |
| 107 | +struct StructWithStaticMethodsReturningFRTWithBothAttributesReturnsRetainedAndReturnsUnretained { |
| 108 | + static FRTStruct* _Nonnull StaticMethodReturningFRT() __attribute__((swift_attr("returns_retained"))) __attribute__((swift_attr("returns_unretained"))); |
| 109 | +}; |
| 110 | + |
| 111 | +struct NonFRTStruct { |
| 112 | +}; |
| 113 | + |
| 114 | +// Global/free C++ functions returning non-FRT |
| 115 | +NonFRTStruct* _Nonnull global_function_returning_non_FRT(); |
| 116 | +NonFRTStruct* _Nonnull global_function_returning_non_FRT_with_attr_returns_retained() __attribute__((swift_attr("returns_retained"))); |
| 117 | +NonFRTStruct* _Nonnull global_function_returning_non_FRT_with_attr_returns_unretained() __attribute__((swift_attr("returns_unretained"))); |
| 118 | +NonFRTStruct* _Nonnull global_function_returning_non_FRT_create(); |
| 119 | +NonFRTStruct* _Nonnull global_function_returning_non_FRT_copy(); |
| 120 | + |
| 121 | + |
| 122 | +// Struct having static method returning non-FRT |
| 123 | +struct StructWithStaticMethodsReturningNonFRT { |
| 124 | + static NonFRTStruct* _Nonnull StaticMethodReturningNonFRT(); |
| 125 | + static NonFRTStruct* _Nonnull StaticMethodReturningNonFRTWithAttrReturnsRetained() __attribute__((swift_attr("returns_retained"))); |
| 126 | + static NonFRTStruct* _Nonnull StaticMethodReturningNonFRTWithAttrReturnsUnretained() __attribute__((swift_attr("returns_unretained"))); |
| 127 | + static NonFRTStruct* _Nonnull StaticMethodReturningNonFRT_create(); |
| 128 | + static NonFRTStruct* _Nonnull StaticMethodReturningNonFRT_copy(); |
| 129 | +}; |
| 130 | + |
| 131 | +// Tests for templated functions |
| 132 | +template <typename T> |
| 133 | +FRTStruct * _Nonnull global_templated_function_returning_FRT(T a); |
| 134 | + |
| 135 | +template <typename T> |
| 136 | +FRTStruct * _Nonnull global_templated_function_returning_FRT_copy(T a); |
| 137 | + |
| 138 | +template <typename T> |
| 139 | +FRTStruct * _Nonnull global_templated_function_returning_FRT_create(T a); |
| 140 | + |
| 141 | +template <typename T> |
| 142 | +FRTStruct * _Nonnull global_templated_function_returning_FRT_init(T a); |
| 143 | + |
| 144 | +template <typename T> |
| 145 | +FRTStruct * _Nonnull global_templated_function_returning_FRT_clone(T a); |
| 146 | + |
| 147 | +template <typename T> |
| 148 | +FRTStruct * _Nonnull global_templated_function_returning_FRT_with_attr_returns_retained(T a) __attribute__((swift_attr("returns_retained"))); |
| 149 | + |
| 150 | +template <typename T> |
| 151 | +FRTStruct * _Nonnull global_templated_function_returning_FRT_copy_with_attr_returns_retained(T a) __attribute__((swift_attr("returns_retained"))); |
| 152 | + |
| 153 | +template <typename T> |
| 154 | +FRTStruct * _Nonnull global_templated_function_returning_FRT_create_with_attr_returns_retained(T a) __attribute__((swift_attr("returns_retained"))); |
| 155 | + |
| 156 | +template <typename T> |
| 157 | +FRTStruct * _Nonnull global_templated_function_returning_FRT_with_attr_returns_unretained(T a) __attribute__((swift_attr("returns_unretained"))); |
| 158 | + |
| 159 | +template <typename T> |
| 160 | +FRTStruct * _Nonnull global_templated_function_returning_FRT_copy_with_attr_returns_unretained(T a) __attribute__((swift_attr("returns_unretained"))); |
| 161 | + |
| 162 | +template <typename T> |
| 163 | +FRTStruct * _Nonnull global_templated_function_returning_FRT_create_with_attr_returns_unretained(T a) __attribute__((swift_attr("returns_unretained"))); |
0 commit comments