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 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
|
#ifndef TEST_INTEROP_CXX_FOREIGN_REFERENCE_INPUTS_POD_H
#define TEST_INTEROP_CXX_FOREIGN_REFERENCE_INPUTS_POD_H
#include <stdlib.h>
#if defined(_WIN32)
inline void *operator new(size_t, void *p) { return p; }
#else
#include <new>
#endif
#include "visibility.h"
SWIFT_BEGIN_NULLABILITY_ANNOTATIONS
struct __attribute__((swift_attr("import_reference")))
__attribute__((swift_attr("retain:immortal")))
__attribute__((swift_attr("release:immortal"))) Empty {
int test() const { return 42; }
int testMutable() { return 42; }
static Empty *create() { return new (malloc(sizeof(Empty))) Empty(); }
};
void takesConstRefEmpty(const Empty &e) {}
void takesConstRefEmptyDefaulted(const Empty &e = {}) {}
void mutateIt(Empty &) {}
Empty passThroughByValue(Empty x) { return x; }
struct __attribute__((swift_attr("@actor")))
__attribute__((swift_attr("import_reference")))
__attribute__((swift_attr("retain:immortal")))
__attribute__((swift_attr("release:immortal"))) MultipleAttrs {
int test() const { return 42; }
int testMutable() { return 42; }
static MultipleAttrs *create() {
return new (malloc(sizeof(MultipleAttrs))) MultipleAttrs();
}
};
struct __attribute__((swift_attr("import_reference")))
__attribute__((swift_attr("retain:immortal")))
__attribute__((swift_attr("release:immortal"))) IntPair {
int a = 1;
int b = 2;
int test() const { return b - a; }
int testMutable() { return b - a; }
static IntPair *create() { return new (malloc(sizeof(IntPair))) IntPair(); }
};
void mutateIt(IntPair &x) {
x.a = 2;
x.b = 4;
}
IntPair passThroughByValue(IntPair x) { return x; }
struct __attribute__((swift_attr("import_reference")))
__attribute__((swift_attr("retain:immortal")))
__attribute__((swift_attr("release:immortal"))) RefHoldingPair {
// REVIEW-NOTE: I added support for this but then removed it, as this sort of
// indicates incorrect usage of a "reference type" and has weird semantics.
IntPair pair;
int otherValue = 3;
int test() const { return otherValue - pair.test(); }
int testMutable() { return otherValue - pair.test(); }
static RefHoldingPair *create() {
return new (malloc(sizeof(RefHoldingPair))) RefHoldingPair();
}
};
struct __attribute__((swift_attr("import_reference")))
__attribute__((swift_attr("retain:immortal")))
__attribute__((swift_attr("release:immortal"))) RefHoldingPairRef {
IntPair &pair;
int otherValue;
RefHoldingPairRef(IntPair &pair) : pair(pair), otherValue(42) {}
int test() const { return otherValue - pair.test(); }
int testMutable() { return otherValue - pair.test(); }
static RefHoldingPairRef *create() {
IntPair *pair = new (malloc(sizeof(IntPair))) IntPair();
return new (malloc(sizeof(RefHoldingPairRef))) RefHoldingPairRef(*pair);
}
};
struct __attribute__((swift_attr("import_reference")))
__attribute__((swift_attr("retain:immortal")))
__attribute__((swift_attr("release:immortal"))) RefHoldingPairPtr {
IntPair *pair;
int otherValue = 42;
int test() const { return otherValue - pair->test(); }
int testMutable() { return otherValue - pair->test(); }
static RefHoldingPairPtr *create() {
RefHoldingPairPtr *out =
new (malloc(sizeof(RefHoldingPairPtr))) RefHoldingPairPtr();
out->pair = new (malloc(sizeof(IntPair))) IntPair();
return out;
}
};
struct ValueHoldingPair {
IntPair pair;
int otherValue = 3;
int test() const { return otherValue - pair.test(); }
int testMutable() { return otherValue - pair.test(); }
static ValueHoldingPair *create()
__attribute__((swift_attr("import_unsafe"))) {
return new (malloc(sizeof(ValueHoldingPair))) ValueHoldingPair();
}
};
struct __attribute__((swift_attr("import_reference")))
__attribute__((swift_attr("retain:immortal")))
__attribute__((swift_attr("release:immortal"))) BigType {
int a = 1;
int b = 2;
char buffer[32];
int test() const { return b - a; }
int testMutable() { return b - a; }
static BigType *create() { return new (malloc(sizeof(BigType))) BigType(); }
};
void mutateIt(BigType &x) {
x.a = 2;
x.b = 4;
}
BigType passThroughByValue(BigType x) { return x; }
struct __attribute__((swift_attr("import_reference")))
__attribute__((swift_attr("retain:immortal")))
__attribute__((swift_attr("release:immortal"))) BaseRef {
int a = 1;
int b = 2;
int test() const { return b - a; }
int test() { return b - a; }
static BaseRef *create() { return new (malloc(sizeof(BaseRef))) BaseRef(); }
};
struct __attribute__((swift_attr("import_reference")))
__attribute__((swift_attr("retain:immortal")))
__attribute__((swift_attr("release:immortal"))) DerivedRef : BaseRef {
int c = 1;
int testDerived() const { return test() + c; }
int testDerived() { return test() + c; }
static DerivedRef *create() { return new (malloc(sizeof(DerivedRef))) DerivedRef(); }
};
SWIFT_END_NULLABILITY_ANNOTATIONS
#endif // TEST_INTEROP_CXX_FOREIGN_REFERENCE_INPUTS_POD_H
|