From: Benjamin Kramer Date: Fri, 22 Feb 2013 16:08:12 +0000 (+0000) Subject: Push the raw_ostream through the template diffing code. X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8de9046c6d4428185e47b9bdc073e1f3ede244a7;p=platform%2Fupstream%2Fllvm.git Push the raw_ostream through the template diffing code. llvm-svn: 175896 --- diff --git a/clang/lib/AST/ASTDiagnostic.cpp b/clang/lib/AST/ASTDiagnostic.cpp index 7ab87cd..87fd4453 100644 --- a/clang/lib/AST/ASTDiagnostic.cpp +++ b/clang/lib/AST/ASTDiagnostic.cpp @@ -231,7 +231,7 @@ ConvertTypeToDiagnosticString(ASTContext &Context, QualType Ty, 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::FormatASTNodeDiagnosticArgument( QualType ToType = QualType::getFromOpaquePtr(reinterpret_cast(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(); }