Remove uses of std::ostream from libAnalysis.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@74136 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Analysis/BasicConstraintManager.cpp b/lib/Analysis/BasicConstraintManager.cpp
index ffa8a86..cb89d30 100644
--- a/lib/Analysis/BasicConstraintManager.cpp
+++ b/lib/Analysis/BasicConstraintManager.cpp
@@ -83,7 +83,7 @@
 
   const GRState* RemoveDeadBindings(const GRState* state, SymbolReaper& SymReaper);
 
-  void print(const GRState* state, std::ostream& Out, 
+  void print(const GRState* state, llvm::raw_ostream& Out, 
              const char* nl, const char *sep);
 };
 
@@ -280,7 +280,7 @@
   return state->set<ConstNotEq>(CNE);
 }
 
-void BasicConstraintManager::print(const GRState* state, std::ostream& Out, 
+void BasicConstraintManager::print(const GRState* state, llvm::raw_ostream& Out, 
                                    const char* nl, const char *sep) {
   // Print equality constraints.
 
@@ -288,12 +288,8 @@
 
   if (!CE.isEmpty()) {
     Out << nl << sep << "'==' constraints:";
-
-    for (ConstEqTy::iterator I = CE.begin(), E = CE.end(); I!=E; ++I) {
-      Out << nl << " $" << I.getKey();
-      llvm::raw_os_ostream OS(Out);
-      OS << " : "   << *I.getData();
-    }
+    for (ConstEqTy::iterator I = CE.begin(), E = CE.end(); I!=E; ++I)
+      Out << nl << " $" << I.getKey() << " : " << *I.getData();
   }
 
   // Print != constraints.
diff --git a/lib/Analysis/BasicStore.cpp b/lib/Analysis/BasicStore.cpp
index e4ea260..8fbce52 100644
--- a/lib/Analysis/BasicStore.cpp
+++ b/lib/Analysis/BasicStore.cpp
@@ -112,7 +112,8 @@
     return BindingsTy(static_cast<const BindingsTy::TreeTy*>(store));
   }
 
-  void print(Store store, std::ostream& Out, const char* nl, const char *sep);
+  void print(Store store, llvm::raw_ostream& Out, const char* nl,
+             const char *sep);
 
 private:
   ASTContext& getContext() { return StateMgr.getContext(); }
@@ -602,18 +603,19 @@
   return store;
 }
 
-void BasicStoreManager::print(Store store, std::ostream& O,
+void BasicStoreManager::print(Store store, llvm::raw_ostream& Out,
                               const char* nl, const char *sep) {
       
-  llvm::raw_os_ostream Out(O);
   BindingsTy B = GetBindings(store);
   Out << "Variables:" << nl;
   
   bool isFirst = true;
   
   for (BindingsTy::iterator I=B.begin(), E=B.end(); I != E; ++I) {
-    if (isFirst) isFirst = false;
-    else Out << nl;
+    if (isFirst)
+      isFirst = false;
+    else
+      Out << nl;
     
     Out << ' ' << I.getKey() << " : ";
     I.getData().print(Out);
diff --git a/lib/Analysis/CFRefCount.cpp b/lib/Analysis/CFRefCount.cpp
index d4d10cf..5e542a3 100644
--- a/lib/Analysis/CFRefCount.cpp
+++ b/lib/Analysis/CFRefCount.cpp
@@ -30,7 +30,6 @@
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/ADT/STLExtras.h"
-#include <ostream>
 #include <stdarg.h>
 
 using namespace clang;
@@ -1674,10 +1673,10 @@
     ID.Add(T);
   }
 
-  void print(std::ostream& Out) const;
+  void print(llvm::raw_ostream& Out) const;
 };
   
-void RefVal::print(std::ostream& Out) const {
+void RefVal::print(llvm::raw_ostream& Out) const {
   if (!T.isNull())
     Out << "Tracked Type:" << T.getAsString() << '\n';
     
@@ -1831,7 +1830,7 @@
 public:
   class BindingsPrinter : public GRState::Printer {
   public:
-    virtual void Print(std::ostream& Out, const GRState* state,
+    virtual void Print(llvm::raw_ostream& Out, const GRState* state,
                        const char* nl, const char* sep);
   };
 
@@ -1959,7 +1958,8 @@
 
 } // end anonymous namespace
 
-static void PrintPool(std::ostream &Out, SymbolRef Sym, const GRState *state) {
+static void PrintPool(llvm::raw_ostream &Out, SymbolRef Sym,
+                      const GRState *state) {
   Out << ' ';
   if (Sym)
     Out << Sym->getSymbolID();
@@ -1975,10 +1975,9 @@
   Out << '}';  
 }
 
-void CFRefCount::BindingsPrinter::Print(std::ostream& Out, const GRState* state,
+void CFRefCount::BindingsPrinter::Print(llvm::raw_ostream& Out,
+                                        const GRState* state,
                                         const char* nl, const char* sep) {
-  
-  
     
   RefBindings B = state->get<RefBindings>();
   
diff --git a/lib/Analysis/CheckObjCUnusedIVars.cpp b/lib/Analysis/CheckObjCUnusedIVars.cpp
index 92c50e2..21dc658 100644
--- a/lib/Analysis/CheckObjCUnusedIVars.cpp
+++ b/lib/Analysis/CheckObjCUnusedIVars.cpp
@@ -20,7 +20,6 @@
 #include "clang/AST/Expr.h"
 #include "clang/AST/DeclObjC.h"
 #include "clang/Basic/LangOptions.h"
-#include <sstream>
 
 using namespace clang;
 
@@ -97,8 +96,8 @@
   // Find ivars that are unused.
   for (IvarUsageMap::iterator I = M.begin(), E = M.end(); I!=E; ++I)
     if (I->second == Unused) {
-      
-      std::ostringstream os;
+      std::string sbuf;
+      llvm::raw_string_ostream os(sbuf);
       os << "Instance variable '" << I->first->getNameAsString()
          << "' in class '" << ID->getNameAsString() 
          << "' is never used by the methods in its @implementation "
diff --git a/lib/Analysis/GRExprEngine.cpp b/lib/Analysis/GRExprEngine.cpp
index 8266cdc..d3df92d 100644
--- a/lib/Analysis/GRExprEngine.cpp
+++ b/lib/Analysis/GRExprEngine.cpp
@@ -3158,7 +3158,9 @@
     
   static std::string getNodeLabel(const GRExprEngine::NodeTy* N, void*,
                                   bool ShortNames) {
-    std::ostringstream Out;
+    
+    std::string sbuf;
+    llvm::raw_string_ostream Out(sbuf);
 
     // Program Location.
     ProgramPoint Loc = N->getLocation();
@@ -3180,9 +3182,7 @@
           SourceLocation SLoc = S->getLocStart();
 
           Out << S->getStmtClassName() << ' ' << (void*) S << ' ';        
-          llvm::raw_os_ostream OutS(Out);
-          S->printPretty(OutS);
-          OutS.flush();
+          S->printPretty(Out);
           
           if (SLoc.isFileID()) {        
             Out << "\\lline="
@@ -3236,10 +3236,7 @@
           SourceLocation SLoc = T->getLocStart();
          
           Out << "\\|Terminator: ";
-          
-          llvm::raw_os_ostream OutS(Out);
-          E.getSrc()->printTerminator(OutS);
-          OutS.flush();
+          E.getSrc()->printTerminator(Out);
           
           if (SLoc.isFileID()) {
             Out << "\\lline="
@@ -3254,14 +3251,11 @@
             if (Label) {                        
               if (CaseStmt* C = dyn_cast<CaseStmt>(Label)) {
                 Out << "\\lcase ";
-                llvm::raw_os_ostream OutS(Out);
-                C->getLHS()->printPretty(OutS);
-                OutS.flush();
+                C->getLHS()->printPretty(Out);
               
                 if (Stmt* RHS = C->getRHS()) {
                   Out << " .. ";
-                  RHS->printPretty(OutS);
-                  OutS.flush();
+                  RHS->printPretty(Out);
                 }
                 
                 Out << ":";
diff --git a/lib/Analysis/GRState.cpp b/lib/Analysis/GRState.cpp
index 65db6a2..5ee4e6f 100644
--- a/lib/Analysis/GRState.cpp
+++ b/lib/Analysis/GRState.cpp
@@ -1,4 +1,4 @@
-//= GRState*cpp - Path-Sens. "State" for tracking valuues -----*- C++ -*--=//
+//= GRState.cpp - Path-Sensitive "State" for tracking values -----*- C++ -*--=//
 //
 //                     The LLVM Compiler Infrastructure
 //
@@ -7,7 +7,7 @@
 //
 //===----------------------------------------------------------------------===//
 //
-//  This file defines SymbolRef, ExprBindKey, and GRState*
+//  This file implements GRState and GRStateManager.
 //
 //===----------------------------------------------------------------------===//
 
@@ -20,6 +20,7 @@
 using namespace clang;
 
 // Give the vtable for ConstraintManager somewhere to live.
+// FIXME: Move this elsewhere.
 ConstraintManager::~ConstraintManager() {}
 
 GRStateManager::~GRStateManager() {
@@ -117,7 +118,8 @@
 //  State pretty-printing.
 //===----------------------------------------------------------------------===//
 
-void GRState::print(std::ostream& Out, const char* nl, const char* sep) const {  
+void GRState::print(llvm::raw_ostream& Out, const char* nl,
+                    const char* sep) const {  
   // Print the store.
   Mgr->getStoreManager().print(getStore(), Out, nl, sep);
   
@@ -133,9 +135,7 @@
     else { Out << nl; }
     
     Out << " (" << (void*) I.getKey() << ") ";
-    llvm::raw_os_ostream OutS(Out);
-    I.getKey()->printPretty(OutS);
-    OutS.flush();
+    I.getKey()->printPretty(Out);
     Out << " : ";
     I.getData().print(Out);
   }
@@ -152,9 +152,7 @@
     else { Out << nl; }
     
     Out << " (" << (void*) I.getKey() << ") ";
-    llvm::raw_os_ostream OutS(Out);
-    I.getKey()->printPretty(OutS);
-    OutS.flush();
+    I.getKey()->printPretty(Out);
     Out << " : ";
     I.getData().print(Out);
   }
@@ -168,12 +166,12 @@
   }
 }
 
-void GRState::printDOT(std::ostream& Out) const {
+void GRState::printDOT(llvm::raw_ostream& Out) const {
   print(Out, "\\l", "\\|");
 }
 
 void GRState::printStdErr() const {
-  print(*llvm::cerr);
+  print(llvm::errs());
 }
 
 //===----------------------------------------------------------------------===//
diff --git a/lib/Analysis/RangeConstraintManager.cpp b/lib/Analysis/RangeConstraintManager.cpp
index 73c68bc..079462e 100644
--- a/lib/Analysis/RangeConstraintManager.cpp
+++ b/lib/Analysis/RangeConstraintManager.cpp
@@ -200,7 +200,7 @@
     return newRanges;
   }
 
-  void Print(std::ostream &os) const {
+  void print(llvm::raw_ostream &os) const {
     bool isFirst = true;
     os << "{ ";
     for (iterator i = begin(), e = end(); i != e; ++i) {
@@ -265,7 +265,7 @@
 
   const GRState* RemoveDeadBindings(const GRState* St, SymbolReaper& SymReaper);
 
-  void print(const GRState* St, std::ostream& Out, 
+  void print(const GRState* St, llvm::raw_ostream& Out, 
              const char* nl, const char *sep);
 
 private:
@@ -341,7 +341,7 @@
 // Pretty-printing.
 //===------------------------------------------------------------------------===/
 
-void RangeConstraintManager::print(const GRState* St, std::ostream& Out, 
+void RangeConstraintManager::print(const GRState* St, llvm::raw_ostream& Out, 
                                    const char* nl, const char *sep) {
   
   ConstraintRangeTy Ranges = St->get<ConstraintRange>();
@@ -353,6 +353,6 @@
   
   for (ConstraintRangeTy::iterator I=Ranges.begin(), E=Ranges.end(); I!=E; ++I){
     Out << nl << ' ' << I.getKey() << " : ";
-    I.getData().Print(Out);
+    I.getData().print(Out);
   }
 }
diff --git a/lib/Analysis/RegionStore.cpp b/lib/Analysis/RegionStore.cpp
index c9c923a..65afe46 100644
--- a/lib/Analysis/RegionStore.cpp
+++ b/lib/Analysis/RegionStore.cpp
@@ -238,10 +238,8 @@
   CastResult CastRegion(const GRState *state, const MemRegion* R,
                         QualType CastToTy);
 
-  SVal EvalBinOp(const GRState *state, BinaryOperator::Opcode Op,Loc L,NonLoc R);
-
-
-
+  SVal EvalBinOp(const GRState *state, BinaryOperator::Opcode Op,Loc L,
+                 NonLoc R);
 
   Store getInitialStore() { return RBFactory.GetEmptyMap().getRoot(); }
   
@@ -260,8 +258,6 @@
     
     return SelfRegion;
   }
-  
-
  
   //===-------------------------------------------------------------------===//
   // Binding values to regions.
@@ -352,7 +348,8 @@
    return RegionBindingsTy(static_cast<const RegionBindingsTy::TreeTy*>(store));
   }
 
-  void print(Store store, std::ostream& Out, const char* nl, const char *sep);
+  void print(Store store, llvm::raw_ostream& Out, const char* nl,
+             const char *sep);
 
   void iterBindings(Store store, BindingsHandler& f) {
     // FIXME: Implement.
@@ -1423,9 +1420,8 @@
 // Utility methods.
 //===----------------------------------------------------------------------===//
 
-void RegionStoreManager::print(Store store, std::ostream& Out, 
+void RegionStoreManager::print(Store store, llvm::raw_ostream& OS,
                                const char* nl, const char *sep) {
-  llvm::raw_os_ostream OS(Out);
   RegionBindingsTy B = GetRegionBindings(store);
   OS << "Store:" << nl;
   
diff --git a/lib/Analysis/SVals.cpp b/lib/Analysis/SVals.cpp
index dd9490b..a69b611 100644
--- a/lib/Analysis/SVals.cpp
+++ b/lib/Analysis/SVals.cpp
@@ -242,11 +242,6 @@
 
 void SVal::printStdErr() const { print(llvm::errs()); }
 
-void SVal::print(std::ostream& Out) const {
-  llvm::raw_os_ostream out(Out);
-  print(out);
-}
-
 void SVal::print(llvm::raw_ostream& Out) const {
 
   switch (getBaseKind()) {
diff --git a/lib/Analysis/SymbolManager.cpp b/lib/Analysis/SymbolManager.cpp
index 4e38a34..275f30a 100644
--- a/lib/Analysis/SymbolManager.cpp
+++ b/lib/Analysis/SymbolManager.cpp
@@ -85,12 +85,6 @@
   return os;
 }
 
-std::ostream& std::operator<<(std::ostream& os, const SymExpr *SE) {
-  llvm::raw_os_ostream O(os);
-  print(O, SE);
-  return os;
-}
-
 const SymbolRegionValue* 
 SymbolManager::getRegionValueSymbol(const MemRegion* R, QualType T) {
   llvm::FoldingSetNodeID profile;