Skip to content

Commit 8fa65a8

Browse files
authored
Merge pull request #15871 from rintaro/sourcekit-demangle
[SourceKit] Update demangle for new mangling
2 parents 8c4f18e + ad3e6b9 commit 8fa65a8

File tree

4 files changed

+10
-13
lines changed

4 files changed

+10
-13
lines changed

test/SourceKit/Demangle/demangle.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1-
// RUN: %sourcekitd-test -req=demangle unmangled _TtBf80_ _TtP3foo3bar_ | %FileCheck %s
1+
// RUN: %sourcekitd-test -req=demangle unmangled _TtBf80_ _TtP3foo3bar_ '$S3Foo11AppDelegateC29applicationDidFinishLaunchingyy10Foundation12NotificationVF' | %FileCheck %s
22
// CHECK: START DEMANGLE
33
// CHECK-NEXT: <empty>
44
// CHECK-NEXT: Builtin.Float80
55
// CHECK-NEXT: foo.bar
6+
// CHECK-NEXT: Foo.AppDelegate.applicationDidFinishLaunching(Foundation.Notification) -> ()
67
// CHECK-NEXT: END DEMANGLE
78

8-
// RUN: %sourcekitd-test -req=demangle unmangled _TtBf80_ _TtP3foo3bar_ -simplified-demangling | %FileCheck %s -check-prefix=SIMPLIFIED
9+
// RUN: %sourcekitd-test -req=demangle unmangled _TtBf80_ _TtP3foo3bar_ '$S3Foo11AppDelegateC29applicationDidFinishLaunchingyy10Foundation12NotificationVF' -simplified-demangling | %FileCheck %s -check-prefix=SIMPLIFIED
910
// SIMPLIFIED: START DEMANGLE
1011
// SIMPLIFIED-NEXT: <empty>
1112
// SIMPLIFIED-NEXT: Builtin.Float80
1213
// SIMPLIFIED-NEXT: bar
14+
// SIMPLIFIED-NEXT: AppDelegate.applicationDidFinishLaunching(_:)
1315
// SIMPLIFIED-NEXT: END DEMANGLE
1416

1517
// RUN: %sourcekitd-test -req=mangle Foo.Baru Swift.Beer | %FileCheck %s -check-prefix=MANGLED

tools/SourceKit/tools/sourcekitd-test/sourcekitd-test.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1663,10 +1663,13 @@ static void prepareDemangleRequest(sourcekitd_object_t Req,
16631663
llvm::StringRef inputContents = input.get()->getBuffer();
16641664

16651665
// This doesn't handle Unicode symbols, but maybe that's okay.
1666-
llvm::Regex maybeSymbol("(_T|" MANGLING_PREFIX_STR ")[_a-zA-Z0-9$]+");
1666+
// Also accept the future mangling prefix.
1667+
llvm::Regex maybeSymbol("(_T|_?\\$[Ss])[_a-zA-Z0-9$.]+");
16671668
llvm::SmallVector<llvm::StringRef, 1> matches;
16681669
while (maybeSymbol.match(inputContents, &matches)) {
16691670
addName(matches.front());
1671+
auto offset = matches.front().data() - inputContents.data();
1672+
inputContents = inputContents.substr(offset + matches.front().size());
16701673
}
16711674

16721675
} else {

tools/SourceKit/tools/sourcekitd/lib/API/Requests.cpp

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,13 +1230,6 @@ class SKDocConsumer : public DocInfoConsumer {
12301230
};
12311231
} // end anonymous namespace
12321232

1233-
static bool isSwiftPrefixed(StringRef MangledName) {
1234-
if (MangledName.size() < 2)
1235-
return false;
1236-
return MangledName[0] == '_' &&
1237-
(MangledName[1] == 'T' || MangledName[1] == MANGLING_PREFIX_STR[1]);
1238-
}
1239-
12401233
static sourcekitd_response_t demangleNames(ArrayRef<const char *> MangledNames,
12411234
bool Simplified) {
12421235
swift::Demangle::DemangleOptions DemangleOptions;
@@ -1246,7 +1239,7 @@ static sourcekitd_response_t demangleNames(ArrayRef<const char *> MangledNames,
12461239
}
12471240

12481241
auto getDemangledName = [&](StringRef MangledName) -> std::string {
1249-
if (!isSwiftPrefixed(MangledName))
1242+
if (!swift::Demangle::isSwiftSymbol(MangledName))
12501243
return std::string(); // Not a mangled name
12511244

12521245
std::string Result = swift::Demangle::demangleSymbolAsString(
@@ -2753,4 +2746,4 @@ static void enableCompileNotifications(bool value) {
27532746
} else {
27542747
trace::unregisterConsumer(&compileConsumer);
27552748
}
2756-
}
2749+
}

tools/swift-demangle/swift-demangle.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,6 @@ static void demangle(llvm::raw_ostream &os, llvm::StringRef name,
174174
static int demangleSTDIN(const swift::Demangle::DemangleOptions &options) {
175175
// This doesn't handle Unicode symbols, but maybe that's okay.
176176
// Also accept the future mangling prefix.
177-
// TODO: remove the "_S" as soon as MANGLING_PREFIX_STR gets "_S".
178177
llvm::Regex maybeSymbol("(_T|_?\\$[Ss])[_a-zA-Z0-9$.]+");
179178

180179
swift::Demangle::Context DCtx;

0 commit comments

Comments
 (0)