Patch by Csaba Hruska!

"Here is a patch what replaces std::ostream with llvm::raw_ostream. This patch
covers the AST library, but ignores Analysis lib."


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@56185 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/AST/CFG.cpp b/lib/AST/CFG.cpp
index 84bf1e7..78c8dca 100644
--- a/lib/AST/CFG.cpp
+++ b/lib/AST/CFG.cpp
@@ -21,6 +21,7 @@
 #include "llvm/Support/Streams.h"
 #include "llvm/Support/Compiler.h"
 #include <llvm/Support/Allocator.h>
+#include <llvm/Support/Format.h>
 #include <iomanip>
 #include <algorithm>
 #include <sstream>
@@ -1306,7 +1307,7 @@
   void setBlockID(signed i) { CurrentBlock = i; }
   void setStmtID(unsigned i) { CurrentStmt = i; }
   
-  virtual bool handledStmt(Stmt* Terminator, std::ostream& OS) {
+  virtual bool handledStmt(Stmt* Terminator, llvm::raw_ostream& OS) {
     
     StmtMapTy::iterator I = StmtMap.find(Terminator);
 
@@ -1325,10 +1326,10 @@
 class VISIBILITY_HIDDEN CFGBlockTerminatorPrint
   : public StmtVisitor<CFGBlockTerminatorPrint,void> {
   
-  std::ostream& OS;
+  llvm::raw_ostream& OS;
   StmtPrinterHelper* Helper;
 public:
-  CFGBlockTerminatorPrint(std::ostream& os, StmtPrinterHelper* helper)
+  CFGBlockTerminatorPrint(llvm::raw_ostream& os, StmtPrinterHelper* helper)
     : OS(os), Helper(helper) {}
   
   void VisitIfStmt(IfStmt* I) {
@@ -1406,7 +1407,7 @@
 };
   
   
-void print_stmt(std::ostream&OS, StmtPrinterHelper* Helper, Stmt* Terminator) {    
+void print_stmt(llvm::raw_ostream&OS, StmtPrinterHelper* Helper, Stmt* Terminator) {    
   if (Helper) {
     // special printing for statement-expressions.
     if (StmtExpr* SE = dyn_cast<StmtExpr>(Terminator)) {
@@ -1437,7 +1438,7 @@
   if (isa<Expr>(Terminator)) OS << '\n';
 }
   
-void print_block(std::ostream& OS, const CFG* cfg, const CFGBlock& B,
+void print_block(llvm::raw_ostream& OS, const CFG* cfg, const CFGBlock& B,
                  StmtPrinterHelper* Helper, bool print_edges) {
  
   if (Helper) Helper->setBlockID(B.getBlockID());
@@ -1488,7 +1489,7 @@
     if (print_edges)
       OS << "    ";
       
-    OS << std::setw(3) << j << ": ";
+    OS << llvm::format("%3d", j) << ": ";
     
     if (Helper)
       Helper->setStmtID(j);
@@ -1546,10 +1547,10 @@
 } // end anonymous namespace
 
 /// dump - A simple pretty printer of a CFG that outputs to stderr.
-void CFG::dump() const { print(*llvm::cerr.stream()); }
+void CFG::dump() const { print(llvm::errs()); }
 
 /// print - A simple pretty printer of a CFG that outputs to an ostream.
-void CFG::print(std::ostream& OS) const {
+void CFG::print(llvm::raw_ostream& OS) const {
   
   StmtPrinterHelper Helper(this);
   
@@ -1570,17 +1571,17 @@
 }  
 
 /// dump - A simply pretty printer of a CFGBlock that outputs to stderr.
-void CFGBlock::dump(const CFG* cfg) const { print(*llvm::cerr.stream(), cfg); }
+void CFGBlock::dump(const CFG* cfg) const { print(llvm::errs(), cfg); }
 
 /// print - A simple pretty printer of a CFGBlock that outputs to an ostream.
 ///   Generally this will only be called from CFG::print.
-void CFGBlock::print(std::ostream& OS, const CFG* cfg) const {
+void CFGBlock::print(llvm::raw_ostream& OS, const CFG* cfg) const {
   StmtPrinterHelper Helper(cfg);
   print_block(OS, cfg, *this, &Helper, true);
 }
 
 /// printTerminator - A simple pretty printer of the terminator of a CFGBlock.
-void CFGBlock::printTerminator(std::ostream& OS) const {  
+void CFGBlock::printTerminator(llvm::raw_ostream& OS) const {  
   CFGBlockTerminatorPrint TPrinter(OS,NULL);
   TPrinter.Visit(const_cast<Stmt*>(getTerminator()));
 }
@@ -1685,9 +1686,10 @@
   static std::string getNodeLabel(const CFGBlock* Node, const CFG* Graph) {
 
 #ifndef NDEBUG
-    std::ostringstream Out;
+    std::string OutSStr;
+    llvm::raw_string_ostream Out(OutSStr);
     print_block(Out,Graph, *Node, GraphHelper, false);
-    std::string OutStr = Out.str();
+    std::string& OutStr = Out.str();
 
     if (OutStr[0] == '\n') OutStr.erase(OutStr.begin());
 
diff --git a/lib/AST/StmtPrinter.cpp b/lib/AST/StmtPrinter.cpp
index 3c3e207..566ab71 100644
--- a/lib/AST/StmtPrinter.cpp
+++ b/lib/AST/StmtPrinter.cpp
@@ -17,6 +17,7 @@
 #include "clang/AST/PrettyPrinter.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/Streams.h"
+#include "llvm/Support/Format.h"
 using namespace clang;
 
 //===----------------------------------------------------------------------===//
@@ -25,11 +26,11 @@
 
 namespace  {
   class VISIBILITY_HIDDEN StmtPrinter : public StmtVisitor<StmtPrinter> {
-    std::ostream &OS;
+    llvm::raw_ostream &OS;
     unsigned IndentLevel;
     clang::PrinterHelper* Helper;
   public:
-    StmtPrinter(std::ostream &os, PrinterHelper* helper) : 
+    StmtPrinter(llvm::raw_ostream &os, PrinterHelper* helper) : 
       OS(os), IndentLevel(0), Helper(helper) {}
     
     void PrintStmt(Stmt *S, int SubIndent = 1) {
@@ -58,7 +59,7 @@
         OS << "<null expr>";
     }
     
-    std::ostream &Indent(int Delta = 0) const {
+    llvm::raw_ostream &Indent(int Delta = 0) const {
       for (int i = 0, e = IndentLevel+Delta; i < e; ++i)
         OS << "  ";
       return OS;
@@ -547,7 +548,7 @@
     if (value < 256 && isprint(value)) {
       OS << "'" << (char)value << "'";
     } else if (value < 256) {
-      OS << "'\\x" << std::hex << value << std::dec << "'";
+      OS << "'\\x" << llvm::format("%x", value) << "'";
     } else {
       // FIXME what to really do here?
       OS << value;
@@ -924,10 +925,10 @@
 //===----------------------------------------------------------------------===//
 
 void Stmt::dumpPretty() const {
-  printPretty(*llvm::cerr.stream());
+  printPretty(llvm::errs());
 }
 
-void Stmt::printPretty(std::ostream &OS, PrinterHelper* Helper) const {
+void Stmt::printPretty(llvm::raw_ostream &OS, PrinterHelper* Helper) const {
   if (this == 0) {
     OS << "<NULL>";
     return;
diff --git a/lib/AST/StmtViz.cpp b/lib/AST/StmtViz.cpp
index 51d514b..6790efb 100644
--- a/lib/AST/StmtViz.cpp
+++ b/lib/AST/StmtViz.cpp
@@ -33,7 +33,8 @@
   static std::string getNodeLabel(const Stmt* Node, const Stmt* Graph) {
     
 #ifndef NDEBUG
-    std::ostringstream Out;
+    std::string OutSStr;
+    llvm::raw_string_ostream Out(OutSStr);
     
     if (Node)
       Out << Node->getStmtClassName();
diff --git a/lib/AST/Type.cpp b/lib/AST/Type.cpp
index 2ecc357..f836e5b 100644
--- a/lib/AST/Type.cpp
+++ b/lib/AST/Type.cpp
@@ -910,7 +910,8 @@
     S += '*';
   
   if (getSizeExpr()) {
-    std::ostringstream s;
+    std::string SStr;
+    llvm::raw_string_ostream s(SStr);
     getSizeExpr()->printPretty(s);
     S += s.str();
   }
@@ -937,7 +938,8 @@
 void TypeOfExpr::getAsStringInternal(std::string &InnerString) const {
   if (!InnerString.empty())    // Prefix the basic type, e.g. 'typeof(e) X'.
     InnerString = ' ' + InnerString;
-  std::ostringstream s;
+  std::string Str;
+  llvm::raw_string_ostream s(Str);
   getUnderlyingExpr()->printPretty(s);
   InnerString = "typeof(" + s.str() + ")" + InnerString;
 }