Jordan Rose | 0832f82 | 2012-06-04 16:57:50 +0000 | [diff] [blame] | 1 | //===- DiagnosticNames.cpp - Defines a table of all builtin diagnostics ----==// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #include "DiagnosticNames.h" |
| 11 | #include "clang/Basic/AllDiagnostics.h" |
Jordan Rose | e742763 | 2012-06-24 00:07:45 +0000 | [diff] [blame] | 12 | #include "llvm/ADT/STLExtras.h" |
Jordan Rose | 0832f82 | 2012-06-04 16:57:50 +0000 | [diff] [blame] | 13 | |
| 14 | using namespace clang; |
Jordan Rose | e742763 | 2012-06-24 00:07:45 +0000 | [diff] [blame] | 15 | using namespace diagtool; |
Jordan Rose | 0832f82 | 2012-06-04 16:57:50 +0000 | [diff] [blame] | 16 | |
Jordan Rose | e742763 | 2012-06-24 00:07:45 +0000 | [diff] [blame] | 17 | static const DiagnosticRecord BuiltinDiagnosticsByName[] = { |
Jordan Rose | 0832f82 | 2012-06-04 16:57:50 +0000 | [diff] [blame] | 18 | #define DIAG_NAME_INDEX(ENUM) { #ENUM, diag::ENUM, STR_SIZE(#ENUM, uint8_t) }, |
| 19 | #include "clang/Basic/DiagnosticIndexName.inc" |
| 20 | #undef DIAG_NAME_INDEX |
Jordan Rose | 0832f82 | 2012-06-04 16:57:50 +0000 | [diff] [blame] | 21 | }; |
| 22 | |
Jordan Rose | e742763 | 2012-06-24 00:07:45 +0000 | [diff] [blame] | 23 | llvm::ArrayRef<DiagnosticRecord> diagtool::getBuiltinDiagnosticsByName() { |
Jordan Rose | 19bf662 | 2012-06-24 00:27:36 +0000 | [diff] [blame] | 24 | return llvm::makeArrayRef(BuiltinDiagnosticsByName); |
Jordan Rose | e742763 | 2012-06-24 00:07:45 +0000 | [diff] [blame] | 25 | } |
Jordan Rose | 0832f82 | 2012-06-04 16:57:50 +0000 | [diff] [blame] | 26 | |
Jordan Rose | e742763 | 2012-06-24 00:07:45 +0000 | [diff] [blame] | 27 | |
| 28 | // FIXME: Is it worth having two tables, especially when this one can get |
| 29 | // out of sync easily? |
| 30 | static const DiagnosticRecord BuiltinDiagnosticsByID[] = { |
| 31 | #define DIAG(ENUM,CLASS,DEFAULT_MAPPING,DESC,GROUP, \ |
| 32 | SFINAE,ACCESS,NOWERROR,SHOWINSYSHEADER, \ |
| 33 | CATEGORY) \ |
| 34 | { #ENUM, diag::ENUM, STR_SIZE(#ENUM, uint8_t) }, |
| 35 | #include "clang/Basic/DiagnosticCommonKinds.inc" |
| 36 | #include "clang/Basic/DiagnosticDriverKinds.inc" |
| 37 | #include "clang/Basic/DiagnosticFrontendKinds.inc" |
| 38 | #include "clang/Basic/DiagnosticSerializationKinds.inc" |
| 39 | #include "clang/Basic/DiagnosticLexKinds.inc" |
| 40 | #include "clang/Basic/DiagnosticParseKinds.inc" |
| 41 | #include "clang/Basic/DiagnosticASTKinds.inc" |
Dmitri Gribenko | a5ef44f | 2012-07-11 21:38:39 +0000 | [diff] [blame] | 42 | #include "clang/Basic/DiagnosticCommentKinds.inc" |
Jordan Rose | e742763 | 2012-06-24 00:07:45 +0000 | [diff] [blame] | 43 | #include "clang/Basic/DiagnosticSemaKinds.inc" |
| 44 | #include "clang/Basic/DiagnosticAnalysisKinds.inc" |
| 45 | #undef DIAG |
| 46 | }; |
| 47 | |
| 48 | static bool orderByID(const DiagnosticRecord &Left, |
| 49 | const DiagnosticRecord &Right) { |
| 50 | return Left.DiagID < Right.DiagID; |
| 51 | } |
| 52 | |
| 53 | const DiagnosticRecord &diagtool::getDiagnosticForID(short DiagID) { |
| 54 | DiagnosticRecord Key = {0, DiagID, 0}; |
| 55 | |
| 56 | const DiagnosticRecord *Result = |
| 57 | std::lower_bound(BuiltinDiagnosticsByID, |
| 58 | llvm::array_endof(BuiltinDiagnosticsByID), |
| 59 | Key, orderByID); |
| 60 | assert(Result && "diagnostic not found; table may be out of date"); |
| 61 | return *Result; |
| 62 | } |
| 63 | |
| 64 | |
| 65 | #define GET_DIAG_ARRAYS |
| 66 | #include "clang/Basic/DiagnosticGroups.inc" |
| 67 | #undef GET_DIAG_ARRAYS |
| 68 | |
| 69 | // Second the table of options, sorted by name for fast binary lookup. |
| 70 | static const GroupRecord OptionTable[] = { |
| 71 | #define GET_DIAG_TABLE |
| 72 | #include "clang/Basic/DiagnosticGroups.inc" |
| 73 | #undef GET_DIAG_TABLE |
| 74 | }; |
| 75 | |
| 76 | llvm::ArrayRef<GroupRecord> diagtool::getDiagnosticGroups() { |
Jordan Rose | 19bf662 | 2012-06-24 00:27:36 +0000 | [diff] [blame] | 77 | return llvm::makeArrayRef(OptionTable); |
Jordan Rose | e742763 | 2012-06-24 00:07:45 +0000 | [diff] [blame] | 78 | } |