@@ -45,6 +45,10 @@ static llvm::cl::opt<bool>
45
45
TreeOnly (" tree-only" ,
46
46
llvm::cl::desc (" Tree-only mode (do not show the demangled string)" ));
47
47
48
+ static llvm::cl::opt<bool >
49
+ DemangleType (" type" ,
50
+ llvm::cl::desc (" Demangle a runtime type string" ));
51
+
48
52
static llvm::cl::opt<bool >
49
53
StripSpecialization (" strip-specialization" ,
50
54
llvm::cl::desc (" Remangle the origin of a specialized function" ));
@@ -141,7 +145,17 @@ static void demangle(llvm::raw_ostream &os, llvm::StringRef name,
141
145
hadLeadingUnderscore = true ;
142
146
name = name.substr (1 );
143
147
}
144
- swift::Demangle::NodePointer pointer = DCtx.demangleSymbolAsNode (name);
148
+ swift::Demangle::NodePointer pointer;
149
+ if (DemangleType) {
150
+ pointer = DCtx.demangleTypeAsNode (name);
151
+ if (!pointer) {
152
+ os << " <<invalid type>>" ;
153
+ return ;
154
+ }
155
+ } else {
156
+ pointer = DCtx.demangleSymbolAsNode (name);
157
+ }
158
+
145
159
if (ExpandMode || TreeOnly) {
146
160
os << " Demangling for " << name << ' \n ' ;
147
161
os << getNodeTreeAsString (pointer);
@@ -399,6 +413,10 @@ int main(int argc, char **argv) {
399
413
400
414
if (InputNames.empty ()) {
401
415
CompactMode = true ;
416
+ if (DemangleType) {
417
+ llvm::errs () << " The option -type cannot be used to demangle stdin.\n " ;
418
+ return EXIT_FAILURE;
419
+ }
402
420
return demangleSTDIN (options);
403
421
} else {
404
422
swift::Demangle::Context DCtx;
@@ -415,7 +433,7 @@ int main(int argc, char **argv) {
415
433
" is quoted or escaped.\n " ;
416
434
continue ;
417
435
}
418
- if (name.starts_with (" S" ) || name.starts_with (" s" ) ) {
436
+ if (!DemangleType && ( name.starts_with (" S" ) || name.starts_with (" s" )) ) {
419
437
std::string correctedName = std::string (" $" ) + name.str ();
420
438
demangle (llvm::outs (), correctedName, DCtx, options);
421
439
} else {
0 commit comments