#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 {
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.
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;
#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>
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"
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;
}