diff options
author | John McCall <rjmccall@apple.com> | 2010-01-13 23:58:20 +0000 |
---|---|---|
committer | John McCall <rjmccall@apple.com> | 2010-01-13 23:58:20 +0000 |
commit | 9f28614bf1a8387000d8df57a713fcf69e198145 (patch) | |
tree | f96014f660a9423f9b3348bc7b25c566d7526ce8 | |
parent | bca403c17b3eee38ea0644fb70f652629b285faf (diff) |
Perform format-expansion on %select results.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@93377 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/clang/Basic/Diagnostic.h | 5 | ||||
-rw-r--r-- | lib/Basic/Diagnostic.cpp | 18 |
2 files changed, 18 insertions, 5 deletions
diff --git a/include/clang/Basic/Diagnostic.h b/include/clang/Basic/Diagnostic.h index a2ccea7525..c5d6d7c713 100644 --- a/include/clang/Basic/Diagnostic.h +++ b/include/clang/Basic/Diagnostic.h @@ -781,6 +781,11 @@ public: /// formal arguments into the %0 slots. The result is appended onto the Str /// array. void FormatDiagnostic(llvm::SmallVectorImpl<char> &OutStr) const; + + /// FormatDiagnostic - Format the given format-string into the + /// output buffer using the arguments stored in this diagnostic. + void FormatDiagnostic(const char *DiagStr, const char *DiagEnd, + llvm::SmallVectorImpl<char> &OutStr) const; }; /// DiagnosticClient - This is an abstract interface implemented by clients of diff --git a/lib/Basic/Diagnostic.cpp b/lib/Basic/Diagnostic.cpp index 4351f66be3..5304993e71 100644 --- a/lib/Basic/Diagnostic.cpp +++ b/lib/Basic/Diagnostic.cpp @@ -546,7 +546,7 @@ static bool ModifierIs(const char *Modifier, unsigned ModifierLen, /// "%2" has a value from 0-2. If the value is 0, the diagnostic prints 'foo'. /// If the value is 1, it prints 'bar'. If it has the value 2, it prints 'baz'. /// This is very useful for certain classes of variant diagnostics. -static void HandleSelectModifier(unsigned ValNo, +static void HandleSelectModifier(const DiagnosticInfo &DInfo, unsigned ValNo, const char *Argument, unsigned ArgumentLen, llvm::SmallVectorImpl<char> &OutStr) { const char *ArgumentEnd = Argument+ArgumentLen; @@ -562,8 +562,9 @@ static void HandleSelectModifier(unsigned ValNo, // Get the end of the value. This is either the } or the |. const char *EndPtr = std::find(Argument, ArgumentEnd, '|'); - // Add the value to the output string. - OutStr.append(Argument, EndPtr); + + // Recursively format the result of the select clause into the output string. + DInfo.FormatDiagnostic(Argument, EndPtr, OutStr); } /// HandleIntegerSModifier - Handle the integer 's' modifier. This adds the @@ -702,6 +703,13 @@ FormatDiagnostic(llvm::SmallVectorImpl<char> &OutStr) const { const char *DiagStr = getDiags()->getDescription(getID()); const char *DiagEnd = DiagStr+strlen(DiagStr); + FormatDiagnostic(DiagStr, DiagEnd, OutStr); +} + +void DiagnosticInfo:: +FormatDiagnostic(const char *DiagStr, const char *DiagEnd, + llvm::SmallVectorImpl<char> &OutStr) const { + /// FormattedArgs - Keep track of all of the arguments formatted by /// ConvertArgToString and pass them into subsequent calls to /// ConvertArgToString, allowing the implementation to avoid redundancies in @@ -781,7 +789,7 @@ FormatDiagnostic(llvm::SmallVectorImpl<char> &OutStr) const { int Val = getArgSInt(ArgNo); if (ModifierIs(Modifier, ModifierLen, "select")) { - HandleSelectModifier((unsigned)Val, Argument, ArgumentLen, OutStr); + HandleSelectModifier(*this, (unsigned)Val, Argument, ArgumentLen, OutStr); } else if (ModifierIs(Modifier, ModifierLen, "s")) { HandleIntegerSModifier(Val, OutStr); } else if (ModifierIs(Modifier, ModifierLen, "plural")) { @@ -796,7 +804,7 @@ FormatDiagnostic(llvm::SmallVectorImpl<char> &OutStr) const { unsigned Val = getArgUInt(ArgNo); if (ModifierIs(Modifier, ModifierLen, "select")) { - HandleSelectModifier(Val, Argument, ArgumentLen, OutStr); + HandleSelectModifier(*this, Val, Argument, ArgumentLen, OutStr); } else if (ModifierIs(Modifier, ModifierLen, "s")) { HandleIntegerSModifier(Val, OutStr); } else if (ModifierIs(Modifier, ModifierLen, "plural")) { |