diff options
author | Chris Lattner <sabre@nondot.org> | 2009-04-19 22:34:23 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2009-04-19 22:34:23 +0000 |
commit | c6fafed04c516a9ab3495e54050169125c116353 (patch) | |
tree | 90f496bd73bc5c96a56a10e94b6c3cc233362156 /clang/lib/Basic/Diagnostic.cpp | |
parent | 3251e3cfaa250e1d07f54dd51e515e738ebdf6c1 (diff) | |
download | bcm5719-llvm-c6fafed04c516a9ab3495e54050169125c116353.tar.gz bcm5719-llvm-c6fafed04c516a9ab3495e54050169125c116353.zip |
move group twiddling options into Diagnostic.cpp instead of
Warnings.cpp. Warnings.cpp now doesn't need to #include
tblgen produced output directly.
llvm-svn: 69559
Diffstat (limited to 'clang/lib/Basic/Diagnostic.cpp')
-rw-r--r-- | clang/lib/Basic/Diagnostic.cpp | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/clang/lib/Basic/Diagnostic.cpp b/clang/lib/Basic/Diagnostic.cpp index bf11a13dc2b..9986fc5a41b 100644 --- a/clang/lib/Basic/Diagnostic.cpp +++ b/clang/lib/Basic/Diagnostic.cpp @@ -344,6 +344,64 @@ Diagnostic::getDiagnosticLevel(unsigned DiagID, unsigned DiagClass) const { return Result; } +struct WarningOption { + const char *Name; + const short *Members; + const char *SubGroups; +}; + +#define GET_DIAG_ARRAYS +#include "clang/Basic/DiagnosticGroups.inc" +#undef GET_DIAG_ARRAYS + +// Second the table of options, sorted by name for fast binary lookup. +static const WarningOption OptionTable[] = { +#define GET_DIAG_TABLE +#include "clang/Basic/DiagnosticGroups.inc" +#undef GET_DIAG_TABLE +}; +static const size_t OptionTableSize = +sizeof(OptionTable) / sizeof(OptionTable[0]); + +static bool WarningOptionCompare(const WarningOption &LHS, + const WarningOption &RHS) { + return strcmp(LHS.Name, RHS.Name) < 0; +} + +static void MapGroupMembers(const WarningOption *Group, diag::Mapping Mapping, + Diagnostic &Diags) { + // Option exists, poke all the members of its diagnostic set. + if (const short *Member = Group->Members) { + for (; *Member != -1; ++Member) + Diags.setDiagnosticMapping(*Member, Mapping); + } + + // Enable/disable all subgroups along with this one. + if (const char *SubGroups = Group->SubGroups) { + for (; *SubGroups != (char)-1; ++SubGroups) + MapGroupMembers(&OptionTable[(unsigned char)*SubGroups], Mapping, 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 Diagnostic::setDiagnosticGroupMapping(const char *Group, + diag::Mapping Map) { + + WarningOption Key = { Group, 0, 0 }; + const WarningOption *Found = + std::lower_bound(OptionTable, OptionTable + OptionTableSize, Key, + WarningOptionCompare); + if (Found == OptionTable + OptionTableSize || + strcmp(Found->Name, Group) != 0) + return true; // Option not found. + + MapGroupMembers(Found, Map, *this); + return false; +} + + /// ProcessDiag - This is the method used to report a diagnostic that is /// finally fully formed. void Diagnostic::ProcessDiag() { |