Skip to content

Commit 6e96aa6

Browse files
install a list of symbols generated by the PrintAsClang header
rdar://93504690
1 parent 5b8cd58 commit 6e96aa6

File tree

5 files changed

+382
-187
lines changed

5 files changed

+382
-187
lines changed
Lines changed: 226 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,226 @@
1+
//===--- ClangMacros.def - Macros emitted by PrintAsClang ----=--*- C++ -*-===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2022 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 the database of macros emitted into compatibility headers
14+
// generated by PrintAsClang.
15+
//
16+
//===----------------------------------------------------------------------===//
17+
18+
// CLANG_MACRO(NAME, ARGS, VALUE)
19+
// A simple name/value macro that does not depend on a condition.
20+
#ifndef CLANG_MACRO
21+
#define CLANG_MACRO(NAME, ARGS, VALUE)
22+
#endif
23+
24+
// CLANG_MACRO_BODY(NAME, BODY)
25+
// A macro conditionalized on the name, but that defines a helper macro or
26+
// other kind of additional definitions other than the macro itself.
27+
#ifndef CLANG_MACRO_BODY
28+
#define CLANG_MACRO_BODY(NAME, BODY)
29+
#endif
30+
31+
// CLANG_MACRO_DEFINED(NAME)
32+
// Used to signal that a macro is defined by another CLANG_MACRO_BODY call.
33+
// This is included so that these macros can be included in the generated
34+
// `compatibility_symbols` file.
35+
#ifndef CLANG_MACRO_DEFINED
36+
#define CLANG_MACRO_DEFINED(NAME)
37+
#endif
38+
39+
// CLANG_MACRO_ALTERNATIVE(NAME, ARGS, CONDITION, VALUE, ALTERNATIVE)
40+
// A simple name/value macro that evaluates to the given value when the given
41+
// condition is true, or to the alternative value when it is false.
42+
#ifndef CLANG_MACRO_ALTERNATIVE
43+
#define CLANG_MACRO_ALTERNATIVE(NAME, ARGS, CONDITION, VALUE, ALTERNATIVE)
44+
#endif
45+
46+
// CLANG_MACRO_CONDITIONAL(NAME, ARGS, CONDITION, VALUE)
47+
// A simple name/value macro that only evaluates to the given value when the
48+
// given condition is true. Otherwise the macro will evaluate to nothing.
49+
#ifndef CLANG_MACRO_CONDITIONAL
50+
#define CLANG_MACRO_CONDITIONAL(NAME, ARGS, CONDITION, VALUE) \
51+
CLANG_MACRO_ALTERNATIVE(NAME, ARGS, CONDITION, VALUE, )
52+
#endif
53+
54+
// CLANG_MACRO_OBJC(NAME, ARGS, VALUE)
55+
// A simple name/value macro that is only defined when being compiled as
56+
// Objective-C.
57+
#ifndef CLANG_MACRO_OBJC
58+
#define CLANG_MACRO_OBJC(NAME, ARGS, VALUE)
59+
#endif
60+
61+
// CLANG_MACRO_CXX(NAME, ARGS, VALUE, ALTERNATIVE)
62+
// A simple name/value macro that evaluates to the given value when being
63+
// compiled as C++, or as the alternative when not.
64+
#ifndef CLANG_MACRO_CXX
65+
#define CLANG_MACRO_CXX(NAME, ARGS, VALUE, ALTERNATIVE)
66+
#endif
67+
68+
// CLANG_MACRO_CXX_BODY(NAME, BODY)
69+
// A complex macro conditionalized on whether the source is being compiled as
70+
// C++.
71+
#ifndef CLANG_MACRO_CXX_BODY
72+
#define CLANG_MACRO_CXX_BODY(NAME, BODY)
73+
#endif
74+
75+
CLANG_MACRO_BODY("SWIFT_PASTE", \
76+
"# define SWIFT_PASTE_HELPER(x, y) x##y\n" \
77+
"# define SWIFT_PASTE(x, y) SWIFT_PASTE_HELPER(x, y)")
78+
CLANG_MACRO_DEFINED("SWIFT_PASTE_HELPER")
79+
80+
CLANG_MACRO("SWIFT_METATYPE", "(X)", "Class")
81+
82+
CLANG_MACRO_CONDITIONAL("SWIFT_CLASS_PROPERTY", \
83+
"(...)", \
84+
"__has_feature(objc_class_property)", \
85+
"__VA_ARGS__")
86+
87+
CLANG_MACRO_CONDITIONAL("SWIFT_RUNTIME_NAME", \
88+
"(X)", \
89+
"__has_attribute(objc_runtime_name)", \
90+
"__attribute__((objc_runtime_name(X)))")
91+
92+
CLANG_MACRO_CONDITIONAL("SWIFT_COMPILE_NAME", \
93+
"(X)", \
94+
"__has_attribute(swift_name)", \
95+
"__attribute__((swift_name(X)))")
96+
97+
CLANG_MACRO_CONDITIONAL("SWIFT_METHOD_FAMILY", \
98+
"(X)", \
99+
"__has_attribute(objc_method_family)",
100+
"__attribute__((objc_method_family(X)))")
101+
102+
CLANG_MACRO_CONDITIONAL("SWIFT_NOESCAPE", , \
103+
"__has_attribute(noescape)", \
104+
"__attribute__((noescape))")
105+
106+
CLANG_MACRO_CONDITIONAL("SWIFT_RELEASES_ARGUMENT", , \
107+
"__has_attribute(ns_consumed)", \
108+
"__attribute__((ns_consumed))")
109+
110+
CLANG_MACRO_CONDITIONAL("SWIFT_WARN_UNUSED_RESULT", , \
111+
"__has_attribute(warn_unused_result)", \
112+
"__attribute__((warn_unused_result))")
113+
114+
CLANG_MACRO_CONDITIONAL("SWIFT_NORETURN", , \
115+
"__has_attribute(noreturn)", \
116+
"__attribute__((noreturn))")
117+
118+
CLANG_MACRO("SWIFT_CLASS_EXTRA", , )
119+
CLANG_MACRO("SWIFT_PROTOCOL_EXTRA", , )
120+
CLANG_MACRO("SWIFT_ENUM_EXTRA", , )
121+
122+
CLANG_MACRO_BODY("SWIFT_CLASS", \
123+
"# if __has_attribute(objc_subclassing_restricted)\n" \
124+
"# define SWIFT_CLASS(SWIFT_NAME) " \
125+
"SWIFT_RUNTIME_NAME(SWIFT_NAME) __attribute__((objc_subclassing_restricted)) " \
126+
"SWIFT_CLASS_EXTRA\n" \
127+
"# define SWIFT_CLASS_NAMED(SWIFT_NAME) " \
128+
"__attribute((objc_subclassing_restricted)) SWIFT_COMPILE_NAME(SWIFT_NAME) " \
129+
"SWIFT_CLASS_EXTRA\n" \
130+
"# else\n" \
131+
"# define SWIFT_CLASS(SWIFT_NAME) " \
132+
"SWIFT_RUNTIME_NAME(SWIFT_NAME) SWIFT_CLASS_EXTRA\n" \
133+
"# define SWIFT_CLASS_NAMED(SWIFT_NAME) " \
134+
"SWIFT_COMPILE_NAME(SWIFT_NAME) SWIFT_CLASS_EXTRA\n" \
135+
"# endif")
136+
CLANG_MACRO_DEFINED("SWIFT_CLASS_NAMED")
137+
138+
CLANG_MACRO_BODY("SWIFT_RESILIENT_CLASS", \
139+
"# if __has_attribute(objc_class_stub)\n" \
140+
"# define SWIFT_RESILIENT_CLASS(SWIFT_NAME) " \
141+
"SWIFT_CLASS(SWIFT_NAME) __attribute__((objc_class_stub))\n" \
142+
"# define SWIFT_RESILIENT_CLASS_NAMED(SWIFT_NAME) " \
143+
"__attribute__((objc_class_stub)) SWIFT_CLASS_NAMED(SWIFT_NAME)\n" \
144+
"# else\n" \
145+
"# define SWIFT_RESILIENT_CLASS(SWIFT_NAME) SWIFT_CLASS(SWIFT_NAME)\n" \
146+
"# define SWIFT_RESILIENT_CLASS_NAMED(SWIFT_NAME) SWIFT_CLASS_NAMED(SWIFT_NAME)\n" \
147+
"# endif")
148+
CLANG_MACRO_DEFINED("SWIFT_RESILIENT_CLASS_NAMED")
149+
150+
CLANG_MACRO_BODY("SWIFT_PROTOCOL", \
151+
"# define SWIFT_PROTOCOL(SWIFT_NAME) " \
152+
"SWIFT_RUNTIME_NAME(SWIFT_NAME) SWIFT_PROTOCOL_EXTRA\n" \
153+
"# define SWIFT_PROTOCOL_NAMED(SWIFT_NAME) " \
154+
"SWIFT_COMPILE_NAME(SWIFT_NAME) SWIFT_PROTOCOL_EXTRA")
155+
CLANG_MACRO_DEFINED("SWIFT_PROTOCOL_NAMED")
156+
157+
CLANG_MACRO("SWIFT_EXTENSION", "(M)", "SWIFT_PASTE(M##_Swift_, __LINE__)")
158+
159+
CLANG_MACRO_CONDITIONAL("OBJC_DESIGNATED_INITIALIZER", , \
160+
"__has_attribute(objc_designated_initializer)", \
161+
"__attribute__((objc_designated_initializer))")
162+
163+
CLANG_MACRO_CONDITIONAL("SWIFT_ENUM_ATTR", "(_extensibility)", \
164+
"__has_attribute(enum_extensibility)", \
165+
"__attribute__((enum_extensibility(_extensibility)))")
166+
167+
CLANG_MACRO_BODY("SWIFT_ENUM", \
168+
"# define SWIFT_ENUM(_type, _name, _extensibility) " \
169+
"enum _name : _type _name; " \
170+
"enum SWIFT_ENUM_ATTR(_extensibility) SWIFT_ENUM_EXTRA _name: _type\n" \
171+
"# if __has_feature(generalized_swift_name)\n" \
172+
"# define SWIFT_ENUM_NAMED(_type, _name, SWIFT_NAME, _extensibility) " \
173+
"enum _name : _type _name SWIFT_COMPILE_NAME(SWIFT_NAME); " \
174+
"enum SWIFT_COMPILE_NAME(SWIFT_NAME) SWIFT_ENUM_ATTR(_extensibility) " \
175+
"SWIFT_ENUM_EXTRA _name : _type\n" \
176+
"# else\n" \
177+
"# define SWIFT_ENUM_NAMED(_type, _name, SWIFT_NAME, _extensibility) " \
178+
"SWIFT_ENUM(_type, _name, _extensibility)\n" \
179+
"# endif")
180+
181+
CLANG_MACRO("SWIFT_UNAVAILABLE", , "__attribute__((unavailable))")
182+
CLANG_MACRO("SWIFT_UNAVAILABLE_MSG", "(msg)", "__attribute__((unavailable(msg)))")
183+
184+
CLANG_MACRO("SWIFT_AVAILABILITY", "(plat, ...)", "__attribute__((availability(plat, __VA_ARGS__)))")
185+
186+
CLANG_MACRO("SWIFT_WEAK_IMPORT", , "__attribute__((weak_import))")
187+
188+
CLANG_MACRO("SWIFT_DEPRECATED", , "__attribute__((deprecated))")
189+
CLANG_MACRO("SWIFT_DEPRECATED_MSG", "(...)", "__attribute__((deprecated(__VA_ARGS__)))")
190+
191+
CLANG_MACRO_ALTERNATIVE("SWIFT_DEPRECATED_OBJC", "(Msg)", \
192+
"__has_feature(attribute_diagnost_if_objc)", \
193+
"__attribute__((diagnose_if(1, Msg, \"warning\")))", \
194+
"SWIFT_DEPRECATED_MSG(Msg)")
195+
196+
CLANG_MACRO_OBJC("IBSegueAction", , )
197+
198+
CLANG_MACRO_BODY("SWIFT_EXTERN", \
199+
"# if defined(__cplusplus)\n" \
200+
"# define SWIFT_EXTERN extern \"C\"\n" \
201+
"# else\n" \
202+
"# define SWIFT_EXTERN extern\n"
203+
"# endif")
204+
205+
CLANG_MACRO("SWIFT_CALL", , "__attribute__((swiftcall))")
206+
207+
CLANG_MACRO("SWIFT_INDIRECT_RESULT", , "__attribute__((swift_indirect_result))")
208+
209+
CLANG_MACRO("SWIFT_CONTEXT", , "__attribute__((swift_context))")
210+
211+
CLANG_MACRO("SWIFT_ERROR_RESULT", , "__attribute__((swift_error_result))")
212+
213+
// The expansion of this depends on whether stdlib is built as a dynamic library, so do that print
214+
// in PrintAsClang.cpp instead of here since it can't be done in a preprocessor macro
215+
CLANG_MACRO_DEFINED("SWIFT_IMPORT_STDLIB_SYMBOL")
216+
217+
CLANG_MACRO_CXX("SWIFT_NOEXCEPT", , "noexcept", )
218+
219+
#undef CLANG_MACRO
220+
#undef CLANG_MACRO_BODY
221+
#undef CLANG_MACRO_DEFINED
222+
#undef CLANG_MACRO_ALTERNATIVE
223+
#undef CLANG_MACRO_CONDITIONAL
224+
#undef CLANG_MACRO_OBJC
225+
#undef CLANG_MACRO_CXX
226+
#undef CLANG_MACRO_CXX_BODY

0 commit comments

Comments
 (0)