r175896 - Push the raw_ostream through the template diffing code.

Benjamin Kramer benny.kra at googlemail.com
Fri Feb 22 08:08:13 PST 2013


Author: d0k
Date: Fri Feb 22 10:08:12 2013
New Revision: 175896

URL: http://llvm.org/viewvc/llvm-project?rev=175896&view=rev
Log:
Push the raw_ostream through the template diffing code.

Modified:
    cfe/trunk/lib/AST/ASTDiagnostic.cpp

Modified: cfe/trunk/lib/AST/ASTDiagnostic.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTDiagnostic.cpp?rev=175896&r1=175895&r2=175896&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTDiagnostic.cpp (original)
+++ cfe/trunk/lib/AST/ASTDiagnostic.cpp Fri Feb 22 10:08:12 2013
@@ -231,7 +231,7 @@ ConvertTypeToDiagnosticString(ASTContext
 static bool FormatTemplateTypeDiff(ASTContext &Context, QualType FromType,
                                    QualType ToType, bool PrintTree,
                                    bool PrintFromType, bool ElideType,
-                                   bool ShowColors, std::string &S);
+                                   bool ShowColors, raw_ostream &OS);
 
 void clang::FormatASTNodeDiagnosticArgument(
     DiagnosticsEngine::ArgumentKind Kind,
@@ -260,15 +260,13 @@ void clang::FormatASTNodeDiagnosticArgum
       QualType ToType =
           QualType::getFromOpaquePtr(reinterpret_cast<void*>(TDT.ToType));
 
-      std::string S;
       if (FormatTemplateTypeDiff(Context, FromType, ToType, TDT.PrintTree,
                                  TDT.PrintFromType, TDT.ElideType,
-                                 TDT.ShowColors, S)) {
+                                 TDT.ShowColors, OS)) {
         NeedQuotes = !TDT.PrintTree;
         TDT.TemplateDiffUsed = true;
         break;
       }
-      OS << S;
 
       // Don't fall-back during tree printing.  The caller will handle
       // this case.
@@ -397,11 +395,8 @@ class TemplateDiff {
   /// will this type be outputed.
   QualType ToType;
 
-  /// Str - Storage for the output stream.
-  SmallString<128> Str;
-
   /// OS - The stream used to construct the output strings.
-  llvm::raw_svector_ostream OS;
+  raw_ostream &OS;
 
   /// IsBold - Keeps track of the bold formatting for the output string.
   bool IsBold;
@@ -1415,9 +1410,9 @@ class TemplateDiff {
 
 public:
 
-  TemplateDiff(ASTContext &Context, QualType FromType, QualType ToType,
-               bool PrintTree, bool PrintFromType, bool ElideType,
-               bool ShowColor)
+  TemplateDiff(raw_ostream &OS, ASTContext &Context, QualType FromType,
+               QualType ToType, bool PrintTree, bool PrintFromType,
+               bool ElideType, bool ShowColor)
     : Context(Context),
       Policy(Context.getLangOpts()),
       ElideType(ElideType),
@@ -1426,7 +1421,7 @@ public:
       // When printing a single type, the FromType is the one printed.
       FromType(PrintFromType ? FromType : ToType),
       ToType(PrintFromType ? ToType : FromType),
-      OS(Str),
+      OS(OS),
       IsBold(false) {
   }
 
@@ -1464,14 +1459,13 @@ public:
   /// MakeString - When the two types given are templated types with the same
   /// base template, a string representation of the type difference will be
   /// loaded into S and return true.  Otherwise, return false.
-  bool MakeString(std::string &S) {
+  bool Emit() {
     Tree.StartTraverse();
     if (Tree.Empty())
       return false;
 
     TreeToString();
     assert(!IsBold && "Bold is applied to end of string.");
-    S = OS.str();
     return true;
   }
 }; // end class TemplateDiff
@@ -1483,11 +1477,11 @@ public:
 static bool FormatTemplateTypeDiff(ASTContext &Context, QualType FromType,
                                    QualType ToType, bool PrintTree,
                                    bool PrintFromType, bool ElideType, 
-                                   bool ShowColors, std::string &S) {
+                                   bool ShowColors, raw_ostream &OS) {
   if (PrintTree)
     PrintFromType = true;
-  TemplateDiff TD(Context, FromType, ToType, PrintTree, PrintFromType,
+  TemplateDiff TD(OS, Context, FromType, ToType, PrintTree, PrintFromType,
                   ElideType, ShowColors);
   TD.DiffTemplate();
-  return TD.MakeString(S);
+  return TD.Emit();
 }





More information about the cfe-commits mailing list