@@ -73,9 +73,10 @@ void printCTypeMetadataTypeFunction(raw_ostream &os,
73
73
os << " SWIFT_NOEXCEPT SWIFT_CALL;\n\n " ;
74
74
}
75
75
76
- void ClangValueTypePrinter::printStructDecl (const StructDecl *SD) {
76
+ void ClangValueTypePrinter::printValueTypeDecl (
77
+ const NominalTypeDecl *typeDecl) {
77
78
auto typeSizeAlign =
78
- interopContext.getIrABIDetails ().getTypeSizeAlignment (SD );
79
+ interopContext.getIrABIDetails ().getTypeSizeAlignment (typeDecl );
79
80
if (!typeSizeAlign) {
80
81
// FIXME: handle non-fixed layout structs.
81
82
return ;
@@ -88,31 +89,31 @@ void ClangValueTypePrinter::printStructDecl(const StructDecl *SD) {
88
89
ClangSyntaxPrinter printer (os);
89
90
90
91
auto typeMetadataFunc = irgen::LinkEntity::forTypeMetadataAccessFunction (
91
- SD ->getDeclaredType ()->getCanonicalType ());
92
+ typeDecl ->getDeclaredType ()->getCanonicalType ());
92
93
std::string typeMetadataFuncName = typeMetadataFunc.mangleAsString ();
93
94
94
95
// Print out a forward declaration of the "hidden" _impl class.
95
96
printer.printNamespace (cxx_synthesis::getCxxImplNamespaceName (),
96
97
[&](raw_ostream &os) {
97
98
os << " class " ;
98
- printCxxImplClassName (os, SD );
99
+ printCxxImplClassName (os, typeDecl );
99
100
os << " ;\n\n " ;
100
101
101
102
// Print out special functions, like functions that
102
103
// access type metadata.
103
- printCTypeMetadataTypeFunction (os, SD ,
104
+ printCTypeMetadataTypeFunction (os, typeDecl ,
104
105
typeMetadataFuncName);
105
106
});
106
107
107
108
// Print out the C++ class itself.
108
109
os << " class " ;
109
- ClangSyntaxPrinter (os).printBaseName (SD );
110
+ ClangSyntaxPrinter (os).printBaseName (typeDecl );
110
111
os << " final {\n " ;
111
112
os << " public:\n " ;
112
113
113
114
// Print out the destructor.
114
115
os << " inline ~" ;
115
- printer.printBaseName (SD );
116
+ printer.printBaseName (typeDecl );
116
117
os << " () {\n " ;
117
118
os << " auto metadata = " << cxx_synthesis::getCxxImplNamespaceName ()
118
119
<< " ::" ;
@@ -125,9 +126,9 @@ void ClangValueTypePrinter::printStructDecl(const StructDecl *SD) {
125
126
os << " }\n " ;
126
127
127
128
os << " inline " ;
128
- printer.printBaseName (SD );
129
+ printer.printBaseName (typeDecl );
129
130
os << " (const " ;
130
- printer.printBaseName (SD );
131
+ printer.printBaseName (typeDecl );
131
132
os << " &other) {\n " ;
132
133
os << " auto metadata = " << cxx_synthesis::getCxxImplNamespaceName ()
133
134
<< " ::" ;
@@ -142,24 +143,24 @@ void ClangValueTypePrinter::printStructDecl(const StructDecl *SD) {
142
143
143
144
// FIXME: the move constructor should be hidden somehow.
144
145
os << " inline " ;
145
- printer.printBaseName (SD );
146
+ printer.printBaseName (typeDecl );
146
147
os << " (" ;
147
- printer.printBaseName (SD );
148
+ printer.printBaseName (typeDecl );
148
149
os << " &&) = default;\n " ;
149
150
150
151
// FIXME: Print the other members of the struct.
151
152
os << " private:\n " ;
152
153
153
154
// Print out private default constructor.
154
155
os << " inline " ;
155
- printer.printBaseName (SD );
156
+ printer.printBaseName (typeDecl );
156
157
os << " () {}\n " ;
157
158
// Print out '_make' function which returns an unitialized instance for
158
159
// passing to Swift.
159
160
os << " static inline " ;
160
- printer.printBaseName (SD );
161
+ printer.printBaseName (typeDecl );
161
162
os << " _make() { return " ;
162
- printer.printBaseName (SD );
163
+ printer.printBaseName (typeDecl );
163
164
os << " (); }\n " ;
164
165
// Print out the private accessors to the underlying Swift value storage.
165
166
os << " inline const char * _Nonnull _getOpaquePointer() const { return "
@@ -172,32 +173,32 @@ void ClangValueTypePrinter::printStructDecl(const StructDecl *SD) {
172
173
os << " char _storage[" << typeSizeAlign->size << " ];\n " ;
173
174
// Wrap up the value type.
174
175
os << " friend class " << cxx_synthesis::getCxxImplNamespaceName () << " ::" ;
175
- printCxxImplClassName (os, SD );
176
+ printCxxImplClassName (os, typeDecl );
176
177
os << " ;\n " ;
177
178
os << " };\n\n " ;
178
179
179
180
// Print out the "hidden" _impl class.
180
181
printer.printNamespace (
181
182
cxx_synthesis::getCxxImplNamespaceName (), [&](raw_ostream &os) {
182
183
os << " class " ;
183
- printCxxImplClassName (os, SD );
184
+ printCxxImplClassName (os, typeDecl );
184
185
os << " {\n " ;
185
186
os << " public:\n " ;
186
187
187
188
os << " static inline char * _Nonnull getOpaquePointer(" ;
188
- printCxxTypeName (os, SD );
189
+ printCxxTypeName (os, typeDecl );
189
190
os << " &object) { return object._getOpaquePointer(); }\n " ;
190
191
191
192
os << " static inline const char * _Nonnull getOpaquePointer(const " ;
192
- printCxxTypeName (os, SD );
193
+ printCxxTypeName (os, typeDecl );
193
194
os << " &object) { return object._getOpaquePointer(); }\n " ;
194
195
195
196
os << " template<class T>\n " ;
196
197
os << " static inline " ;
197
- printCxxTypeName (os, SD );
198
+ printCxxTypeName (os, typeDecl );
198
199
os << " returnNewValue(T callable) {\n " ;
199
200
os << " auto result = " ;
200
- printCxxTypeName (os, SD );
201
+ printCxxTypeName (os, typeDecl );
201
202
os << " ::_make();\n " ;
202
203
os << " callable(result._getOpaquePointer());\n " ;
203
204
os << " return result;\n " ;
@@ -206,7 +207,7 @@ void ClangValueTypePrinter::printStructDecl(const StructDecl *SD) {
206
207
os << " };\n " ;
207
208
});
208
209
209
- printCValueTypeStorageStruct (cPrologueOS, SD , *typeSizeAlign);
210
+ printCValueTypeStorageStruct (cPrologueOS, typeDecl , *typeSizeAlign);
210
211
}
211
212
212
213
// / Print the name of the C stub struct for passing/returning a value type
0 commit comments