diff options
author | Diego Novillo <dnovillo@google.com> | 2014-04-22 19:56:49 +0000 |
---|---|---|
committer | Diego Novillo <dnovillo@google.com> | 2014-04-22 19:56:49 +0000 |
commit | 0436233a662589d5e8c95fe395a0cfa8addd6cbf (patch) | |
tree | 9aad1257860a569e49c8c600319e2636ff7a454a /include/clang/Basic/Diagnostic.h | |
parent | 53326f980c7255d89618c1a341868c9514efc694 (diff) | |
download | clang-0436233a662589d5e8c95fe395a0cfa8addd6cbf.tar.gz clang-0436233a662589d5e8c95fe395a0cfa8addd6cbf.tar.bz2 clang-0436233a662589d5e8c95fe395a0cfa8addd6cbf.tar.xz |
Use a manipulator to add a value to the current diagnostic flag.
Summary:
This addresses the feedback to
http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20140421/103598.html
Reviewers: rsmith
Subscribers: cfe-commits
Differential Revision: http://reviews.llvm.org/D3453
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@206920 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/clang/Basic/Diagnostic.h')
-rw-r--r-- | include/clang/Basic/Diagnostic.h | 40 |
1 files changed, 25 insertions, 15 deletions
diff --git a/include/clang/Basic/Diagnostic.h b/include/clang/Basic/Diagnostic.h index f9764d18ef..f7f84440a5 100644 --- a/include/clang/Basic/Diagnostic.h +++ b/include/clang/Basic/Diagnostic.h @@ -654,11 +654,6 @@ public: /// \param DiagID A member of the @c diag::kind enum. /// \param Loc Represents the source location associated with the diagnostic, /// which can be an invalid location if no position information is available. - /// \param Val A string that represents the value that triggered - /// this diagnostic. If given, this value will be emitted as "=value" - /// after the flag name. - inline DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID, - StringRef Val); inline DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID); inline DiagnosticBuilder Report(unsigned DiagID); @@ -694,9 +689,12 @@ public: /// \brief Clear out the current diagnostic. void Clear() { CurDiagID = ~0U; } - /// \brief Return the overridden name for this diagnostic flag. + /// \brief Return the value associated to this diagnostic flag. StringRef getFlagNameValue() const { return StringRef(FlagNameValue); } + /// \brief Set the value associated to this diagnostic flag. + void setFlagNameValue(StringRef V) { FlagNameValue = V; } + private: /// \brief Report the delayed diagnostic. void ReportDelayed(); @@ -1010,8 +1008,25 @@ public: bool hasMaxFixItHints() const { return NumFixits == DiagnosticsEngine::MaxFixItHints; } + + void addFlagValue(StringRef V) const { DiagObj->setFlagNameValue(V); } +}; + +struct AddFlagValue { + explicit AddFlagValue(StringRef V) : Val(V) {} + StringRef Val; }; +/// \brief Register a value for the flag in the current diagnostic. This +/// value will be shown as the suffix "=value" after the flag name. It is +/// useful in cases where the diagnostic flag accepts values (e.g., +/// -Rpass or -Wframe-larger-than). +inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, + const AddFlagValue V) { + DB.addFlagValue(V.Val); + return DB; +} + inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, StringRef S) { DB.AddString(S); @@ -1100,22 +1115,17 @@ inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, return DB; } -inline DiagnosticBuilder -DiagnosticsEngine::Report(SourceLocation Loc, unsigned DiagID, StringRef Val) { +inline DiagnosticBuilder DiagnosticsEngine::Report(SourceLocation Loc, + unsigned DiagID) { assert(CurDiagID == ~0U && "Multiple diagnostics in flight at once!"); CurDiagLoc = Loc; CurDiagID = DiagID; - FlagNameValue = Val.str(); + FlagNameValue.clear(); return DiagnosticBuilder(this); } -inline DiagnosticBuilder DiagnosticsEngine::Report(SourceLocation Loc, - unsigned DiagID) { - return Report(Loc, DiagID, ""); -} - inline DiagnosticBuilder DiagnosticsEngine::Report(unsigned DiagID) { - return Report(SourceLocation(), DiagID, ""); + return Report(SourceLocation(), DiagID); } //===----------------------------------------------------------------------===// |