Add a basic "re-mangler", which turns a parsed

demangling tree back into a mangled string.

Also, extend the demangling API in a few obvious
ways, and simplify testing for failure in the
node-returning APIs by having them simply return
null instead of a spurious Failure node.

Also, preserve slightly more information in the
demangling tree.  The goal here is eventually to
always allow a perfect round-trip through the
demangler parse tree.  This patch gets us close,
but we're not quite there yet.

Tests to follow.

Swift SVN r24473
This commit is contained in:
John McCall
2015-01-16 06:33:08 +00:00
parent cb702a9035
commit bb675b6ac9
9 changed files with 1821 additions and 502 deletions

View File

@@ -36,6 +36,10 @@ static llvm::cl::opt<bool>
TreeOnly("tree-only",
llvm::cl::desc("Tree-only mode (do not show the demangled string)"));
static llvm::cl::opt<bool>
RemangleMode("remangle",
llvm::cl::desc("Remangle mode (show the remangled string)"));
static llvm::cl::opt<bool>
DisableSugar("no-sugar",
llvm::cl::desc("No sugar mode (disable common language idioms such as ? and [] from the output)"));
@@ -54,6 +58,11 @@ static void demangle(llvm::raw_ostream &os, llvm::StringRef name,
llvm::outs() << "Demangling for " << name << '\n';
swift::demangle_wrappers::NodeDumper(pointer).print(llvm::outs());
}
if (RemangleMode) {
llvm::outs() << "Remangling for " << name << " ---> ";
llvm::outs() << swift::Demangle::mangleNode(pointer);
llvm::outs() << '\n';
}
if (!TreeOnly) {
std::string string = swift::Demangle::nodeToString(pointer, options);
if (!CompactMode)