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 | d908c12db83674706c75453446043d4d7763a01c (patch) | |
| tree | 30300bfc170117bf92e9a56db8b511b72d2d560f /clang/lib | |
| parent | e8c12a2979e384405ccdf5fe6e670a1586448ce6 (diff) | |
| download | bcm5719-llvm-d908c12db83674706c75453446043d4d7763a01c.tar.gz bcm5719-llvm-d908c12db83674706c75453446043d4d7763a01c.zip | |
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.
llvm-svn: 140766
Diffstat (limited to 'clang/lib')
| -rw-r--r-- | clang/lib/Basic/Diagnostic.cpp | 15 | ||||
| -rw-r--r-- | clang/lib/Basic/DiagnosticIDs.cpp | 66 |
2 files changed, 42 insertions, 39 deletions
diff --git a/clang/lib/Basic/Diagnostic.cpp b/clang/lib/Basic/Diagnostic.cpp index 18220f0fd1e..0402aaa1af3 100644 --- a/clang/lib/Basic/Diagnostic.cpp +++ b/clang/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/clang/lib/Basic/DiagnosticIDs.cpp b/clang/lib/Basic/DiagnosticIDs.cpp index f865e0b594e..3129f731f18 100644 --- a/clang/lib/Basic/DiagnosticIDs.cpp +++ b/clang/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; } |

