diff options
author | Daniel Dunbar <daniel@zuster.org> | 2011-09-29 01:47:16 +0000 |
---|---|---|
committer | Daniel Dunbar <daniel@zuster.org> | 2011-09-29 01:47:16 +0000 |
commit | 3f8394669673451061f57ced81f0a2cae087f119 (patch) | |
tree | 91539e38a71150b0aeb89cd7c63b8ead3c04ecf0 | |
parent | ba494c64365d78b1cdb6baea4d1e79263389fda9 (diff) |
Basic/Diagnostics: Add a DiagnosticIDs::getDiagnosticsInGroup method, and use
that in DiagnosticEngine instead of the convoluted calling into DiagnosticIDs
which then calls back into the DiagnosticsEngine.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@140766 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/clang/Basic/Diagnostic.h | 4 | ||||
-rw-r--r-- | include/clang/Basic/DiagnosticIDs.h | 23 | ||||
-rw-r--r-- | lib/Basic/Diagnostic.cpp | 15 | ||||
-rw-r--r-- | lib/Basic/DiagnosticIDs.cpp | 66 |
4 files changed, 60 insertions, 48 deletions
diff --git a/include/clang/Basic/Diagnostic.h b/include/clang/Basic/Diagnostic.h index 1d39dec2f6..02a937d1a9 100644 --- a/include/clang/Basic/Diagnostic.h +++ b/include/clang/Basic/Diagnostic.h @@ -455,9 +455,7 @@ public: /// 'Loc' is the source location that this change of diagnostic state should /// take affect. It can be null if we are setting the state from command-line. bool setDiagnosticGroupMapping(StringRef Group, diag::Mapping Map, - SourceLocation Loc = SourceLocation()) { - return Diags->setDiagnosticGroupMapping(Group, Map, Loc, *this); - } + SourceLocation Loc = SourceLocation()); /// \brief Set the warning-as-error flag for the given diagnostic group. /// diff --git a/include/clang/Basic/DiagnosticIDs.h b/include/clang/Basic/DiagnosticIDs.h index f11293c6c8..6a6a87e0fd 100644 --- a/include/clang/Basic/DiagnosticIDs.h +++ b/include/clang/Basic/DiagnosticIDs.h @@ -18,9 +18,14 @@ #include "llvm/ADT/StringRef.h" #include "clang/Basic/LLVM.h" +namespace llvm { + template<typename T, unsigned> class SmallVector; +} + namespace clang { class DiagnosticsEngine; class SourceLocation; + struct WarningOption; // Import the diagnostic enums themselves. namespace diag { @@ -248,13 +253,19 @@ public: static diag_iterator diags_end(); private: - /// setDiagnosticGroupMapping - Change an entire diagnostic group (e.g. - /// "unknown-pragmas" to have the specified mapping. This returns true and - /// ignores the request if "Group" was unknown, false otherwise. - bool setDiagnosticGroupMapping(StringRef Group, diag::Mapping Map, - SourceLocation Loc, - DiagnosticsEngine &Diag) const; + /// \brief Get the set of all diagnostic IDs in the group with the given name. + /// + /// \param Diags [out] - On return, the diagnostics in the group. + /// \returns True if the given group is unknown, false otherwise. + bool getDiagnosticsInGroup(StringRef Group, + llvm::SmallVectorImpl<diag::kind> &Diags) const; + /// \brief Get the set of all diagnostic IDs in the given group. + /// + /// \param Diags [out] - On return, the diagnostics in the group. + void getDiagnosticsInGroup(const WarningOption *Group, + llvm::SmallVectorImpl<diag::kind> &Diags) const; + /// \brief Based on the way the client configured the DiagnosticsEngine /// object, classify the specified diagnostic ID into a Level, consumable by /// the DiagnosticClient. diff --git a/lib/Basic/Diagnostic.cpp b/lib/Basic/Diagnostic.cpp index 18220f0fd1..0402aaa1af 100644 --- a/lib/Basic/Diagnostic.cpp +++ b/lib/Basic/Diagnostic.cpp @@ -222,6 +222,21 @@ void DiagnosticsEngine::setDiagnosticMapping(diag::kind Diag, diag::Mapping Map, FullSourceLoc(Loc, *SourceMgr))); } +bool DiagnosticsEngine::setDiagnosticGroupMapping( + StringRef Group, diag::Mapping Map, SourceLocation Loc) +{ + // Get the diagnostics in this group. + llvm::SmallVector<diag::kind, 8> GroupDiags; + if (Diags->getDiagnosticsInGroup(Group, GroupDiags)) + return true; + + // Set the mapping. + for (unsigned i = 0, e = GroupDiags.size(); i != e; ++i) + setDiagnosticMapping(GroupDiags[i], Map, Loc); + + return false; +} + bool DiagnosticsEngine::setDiagnosticGroupWarningAsError(StringRef Group, bool Enabled) { diag::Mapping Map = Enabled ? diag::MAP_ERROR : diag::MAP_WARNING_NO_WERROR; diff --git a/lib/Basic/DiagnosticIDs.cpp b/lib/Basic/DiagnosticIDs.cpp index f865e0b594..3129f731f1 100644 --- a/lib/Basic/DiagnosticIDs.cpp +++ b/lib/Basic/DiagnosticIDs.cpp @@ -21,6 +21,7 @@ #include "clang/Lex/LexDiagnostic.h" #include "clang/Parse/ParseDiagnostic.h" #include "clang/Sema/SemaDiagnostic.h" +#include "llvm/ADT/SmallVector.h" #include "llvm/Support/ErrorHandling.h" #include <map> @@ -630,21 +631,19 @@ DiagnosticIDs::getDiagnosticLevel(unsigned DiagID, unsigned DiagClass, return Result; } -namespace { - struct WarningOption { - // Be safe with the size of 'NameLen' because we don't statically check if - // the size will fit in the field; the struct size won't decrease with a - // shorter type anyway. - size_t NameLen; - const char *NameStr; - const short *Members; - const short *SubGroups; +struct clang::WarningOption { + // Be safe with the size of 'NameLen' because we don't statically check if + // the size will fit in the field; the struct size won't decrease with a + // shorter type anyway. + size_t NameLen; + const char *NameStr; + const short *Members; + const short *SubGroups; - StringRef getName() const { - return StringRef(NameStr, NameLen); - } - }; -} + StringRef getName() const { + return StringRef(NameStr, NameLen); + } +}; #define GET_DIAG_ARRAYS #include "clang/Basic/DiagnosticGroups.inc" @@ -664,47 +663,36 @@ static bool WarningOptionCompare(const WarningOption &LHS, return LHS.getName() < RHS.getName(); } -static void MapGroupMembers(const WarningOption *Group, diag::Mapping Mapping, - SourceLocation Loc, DiagnosticsEngine &Diag) { - // Option exists, poke all the members of its diagnostic set. +void DiagnosticIDs::getDiagnosticsInGroup( + const WarningOption *Group, + llvm::SmallVectorImpl<diag::kind> &Diags) const +{ + // Add the members of the option diagnostic set. if (const short *Member = Group->Members) { for (; *Member != -1; ++Member) - Diag.setDiagnosticMapping(*Member, Mapping, Loc); + Diags.push_back(*Member); } - // Enable/disable all subgroups along with this one. + // Add the members of the subgroups. if (const short *SubGroups = Group->SubGroups) { for (; *SubGroups != (short)-1; ++SubGroups) - MapGroupMembers(&OptionTable[(short)*SubGroups], Mapping, Loc, Diag); + getDiagnosticsInGroup(&OptionTable[(short)*SubGroups], Diags); } } -/// setDiagnosticGroupMapping - Change an entire diagnostic group (e.g. -/// "unknown-pragmas" to have the specified mapping. This returns true and -/// ignores the request if "Group" was unknown, false otherwise. -bool DiagnosticIDs::setDiagnosticGroupMapping(StringRef Group, - diag::Mapping Map, - SourceLocation Loc, - DiagnosticsEngine &Diag) const { - assert((Loc.isValid() || - Diag.DiagStatePoints.empty() || - Diag.DiagStatePoints.back().Loc.isInvalid()) && - "Loc should be invalid only when the mapping comes from command-line"); - assert((Loc.isInvalid() || Diag.DiagStatePoints.empty() || - Diag.DiagStatePoints.back().Loc.isInvalid() || - !Diag.SourceMgr->isBeforeInTranslationUnit(Loc, - Diag.DiagStatePoints.back().Loc)) && - "Source location of new mapping is before the previous one!"); - +bool DiagnosticIDs::getDiagnosticsInGroup( + StringRef Group, + llvm::SmallVectorImpl<diag::kind> &Diags) const +{ WarningOption Key = { Group.size(), Group.data(), 0, 0 }; const WarningOption *Found = std::lower_bound(OptionTable, OptionTable + OptionTableSize, Key, WarningOptionCompare); if (Found == OptionTable + OptionTableSize || Found->getName() != Group) - return true; // Option not found. + return true; // Option not found. - MapGroupMembers(Found, Map, Loc, Diag); + getDiagnosticsInGroup(Found, Diags); return false; } |