|
24 | 24 | #include "swift/AST/ParameterList.h"
|
25 | 25 | #include "swift/AST/ProtocolConformance.h"
|
26 | 26 | #include "swift/Demangling/ManglingUtils.h"
|
| 27 | +#include "swift/Demangling/Demangler.h" |
27 | 28 | #include "swift/Strings.h"
|
28 | 29 | #include "clang/Basic/CharInfo.h"
|
29 | 30 | #include "clang/AST/Attr.h"
|
@@ -301,12 +302,18 @@ std::string ASTMangler::mangleDeclType(const ValueDecl *decl) {
|
301 | 302 | return finalize();
|
302 | 303 | }
|
303 | 304 |
|
| 305 | +#ifdef USE_NEW_MANGLING_FOR_OBJC_RUNTIME_NAMES |
304 | 306 | static bool isPrivate(const NominalTypeDecl *Nominal) {
|
305 | 307 | return Nominal->hasAccessibility() &&
|
306 | 308 | Nominal->getFormalAccess() <= Accessibility::FilePrivate;
|
307 | 309 | }
|
| 310 | +#endif |
308 | 311 |
|
309 | 312 | std::string ASTMangler::mangleObjCRuntimeName(const NominalTypeDecl *Nominal) {
|
| 313 | +#ifdef USE_NEW_MANGLING_FOR_OBJC_RUNTIME_NAMES |
| 314 | + // Using the new mangling for ObjC runtime names (except for top-level |
| 315 | + // classes). This is currently disabled to support old archives. |
| 316 | + // TODO: re-enable this as we switch to the new mangling for ObjC names. |
310 | 317 | DeclContext *Ctx = Nominal->getDeclContext();
|
311 | 318 |
|
312 | 319 | if (Ctx->isModuleScopeContext() && !isPrivate(Nominal)) {
|
@@ -338,6 +345,34 @@ std::string ASTMangler::mangleObjCRuntimeName(const NominalTypeDecl *Nominal) {
|
338 | 345 | beginMangling();
|
339 | 346 | appendAnyGenericType(Nominal);
|
340 | 347 | return finalize();
|
| 348 | +#else |
| 349 | + // Use the old mangling for ObjC runtime names. |
| 350 | + beginMangling(); |
| 351 | + appendAnyGenericType(Nominal); |
| 352 | + std::string NewName = finalize(); |
| 353 | + Demangle::Demangler Dem; |
| 354 | + Demangle::Node *Root = Dem.demangleSymbol(NewName); |
| 355 | + assert(Root->getKind() == Node::Kind::Global); |
| 356 | + Node *NomTy = Root->getFirstChild(); |
| 357 | + if (NomTy->getKind() == Node::Kind::Protocol) { |
| 358 | + // Protocols are actually mangled as protocol lists. |
| 359 | + Node *PTy = Dem.createNode(Node::Kind::Type); |
| 360 | + PTy->addChild(NomTy, Dem); |
| 361 | + Node *TList = Dem.createNode(Node::Kind::TypeList); |
| 362 | + TList->addChild(PTy, Dem); |
| 363 | + NomTy = Dem.createNode(Node::Kind::ProtocolList); |
| 364 | + NomTy->addChild(TList, Dem); |
| 365 | + } |
| 366 | + // Add a TypeMangling node at the top |
| 367 | + Node *Ty = Dem.createNode(Node::Kind::Type); |
| 368 | + Ty->addChild(NomTy, Dem); |
| 369 | + Node *TyMangling = Dem.createNode(Node::Kind::TypeMangling); |
| 370 | + TyMangling->addChild(Ty, Dem); |
| 371 | + Node *NewGlobal = Dem.createNode(Node::Kind::Global); |
| 372 | + NewGlobal->addChild(TyMangling, Dem); |
| 373 | + std::string OldName = mangleNodeOld(NewGlobal); |
| 374 | + return OldName; |
| 375 | +#endif |
341 | 376 | }
|
342 | 377 |
|
343 | 378 | std::string ASTMangler::mangleTypeAsContextUSR(const NominalTypeDecl *type) {
|
|
0 commit comments