Jordan Rose | 2fe20dc | 2012-06-04 16:57:50 +0000 | [diff] [blame] | 1 | //===- DiagnosticNames.cpp - Defines a table of all builtin diagnostics ----==// |
| 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Jordan Rose | 2fe20dc | 2012-06-04 16:57:50 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #include "DiagnosticNames.h" |
| 10 | #include "clang/Basic/AllDiagnostics.h" |
Jordan Rose | 473e877 | 2012-06-24 00:07:45 +0000 | [diff] [blame] | 11 | #include "llvm/ADT/STLExtras.h" |
Jordan Rose | 2fe20dc | 2012-06-04 16:57:50 +0000 | [diff] [blame] | 12 | |
| 13 | using namespace clang; |
Jordan Rose | 473e877 | 2012-06-24 00:07:45 +0000 | [diff] [blame] | 14 | using namespace diagtool; |
Jordan Rose | 2fe20dc | 2012-06-04 16:57:50 +0000 | [diff] [blame] | 15 | |
Jordan Rose | 473e877 | 2012-06-24 00:07:45 +0000 | [diff] [blame] | 16 | static const DiagnosticRecord BuiltinDiagnosticsByName[] = { |
Jordan Rose | 2fe20dc | 2012-06-04 16:57:50 +0000 | [diff] [blame] | 17 | #define DIAG_NAME_INDEX(ENUM) { #ENUM, diag::ENUM, STR_SIZE(#ENUM, uint8_t) }, |
| 18 | #include "clang/Basic/DiagnosticIndexName.inc" |
| 19 | #undef DIAG_NAME_INDEX |
Jordan Rose | 2fe20dc | 2012-06-04 16:57:50 +0000 | [diff] [blame] | 20 | }; |
| 21 | |
Jordan Rose | 473e877 | 2012-06-24 00:07:45 +0000 | [diff] [blame] | 22 | llvm::ArrayRef<DiagnosticRecord> diagtool::getBuiltinDiagnosticsByName() { |
Jordan Rose | 21e22db | 2012-06-24 00:27:36 +0000 | [diff] [blame] | 23 | return llvm::makeArrayRef(BuiltinDiagnosticsByName); |
Jordan Rose | 473e877 | 2012-06-24 00:07:45 +0000 | [diff] [blame] | 24 | } |
Jordan Rose | 2fe20dc | 2012-06-04 16:57:50 +0000 | [diff] [blame] | 25 | |
Jordan Rose | 473e877 | 2012-06-24 00:07:45 +0000 | [diff] [blame] | 26 | |
| 27 | // FIXME: Is it worth having two tables, especially when this one can get |
| 28 | // out of sync easily? |
| 29 | static const DiagnosticRecord BuiltinDiagnosticsByID[] = { |
| 30 | #define DIAG(ENUM,CLASS,DEFAULT_MAPPING,DESC,GROUP, \ |
Richard Smith | 16e1b07 | 2013-11-12 02:41:45 +0000 | [diff] [blame] | 31 | SFINAE,NOWERROR,SHOWINSYSHEADER,CATEGORY) \ |
Jordan Rose | 473e877 | 2012-06-24 00:07:45 +0000 | [diff] [blame] | 32 | { #ENUM, diag::ENUM, STR_SIZE(#ENUM, uint8_t) }, |
| 33 | #include "clang/Basic/DiagnosticCommonKinds.inc" |
Gabor Horvath | e350b0a | 2017-09-22 11:11:01 +0000 | [diff] [blame] | 34 | #include "clang/Basic/DiagnosticCrossTUKinds.inc" |
Jordan Rose | 473e877 | 2012-06-24 00:07:45 +0000 | [diff] [blame] | 35 | #include "clang/Basic/DiagnosticDriverKinds.inc" |
| 36 | #include "clang/Basic/DiagnosticFrontendKinds.inc" |
| 37 | #include "clang/Basic/DiagnosticSerializationKinds.inc" |
| 38 | #include "clang/Basic/DiagnosticLexKinds.inc" |
| 39 | #include "clang/Basic/DiagnosticParseKinds.inc" |
| 40 | #include "clang/Basic/DiagnosticASTKinds.inc" |
Dmitri Gribenko | f26054f | 2012-07-11 21:38:39 +0000 | [diff] [blame] | 41 | #include "clang/Basic/DiagnosticCommentKinds.inc" |
Jordan Rose | 473e877 | 2012-06-24 00:07:45 +0000 | [diff] [blame] | 42 | #include "clang/Basic/DiagnosticSemaKinds.inc" |
| 43 | #include "clang/Basic/DiagnosticAnalysisKinds.inc" |
Alex Lorenz | f5ca27c | 2017-10-16 18:28:26 +0000 | [diff] [blame] | 44 | #include "clang/Basic/DiagnosticRefactoringKinds.inc" |
Jordan Rose | 473e877 | 2012-06-24 00:07:45 +0000 | [diff] [blame] | 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) { |
Craig Topper | 69186e7 | 2014-06-08 08:38:04 +0000 | [diff] [blame] | 54 | DiagnosticRecord Key = {nullptr, DiagID, 0}; |
Jordan Rose | 473e877 | 2012-06-24 00:07:45 +0000 | [diff] [blame] | 55 | |
| 56 | const DiagnosticRecord *Result = |
Benjamin Kramer | 5c323b8 | 2014-04-12 15:42:48 +0000 | [diff] [blame] | 57 | std::lower_bound(std::begin(BuiltinDiagnosticsByID), |
| 58 | std::end(BuiltinDiagnosticsByID), |
Jordan Rose | 473e877 | 2012-06-24 00:07:45 +0000 | [diff] [blame] | 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 | |
Craig Topper | da7cf8a | 2013-08-29 05:18:04 +0000 | [diff] [blame] | 76 | llvm::StringRef GroupRecord::getName() const { |
| 77 | return StringRef(DiagGroupNames + NameOffset + 1, DiagGroupNames[NameOffset]); |
| 78 | } |
| 79 | |
Craig Topper | d80c17e | 2013-08-28 04:02:50 +0000 | [diff] [blame] | 80 | GroupRecord::subgroup_iterator GroupRecord::subgroup_begin() const { |
| 81 | return DiagSubGroups + SubGroups; |
| 82 | } |
| 83 | |
| 84 | GroupRecord::subgroup_iterator GroupRecord::subgroup_end() const { |
Craig Topper | 69186e7 | 2014-06-08 08:38:04 +0000 | [diff] [blame] | 85 | return nullptr; |
Craig Topper | d80c17e | 2013-08-28 04:02:50 +0000 | [diff] [blame] | 86 | } |
| 87 | |
Jonas Devlieghere | e4563d1 | 2017-09-05 18:04:34 +0000 | [diff] [blame] | 88 | llvm::iterator_range<diagtool::GroupRecord::subgroup_iterator> |
| 89 | GroupRecord::subgroups() const { |
| 90 | return llvm::make_range(subgroup_begin(), subgroup_end()); |
| 91 | } |
| 92 | |
Craig Topper | d80c17e | 2013-08-28 04:02:50 +0000 | [diff] [blame] | 93 | GroupRecord::diagnostics_iterator GroupRecord::diagnostics_begin() const { |
| 94 | return DiagArrays + Members; |
| 95 | } |
| 96 | |
| 97 | GroupRecord::diagnostics_iterator GroupRecord::diagnostics_end() const { |
Craig Topper | 69186e7 | 2014-06-08 08:38:04 +0000 | [diff] [blame] | 98 | return nullptr; |
Craig Topper | d80c17e | 2013-08-28 04:02:50 +0000 | [diff] [blame] | 99 | } |
| 100 | |
Jonas Devlieghere | e4563d1 | 2017-09-05 18:04:34 +0000 | [diff] [blame] | 101 | llvm::iterator_range<diagtool::GroupRecord::diagnostics_iterator> |
| 102 | GroupRecord::diagnostics() const { |
| 103 | return llvm::make_range(diagnostics_begin(), diagnostics_end()); |
| 104 | } |
| 105 | |
Jordan Rose | 473e877 | 2012-06-24 00:07:45 +0000 | [diff] [blame] | 106 | llvm::ArrayRef<GroupRecord> diagtool::getDiagnosticGroups() { |
Jordan Rose | 21e22db | 2012-06-24 00:27:36 +0000 | [diff] [blame] | 107 | return llvm::makeArrayRef(OptionTable); |
Jordan Rose | 473e877 | 2012-06-24 00:07:45 +0000 | [diff] [blame] | 108 | } |