[MS Demangler] Add a helper function to print a Node as a string.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@349359 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/llvm/Demangle/MicrosoftDemangleNodes.h b/include/llvm/Demangle/MicrosoftDemangleNodes.h
index 1d0b66a..1eca676 100644
--- a/include/llvm/Demangle/MicrosoftDemangleNodes.h
+++ b/include/llvm/Demangle/MicrosoftDemangleNodes.h
@@ -235,6 +235,8 @@
 
   virtual void output(OutputStream &OS, OutputFlags Flags) const = 0;
 
+  std::string toString() const;
+
 private:
   NodeKind Kind;
 };
diff --git a/lib/Demangle/MicrosoftDemangleNodes.cpp b/lib/Demangle/MicrosoftDemangleNodes.cpp
index c57f0cf..930c838 100644
--- a/lib/Demangle/MicrosoftDemangleNodes.cpp
+++ b/lib/Demangle/MicrosoftDemangleNodes.cpp
@@ -113,6 +113,14 @@
   }
 }
 
+std::string Node::toString() const {
+  OutputStream OS;
+  initializeOutputStream(nullptr, nullptr, OS, 1024);
+  this->output(OS, llvm::ms_demangle::OF_Default);
+  OS << '\0';
+  return {OS.getBuffer()};
+}
+
 void TypeNode::outputQuals(bool SpaceBefore, bool SpaceAfter) const {}
 
 void PrimitiveTypeNode::outputPre(OutputStream &OS, OutputFlags Flags) const {