@@ -73,18 +73,25 @@ namespace {
73
73
};
74
74
}
75
75
76
- static Identifier getNameForObjC (const ValueDecl *VD,
77
- CustomNamesOnly_t customNamesOnly = Normal) {
78
- assert (isa<ClassDecl>(VD) || isa<ProtocolDecl>(VD)
79
- || isa<EnumDecl>(VD) || isa<EnumElementDecl>(VD));
76
+ static StringRef getNameForObjC (const ValueDecl *VD,
77
+ CustomNamesOnly_t customNamesOnly = Normal) {
78
+ assert (isa<ClassDecl>(VD) || isa<ProtocolDecl>(VD) || isa<StructDecl>(VD) ||
79
+ isa<EnumDecl>(VD) || isa<EnumElementDecl>(VD));
80
80
if (auto objc = VD->getAttrs ().getAttribute <ObjCAttr>()) {
81
81
if (auto name = objc->getName ()) {
82
82
assert (name->getNumSelectorPieces () == 1 );
83
- return name->getSelectorPieces ().front ();
83
+ return name->getSelectorPieces ().front (). str () ;
84
84
}
85
85
}
86
86
87
- return customNamesOnly ? Identifier () : VD->getName ();
87
+ if (customNamesOnly)
88
+ return StringRef ();
89
+
90
+ if (auto clangDecl = dyn_cast_or_null<clang::NamedDecl>(VD->getClangDecl ()))
91
+ if (const clang::IdentifierInfo *II = clangDecl->getIdentifier ())
92
+ return II->getName ();
93
+
94
+ return VD->getName ().str ();
88
95
}
89
96
90
97
@@ -187,7 +194,7 @@ class ObjCPrinter : private DeclVisitor<ObjCPrinter>,
187
194
void visitClassDecl (ClassDecl *CD) {
188
195
printDocumentationComment (CD);
189
196
190
- Identifier customName = getNameForObjC (CD, CustomNamesOnly);
197
+ StringRef customName = getNameForObjC (CD, CustomNamesOnly);
191
198
if (customName.empty ()) {
192
199
llvm::SmallString<32 > scratch;
193
200
os << " SWIFT_CLASS(\" " << CD->getObjCRuntimeName (scratch) << " \" )\n "
@@ -219,7 +226,7 @@ class ObjCPrinter : private DeclVisitor<ObjCPrinter>,
219
226
void visitProtocolDecl (ProtocolDecl *PD) {
220
227
printDocumentationComment (PD);
221
228
222
- Identifier customName = getNameForObjC (PD, CustomNamesOnly);
229
+ StringRef customName = getNameForObjC (PD, CustomNamesOnly);
223
230
if (customName.empty ()) {
224
231
llvm::SmallString<32 > scratch;
225
232
os << " SWIFT_PROTOCOL(\" " << PD->getObjCRuntimeName (scratch) << " \" )\n "
@@ -240,7 +247,7 @@ class ObjCPrinter : private DeclVisitor<ObjCPrinter>,
240
247
void visitEnumDecl (EnumDecl *ED) {
241
248
printDocumentationComment (ED);
242
249
os << " typedef " ;
243
- Identifier customName = getNameForObjC (ED, CustomNamesOnly);
250
+ StringRef customName = getNameForObjC (ED, CustomNamesOnly);
244
251
if (customName.empty ()) {
245
252
os << " SWIFT_ENUM(" ;
246
253
} else {
@@ -260,7 +267,7 @@ class ObjCPrinter : private DeclVisitor<ObjCPrinter>,
260
267
// Print the cases as the concatenation of the enum name with the case
261
268
// name.
262
269
os << " " ;
263
- Identifier customEltName = getNameForObjC (Elt, CustomNamesOnly);
270
+ StringRef customEltName = getNameForObjC (Elt, CustomNamesOnly);
264
271
if (customEltName.empty ()) {
265
272
if (customName.empty ()) {
266
273
os << ED->getName ();
@@ -1014,7 +1021,7 @@ class ObjCPrinter : private DeclVisitor<ObjCPrinter>,
1014
1021
return ;
1015
1022
1016
1023
maybePrintTagKeyword (SD);
1017
- os << SD-> getName ( );
1024
+ os << getNameForObjC (SD );
1018
1025
}
1019
1026
1020
1027
// / Print a collection element type using Objective-C generics syntax.
0 commit comments