Skip to content

Commit b607ec7

Browse files
committed
[AST] Introduce ASTMangler::forUSR
Rather than setting the USR-specific bits for each USR entrypoint into the mangler just expose a convenience constructor for USR generation that sets them.
1 parent 28e0010 commit b607ec7

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

include/swift/AST/ASTMangler.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,12 @@ class ASTMangler : public Mangler {
198198
: ManglingFlavor::Default;
199199
}
200200

201+
/// Create an ASTMangler suitable for mangling a USR for use in semantic
202+
/// functionality.
203+
static ASTMangler forUSR(const ASTContext &Ctx) {
204+
return ASTMangler(Ctx, /*DWARFMangling*/ true);
205+
}
206+
201207
const ASTContext &getASTContext() { return Context; }
202208

203209
void addTypeSubstitution(Type type, GenericSignature sig) {

lib/AST/ASTMangler.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -958,8 +958,6 @@ std::string ASTMangler::mangleTypeAsContextUSR(const NominalTypeDecl *type) {
958958
}
959959

960960
std::string ASTMangler::mangleTypeAsUSR(Type Ty) {
961-
DWARFMangling = true;
962-
RespectOriginallyDefinedIn = false;
963961
beginMangling();
964962

965963
Ty = getTypeForDWARFMangling(Ty);
@@ -1019,8 +1017,6 @@ ASTMangler::mangleAnyDecl(const ValueDecl *Decl,
10191017

10201018
std::string ASTMangler::mangleDeclAsUSR(const ValueDecl *Decl,
10211019
StringRef USRPrefix) {
1022-
llvm::SaveAndRestore<bool> respectOriginallyDefinedInRAII(
1023-
RespectOriginallyDefinedIn, false);
10241020
return (llvm::Twine(USRPrefix) + mangleAnyDecl(Decl, false)).str();
10251021
}
10261022

@@ -1029,8 +1025,6 @@ std::string ASTMangler::mangleAccessorEntityAsUSR(AccessorKind kind,
10291025
StringRef USRPrefix,
10301026
bool isStatic) {
10311027
beginManglingWithoutPrefix();
1032-
llvm::SaveAndRestore<bool> respectOriginallyDefinedInRAII(
1033-
RespectOriginallyDefinedIn, false);
10341028
llvm::SaveAndRestore<bool> allowUnnamedRAII(AllowNamelessEntities, true);
10351029
Buffer << USRPrefix;
10361030
appendAccessorEntity(getCodeForAccessorKind(kind), decl, isStatic);

lib/AST/USRGeneration.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ static inline StringRef getUSRSpacePrefix() {
4040
bool ide::printTypeUSR(Type Ty, raw_ostream &OS) {
4141
assert(!Ty->hasArchetype() && "cannot have contextless archetypes mangled.");
4242
Ty = Ty->getCanonicalType()->getRValueType();
43-
Mangle::ASTMangler Mangler(Ty->getASTContext());
43+
using namespace Mangle;
44+
ASTMangler Mangler = ASTMangler::forUSR(Ty->getASTContext());
4445
OS << Mangler.mangleTypeAsUSR(Ty);
4546
return false;
4647
}
@@ -245,7 +246,8 @@ swift::SwiftUSRGenerationRequest::evaluate(Evaluator &evaluator,
245246
if (declIFaceTy.findIf([](Type t) -> bool { return t->is<ModuleType>(); }))
246247
return std::string();
247248

248-
Mangle::ASTMangler NewMangler(D->getASTContext());
249+
using namespace Mangle;
250+
ASTMangler NewMangler = ASTMangler::forUSR(D->getASTContext());
249251
return NewMangler.mangleDeclAsUSR(D, getUSRSpacePrefix());
250252
}
251253

@@ -375,7 +377,8 @@ bool ide::printAccessorUSR(const AbstractStorageDecl *D, AccessorKind AccKind,
375377
return printObjCUSRForAccessor(SD, AccKind, OS);
376378
}
377379

378-
Mangle::ASTMangler NewMangler(D->getASTContext());
380+
using namespace Mangle;
381+
ASTMangler NewMangler = ASTMangler::forUSR(D->getASTContext());
379382
std::string Mangled = NewMangler.mangleAccessorEntityAsUSR(AccKind,
380383
SD, getUSRSpacePrefix(), SD->isStatic());
381384

0 commit comments

Comments
 (0)