@@ -30,14 +30,22 @@ static void printCTypeName(raw_ostream &os, const NominalTypeDecl *type) {
30
30
ClangSyntaxPrinter printer (os);
31
31
printer.printModuleNameCPrefix (*type->getParentModule ());
32
32
// FIXME: add nested type qualifiers to fully disambiguate the name.
33
- printer.printIdentifier (type-> getName (). str () );
33
+ printer.printBaseName (type);
34
34
}
35
35
36
36
// / Print out the C++ type name of a struct/enum declaration.
37
37
static void printCxxTypeName (raw_ostream &os, const NominalTypeDecl *type) {
38
38
// FIXME: Print namespace qualifiers for references from other modules.
39
39
// FIXME: Print class qualifiers for nested class references.
40
- ClangSyntaxPrinter (os).printIdentifier (type->getName ().str ());
40
+ ClangSyntaxPrinter (os).printBaseName (type);
41
+ }
42
+
43
+ // / Print out the C++ type name of the implementation class that provides hidden
44
+ // / access to the private class APIs.
45
+ static void printCxxImplClassName (raw_ostream &os,
46
+ const NominalTypeDecl *type) {
47
+ os << " _impl_" ;
48
+ ClangSyntaxPrinter (os).printBaseName (type);
41
49
}
42
50
43
51
static void
@@ -68,28 +76,28 @@ void ClangValueTypePrinter::printStructDecl(const StructDecl *SD) {
68
76
// Print out a forward declaration of the "hidden" _impl class.
69
77
printer.printNamespace (cxx_synthesis::getCxxImplNamespaceName (),
70
78
[&](raw_ostream &os) {
71
- os << " class _impl_ " ;
72
- printer. printIdentifier (SD-> getName (). str () );
79
+ os << " class " ;
80
+ printCxxImplClassName (os, SD );
73
81
os << " ;\n " ;
74
82
});
75
83
76
84
// Print out the C++ class itself.
77
85
os << " class " ;
78
- ClangSyntaxPrinter (os).printIdentifier (SD-> getName (). str () );
86
+ ClangSyntaxPrinter (os).printBaseName (SD);
79
87
os << " final {\n " ;
80
88
// FIXME: Print the other members of the struct.
81
89
os << " private:\n " ;
82
90
83
91
// Print out private default constructor.
84
92
os << " inline " ;
85
- printer.printIdentifier (SD-> getName (). str () );
93
+ printer.printBaseName (SD);
86
94
os << " () {}\n " ;
87
95
// Print out '_make' function which returns an unitialized instance for
88
96
// passing to Swift.
89
97
os << " static inline " ;
90
- printer.printIdentifier (SD-> getName (). str () );
98
+ printer.printBaseName (SD);
91
99
os << " _make() { return " ;
92
- printer.printIdentifier (SD-> getName (). str () );
100
+ printer.printBaseName (SD);
93
101
os << " (); }\n " ;
94
102
// Print out the private accessors to the underlying Swift value storage.
95
103
os << " inline const char * _Nonnull _getOpaquePointer() const { return "
@@ -101,17 +109,16 @@ void ClangValueTypePrinter::printStructDecl(const StructDecl *SD) {
101
109
os << " alignas(" << typeSizeAlign->alignment << " ) " ;
102
110
os << " char _storage[" << typeSizeAlign->size << " ];\n " ;
103
111
// Wrap up the value type.
104
- os << " friend class " << cxx_synthesis::getCxxImplNamespaceName ()
105
- << " ::_impl_" ;
106
- ClangSyntaxPrinter (os).printIdentifier (SD->getName ().str ());
112
+ os << " friend class " << cxx_synthesis::getCxxImplNamespaceName () << " ::" ;
113
+ printCxxImplClassName (os, SD);
107
114
os << " ;\n " ;
108
115
os << " };\n\n " ;
109
116
110
117
// Print out the "hidden" _impl class.
111
118
printer.printNamespace (
112
119
cxx_synthesis::getCxxImplNamespaceName (), [&](raw_ostream &os) {
113
- os << " class _impl_ " ;
114
- printer. printIdentifier (SD-> getName (). str () );
120
+ os << " class " ;
121
+ printCxxImplClassName (os, SD );
115
122
os << " {\n " ;
116
123
os << " public:\n " ;
117
124
@@ -140,22 +147,24 @@ void ClangValueTypePrinter::printStructDecl(const StructDecl *SD) {
140
147
printCValueTypeStorageStruct (cPrologueOS, SD, *typeSizeAlign);
141
148
}
142
149
150
+ // / Print the name of the C stub struct for passing/returning a value type
151
+ // / directly to/from swiftcc function.
152
+ static void printStubCTypeName (raw_ostream &os, const NominalTypeDecl *type) {
153
+ os << " swift_interop_stub_" ;
154
+ printCTypeName (os, type);
155
+ }
156
+
143
157
// / Print out the C stub struct that's used to pass/return a value type directly
144
158
// / to/from swiftcc function.
145
159
static void
146
160
printCStructStubForDirectPassing (raw_ostream &os, const NominalTypeDecl *SD,
147
161
PrimitiveTypeMapping &typeMapping,
148
162
SwiftToClangInteropContext &interopContext) {
149
-
150
- auto printStubCTypeName = [&]() {
151
- os << " swift_interop_stub_" ;
152
- printCTypeName (os, SD);
153
- };
154
163
// Print out a C stub for this value type.
155
164
os << " // Stub struct to be used to pass/return values to/from Swift "
156
165
" functions.\n " ;
157
166
os << " struct " ;
158
- printStubCTypeName ();
167
+ printStubCTypeName (os, SD );
159
168
os << " {\n " ;
160
169
llvm::SmallVector<std::pair<clang::CharUnits, clang::CharUnits>, 8 > fields;
161
170
interopContext.getIrABIDetails ().enumerateDirectPassingRecordMembers (
@@ -177,7 +186,7 @@ printCStructStubForDirectPassing(raw_ostream &os, const NominalTypeDecl *SD,
177
186
os << " static inline void swift_interop_returnDirect_" ;
178
187
printCTypeName (os, SD);
179
188
os << " (char * _Nonnull result, struct " ;
180
- printStubCTypeName ();
189
+ printStubCTypeName (os, SD );
181
190
os << " value" ;
182
191
os << " ) __attribute__((always_inline)) {\n " ;
183
192
for (size_t i = 0 ; i < fields.size (); ++i) {
@@ -189,12 +198,12 @@ printCStructStubForDirectPassing(raw_ostream &os, const NominalTypeDecl *SD,
189
198
190
199
// Emit a stub that is used to pass value type directly to swiftcc function.
191
200
os << " static inline struct " ;
192
- printStubCTypeName ();
201
+ printStubCTypeName (os, SD );
193
202
os << " swift_interop_passDirect_" ;
194
203
printCTypeName (os, SD);
195
204
os << " (const char * _Nonnull value) __attribute__((always_inline)) {\n " ;
196
205
os << " struct " ;
197
- printStubCTypeName ();
206
+ printStubCTypeName (os, SD );
198
207
os << " result;\n " ;
199
208
for (size_t i = 0 ; i < fields.size (); ++i) {
200
209
os << " memcpy(&result._" << (i + 1 ) << " , value + "
@@ -206,8 +215,7 @@ printCStructStubForDirectPassing(raw_ostream &os, const NominalTypeDecl *SD,
206
215
}
207
216
208
217
void ClangValueTypePrinter::printCStubTypeName (const NominalTypeDecl *type) {
209
- os << " swift_interop_stub_" ;
210
- printCTypeName (os, type);
218
+ printStubCTypeName (os, type);
211
219
// Ensure the stub is declared in the header.
212
220
interopContext.runIfStubForDeclNotEmitted (type, [&]() {
213
221
printCStructStubForDirectPassing (cPrologueOS, type, typeMapping,
@@ -240,8 +248,8 @@ void ClangValueTypePrinter::printParameterCxxToCUseScaffold(
240
248
printCTypeName (os, type);
241
249
os << ' (' ;
242
250
}
243
- os << cxx_synthesis::getCxxImplNamespaceName () << " ::_impl_ " ;
244
- ClangSyntaxPrinter (os). printIdentifier ( type-> getName (). str () );
251
+ os << cxx_synthesis::getCxxImplNamespaceName () << " ::" ;
252
+ printCxxImplClassName (os, type);
245
253
os << " ::getOpaquePointer(" ;
246
254
cxxParamPrinter ();
247
255
os << ' )' ;
@@ -264,8 +272,8 @@ void ClangValueTypePrinter::printValueTypeIndirectReturnScaffold(
264
272
const NominalTypeDecl *type,
265
273
llvm::function_ref<void (StringRef)> bodyPrinter) {
266
274
assert (isa<StructDecl>(type) || isa<EnumDecl>(type));
267
- os << " return " << cxx_synthesis::getCxxImplNamespaceName () << " ::_impl_ " ;
268
- ClangSyntaxPrinter (os). printIdentifier ( type-> getName (). str () );
275
+ os << " return " << cxx_synthesis::getCxxImplNamespaceName () << " ::" ;
276
+ printCxxImplClassName (os, type);
269
277
os << " ::returnNewValue([&](void * _Nonnull result) {\n " ;
270
278
bodyPrinter (" result" );
271
279
os << " ;\n " ;
@@ -275,8 +283,8 @@ void ClangValueTypePrinter::printValueTypeIndirectReturnScaffold(
275
283
void ClangValueTypePrinter::printValueTypeDirectReturnScaffold (
276
284
const NominalTypeDecl *type, llvm::function_ref<void ()> bodyPrinter) {
277
285
assert (isa<StructDecl>(type) || isa<EnumDecl>(type));
278
- os << " return " << cxx_synthesis::getCxxImplNamespaceName () << " ::_impl_ " ;
279
- ClangSyntaxPrinter (os). printIdentifier ( type-> getName (). str () );
286
+ os << " return " << cxx_synthesis::getCxxImplNamespaceName () << " ::" ;
287
+ printCxxImplClassName (os, type);
280
288
os << " ::returnNewValue([&](char * _Nonnull result) {\n " ;
281
289
os << " " ;
282
290
os << cxx_synthesis::getCxxImplNamespaceName () << " ::"
0 commit comments