Skip to content

Commit 051beca

Browse files
committed
Add a demangler option to hide a current module.
This is analogous to ASTPrinter's FullyQualifiedTypesIfAmbiguous option. This part of a series of patches to bring ASTPrinter and Swift Demangler to feature parity, which is needed by LLDB, which depends on using the strings produced by either interchangibly. rdar://problem/63700540
1 parent fe93b19 commit 051beca

File tree

4 files changed

+14
-0
lines changed

4 files changed

+14
-0
lines changed

include/swift/Demangling/Demangle.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ struct DemangleOptions {
5959
bool DisplayDebuggerGeneratedModule = true;
6060
bool DisplayStdlibModule = true;
6161
bool DisplayObjCModule = true;
62+
/// If this is nonempty, entities in this module name will not be qualified.
63+
llvm::StringRef HidingCurrentModule;
64+
/// A function to render generic parameter names.
6265
std::function<std::string(uint64_t, uint64_t)> GenericParameterName =
6366
genericParameterName;
6467

lib/Demangling/NodePrinter.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,8 @@ class NodePrinter {
248248
return Options.DisplayStdlibModule;
249249
if (Context->getText() == swift::MANGLING_MODULE_OBJC)
250250
return Options.DisplayObjCModule;
251+
if (Context->getText() == Options.HidingCurrentModule)
252+
return false;
251253
if (Context->getText().startswith(LLDB_EXPRESSIONS_MODULE_NAME_PREFIX))
252254
return Options.DisplayDebuggerGeneratedModule;
253255
}

test/Demangle/demangle-special-options.test

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,6 @@ RUN: swift-demangle -display-objc-module=true sSo6CGRectVD | %FileCheck %s --che
77
OBJC-CGRECT: {{ __C.CGRect$}}
88
RUN: swift-demangle -display-objc-module=false sSo6CGRectVD | %FileCheck %s --check-prefix=CGRECT
99
CGRECT: {{ CGRect$}}
10+
11+
RUN: swift-demangle -hiding-module=foo _TtC3foo3bar | %FileCheck %s --check-prefix=BAR
12+
BAR: {{ bar$}}

tools/swift-demangle/swift-demangle.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ static llvm::cl::opt<bool> DisplayObjCModule(
8585
"display-objc-module", llvm::cl::init(true),
8686
llvm::cl::desc("Qualify types originating from the __ObjC module"),
8787
llvm::cl::Hidden);
88+
89+
static llvm::cl::opt<std::string> HidingModule(
90+
"hiding-module",
91+
llvm::cl::desc("Don't qualify types originating from this module"),
92+
llvm::cl::Hidden);
8893
/// \}
8994

9095

@@ -249,6 +254,7 @@ int main(int argc, char **argv) {
249254
options = swift::Demangle::DemangleOptions::SimplifiedUIDemangleOptions();
250255
options.DisplayStdlibModule = DisplayStdlibModule;
251256
options.DisplayObjCModule = DisplayObjCModule;
257+
options.HidingCurrentModule = HidingModule;
252258

253259
if (InputNames.empty()) {
254260
CompactMode = true;

0 commit comments

Comments
 (0)