|
| 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 | +} __attribute__((swift_attr("import_reference"))) |
| 10 | +__attribute__((swift_attr("retain:retainFRTStruct"))) |
| 11 | +__attribute__((swift_attr("release:releaseFRTStruct"))); |
| 12 | + |
| 13 | +// Retain function for the FRT or SWIFT_SHARED_REFERENCE type FRTStruct |
| 14 | +void retainFRTStruct(FRTStruct *_Nonnull b) {} |
| 15 | + |
| 16 | +// Release function for the FRT or SWIFT_SHARED_REFERENCE type FRTStruct |
| 17 | +void releaseFRTStruct(FRTStruct *_Nonnull b) {} |
| 18 | + |
| 19 | +// Friend function definition |
| 20 | +FRTStruct *returnInstanceOfFRTStruct() { return new FRTStruct; } |
| 21 | + |
| 22 | +// Friend function definition |
| 23 | +FRTStruct *returnInstanceOfFRTStructWithAttrReturnsRetained() |
| 24 | + __attribute__((swift_attr("returns_retained"))) { |
| 25 | + return new FRTStruct; |
| 26 | +} |
| 27 | + |
| 28 | +// Friend function definition |
| 29 | +FRTStruct *returnInstanceOfFRTStructWithAttrReturnsUnretained() |
| 30 | + __attribute__((swift_attr("returns_unretained"))) { |
| 31 | + return new FRTStruct; |
| 32 | +} |
| 33 | + |
| 34 | +// Global/free C++ functions returning FRT without any attributes |
| 35 | +FRTStruct *_Nonnull global_function_returning_FRT(); |
| 36 | +FRTStruct *_Nonnull global_function_returning_copy(); |
| 37 | +FRTStruct *_Nonnull global_function_returning_create(); |
| 38 | +FRTStruct *_Nonnull global_function_returning_init(); |
| 39 | +FRTStruct *_Nonnull global_function_returning_clone(); |
| 40 | + |
| 41 | +// Global/free C++ functions returning FRT with attribute |
| 42 | +// swift_attr("returns_retained") or SWIFT_RETURNS_RETAINED |
| 43 | +FRTStruct *_Nonnull global_function_returning_FRT_with_attr_returns_retained() |
| 44 | + __attribute__((swift_attr("returns_retained"))); |
| 45 | +FRTStruct *_Nonnull global_function_returning_copy_with_attr_returns_retained() |
| 46 | + __attribute__((swift_attr("returns_retained"))); |
| 47 | +FRTStruct |
| 48 | + *_Nonnull global_function_returning_create_with_attr_returns_retained() |
| 49 | + __attribute__((swift_attr("returns_retained"))); |
| 50 | +FRTStruct *_Nonnull global_function_returning_init_with_attr_returns_retained() |
| 51 | + __attribute__((swift_attr("returns_retained"))); |
| 52 | +FRTStruct *_Nonnull global_function_returning_clone_with_attr_returns_retained() |
| 53 | + __attribute__((swift_attr("returns_retained"))); |
| 54 | + |
| 55 | +// Global/free C++ functions returning FRT with attribute |
| 56 | +// swift_attr("returns_unretained") or SWIFT_RETURNS_UNRETAINED |
| 57 | +FRTStruct *_Nonnull global_function_returning_FRT_with_attr_returns_unretained() |
| 58 | + __attribute__((swift_attr("returns_unretained"))); |
| 59 | +FRTStruct |
| 60 | + *_Nonnull global_function_returning_copy_with_attr_returns_unretained() |
| 61 | + __attribute__((swift_attr("returns_unretained"))); |
| 62 | +FRTStruct |
| 63 | + *_Nonnull global_function_returning_create_with_attr_returns_unretained() |
| 64 | + __attribute__((swift_attr("returns_unretained"))); |
| 65 | +FRTStruct |
| 66 | + *_Nonnull global_function_returning_init_with_attr_returns_unretained() |
| 67 | + __attribute__((swift_attr("returns_unretained"))); |
| 68 | +FRTStruct |
| 69 | + *_Nonnull global_function_returning_clone_with_attr_returns_unretained() |
| 70 | + __attribute__((swift_attr("returns_unretained"))); |
| 71 | + |
| 72 | +// Static Global/free functions returning FRT |
| 73 | +static FRTStruct *_Nonnull global_static_function_returning_FRT(); |
| 74 | +static FRTStruct |
| 75 | + *_Nonnull global_static_function_returning_FRT_with_attr_returns_retained() |
| 76 | + __attribute__((swift_attr("returns_retained"))); |
| 77 | +static FRTStruct |
| 78 | + *_Nonnull global_static_function_returning_FRT_with_attr_returns_unretained() |
| 79 | + __attribute__((swift_attr("returns_unretained"))); |
| 80 | +static FRTStruct *_Nonnull global_static_function_returning_copy(); |
| 81 | +static FRTStruct *_Nonnull global_static_function_returning_create(); |
| 82 | +static FRTStruct |
| 83 | + *_Nonnull global_static_function_returning_copy_with_attr_returns_retained() |
| 84 | + __attribute__((swift_attr("returns_retained"))); |
| 85 | +static FRTStruct |
| 86 | + *_Nonnull global_static_function_returning_copy_with_attr_returns_unretained() |
| 87 | + __attribute__((swift_attr("returns_unretained"))); |
| 88 | + |
| 89 | +// Global/free functions returning FRT without _Nonnull |
| 90 | +FRTStruct *global_function_returning_FRT_wihout_Nonnull(); |
| 91 | +FRTStruct * |
| 92 | +global_function_returning_FRT_with_attr_returns_retained_wihout_Nonnull() |
| 93 | + __attribute__((swift_attr("returns_retained"))); |
| 94 | +FRTStruct * |
| 95 | +global_function_returning_FRT_with_attr_returns_unretained_wihout_Nonnull() |
| 96 | + __attribute__((swift_attr("returns_unretained"))); |
| 97 | +FRTStruct *global_function_returning_copy_wihout_Nonnull(); |
| 98 | +FRTStruct *global_function_returning_create_wihout_Nonnull(); |
| 99 | +FRTStruct * |
| 100 | +global_function_returning_copy_with_attr_returns_retained_wihout_Nonnull() |
| 101 | + __attribute__((swift_attr("returns_retained"))); |
| 102 | +FRTStruct * |
| 103 | +global_function_returning_copy_with_attr_returns_unretained_wihout_Nonnull() |
| 104 | + __attribute__((swift_attr("returns_unretained"))); |
| 105 | + |
| 106 | +// Struct having static methods returning FRT without any attributes |
| 107 | +struct StructWithStaticMethodsReturningFRTWithoutAttributes { |
| 108 | + static FRTStruct *_Nonnull StaticMethodReturningFRT(); |
| 109 | + static FRTStruct *_Nonnull StaticMethodReturningFRT_copy(); |
| 110 | + static FRTStruct *_Nonnull StaticMethodReturningFRT_create(); |
| 111 | + static FRTStruct *_Nonnull StaticMethodReturningFRT_init(); |
| 112 | + static FRTStruct *_Nonnull StaticMethodReturningFRT_clone(); |
| 113 | +}; |
| 114 | + |
| 115 | +// Struct having static methods returning FRT with attribute |
| 116 | +// swift_attr("returns_retained") or SWIFT_RETURNS_RETAINED |
| 117 | +struct StructWithStaticMethodsReturningFRTWithAttributeReturnsRetained { |
| 118 | + static FRTStruct *_Nonnull StaticMethodReturningFRT() |
| 119 | + __attribute__((swift_attr("returns_retained"))); |
| 120 | + static FRTStruct *_Nonnull StaticMethodReturningFRT_copy() |
| 121 | + __attribute__((swift_attr("returns_retained"))); |
| 122 | + static FRTStruct *_Nonnull StaticMethodReturningFRT_create() |
| 123 | + __attribute__((swift_attr("returns_retained"))); |
| 124 | + static FRTStruct *_Nonnull StaticMethodReturningFRT_init() |
| 125 | + __attribute__((swift_attr("returns_retained"))); |
| 126 | + static FRTStruct *_Nonnull StaticMethodReturningFRT_clone() |
| 127 | + __attribute__((swift_attr("returns_retained"))); |
| 128 | +}; |
| 129 | + |
| 130 | +// Struct having static methods returning FRT with attribute |
| 131 | +// swift_attr("returns_unretained") or SWIFT_RETURNS_UNRETAINED |
| 132 | +struct StructWithStaticMethodsReturningFRTWithAttributeReturnsUnretained { |
| 133 | + static FRTStruct *_Nonnull StaticMethodReturningFRT() |
| 134 | + __attribute__((swift_attr("returns_unretained"))); |
| 135 | + static FRTStruct *_Nonnull StaticMethodReturningFRT_copy() |
| 136 | + __attribute__((swift_attr("returns_unretained"))); |
| 137 | + static FRTStruct *_Nonnull StaticMethodReturningFRT_create() |
| 138 | + __attribute__((swift_attr("returns_unretained"))); |
| 139 | + static FRTStruct *_Nonnull StaticMethodReturningFRT_init() |
| 140 | + __attribute__((swift_attr("returns_unretained"))); |
| 141 | + static FRTStruct *_Nonnull StaticMethodReturningFRT_clone() |
| 142 | + __attribute__((swift_attr("returns_unretained"))); |
| 143 | +}; |
| 144 | + |
| 145 | +// Global/free C++ functions returning FRT with both attributes |
| 146 | +// swift_attr("returns_unretained") and swift_attr("returns_retained") |
| 147 | +FRTStruct |
| 148 | + *_Nonnull global_function_returning_FRT_with_both_attrs_returns_retained_returns_unretained() |
| 149 | + __attribute__((swift_attr("returns_retained"))) |
| 150 | + __attribute__((swift_attr("returns_unretained"))); |
| 151 | + |
| 152 | +// Struct having static method returning FRT with both attributes |
| 153 | +// swift_attr("returns_unretained") and swift_attr("returns_retained") |
| 154 | +struct |
| 155 | + StructWithStaticMethodsReturningFRTWithBothAttributesReturnsRetainedAndReturnsUnretained { |
| 156 | + static FRTStruct *_Nonnull StaticMethodReturningFRT() |
| 157 | + __attribute__((swift_attr("returns_retained"))) |
| 158 | + __attribute__((swift_attr("returns_unretained"))); |
| 159 | +}; |
| 160 | + |
| 161 | +struct NonFRTStruct {}; |
| 162 | + |
| 163 | +// Global/free C++ functions returning non-FRT |
| 164 | +NonFRTStruct *_Nonnull global_function_returning_non_FRT(); |
| 165 | +NonFRTStruct |
| 166 | + *_Nonnull global_function_returning_non_FRT_with_attr_returns_retained() |
| 167 | + __attribute__((swift_attr("returns_retained"))); |
| 168 | +NonFRTStruct |
| 169 | + *_Nonnull global_function_returning_non_FRT_with_attr_returns_unretained() |
| 170 | + __attribute__((swift_attr("returns_unretained"))); |
| 171 | +NonFRTStruct *_Nonnull global_function_returning_non_FRT_create(); |
| 172 | +NonFRTStruct *_Nonnull global_function_returning_non_FRT_copy(); |
| 173 | + |
| 174 | +// Struct having static method returning non-FRT |
| 175 | +struct StructWithStaticMethodsReturningNonFRT { |
| 176 | + static NonFRTStruct *_Nonnull StaticMethodReturningNonFRT(); |
| 177 | + static NonFRTStruct |
| 178 | + *_Nonnull StaticMethodReturningNonFRTWithAttrReturnsRetained() |
| 179 | + __attribute__((swift_attr("returns_retained"))); |
| 180 | + static NonFRTStruct |
| 181 | + *_Nonnull StaticMethodReturningNonFRTWithAttrReturnsUnretained() |
| 182 | + __attribute__((swift_attr("returns_unretained"))); |
| 183 | + static NonFRTStruct *_Nonnull StaticMethodReturningNonFRT_create(); |
| 184 | + static NonFRTStruct *_Nonnull StaticMethodReturningNonFRT_copy(); |
| 185 | +}; |
| 186 | + |
| 187 | +// Tests for templated functions |
| 188 | +template <typename T> |
| 189 | +FRTStruct *_Nonnull global_templated_function_returning_FRT(T a); |
| 190 | + |
| 191 | +template <typename T> |
| 192 | +FRTStruct *_Nonnull global_templated_function_returning_FRT_copy(T a); |
| 193 | + |
| 194 | +template <typename T> |
| 195 | +FRTStruct *_Nonnull global_templated_function_returning_FRT_create(T a); |
| 196 | + |
| 197 | +template <typename T> |
| 198 | +FRTStruct *_Nonnull global_templated_function_returning_FRT_init(T a); |
| 199 | + |
| 200 | +template <typename T> |
| 201 | +FRTStruct *_Nonnull global_templated_function_returning_FRT_clone(T a); |
| 202 | + |
| 203 | +template <typename T> |
| 204 | +FRTStruct |
| 205 | + *_Nonnull global_templated_function_returning_FRT_with_attr_returns_retained( |
| 206 | + T a) __attribute__((swift_attr("returns_retained"))); |
| 207 | + |
| 208 | +template <typename T> |
| 209 | +FRTStruct |
| 210 | + *_Nonnull global_templated_function_returning_FRT_copy_with_attr_returns_retained( |
| 211 | + T a) __attribute__((swift_attr("returns_retained"))); |
| 212 | + |
| 213 | +template <typename T> |
| 214 | +FRTStruct |
| 215 | + *_Nonnull global_templated_function_returning_FRT_create_with_attr_returns_retained( |
| 216 | + T a) __attribute__((swift_attr("returns_retained"))); |
| 217 | + |
| 218 | +template <typename T> |
| 219 | +FRTStruct |
| 220 | + *_Nonnull global_templated_function_returning_FRT_with_attr_returns_unretained( |
| 221 | + T a) __attribute__((swift_attr("returns_unretained"))); |
| 222 | + |
| 223 | +template <typename T> |
| 224 | +FRTStruct |
| 225 | + *_Nonnull global_templated_function_returning_FRT_copy_with_attr_returns_unretained( |
| 226 | + T a) __attribute__((swift_attr("returns_unretained"))); |
| 227 | + |
| 228 | +template <typename T> |
| 229 | +FRTStruct |
| 230 | + *_Nonnull global_templated_function_returning_FRT_create_with_attr_returns_unretained( |
| 231 | + T a) __attribute__((swift_attr("returns_unretained"))); |
0 commit comments