Skip to content

Commit b17b4d5

Browse files
committed
[interop][SwiftToCxx] NFC, rename printStructDecl to printValueTypeDecl
1 parent f9aa02b commit b17b4d5

File tree

3 files changed

+27
-25
lines changed

3 files changed

+27
-25
lines changed

lib/PrintAsClang/DeclAndTypePrinter.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,11 +331,12 @@ class DeclAndTypePrinter::Implementation
331331
void visitStructDecl(StructDecl *SD) {
332332
if (outputLang != OutputLanguageMode::Cxx)
333333
return;
334+
// FIXME: Print struct's doc comment.
334335
// FIXME: Print struct's availability.
335336
ClangValueTypePrinter printer(os, owningPrinter.prologueOS,
336337
owningPrinter.typeMapping,
337338
owningPrinter.interopContext);
338-
printer.printStructDecl(SD);
339+
printer.printValueTypeDecl(SD);
339340
}
340341

341342
void visitExtensionDecl(ExtensionDecl *ED) {

lib/PrintAsClang/PrintClangValueType.cpp

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,10 @@ void printCTypeMetadataTypeFunction(raw_ostream &os,
7373
os << " SWIFT_NOEXCEPT SWIFT_CALL;\n\n";
7474
}
7575

76-
void ClangValueTypePrinter::printStructDecl(const StructDecl *SD) {
76+
void ClangValueTypePrinter::printValueTypeDecl(
77+
const NominalTypeDecl *typeDecl) {
7778
auto typeSizeAlign =
78-
interopContext.getIrABIDetails().getTypeSizeAlignment(SD);
79+
interopContext.getIrABIDetails().getTypeSizeAlignment(typeDecl);
7980
if (!typeSizeAlign) {
8081
// FIXME: handle non-fixed layout structs.
8182
return;
@@ -88,31 +89,31 @@ void ClangValueTypePrinter::printStructDecl(const StructDecl *SD) {
8889
ClangSyntaxPrinter printer(os);
8990

9091
auto typeMetadataFunc = irgen::LinkEntity::forTypeMetadataAccessFunction(
91-
SD->getDeclaredType()->getCanonicalType());
92+
typeDecl->getDeclaredType()->getCanonicalType());
9293
std::string typeMetadataFuncName = typeMetadataFunc.mangleAsString();
9394

9495
// Print out a forward declaration of the "hidden" _impl class.
9596
printer.printNamespace(cxx_synthesis::getCxxImplNamespaceName(),
9697
[&](raw_ostream &os) {
9798
os << "class ";
98-
printCxxImplClassName(os, SD);
99+
printCxxImplClassName(os, typeDecl);
99100
os << ";\n\n";
100101

101102
// Print out special functions, like functions that
102103
// access type metadata.
103-
printCTypeMetadataTypeFunction(os, SD,
104+
printCTypeMetadataTypeFunction(os, typeDecl,
104105
typeMetadataFuncName);
105106
});
106107

107108
// Print out the C++ class itself.
108109
os << "class ";
109-
ClangSyntaxPrinter(os).printBaseName(SD);
110+
ClangSyntaxPrinter(os).printBaseName(typeDecl);
110111
os << " final {\n";
111112
os << "public:\n";
112113

113114
// Print out the destructor.
114115
os << " inline ~";
115-
printer.printBaseName(SD);
116+
printer.printBaseName(typeDecl);
116117
os << "() {\n";
117118
os << " auto metadata = " << cxx_synthesis::getCxxImplNamespaceName()
118119
<< "::";
@@ -125,9 +126,9 @@ void ClangValueTypePrinter::printStructDecl(const StructDecl *SD) {
125126
os << " }\n";
126127

127128
os << " inline ";
128-
printer.printBaseName(SD);
129+
printer.printBaseName(typeDecl);
129130
os << "(const ";
130-
printer.printBaseName(SD);
131+
printer.printBaseName(typeDecl);
131132
os << " &other) {\n";
132133
os << " auto metadata = " << cxx_synthesis::getCxxImplNamespaceName()
133134
<< "::";
@@ -142,24 +143,24 @@ void ClangValueTypePrinter::printStructDecl(const StructDecl *SD) {
142143

143144
// FIXME: the move constructor should be hidden somehow.
144145
os << " inline ";
145-
printer.printBaseName(SD);
146+
printer.printBaseName(typeDecl);
146147
os << "(";
147-
printer.printBaseName(SD);
148+
printer.printBaseName(typeDecl);
148149
os << " &&) = default;\n";
149150

150151
// FIXME: Print the other members of the struct.
151152
os << "private:\n";
152153

153154
// Print out private default constructor.
154155
os << " inline ";
155-
printer.printBaseName(SD);
156+
printer.printBaseName(typeDecl);
156157
os << "() {}\n";
157158
// Print out '_make' function which returns an unitialized instance for
158159
// passing to Swift.
159160
os << " static inline ";
160-
printer.printBaseName(SD);
161+
printer.printBaseName(typeDecl);
161162
os << " _make() { return ";
162-
printer.printBaseName(SD);
163+
printer.printBaseName(typeDecl);
163164
os << "(); }\n";
164165
// Print out the private accessors to the underlying Swift value storage.
165166
os << " inline const char * _Nonnull _getOpaquePointer() const { return "
@@ -172,32 +173,32 @@ void ClangValueTypePrinter::printStructDecl(const StructDecl *SD) {
172173
os << "char _storage[" << typeSizeAlign->size << "];\n";
173174
// Wrap up the value type.
174175
os << " friend class " << cxx_synthesis::getCxxImplNamespaceName() << "::";
175-
printCxxImplClassName(os, SD);
176+
printCxxImplClassName(os, typeDecl);
176177
os << ";\n";
177178
os << "};\n\n";
178179

179180
// Print out the "hidden" _impl class.
180181
printer.printNamespace(
181182
cxx_synthesis::getCxxImplNamespaceName(), [&](raw_ostream &os) {
182183
os << "class ";
183-
printCxxImplClassName(os, SD);
184+
printCxxImplClassName(os, typeDecl);
184185
os << " {\n";
185186
os << "public:\n";
186187

187188
os << " static inline char * _Nonnull getOpaquePointer(";
188-
printCxxTypeName(os, SD);
189+
printCxxTypeName(os, typeDecl);
189190
os << " &object) { return object._getOpaquePointer(); }\n";
190191

191192
os << " static inline const char * _Nonnull getOpaquePointer(const ";
192-
printCxxTypeName(os, SD);
193+
printCxxTypeName(os, typeDecl);
193194
os << " &object) { return object._getOpaquePointer(); }\n";
194195

195196
os << " template<class T>\n";
196197
os << " static inline ";
197-
printCxxTypeName(os, SD);
198+
printCxxTypeName(os, typeDecl);
198199
os << " returnNewValue(T callable) {\n";
199200
os << " auto result = ";
200-
printCxxTypeName(os, SD);
201+
printCxxTypeName(os, typeDecl);
201202
os << "::_make();\n";
202203
os << " callable(result._getOpaquePointer());\n";
203204
os << " return result;\n";
@@ -206,7 +207,7 @@ void ClangValueTypePrinter::printStructDecl(const StructDecl *SD) {
206207
os << "};\n";
207208
});
208209

209-
printCValueTypeStorageStruct(cPrologueOS, SD, *typeSizeAlign);
210+
printCValueTypeStorageStruct(cPrologueOS, typeDecl, *typeSizeAlign);
210211
}
211212

212213
/// Print the name of the C stub struct for passing/returning a value type

lib/PrintAsClang/PrintClangValueType.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ class ClangValueTypePrinter {
3535
: os(os), cPrologueOS(cPrologueOS), typeMapping(typeMapping),
3636
interopContext(interopContext) {}
3737

38-
/// Print the C struct thunk or the C++ class definition that
39-
/// corresponds to the given structure declaration.
40-
void printStructDecl(const StructDecl *SD);
38+
/// Print the C++ class definition that
39+
/// corresponds to the given structure or enum declaration.
40+
void printValueTypeDecl(const NominalTypeDecl *typeDecl);
4141

4242
/// Print the pararameter type that referes to a Swift struct type in C/C++.
4343
void printValueTypeParameterType(const NominalTypeDecl *type,

0 commit comments

Comments
 (0)