Skip to content

Commit 342e53f

Browse files
authored
Merge pull request #27795 from owenv/diag_macro_refactor
[Diagnostics] Move macros used in diagnostic definitions to their own header
2 parents 843a584 + fdb6eab commit 342e53f

12 files changed

+115
-333
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
//===--- DefineDiagnosticMacros.h - Shared Diagnostic Macros ----*- C++ -*-===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2020 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
//
13+
// This file defines macros shared across diagnostic definition files.
14+
//
15+
//===----------------------------------------------------------------------===//
16+
17+
// Define macros
18+
#ifdef DEFINE_DIAGNOSTIC_MACROS
19+
20+
#if !(defined(DIAG) || (defined(ERROR) && defined(WARNING) && defined(NOTE) && \
21+
defined(REMARK)))
22+
#error Must define either DIAG or the set {ERROR,WARNING,NOTE,REMARK}
23+
#endif
24+
25+
#ifndef ERROR
26+
#define ERROR(ID, Options, Text, Signature) \
27+
DIAG(ERROR, ID, Options, Text, Signature)
28+
#endif
29+
30+
#ifndef WARNING
31+
#define WARNING(ID, Options, Text, Signature) \
32+
DIAG(WARNING, ID, Options, Text, Signature)
33+
#endif
34+
35+
#ifndef NOTE
36+
#define NOTE(ID, Options, Text, Signature) \
37+
DIAG(NOTE, ID, Options, Text, Signature)
38+
#endif
39+
40+
#ifndef REMARK
41+
#define REMARK(ID, Options, Text, Signature) \
42+
DIAG(REMARK, ID, Options, Text, Signature)
43+
#endif
44+
45+
#ifndef FIXIT
46+
#define FIXIT(ID, Text, Signature)
47+
#endif
48+
49+
#undef DEFINE_DIAGNOSTIC_MACROS
50+
#endif
51+
52+
// Undefine macros
53+
#ifdef UNDEFINE_DIAGNOSTIC_MACROS
54+
55+
#ifndef DIAG_NO_UNDEF
56+
57+
#if defined(DIAG)
58+
#undef DIAG
59+
#endif
60+
61+
#undef REMARK
62+
#undef NOTE
63+
#undef WARNING
64+
#undef ERROR
65+
#undef FIXIT
66+
67+
#endif
68+
69+
#undef UNDEFINE_DIAGNOSTIC_MACROS
70+
#endif

include/swift/AST/DiagnosticsAll.def

Lines changed: 4 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -14,33 +14,8 @@
1414
//
1515
//===----------------------------------------------------------------------===//
1616

17-
#if !(defined(DIAG) || (defined(ERROR) && defined(WARNING) && defined(NOTE)))
18-
# error Must define either DIAG or the set {ERROR,WARNING,NOTE}
19-
#endif
20-
21-
#ifndef ERROR
22-
# define ERROR(ID,Options,Text,Signature) \
23-
DIAG(ERROR,ID,Options,Text,Signature)
24-
#endif
25-
26-
#ifndef WARNING
27-
# define WARNING(ID,Options,Text,Signature) \
28-
DIAG(WARNING,ID,Options,Text,Signature)
29-
#endif
30-
31-
#ifndef NOTE
32-
# define NOTE(ID,Options,Text,Signature) \
33-
DIAG(NOTE,ID,Options,Text,Signature)
34-
#endif
35-
36-
#ifndef REMARK
37-
# define REMARK(ID,Options,Text,Signature) \
38-
DIAG(REMARK,ID,Options,Text,Signature)
39-
#endif
40-
41-
#ifndef FIXIT
42-
# define FIXIT(ID, Text, Signature)
43-
#endif
17+
#define DEFINE_DIAGNOSTIC_MACROS
18+
#include "DefineDiagnosticMacros.h"
4419

4520
#define DIAG_NO_UNDEF
4621

@@ -57,11 +32,5 @@
5732

5833
#undef DIAG_NO_UNDEF
5934

60-
#if defined(DIAG)
61-
# undef DIAG
62-
#endif
63-
#undef NOTE
64-
#undef WARNING
65-
#undef ERROR
66-
#undef REMARK
67-
#undef FIXIT
35+
#define UNDEFINE_DIAGNOSTIC_MACROS
36+
#include "DefineDiagnosticMacros.h"

include/swift/AST/DiagnosticsClangImporter.def

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -17,29 +17,8 @@
1717
//
1818
//===----------------------------------------------------------------------===//
1919

20-
#if !(defined(DIAG) || (defined(ERROR) && defined(WARNING) && defined(NOTE) && defined(REMARK)))
21-
# error Must define either DIAG or the set {ERROR,WARNING,NOTE,REMARK}
22-
#endif
23-
24-
#ifndef ERROR
25-
# define ERROR(ID,Options,Text,Signature) \
26-
DIAG(ERROR,ID,Options,Text,Signature)
27-
#endif
28-
29-
#ifndef WARNING
30-
# define WARNING(ID,Options,Text,Signature) \
31-
DIAG(WARNING,ID,Options,Text,Signature)
32-
#endif
33-
34-
#ifndef NOTE
35-
# define NOTE(ID,Options,Text,Signature) \
36-
DIAG(NOTE,ID,Options,Text,Signature)
37-
#endif
38-
39-
#ifndef REMARK
40-
# define REMARK(ID,Options,Text,Signature) \
41-
DIAG(REMARK,ID,Options,Text,Signature)
42-
#endif
20+
#define DEFINE_DIAGNOSTIC_MACROS
21+
#include "DefineDiagnosticMacros.h"
4322

4423
WARNING(warning_from_clang,none,
4524
"%0", (StringRef))
@@ -101,12 +80,5 @@ WARNING(implicit_bridging_header_imported_from_module,none,
10180
"is deprecated and will be removed in a later version of Swift",
10281
(StringRef, Identifier))
10382

104-
#ifndef DIAG_NO_UNDEF
105-
# if defined(DIAG)
106-
# undef DIAG
107-
# endif
108-
# undef NOTE
109-
# undef WARNING
110-
# undef ERROR
111-
# undef REMARK
112-
#endif
83+
#define UNDEFINE_DIAGNOSTIC_MACROS
84+
#include "DefineDiagnosticMacros.h"

include/swift/AST/DiagnosticsCommon.def

Lines changed: 4 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -17,33 +17,8 @@
1717
//
1818
//===----------------------------------------------------------------------===//
1919

20-
#if !(defined(DIAG) || (defined(ERROR) && defined(WARNING) && defined(NOTE) && defined(REMARK)))
21-
# error Must define either DIAG or the set {ERROR,WARNING,NOTE,REMARK}
22-
#endif
23-
24-
#ifndef ERROR
25-
# define ERROR(ID,Options,Text,Signature) \
26-
DIAG(ERROR,ID,Options,Text,Signature)
27-
#endif
28-
29-
#ifndef WARNING
30-
# define WARNING(ID,Options,Text,Signature) \
31-
DIAG(WARNING,ID,Options,Text,Signature)
32-
#endif
33-
34-
#ifndef NOTE
35-
# define NOTE(ID,Options,Text,Signature) \
36-
DIAG(NOTE,ID,Options,Text,Signature)
37-
#endif
38-
39-
#ifndef REMARK
40-
# define REMARK(ID,Options,Text,Signature) \
41-
DIAG(REMARK,ID,Options,Text,Signature)
42-
#endif
43-
44-
#ifndef FIXIT
45-
# define FIXIT(ID, Text, Signature)
46-
#endif
20+
#define DEFINE_DIAGNOSTIC_MACROS
21+
#include "DefineDiagnosticMacros.h"
4722

4823
ERROR(invalid_diagnostic,none,
4924
"INTERNAL ERROR: this diagnostic should not be produced", ())
@@ -188,12 +163,5 @@ WARNING(cross_imported_by_both_modules, none,
188163
"please report this bug to the maintainers of these modules",
189164
(Identifier, Identifier, Identifier))
190165

191-
#ifndef DIAG_NO_UNDEF
192-
# if defined(DIAG)
193-
# undef DIAG
194-
# endif
195-
# undef NOTE
196-
# undef WARNING
197-
# undef ERROR
198-
# undef FIXIT
199-
#endif
166+
#define UNDEFINE_DIAGNOSTIC_MACROS
167+
#include "DefineDiagnosticMacros.h"

include/swift/AST/DiagnosticsDriver.def

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -18,29 +18,8 @@
1818
//
1919
//===----------------------------------------------------------------------===//
2020

21-
#if !(defined(DIAG) || (defined(ERROR) && defined(WARNING) && defined(NOTE)))
22-
# error Must define either DIAG or the set {ERROR,WARNING,NOTE}
23-
#endif
24-
25-
#ifndef ERROR
26-
# define ERROR(ID,Options,Text,Signature) \
27-
DIAG(ERROR,ID,Options,Text,Signature)
28-
#endif
29-
30-
#ifndef WARNING
31-
# define WARNING(ID,Options,Text,Signature) \
32-
DIAG(WARNING,ID,Options,Text,Signature)
33-
#endif
34-
35-
#ifndef NOTE
36-
# define NOTE(ID,Options,Text,Signature) \
37-
DIAG(NOTE,ID,Options,Text,Signature)
38-
#endif
39-
40-
#ifndef REMARK
41-
# define REMARK(ID,Options,Text,Signature) \
42-
DIAG(REMARK,ID,Options,Text,Signature)
43-
#endif
21+
#define DEFINE_DIAGNOSTIC_MACROS
22+
#include "DefineDiagnosticMacros.h"
4423

4524
WARNING(warning_parallel_execution_not_supported,none,
4625
"parallel execution not supported; falling back to serial execution",
@@ -211,11 +190,5 @@ WARNING(warn_drv_darwin_sdk_invalid_settings, none,
211190
"SDK settings were ignored because 'SDKSettings.json' could not be parsed",
212191
())
213192

214-
#ifndef DIAG_NO_UNDEF
215-
# if defined(DIAG)
216-
# undef DIAG
217-
# endif
218-
# undef NOTE
219-
# undef WARNING
220-
# undef ERROR
221-
#endif
193+
#define UNDEFINE_DIAGNOSTIC_MACROS
194+
#include "DefineDiagnosticMacros.h"

include/swift/AST/DiagnosticsFrontend.def

Lines changed: 4 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -18,30 +18,8 @@
1818
//
1919
//===----------------------------------------------------------------------===//
2020

21-
#if !(defined(DIAG) || (defined(ERROR) && defined(WARNING) && defined(NOTE) && \
22-
defined(REMARK)))
23-
# error Must define either DIAG or the set {ERROR,WARNING,NOTE,REMARK}
24-
#endif
25-
26-
#ifndef ERROR
27-
# define ERROR(ID,Options,Text,Signature) \
28-
DIAG(ERROR,ID,Options,Text,Signature)
29-
#endif
30-
31-
#ifndef WARNING
32-
# define WARNING(ID,Options,Text,Signature) \
33-
DIAG(WARNING,ID,Options,Text,Signature)
34-
#endif
35-
36-
#ifndef NOTE
37-
# define NOTE(ID,Options,Text,Signature) \
38-
DIAG(NOTE,ID,Options,Text,Signature)
39-
#endif
40-
41-
#ifndef REMARK
42-
# define REMARK(ID,Options,Text,Signature) \
43-
DIAG(REMARK,ID,Options,Text,Signature)
44-
#endif
21+
#define DEFINE_DIAGNOSTIC_MACROS
22+
#include "DefineDiagnosticMacros.h"
4523

4624
WARNING(warning_no_such_sdk,none,
4725
"no such SDK: '%0'", (StringRef))
@@ -407,12 +385,5 @@ ERROR(expectation_missing_opening_braces,none,
407385
ERROR(expectation_missing_closing_braces,none,
408386
"didn't find '}}' to match '{{' in expectation", ())
409387

410-
#ifndef DIAG_NO_UNDEF
411-
# if defined(DIAG)
412-
# undef DIAG
413-
# endif
414-
# undef REMARK
415-
# undef NOTE
416-
# undef WARNING
417-
# undef ERROR
418-
#endif
388+
#define UNDEFINE_DIAGNOSTIC_MACROS
389+
#include "DefineDiagnosticMacros.h"

include/swift/AST/DiagnosticsIRGen.def

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,8 @@
1717
//
1818
//===----------------------------------------------------------------------===//
1919

20-
#if !(defined(DIAG) || (defined(ERROR) && defined(WARNING) && defined(NOTE)))
21-
# error Must define either DIAG or the set {ERROR,WARNING,NOTE}
22-
#endif
23-
24-
#ifndef ERROR
25-
# define ERROR(ID,Options,Text,Signature) \
26-
DIAG(ERROR,ID,Options,Text,Signature)
27-
#endif
28-
29-
#ifndef WARNING
30-
# define WARNING(ID,Options,Text,Signature) \
31-
DIAG(WARNING,ID,Options,Text,Signature)
32-
#endif
33-
34-
#ifndef NOTE
35-
# define NOTE(ID,Options,Text,Signature) \
36-
DIAG(NOTE,ID,Options,Text,Signature)
37-
#endif
38-
20+
#define DEFINE_DIAGNOSTIC_MACROS
21+
#include "DefineDiagnosticMacros.h"
3922

4023
ERROR(no_llvm_target,none,
4124
"error loading LLVM target for triple '%0': %1", (StringRef, StringRef))
@@ -67,11 +50,5 @@ ERROR(alignment_more_than_maximum,none,
6750
"@_alignment cannot increase alignment above maximum alignment of %0",
6851
(unsigned))
6952

70-
#ifndef DIAG_NO_UNDEF
71-
# if defined(DIAG)
72-
# undef DIAG
73-
# endif
74-
# undef NOTE
75-
# undef WARNING
76-
# undef ERROR
77-
#endif
53+
#define UNDEFINE_DIAGNOSTIC_MACROS
54+
#include "DefineDiagnosticMacros.h"

include/swift/AST/DiagnosticsModuleDiffer.def

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,8 @@
1717
//
1818
//===----------------------------------------------------------------------===//
1919

20-
#if !(defined(DIAG) || (defined(ERROR) && defined(WARNING) && defined(NOTE)))
21-
# error Must define either DIAG or the set {ERROR,WARNING,NOTE}
22-
#endif
23-
24-
#ifndef ERROR
25-
# define ERROR(ID,Options,Text,Signature) \
26-
DIAG(ERROR,ID,Options,Text,Signature)
27-
#endif
28-
29-
#ifndef WARNING
30-
# define WARNING(ID,Options,Text,Signature) \
31-
DIAG(WARNING,ID,Options,Text,Signature)
32-
#endif
33-
34-
#ifndef NOTE
35-
# define NOTE(ID,Options,Text,Signature) \
36-
DIAG(NOTE,ID,Options,Text,Signature)
37-
#endif
20+
#define DEFINE_DIAGNOSTIC_MACROS
21+
#include "DefineDiagnosticMacros.h"
3822

3923
ERROR(generic_sig_change,none,"%0 has generic signature change from %1 to %2", (StringRef, StringRef, StringRef))
4024

@@ -104,11 +88,5 @@ ERROR(not_inheriting_convenience_inits,none,"%0 no longer inherits convenience i
10488

10589
ERROR(enum_case_added,none,"%0 has been added as a new enum case", (StringRef))
10690

107-
#ifndef DIAG_NO_UNDEF
108-
# if defined(DIAG)
109-
# undef DIAG
110-
# endif
111-
# undef NOTE
112-
# undef WARNING
113-
# undef ERROR
114-
#endif
91+
#define UNDEFINE_DIAGNOSTIC_MACROS
92+
#include "DefineDiagnosticMacros.h"

0 commit comments

Comments
 (0)