Jordan Rose | 2fe20dc | 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 | 473e877 | 2012-06-24 00:07:45 +0000 | [diff] [blame] | 12 | #include "llvm/ADT/STLExtras.h" |
Jordan Rose | 2fe20dc | 2012-06-04 16:57:50 +0000 | [diff] [blame] | 13 | |
| 14 | using namespace clang; |
Jordan Rose | 473e877 | 2012-06-24 00:07:45 +0000 | [diff] [blame] | 15 | using namespace diagtool; |
Jordan Rose | 2fe20dc | 2012-06-04 16:57:50 +0000 | [diff] [blame] | 16 | |
Jordan Rose | 473e877 | 2012-06-24 00:07:45 +0000 | [diff] [blame] | 17 | static const DiagnosticRecord BuiltinDiagnosticsByName[] = { |
Jordan Rose | 2fe20dc | 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 | 2fe20dc | 2012-06-04 16:57:50 +0000 | [diff] [blame] | 21 | }; |
| 22 | |
Jordan Rose | 473e877 | 2012-06-24 00:07:45 +0000 | [diff] [blame] | 23 | llvm::ArrayRef<DiagnosticRecord> diagtool::getBuiltinDiagnosticsByName() { |
Jordan Rose | 21e22db | 2012-06-24 00:27:36 +0000 | [diff] [blame] | 24 | return llvm::makeArrayRef(BuiltinDiagnosticsByName); |
Jordan Rose | 473e877 | 2012-06-24 00:07:45 +0000 | [diff] [blame] | 25 | } |
Jordan Rose | 2fe20dc | 2012-06-04 16:57:50 +0000 | [diff] [blame] | 26 | |
Jordan Rose | 473e877 | 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, \ |
Richard Smith | 16e1b07 | 2013-11-12 02:41:45 +0000 | [diff] [blame] | 32 | SFINAE,NOWERROR,SHOWINSYSHEADER,CATEGORY) \ |
Jordan Rose | 473e877 | 2012-06-24 00:07:45 +0000 | [diff] [blame] | 33 | { #ENUM, diag::ENUM, STR_SIZE(#ENUM, uint8_t) }, |
| 34 | #include "clang/Basic/DiagnosticCommonKinds.inc" |
Gabor Horvath | e350b0a | 2017-09-22 11:11:01 +0000 | [diff] [blame] | 35 | #include "clang/Basic/DiagnosticCrossTUKinds.inc" |
Jordan Rose | 473e877 | 2012-06-24 00:07:45 +0000 | [diff] [blame] | 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 | f26054f | 2012-07-11 21:38:39 +0000 | [diff] [blame] | 42 | #include "clang/Basic/DiagnosticCommentKinds.inc" |
Jordan Rose | 473e877 | 2012-06-24 00:07:45 +0000 | [diff] [blame] | 43 | #include "clang/Basic/DiagnosticSemaKinds.inc" |
| 44 | #include "clang/Basic/DiagnosticAnalysisKinds.inc" |
Alex Lorenz | f5ca27c | 2017-10-16 18:28:26 +0000 | [diff] [blame^] | 45 | #include "clang/Basic/DiagnosticRefactoringKinds.inc" |
Jordan Rose | 473e877 | 2012-06-24 00:07:45 +0000 | [diff] [blame] | 46 | #undef DIAG |
| 47 | }; |
| 48 | |
| 49 | static bool orderByID(const DiagnosticRecord &Left, |
| 50 | const DiagnosticRecord &Right) { |
| 51 | return Left.DiagID < Right.DiagID; |
| 52 | } |
| 53 | |
| 54 | const DiagnosticRecord &diagtool::getDiagnosticForID(short DiagID) { |
Craig Topper | 69186e7 | 2014-06-08 08:38:04 +0000 | [diff] [blame] | 55 | DiagnosticRecord Key = {nullptr, DiagID, 0}; |
Jordan Rose | 473e877 | 2012-06-24 00:07:45 +0000 | [diff] [blame] | 56 | |
| 57 | const DiagnosticRecord *Result = |
Benjamin Kramer | 5c323b8 | 2014-04-12 15:42:48 +0000 | [diff] [blame] | 58 | std::lower_bound(std::begin(BuiltinDiagnosticsByID), |
| 59 | std::end(BuiltinDiagnosticsByID), |
Jordan Rose | 473e877 | 2012-06-24 00:07:45 +0000 | [diff] [blame] | 60 | Key, orderByID); |
| 61 | assert(Result && "diagnostic not found; table may be out of date"); |
| 62 | return *Result; |
| 63 | } |
| 64 | |
| 65 | |
| 66 | #define GET_DIAG_ARRAYS |
| 67 | #include "clang/Basic/DiagnosticGroups.inc" |
| 68 | #undef GET_DIAG_ARRAYS |
| 69 | |
| 70 | // Second the table of options, sorted by name for fast binary lookup. |
| 71 | static const GroupRecord OptionTable[] = { |
| 72 | #define GET_DIAG_TABLE |
| 73 | #include "clang/Basic/DiagnosticGroups.inc" |
| 74 | #undef GET_DIAG_TABLE |
| 75 | }; |
| 76 | |
Craig Topper | da7cf8a | 2013-08-29 05:18:04 +0000 | [diff] [blame] | 77 | llvm::StringRef GroupRecord::getName() const { |
| 78 | return StringRef(DiagGroupNames + NameOffset + 1, DiagGroupNames[NameOffset]); |
| 79 | } |
| 80 | |
Craig Topper | d80c17e | 2013-08-28 04:02:50 +0000 | [diff] [blame] | 81 | GroupRecord::subgroup_iterator GroupRecord::subgroup_begin() const { |
| 82 | return DiagSubGroups + SubGroups; |
| 83 | } |
| 84 | |
| 85 | GroupRecord::subgroup_iterator GroupRecord::subgroup_end() const { |
Craig Topper | 69186e7 | 2014-06-08 08:38:04 +0000 | [diff] [blame] | 86 | return nullptr; |
Craig Topper | d80c17e | 2013-08-28 04:02:50 +0000 | [diff] [blame] | 87 | } |
| 88 | |
Jonas Devlieghere | e4563d1 | 2017-09-05 18:04:34 +0000 | [diff] [blame] | 89 | llvm::iterator_range<diagtool::GroupRecord::subgroup_iterator> |
| 90 | GroupRecord::subgroups() const { |
| 91 | return llvm::make_range(subgroup_begin(), subgroup_end()); |
| 92 | } |
| 93 | |
Craig Topper | d80c17e | 2013-08-28 04:02:50 +0000 | [diff] [blame] | 94 | GroupRecord::diagnostics_iterator GroupRecord::diagnostics_begin() const { |
| 95 | return DiagArrays + Members; |
| 96 | } |
| 97 | |
| 98 | GroupRecord::diagnostics_iterator GroupRecord::diagnostics_end() const { |
Craig Topper | 69186e7 | 2014-06-08 08:38:04 +0000 | [diff] [blame] | 99 | return nullptr; |
Craig Topper | d80c17e | 2013-08-28 04:02:50 +0000 | [diff] [blame] | 100 | } |
| 101 | |
Jonas Devlieghere | e4563d1 | 2017-09-05 18:04:34 +0000 | [diff] [blame] | 102 | llvm::iterator_range<diagtool::GroupRecord::diagnostics_iterator> |
| 103 | GroupRecord::diagnostics() const { |
| 104 | return llvm::make_range(diagnostics_begin(), diagnostics_end()); |
| 105 | } |
| 106 | |
Jordan Rose | 473e877 | 2012-06-24 00:07:45 +0000 | [diff] [blame] | 107 | llvm::ArrayRef<GroupRecord> diagtool::getDiagnosticGroups() { |
Jordan Rose | 21e22db | 2012-06-24 00:27:36 +0000 | [diff] [blame] | 108 | return llvm::makeArrayRef(OptionTable); |
Jordan Rose | 473e877 | 2012-06-24 00:07:45 +0000 | [diff] [blame] | 109 | } |