blob: b0ca7f980639946a625f35c8b668744f010ecd40 [file] [log] [blame]
Jordan Rose2fe20dc2012-06-04 16:57:50 +00001//===- 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 Rose473e8772012-06-24 00:07:45 +000012#include "llvm/ADT/STLExtras.h"
Jordan Rose2fe20dc2012-06-04 16:57:50 +000013
14using namespace clang;
Jordan Rose473e8772012-06-24 00:07:45 +000015using namespace diagtool;
Jordan Rose2fe20dc2012-06-04 16:57:50 +000016
Jordan Rose473e8772012-06-24 00:07:45 +000017static const DiagnosticRecord BuiltinDiagnosticsByName[] = {
Jordan Rose2fe20dc2012-06-04 16:57:50 +000018#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 Rose2fe20dc2012-06-04 16:57:50 +000021};
22
Jordan Rose473e8772012-06-24 00:07:45 +000023llvm::ArrayRef<DiagnosticRecord> diagtool::getBuiltinDiagnosticsByName() {
Jordan Rose21e22db2012-06-24 00:27:36 +000024 return llvm::makeArrayRef(BuiltinDiagnosticsByName);
Jordan Rose473e8772012-06-24 00:07:45 +000025}
Jordan Rose2fe20dc2012-06-04 16:57:50 +000026
Jordan Rose473e8772012-06-24 00:07:45 +000027
28// FIXME: Is it worth having two tables, especially when this one can get
29// out of sync easily?
30static const DiagnosticRecord BuiltinDiagnosticsByID[] = {
31#define DIAG(ENUM,CLASS,DEFAULT_MAPPING,DESC,GROUP, \
Richard Smith16e1b072013-11-12 02:41:45 +000032 SFINAE,NOWERROR,SHOWINSYSHEADER,CATEGORY) \
Jordan Rose473e8772012-06-24 00:07:45 +000033 { #ENUM, diag::ENUM, STR_SIZE(#ENUM, uint8_t) },
34#include "clang/Basic/DiagnosticCommonKinds.inc"
Gabor Horvathe350b0a2017-09-22 11:11:01 +000035#include "clang/Basic/DiagnosticCrossTUKinds.inc"
Jordan Rose473e8772012-06-24 00:07:45 +000036#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 Gribenkof26054f2012-07-11 21:38:39 +000042#include "clang/Basic/DiagnosticCommentKinds.inc"
Jordan Rose473e8772012-06-24 00:07:45 +000043#include "clang/Basic/DiagnosticSemaKinds.inc"
44#include "clang/Basic/DiagnosticAnalysisKinds.inc"
Alex Lorenzf5ca27c2017-10-16 18:28:26 +000045#include "clang/Basic/DiagnosticRefactoringKinds.inc"
Jordan Rose473e8772012-06-24 00:07:45 +000046#undef DIAG
47};
48
49static bool orderByID(const DiagnosticRecord &Left,
50 const DiagnosticRecord &Right) {
51 return Left.DiagID < Right.DiagID;
52}
53
54const DiagnosticRecord &diagtool::getDiagnosticForID(short DiagID) {
Craig Topper69186e72014-06-08 08:38:04 +000055 DiagnosticRecord Key = {nullptr, DiagID, 0};
Jordan Rose473e8772012-06-24 00:07:45 +000056
57 const DiagnosticRecord *Result =
Benjamin Kramer5c323b82014-04-12 15:42:48 +000058 std::lower_bound(std::begin(BuiltinDiagnosticsByID),
59 std::end(BuiltinDiagnosticsByID),
Jordan Rose473e8772012-06-24 00:07:45 +000060 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.
71static const GroupRecord OptionTable[] = {
72#define GET_DIAG_TABLE
73#include "clang/Basic/DiagnosticGroups.inc"
74#undef GET_DIAG_TABLE
75};
76
Craig Topperda7cf8a2013-08-29 05:18:04 +000077llvm::StringRef GroupRecord::getName() const {
78 return StringRef(DiagGroupNames + NameOffset + 1, DiagGroupNames[NameOffset]);
79}
80
Craig Topperd80c17e2013-08-28 04:02:50 +000081GroupRecord::subgroup_iterator GroupRecord::subgroup_begin() const {
82 return DiagSubGroups + SubGroups;
83}
84
85GroupRecord::subgroup_iterator GroupRecord::subgroup_end() const {
Craig Topper69186e72014-06-08 08:38:04 +000086 return nullptr;
Craig Topperd80c17e2013-08-28 04:02:50 +000087}
88
Jonas Devliegheree4563d12017-09-05 18:04:34 +000089llvm::iterator_range<diagtool::GroupRecord::subgroup_iterator>
90GroupRecord::subgroups() const {
91 return llvm::make_range(subgroup_begin(), subgroup_end());
92}
93
Craig Topperd80c17e2013-08-28 04:02:50 +000094GroupRecord::diagnostics_iterator GroupRecord::diagnostics_begin() const {
95 return DiagArrays + Members;
96}
97
98GroupRecord::diagnostics_iterator GroupRecord::diagnostics_end() const {
Craig Topper69186e72014-06-08 08:38:04 +000099 return nullptr;
Craig Topperd80c17e2013-08-28 04:02:50 +0000100}
101
Jonas Devliegheree4563d12017-09-05 18:04:34 +0000102llvm::iterator_range<diagtool::GroupRecord::diagnostics_iterator>
103GroupRecord::diagnostics() const {
104 return llvm::make_range(diagnostics_begin(), diagnostics_end());
105}
106
Jordan Rose473e8772012-06-24 00:07:45 +0000107llvm::ArrayRef<GroupRecord> diagtool::getDiagnosticGroups() {
Jordan Rose21e22db2012-06-24 00:27:36 +0000108 return llvm::makeArrayRef(OptionTable);
Jordan Rose473e8772012-06-24 00:07:45 +0000109}