Skip to content

Commit 54c90be

Browse files
committed
[NFC][Diagnostics] Reformat DiagnosticIDs.h and AllDiagnostics.h (llvm#154628)
When trying to add a new diagnostic category (e.g. llvm#154618) I discovered `clang-format` really wanted to reformat these files. My initial attempt was just to suppress the reformatting with `// clang-format (on|off)` directives but reviewers preferred just reformatting the files so these two files have been completely reformatted. `clang-format` has been disabled for the enum that declares the `DIAG_START_*` constants because its much less readable after formatting. (cherry picked from commit 0961200) Conflicts: clang/include/clang/Basic/DiagnosticIDs.h
1 parent 582ce5e commit 54c90be

File tree

2 files changed

+82
-79
lines changed

2 files changed

+82
-79
lines changed

clang/include/clang/Basic/AllDiagnostics.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,20 @@
2424
#include "clang/Basic/DiagnosticInstallAPI.h"
2525
#include "clang/Basic/DiagnosticLex.h"
2626
#include "clang/Basic/DiagnosticParse.h"
27+
#include "clang/Basic/DiagnosticRefactoring.h"
2728
#include "clang/Basic/DiagnosticSema.h"
2829
#include "clang/Basic/DiagnosticSerialization.h"
29-
#include "clang/Basic/DiagnosticRefactoring.h"
3030

3131
namespace clang {
32-
template <size_t SizeOfStr, typename FieldType>
33-
class StringSizerHelper {
32+
template <size_t SizeOfStr, typename FieldType> class StringSizerHelper {
3433
static_assert(SizeOfStr <= FieldType(~0U), "Field too small!");
34+
3535
public:
3636
enum { Size = SizeOfStr };
3737
};
3838
} // end namespace clang
3939

40-
#define STR_SIZE(str, fieldTy) clang::StringSizerHelper<sizeof(str)-1, \
41-
fieldTy>::Size
40+
#define STR_SIZE(str, fieldTy) \
41+
clang::StringSizerHelper<sizeof(str) - 1, fieldTy>::Size
4242

4343
#endif

clang/include/clang/Basic/DiagnosticIDs.h

Lines changed: 77 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -23,78 +23,80 @@
2323
#include <vector>
2424

2525
namespace clang {
26-
class DiagnosticsEngine;
27-
class DiagnosticBuilder;
28-
class LangOptions;
29-
class SourceLocation;
30-
31-
// Import the diagnostic enums themselves.
32-
namespace diag {
33-
enum class Group;
34-
35-
// Size of each of the diagnostic categories.
36-
enum {
37-
DIAG_SIZE_COMMON = 300,
38-
DIAG_SIZE_DRIVER = 400,
39-
DIAG_SIZE_FRONTEND = 200,
40-
DIAG_SIZE_SERIALIZATION = 120,
41-
DIAG_SIZE_LEX = 500,
42-
DIAG_SIZE_PARSE = 800,
43-
DIAG_SIZE_AST = 300,
44-
DIAG_SIZE_COMMENT = 100,
45-
DIAG_SIZE_CROSSTU = 100,
46-
DIAG_SIZE_SEMA = 5000,
47-
DIAG_SIZE_ANALYSIS = 100,
48-
DIAG_SIZE_REFACTORING = 1000,
49-
DIAG_SIZE_INSTALLAPI = 100,
50-
DIAG_SIZE_CAS = 100,
51-
};
52-
// Start position for diagnostics.
53-
enum {
54-
DIAG_START_COMMON = 0,
55-
DIAG_START_DRIVER = DIAG_START_COMMON + static_cast<int>(DIAG_SIZE_COMMON),
56-
DIAG_START_FRONTEND = DIAG_START_DRIVER + static_cast<int>(DIAG_SIZE_DRIVER),
57-
DIAG_START_SERIALIZATION = DIAG_START_FRONTEND + static_cast<int>(DIAG_SIZE_FRONTEND),
58-
DIAG_START_LEX = DIAG_START_SERIALIZATION + static_cast<int>(DIAG_SIZE_SERIALIZATION),
59-
DIAG_START_PARSE = DIAG_START_LEX + static_cast<int>(DIAG_SIZE_LEX),
60-
DIAG_START_AST = DIAG_START_PARSE + static_cast<int>(DIAG_SIZE_PARSE),
61-
DIAG_START_COMMENT = DIAG_START_AST + static_cast<int>(DIAG_SIZE_AST),
62-
DIAG_START_CROSSTU = DIAG_START_COMMENT + static_cast<int>(DIAG_SIZE_COMMENT),
63-
DIAG_START_SEMA = DIAG_START_CROSSTU + static_cast<int>(DIAG_SIZE_CROSSTU),
64-
DIAG_START_ANALYSIS = DIAG_START_SEMA + static_cast<int>(DIAG_SIZE_SEMA),
65-
DIAG_START_REFACTORING = DIAG_START_ANALYSIS + static_cast<int>(DIAG_SIZE_ANALYSIS),
66-
DIAG_START_INSTALLAPI = DIAG_START_REFACTORING + static_cast<int>(DIAG_SIZE_REFACTORING),
67-
DIAG_START_CAS = DIAG_START_INSTALLAPI + static_cast<int>(DIAG_START_INSTALLAPI),
68-
DIAG_UPPER_LIMIT = DIAG_START_CAS + static_cast<int>(DIAG_SIZE_CAS)
69-
};
70-
71-
class CustomDiagInfo;
72-
73-
/// All of the diagnostics that can be emitted by the frontend.
74-
typedef unsigned kind;
75-
76-
/// Enum values that allow the client to map NOTEs, WARNINGs, and EXTENSIONs
77-
/// to either Ignore (nothing), Remark (emit a remark), Warning
78-
/// (emit a warning) or Error (emit as an error). It allows clients to
79-
/// map ERRORs to Error or Fatal (stop emitting diagnostics after this one).
80-
enum class Severity : uint8_t {
81-
// NOTE: 0 means "uncomputed".
82-
Ignored = 1, ///< Do not present this diagnostic, ignore it.
83-
Remark = 2, ///< Present this diagnostic as a remark.
84-
Warning = 3, ///< Present this diagnostic as a warning.
85-
Error = 4, ///< Present this diagnostic as an error.
86-
Fatal = 5 ///< Present this diagnostic as a fatal error.
87-
};
88-
89-
/// Flavors of diagnostics we can emit. Used to filter for a particular
90-
/// kind of diagnostic (for instance, for -W/-R flags).
91-
enum class Flavor {
92-
WarningOrError, ///< A diagnostic that indicates a problem or potential
93-
///< problem. Can be made fatal by -Werror.
94-
Remark ///< A diagnostic that indicates normal progress through
95-
///< compilation.
96-
};
97-
} // end namespace diag
26+
class DiagnosticsEngine;
27+
class DiagnosticBuilder;
28+
class LangOptions;
29+
class SourceLocation;
30+
31+
// Import the diagnostic enums themselves.
32+
namespace diag {
33+
enum class Group;
34+
35+
// Size of each of the diagnostic categories.
36+
enum {
37+
DIAG_SIZE_COMMON = 300,
38+
DIAG_SIZE_DRIVER = 400,
39+
DIAG_SIZE_FRONTEND = 200,
40+
DIAG_SIZE_SERIALIZATION = 120,
41+
DIAG_SIZE_LEX = 500,
42+
DIAG_SIZE_PARSE = 800,
43+
DIAG_SIZE_AST = 300,
44+
DIAG_SIZE_COMMENT = 100,
45+
DIAG_SIZE_CROSSTU = 100,
46+
DIAG_SIZE_SEMA = 5000,
47+
DIAG_SIZE_ANALYSIS = 100,
48+
DIAG_SIZE_REFACTORING = 1000,
49+
DIAG_SIZE_INSTALLAPI = 100,
50+
DIAG_SIZE_CAS = 100,
51+
};
52+
// Start position for diagnostics.
53+
// clang-format off
54+
enum {
55+
DIAG_START_COMMON = 0,
56+
DIAG_START_DRIVER = DIAG_START_COMMON + static_cast<int>(DIAG_SIZE_COMMON),
57+
DIAG_START_FRONTEND = DIAG_START_DRIVER + static_cast<int>(DIAG_SIZE_DRIVER),
58+
DIAG_START_SERIALIZATION = DIAG_START_FRONTEND + static_cast<int>(DIAG_SIZE_FRONTEND),
59+
DIAG_START_LEX = DIAG_START_SERIALIZATION + static_cast<int>(DIAG_SIZE_SERIALIZATION),
60+
DIAG_START_PARSE = DIAG_START_LEX + static_cast<int>(DIAG_SIZE_LEX),
61+
DIAG_START_AST = DIAG_START_PARSE + static_cast<int>(DIAG_SIZE_PARSE),
62+
DIAG_START_COMMENT = DIAG_START_AST + static_cast<int>(DIAG_SIZE_AST),
63+
DIAG_START_CROSSTU = DIAG_START_COMMENT + static_cast<int>(DIAG_SIZE_COMMENT),
64+
DIAG_START_SEMA = DIAG_START_CROSSTU + static_cast<int>(DIAG_SIZE_CROSSTU),
65+
DIAG_START_ANALYSIS = DIAG_START_SEMA + static_cast<int>(DIAG_SIZE_SEMA),
66+
DIAG_START_REFACTORING = DIAG_START_ANALYSIS + static_cast<int>(DIAG_SIZE_ANALYSIS),
67+
DIAG_START_INSTALLAPI = DIAG_START_REFACTORING + static_cast<int>(DIAG_SIZE_REFACTORING),
68+
DIAG_START_CAS = DIAG_START_INSTALLAPI + static_cast<int>(DIAG_SIZE_INSTALLAPI),
69+
DIAG_UPPER_LIMIT = DIAG_START_CAS + static_cast<int>(DIAG_SIZE_CAS)
70+
};
71+
// clang-format on
72+
73+
class CustomDiagInfo;
74+
75+
/// All of the diagnostics that can be emitted by the frontend.
76+
typedef unsigned kind;
77+
78+
/// Enum values that allow the client to map NOTEs, WARNINGs, and EXTENSIONs
79+
/// to either Ignore (nothing), Remark (emit a remark), Warning
80+
/// (emit a warning) or Error (emit as an error). It allows clients to
81+
/// map ERRORs to Error or Fatal (stop emitting diagnostics after this one).
82+
enum class Severity : uint8_t {
83+
// NOTE: 0 means "uncomputed".
84+
Ignored = 1, ///< Do not present this diagnostic, ignore it.
85+
Remark = 2, ///< Present this diagnostic as a remark.
86+
Warning = 3, ///< Present this diagnostic as a warning.
87+
Error = 4, ///< Present this diagnostic as an error.
88+
Fatal = 5 ///< Present this diagnostic as a fatal error.
89+
};
90+
91+
/// Flavors of diagnostics we can emit. Used to filter for a particular
92+
/// kind of diagnostic (for instance, for -W/-R flags).
93+
enum class Flavor {
94+
WarningOrError, ///< A diagnostic that indicates a problem or potential
95+
///< problem. Can be made fatal by -Werror.
96+
Remark ///< A diagnostic that indicates normal progress through
97+
///< compilation.
98+
};
99+
} // end namespace diag
98100
} // end namespace clang
99101

100102
// This has to be included *after* the DIAG_START_ enums above are defined.
@@ -175,7 +177,8 @@ class DiagnosticMapping {
175177

176178
/// Used for handling and querying diagnostic IDs.
177179
///
178-
/// Can be used and shared by multiple Diagnostics for multiple translation units.
180+
/// Can be used and shared by multiple Diagnostics for multiple translation
181+
/// units.
179182
class DiagnosticIDs : public RefCountedBase<DiagnosticIDs> {
180183
public:
181184
/// The level of the diagnostic, after it has been through mapping.
@@ -496,6 +499,6 @@ class DiagnosticIDs : public RefCountedBase<DiagnosticIDs> {
496499
friend class DiagnosticsEngine;
497500
};
498501

499-
} // end namespace clang
502+
} // end namespace clang
500503

501504
#endif

0 commit comments

Comments
 (0)