Skip to content

Commit 6c74fe9

Browse files
authored
[Clang] [NFC] Tablegen component diags headers (#134777)
The component diagnostic headers (i.e. `DiagnosticAST.h` and friends) all follow the same format, and there’s enough of them (and in them) to where updating all of them has become rather tedious (at least it was for me while working on #132348), so this patch instead generates all of them (or rather their contents) via Tablegen. Also, it seems that `%enum_select` currently wouldn’t work in `DiagnosticCommonKinds.td` because the infrastructure for that was missing from `DiagnosticIDs.h`; this patch should fix that as well.
1 parent 34e8f00 commit 6c74fe9

17 files changed

+85
-488
lines changed

clang/include/clang/Basic/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ macro(clang_diag_gen component)
1313
-gen-clang-diags-compat-ids -clang-component=${component}
1414
SOURCE Diagnostic.td
1515
TARGET ClangDiagnostic${component}CompatIDs)
16+
17+
clang_tablegen(Diagnostic${component}Interface.inc
18+
-gen-clang-diags-iface -clang-component=${component}
19+
SOURCE Diagnostic.td
20+
TARGET ClangDiagnostic${component}Interface)
1621
endmacro(clang_diag_gen)
1722

1823
clang_diag_gen(Analysis)

clang/include/clang/Basic/DiagnosticAST.h

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -10,44 +10,6 @@
1010
#define LLVM_CLANG_BASIC_DIAGNOSTICAST_H
1111

1212
#include "clang/Basic/Diagnostic.h"
13-
14-
namespace clang {
15-
namespace diag {
16-
enum {
17-
#define DIAG(ENUM, FLAGS, DEFAULT_MAPPING, DESC, GROUP, SFINAE, NOWERROR, \
18-
SHOWINSYSHEADER, SHOWINSYSMACRO, DEFERRABLE, CATEGORY) \
19-
ENUM,
20-
#define ASTSTART
21-
#include "clang/Basic/DiagnosticASTKinds.inc"
22-
#undef DIAG
23-
NUM_BUILTIN_AST_DIAGNOSTICS
24-
};
25-
26-
#define DIAG_ENUM(ENUM_NAME) \
27-
namespace ENUM_NAME { \
28-
enum {
29-
#define DIAG_ENUM_ITEM(IDX, NAME) NAME = IDX,
30-
#define DIAG_ENUM_END() \
31-
} \
32-
; \
33-
}
34-
#include "clang/Basic/DiagnosticASTEnums.inc"
35-
#undef DIAG_ENUM_END
36-
#undef DIAG_ENUM_ITEM
37-
#undef DIAG_ENUM
38-
} // end namespace diag
39-
40-
namespace diag_compat {
41-
#define DIAG_COMPAT_IDS_BEGIN() enum {
42-
#define DIAG_COMPAT_IDS_END() \
43-
} \
44-
;
45-
#define DIAG_COMPAT_ID(IDX, NAME, ...) NAME = IDX,
46-
#include "clang/Basic/DiagnosticASTCompatIDs.inc"
47-
#undef DIAG_COMPAT_ID
48-
#undef DIAG_COMPAT_IDS_BEGIN
49-
#undef DIAG_COMPAT_IDS_END
50-
} // end namespace diag_compat
51-
} // end namespace clang
13+
#include "clang/Basic/DiagnosticASTInterface.inc"
5214

5315
#endif // LLVM_CLANG_BASIC_DIAGNOSTICAST_H

clang/include/clang/Basic/DiagnosticAnalysis.h

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -10,43 +10,6 @@
1010
#define LLVM_CLANG_BASIC_DIAGNOSTICANALYSIS_H
1111

1212
#include "clang/Basic/Diagnostic.h"
13-
14-
namespace clang {
15-
namespace diag {
16-
enum {
17-
#define DIAG(ENUM, FLAGS, DEFAULT_MAPPING, DESC, GROUP, SFINAE, NOWERROR, \
18-
SHOWINSYSHEADER, SHOWINSYSMACRO, DEFERRABLE, CATEGORY) \
19-
ENUM,
20-
#define ANALYSISSTART
21-
#include "clang/Basic/DiagnosticAnalysisKinds.inc"
22-
#undef DIAG
23-
NUM_BUILTIN_ANALYSIS_DIAGNOSTICS
24-
};
25-
#define DIAG_ENUM(ENUM_NAME) \
26-
namespace ENUM_NAME { \
27-
enum {
28-
#define DIAG_ENUM_ITEM(IDX, NAME) NAME = IDX,
29-
#define DIAG_ENUM_END() \
30-
} \
31-
; \
32-
}
33-
#include "clang/Basic/DiagnosticAnalysisEnums.inc"
34-
#undef DIAG_ENUM_END
35-
#undef DIAG_ENUM_ITEM
36-
#undef DIAG_ENUM
37-
} // end namespace diag
38-
39-
namespace diag_compat {
40-
#define DIAG_COMPAT_IDS_BEGIN() enum {
41-
#define DIAG_COMPAT_IDS_END() \
42-
} \
43-
;
44-
#define DIAG_COMPAT_ID(IDX, NAME, ...) NAME = IDX,
45-
#include "clang/Basic/DiagnosticAnalysisCompatIDs.inc"
46-
#undef DIAG_COMPAT_ID
47-
#undef DIAG_COMPAT_IDS_BEGIN
48-
#undef DIAG_COMPAT_IDS_END
49-
} // end namespace diag_compat
50-
} // end namespace clang
13+
#include "clang/Basic/DiagnosticAnalysisInterface.inc"
5114

5215
#endif // LLVM_CLANG_BASIC_DIAGNOSTICANALYSIS_H

clang/include/clang/Basic/DiagnosticComment.h

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -10,44 +10,6 @@
1010
#define LLVM_CLANG_BASIC_DIAGNOSTICCOMMENT_H
1111

1212
#include "clang/Basic/Diagnostic.h"
13-
14-
namespace clang {
15-
namespace diag {
16-
enum {
17-
#define DIAG(ENUM, FLAGS, DEFAULT_MAPPING, DESC, GROUP, SFINAE, NOWERROR, \
18-
SHOWINSYSHEADER, SHOWINSYSMACRO, DEFERRABLE, CATEGORY) \
19-
ENUM,
20-
#define COMMENTSTART
21-
#include "clang/Basic/DiagnosticCommentKinds.inc"
22-
#undef DIAG
23-
NUM_BUILTIN_COMMENT_DIAGNOSTICS
24-
};
25-
26-
#define DIAG_ENUM(ENUM_NAME) \
27-
namespace ENUM_NAME { \
28-
enum {
29-
#define DIAG_ENUM_ITEM(IDX, NAME) NAME = IDX,
30-
#define DIAG_ENUM_END() \
31-
} \
32-
; \
33-
}
34-
#include "clang/Basic/DiagnosticCommentEnums.inc"
35-
#undef DIAG_ENUM_END
36-
#undef DIAG_ENUM_ITEM
37-
#undef DIAG_ENUM
38-
} // end namespace diag
39-
40-
namespace diag_compat {
41-
#define DIAG_COMPAT_IDS_BEGIN() enum {
42-
#define DIAG_COMPAT_IDS_END() \
43-
} \
44-
;
45-
#define DIAG_COMPAT_ID(IDX, NAME, ...) NAME = IDX,
46-
#include "clang/Basic/DiagnosticCommentCompatIDs.inc"
47-
#undef DIAG_COMPAT_ID
48-
#undef DIAG_COMPAT_IDS_BEGIN
49-
#undef DIAG_COMPAT_IDS_END
50-
} // end namespace diag_compat
51-
} // end namespace clang
13+
#include "clang/Basic/DiagnosticCommentInterface.inc"
5214

5315
#endif // LLVM_CLANG_BASIC_DIAGNOSTICCOMMENT_H

clang/include/clang/Basic/DiagnosticCrossTU.h

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -10,44 +10,6 @@
1010
#define LLVM_CLANG_BASIC_DIAGNOSTICCROSSTU_H
1111

1212
#include "clang/Basic/Diagnostic.h"
13-
14-
namespace clang {
15-
namespace diag {
16-
enum {
17-
#define DIAG(ENUM, FLAGS, DEFAULT_MAPPING, DESC, GROUP, SFINAE, NOWERROR, \
18-
SHOWINSYSHEADER, SHOWINSYSMACRO, DEFERRABLE, CATEGORY) \
19-
ENUM,
20-
#define CROSSTUSTART
21-
#include "clang/Basic/DiagnosticCrossTUKinds.inc"
22-
#undef DIAG
23-
NUM_BUILTIN_CROSSTU_DIAGNOSTICS
24-
};
25-
26-
#define DIAG_ENUM(ENUM_NAME) \
27-
namespace ENUM_NAME { \
28-
enum {
29-
#define DIAG_ENUM_ITEM(IDX, NAME) NAME = IDX,
30-
#define DIAG_ENUM_END() \
31-
} \
32-
; \
33-
}
34-
#include "clang/Basic/DiagnosticCrossTUEnums.inc"
35-
#undef DIAG_ENUM_END
36-
#undef DIAG_ENUM_ITEM
37-
#undef DIAG_ENUM
38-
} // end namespace diag
39-
40-
namespace diag_compat {
41-
#define DIAG_COMPAT_IDS_BEGIN() enum {
42-
#define DIAG_COMPAT_IDS_END() \
43-
} \
44-
;
45-
#define DIAG_COMPAT_ID(IDX, NAME, ...) NAME = IDX,
46-
#include "clang/Basic/DiagnosticCrossTUCompatIDs.inc"
47-
#undef DIAG_COMPAT_ID
48-
#undef DIAG_COMPAT_IDS_BEGIN
49-
#undef DIAG_COMPAT_IDS_END
50-
} // end namespace diag_compat
51-
} // end namespace clang
13+
#include "clang/Basic/DiagnosticCrossTUInterface.inc"
5214

5315
#endif // LLVM_CLANG_BASIC_DIAGNOSTICCROSSTU_H

clang/include/clang/Basic/DiagnosticDriver.h

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -10,44 +10,6 @@
1010
#define LLVM_CLANG_BASIC_DIAGNOSTICDRIVER_H
1111

1212
#include "clang/Basic/Diagnostic.h"
13-
14-
namespace clang {
15-
namespace diag {
16-
enum {
17-
#define DIAG(ENUM, FLAGS, DEFAULT_MAPPING, DESC, GROUP, SFINAE, NOWERROR, \
18-
SHOWINSYSHEADER, SHOWINSYSMACRO, DEFERRABLE, CATEGORY) \
19-
ENUM,
20-
#define DRIVERSTART
21-
#include "clang/Basic/DiagnosticDriverKinds.inc"
22-
#undef DIAG
23-
NUM_BUILTIN_DRIVER_DIAGNOSTICS
24-
};
25-
26-
#define DIAG_ENUM(ENUM_NAME) \
27-
namespace ENUM_NAME { \
28-
enum {
29-
#define DIAG_ENUM_ITEM(IDX, NAME) NAME = IDX,
30-
#define DIAG_ENUM_END() \
31-
} \
32-
; \
33-
}
34-
#include "clang/Basic/DiagnosticDriverEnums.inc"
35-
#undef DIAG_ENUM_END
36-
#undef DIAG_ENUM_ITEM
37-
#undef DIAG_ENUM
38-
} // end namespace diag
39-
40-
namespace diag_compat {
41-
#define DIAG_COMPAT_IDS_BEGIN() enum {
42-
#define DIAG_COMPAT_IDS_END() \
43-
} \
44-
;
45-
#define DIAG_COMPAT_ID(IDX, NAME, ...) NAME = IDX,
46-
#include "clang/Basic/DiagnosticDriverCompatIDs.inc"
47-
#undef DIAG_COMPAT_ID
48-
#undef DIAG_COMPAT_IDS_BEGIN
49-
#undef DIAG_COMPAT_IDS_END
50-
} // end namespace diag_compat
51-
} // end namespace clang
13+
#include "clang/Basic/DiagnosticDriverInterface.inc"
5214

5315
#endif // LLVM_CLANG_BASIC_DIAGNOSTICDRIVER_H

clang/include/clang/Basic/DiagnosticFrontend.h

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -10,44 +10,6 @@
1010
#define LLVM_CLANG_BASIC_DIAGNOSTICFRONTEND_H
1111

1212
#include "clang/Basic/Diagnostic.h"
13-
14-
namespace clang {
15-
namespace diag {
16-
enum {
17-
#define DIAG(ENUM, FLAGS, DEFAULT_MAPPING, DESC, GROUP, SFINAE, NOWERROR, \
18-
SHOWINSYSHEADER, SHOWINSYSMACRO, DEFERRABLE, CATEGORY) \
19-
ENUM,
20-
#define FRONTENDSTART
21-
#include "clang/Basic/DiagnosticFrontendKinds.inc"
22-
#undef DIAG
23-
NUM_BUILTIN_FRONTEND_DIAGNOSTICS
24-
};
25-
26-
#define DIAG_ENUM(ENUM_NAME) \
27-
namespace ENUM_NAME { \
28-
enum {
29-
#define DIAG_ENUM_ITEM(IDX, NAME) NAME = IDX,
30-
#define DIAG_ENUM_END() \
31-
} \
32-
; \
33-
}
34-
#include "clang/Basic/DiagnosticFrontendEnums.inc"
35-
#undef DIAG_ENUM_END
36-
#undef DIAG_ENUM_ITEM
37-
#undef DIAG_ENUM
38-
} // end namespace diag
39-
40-
namespace diag_compat {
41-
#define DIAG_COMPAT_IDS_BEGIN() enum {
42-
#define DIAG_COMPAT_IDS_END() \
43-
} \
44-
;
45-
#define DIAG_COMPAT_ID(IDX, NAME, ...) NAME = IDX,
46-
#include "clang/Basic/DiagnosticFrontendCompatIDs.inc"
47-
#undef DIAG_COMPAT_ID
48-
#undef DIAG_COMPAT_IDS_BEGIN
49-
#undef DIAG_COMPAT_IDS_END
50-
} // end namespace diag_compat
51-
} // end namespace clang
13+
#include "clang/Basic/DiagnosticFrontendInterface.inc"
5214

5315
#endif // LLVM_CLANG_BASIC_DIAGNOSTICFRONTEND_H

clang/include/clang/Basic/DiagnosticIDs.h

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -71,17 +71,6 @@ namespace clang {
7171
/// All of the diagnostics that can be emitted by the frontend.
7272
typedef unsigned kind;
7373

74-
// Get typedefs for common diagnostics.
75-
enum {
76-
#define DIAG(ENUM, FLAGS, DEFAULT_MAPPING, DESC, GROUP, SFINAE, CATEGORY, \
77-
NOWERROR, SHOWINSYSHEADER, SHOWINSYSMACRO, DEFFERABLE) \
78-
ENUM,
79-
#define COMMONSTART
80-
#include "clang/Basic/DiagnosticCommonKinds.inc"
81-
NUM_BUILTIN_COMMON_DIAGNOSTICS
82-
#undef DIAG
83-
};
84-
8574
/// Enum values that allow the client to map NOTEs, WARNINGs, and EXTENSIONs
8675
/// to either Ignore (nothing), Remark (emit a remark), Warning
8776
/// (emit a warning) or Error (emit as an error). It allows clients to
@@ -103,20 +92,13 @@ namespace clang {
10392
Remark ///< A diagnostic that indicates normal progress through
10493
///< compilation.
10594
};
106-
}
95+
} // end namespace diag
96+
} // end namespace clang
10797

108-
namespace diag_compat {
109-
#define DIAG_COMPAT_IDS_BEGIN() enum {
110-
#define DIAG_COMPAT_IDS_END() \
111-
} \
112-
;
113-
#define DIAG_COMPAT_ID(IDX, NAME, ...) NAME = IDX,
114-
#include "clang/Basic/DiagnosticCommonCompatIDs.inc"
115-
#undef DIAG_COMPAT_ID
116-
#undef DIAG_COMPAT_IDS_BEGIN
117-
#undef DIAG_COMPAT_IDS_END
118-
} // end namespace diag_compat
98+
// This has to be included *after* the DIAG_START_ enums above are defined.
99+
#include "clang/Basic/DiagnosticCommonInterface.inc"
119100

101+
namespace clang {
120102
class DiagnosticMapping {
121103
LLVM_PREFERRED_TYPE(diag::Severity)
122104
unsigned Severity : 3;

clang/include/clang/Basic/DiagnosticInstallAPI.h

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -10,42 +10,6 @@
1010
#define LLVM_CLANG_BASIC_DIAGNOSTICINSTALLAPI_H
1111

1212
#include "clang/Basic/Diagnostic.h"
13-
namespace clang {
14-
namespace diag {
15-
enum {
16-
#define DIAG(ENUM, FLAGS, DEFAULT_MAPPING, DESC, GROUP, SFINAE, NOWERROR, \
17-
SHOWINSYSHEADER, SHOWINSYSMACRO, DEFERRABLE, CATEGORY) \
18-
ENUM,
19-
#define INSTALLAPISTART
20-
#include "clang/Basic/DiagnosticInstallAPIKinds.inc"
21-
#undef DIAG
22-
NUM_BUILTIN_INSTALLAPI_DIAGNOSTICS
23-
};
13+
#include "clang/Basic/DiagnosticInstallAPIInterface.inc"
2414

25-
#define DIAG_ENUM(ENUM_NAME) \
26-
namespace ENUM_NAME { \
27-
enum {
28-
#define DIAG_ENUM_ITEM(IDX, NAME) NAME = IDX,
29-
#define DIAG_ENUM_END() \
30-
} \
31-
; \
32-
}
33-
#include "clang/Basic/DiagnosticInstallAPIEnums.inc"
34-
#undef DIAG_ENUM_END
35-
#undef DIAG_ENUM_ITEM
36-
#undef DIAG_ENUM
37-
} // namespace diag
38-
39-
namespace diag_compat {
40-
#define DIAG_COMPAT_IDS_BEGIN() enum {
41-
#define DIAG_COMPAT_IDS_END() \
42-
} \
43-
;
44-
#define DIAG_COMPAT_ID(IDX, NAME, ...) NAME = IDX,
45-
#include "clang/Basic/DiagnosticInstallAPICompatIDs.inc"
46-
#undef DIAG_COMPAT_ID
47-
#undef DIAG_COMPAT_IDS_BEGIN
48-
#undef DIAG_COMPAT_IDS_END
49-
} // end namespace diag_compat
50-
} // namespace clang
5115
#endif // LLVM_CLANG_BASIC_DIAGNOSTICINSTALLAPI_H

0 commit comments

Comments
 (0)