@@ -30,14 +30,22 @@ static void printCTypeName(raw_ostream &os, const NominalTypeDecl *type) {
3030 ClangSyntaxPrinter printer (os);
3131 printer.printModuleNameCPrefix (*type->getParentModule ());
3232 // FIXME: add nested type qualifiers to fully disambiguate the name.
33- printer.printIdentifier (type-> getName (). str () );
33+ printer.printBaseName (type);
3434}
3535
3636// / Print out the C++ type name of a struct/enum declaration.
3737static void printCxxTypeName (raw_ostream &os, const NominalTypeDecl *type) {
3838 // FIXME: Print namespace qualifiers for references from other modules.
3939 // 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);
4149}
4250
4351static void
@@ -68,28 +76,28 @@ void ClangValueTypePrinter::printStructDecl(const StructDecl *SD) {
6876 // Print out a forward declaration of the "hidden" _impl class.
6977 printer.printNamespace (cxx_synthesis::getCxxImplNamespaceName (),
7078 [&](raw_ostream &os) {
71- os << " class _impl_ " ;
72- printer. printIdentifier (SD-> getName (). str () );
79+ os << " class " ;
80+ printCxxImplClassName (os, SD );
7381 os << " ;\n " ;
7482 });
7583
7684 // Print out the C++ class itself.
7785 os << " class " ;
78- ClangSyntaxPrinter (os).printIdentifier (SD-> getName (). str () );
86+ ClangSyntaxPrinter (os).printBaseName (SD);
7987 os << " final {\n " ;
8088 // FIXME: Print the other members of the struct.
8189 os << " private:\n " ;
8290
8391 // Print out private default constructor.
8492 os << " inline " ;
85- printer.printIdentifier (SD-> getName (). str () );
93+ printer.printBaseName (SD);
8694 os << " () {}\n " ;
8795 // Print out '_make' function which returns an unitialized instance for
8896 // passing to Swift.
8997 os << " static inline " ;
90- printer.printIdentifier (SD-> getName (). str () );
98+ printer.printBaseName (SD);
9199 os << " _make() { return " ;
92- printer.printIdentifier (SD-> getName (). str () );
100+ printer.printBaseName (SD);
93101 os << " (); }\n " ;
94102 // Print out the private accessors to the underlying Swift value storage.
95103 os << " inline const char * _Nonnull _getOpaquePointer() const { return "
@@ -101,17 +109,16 @@ void ClangValueTypePrinter::printStructDecl(const StructDecl *SD) {
101109 os << " alignas(" << typeSizeAlign->alignment << " ) " ;
102110 os << " char _storage[" << typeSizeAlign->size << " ];\n " ;
103111 // 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);
107114 os << " ;\n " ;
108115 os << " };\n\n " ;
109116
110117 // Print out the "hidden" _impl class.
111118 printer.printNamespace (
112119 cxx_synthesis::getCxxImplNamespaceName (), [&](raw_ostream &os) {
113- os << " class _impl_ " ;
114- printer. printIdentifier (SD-> getName (). str () );
120+ os << " class " ;
121+ printCxxImplClassName (os, SD );
115122 os << " {\n " ;
116123 os << " public:\n " ;
117124
@@ -140,22 +147,24 @@ void ClangValueTypePrinter::printStructDecl(const StructDecl *SD) {
140147 printCValueTypeStorageStruct (cPrologueOS, SD, *typeSizeAlign);
141148}
142149
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+
143157// / Print out the C stub struct that's used to pass/return a value type directly
144158// / to/from swiftcc function.
145159static void
146160printCStructStubForDirectPassing (raw_ostream &os, const NominalTypeDecl *SD,
147161 PrimitiveTypeMapping &typeMapping,
148162 SwiftToClangInteropContext &interopContext) {
149-
150- auto printStubCTypeName = [&]() {
151- os << " swift_interop_stub_" ;
152- printCTypeName (os, SD);
153- };
154163 // Print out a C stub for this value type.
155164 os << " // Stub struct to be used to pass/return values to/from Swift "
156165 " functions.\n " ;
157166 os << " struct " ;
158- printStubCTypeName ();
167+ printStubCTypeName (os, SD );
159168 os << " {\n " ;
160169 llvm::SmallVector<std::pair<clang::CharUnits, clang::CharUnits>, 8 > fields;
161170 interopContext.getIrABIDetails ().enumerateDirectPassingRecordMembers (
@@ -177,7 +186,7 @@ printCStructStubForDirectPassing(raw_ostream &os, const NominalTypeDecl *SD,
177186 os << " static inline void swift_interop_returnDirect_" ;
178187 printCTypeName (os, SD);
179188 os << " (char * _Nonnull result, struct " ;
180- printStubCTypeName ();
189+ printStubCTypeName (os, SD );
181190 os << " value" ;
182191 os << " ) __attribute__((always_inline)) {\n " ;
183192 for (size_t i = 0 ; i < fields.size (); ++i) {
@@ -189,12 +198,12 @@ printCStructStubForDirectPassing(raw_ostream &os, const NominalTypeDecl *SD,
189198
190199 // Emit a stub that is used to pass value type directly to swiftcc function.
191200 os << " static inline struct " ;
192- printStubCTypeName ();
201+ printStubCTypeName (os, SD );
193202 os << " swift_interop_passDirect_" ;
194203 printCTypeName (os, SD);
195204 os << " (const char * _Nonnull value) __attribute__((always_inline)) {\n " ;
196205 os << " struct " ;
197- printStubCTypeName ();
206+ printStubCTypeName (os, SD );
198207 os << " result;\n " ;
199208 for (size_t i = 0 ; i < fields.size (); ++i) {
200209 os << " memcpy(&result._" << (i + 1 ) << " , value + "
@@ -206,8 +215,7 @@ printCStructStubForDirectPassing(raw_ostream &os, const NominalTypeDecl *SD,
206215}
207216
208217void ClangValueTypePrinter::printCStubTypeName (const NominalTypeDecl *type) {
209- os << " swift_interop_stub_" ;
210- printCTypeName (os, type);
218+ printStubCTypeName (os, type);
211219 // Ensure the stub is declared in the header.
212220 interopContext.runIfStubForDeclNotEmitted (type, [&]() {
213221 printCStructStubForDirectPassing (cPrologueOS, type, typeMapping,
@@ -240,8 +248,8 @@ void ClangValueTypePrinter::printParameterCxxToCUseScaffold(
240248 printCTypeName (os, type);
241249 os << ' (' ;
242250 }
243- os << cxx_synthesis::getCxxImplNamespaceName () << " ::_impl_ " ;
244- ClangSyntaxPrinter (os). printIdentifier ( type-> getName (). str () );
251+ os << cxx_synthesis::getCxxImplNamespaceName () << " ::" ;
252+ printCxxImplClassName (os, type);
245253 os << " ::getOpaquePointer(" ;
246254 cxxParamPrinter ();
247255 os << ' )' ;
@@ -264,8 +272,8 @@ void ClangValueTypePrinter::printValueTypeIndirectReturnScaffold(
264272 const NominalTypeDecl *type,
265273 llvm::function_ref<void (StringRef)> bodyPrinter) {
266274 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);
269277 os << " ::returnNewValue([&](void * _Nonnull result) {\n " ;
270278 bodyPrinter (" result" );
271279 os << " ;\n " ;
@@ -275,8 +283,8 @@ void ClangValueTypePrinter::printValueTypeIndirectReturnScaffold(
275283void ClangValueTypePrinter::printValueTypeDirectReturnScaffold (
276284 const NominalTypeDecl *type, llvm::function_ref<void ()> bodyPrinter) {
277285 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);
280288 os << " ::returnNewValue([&](char * _Nonnull result) {\n " ;
281289 os << " " ;
282290 os << cxx_synthesis::getCxxImplNamespaceName () << " ::"
0 commit comments