Skip to content

Commit 52e13af

Browse files
committed
Add a demangler option to hide the "Swift" module name.
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 456775f commit 52e13af

File tree

5 files changed

+25
-6
lines changed

5 files changed

+25
-6
lines changed

include/swift/Demangling/Demangle.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ std::string genericParameterName(uint64_t depth, uint64_t index);
4242
/// Display style options for the demangler.
4343
struct DemangleOptions {
4444
bool SynthesizeSugarOnTypes = false;
45-
bool DisplayDebuggerGeneratedModule = true;
4645
bool QualifyEntities = true;
4746
bool DisplayExtensionContexts = true;
4847
bool DisplayUnmangledSuffix = true;
@@ -57,6 +56,8 @@ struct DemangleOptions {
5756
bool ShortenArchetype = false;
5857
bool ShowPrivateDiscriminators = true;
5958
bool ShowFunctionArgumentTypes = true;
59+
bool DisplayDebuggerGeneratedModule = true;
60+
bool DisplayStdlibModule = true;
6061
std::function<std::string(uint64_t, uint64_t)> GenericParameterName =
6162
genericParameterName;
6263

lib/Demangling/NodePrinter.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -243,9 +243,11 @@ class NodePrinter {
243243
if (!Options.QualifyEntities)
244244
return false;
245245

246-
if (Context->getKind() == Node::Kind::Module &&
247-
Context->getText().startswith(LLDB_EXPRESSIONS_MODULE_NAME_PREFIX)) {
248-
return Options.DisplayDebuggerGeneratedModule;
246+
if (Context->getKind() == Node::Kind::Module) {
247+
if (Context->getText() == swift::STDLIB_NAME)
248+
return Options.DisplayStdlibModule;
249+
if (Context->getText().startswith(LLDB_EXPRESSIONS_MODULE_NAME_PREFIX))
250+
return Options.DisplayDebuggerGeneratedModule;
249251
}
250252
return true;
251253
}
@@ -1945,8 +1947,8 @@ NodePointer NodePrinter::print(NodePointer Node, bool asPrefixContext) {
19451947
printChildren(type_list, " & ");
19461948
Printer << " & ";
19471949
}
1948-
if (Options.QualifyEntities)
1949-
Printer << "Swift.";
1950+
if (Options.QualifyEntities && Options.DisplayStdlibModule)
1951+
Printer << swift::STDLIB_NAME << ".";
19501952
Printer << "AnyObject";
19511953
return nullptr;
19521954
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
RUN: swift-demangle -display-stdlib-module=true sSi | %FileCheck %s --check-prefix=SWIFT-INT
2+
SWIFT-INT: {{ Swift.Int$}}
3+
RUN: swift-demangle -display-stdlib-module=false sSi | %FileCheck %s --check-prefix=INT
4+
INT: {{ Int$}}

test/Demangle/lit.local.cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# suffixes: A list of file extensions to treat as test files.
2+
config.suffixes.add('.test')

tools/swift-demangle/swift-demangle.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,15 @@ static llvm::cl::opt<bool>
7474
Classify("classify",
7575
llvm::cl::desc("Display symbol classification characters"));
7676

77+
/// Options that are primarily used for testing.
78+
/// \{
79+
static llvm::cl::opt<bool> DisplayStdlibModule(
80+
"display-stdlib-module", llvm::cl::init(true),
81+
llvm::cl::desc("Qualify types originating from the Swift standard library"),
82+
llvm::cl::Hidden);
83+
/// \}
84+
85+
7786
static llvm::cl::list<std::string>
7887
InputNames(llvm::cl::Positional, llvm::cl::desc("[mangled name...]"),
7988
llvm::cl::ZeroOrMore);
@@ -233,6 +242,7 @@ int main(int argc, char **argv) {
233242
options.SynthesizeSugarOnTypes = !DisableSugar;
234243
if (Simplified)
235244
options = swift::Demangle::DemangleOptions::SimplifiedUIDemangleOptions();
245+
options.DisplayStdlibModule = DisplayStdlibModule;
236246

237247
if (InputNames.empty()) {
238248
CompactMode = true;

0 commit comments

Comments
 (0)