Skip to content

Commit 5e9fba1

Browse files
committed
NFC: provide deprecation & unavailable attribute macros
1 parent b30f635 commit 5e9fba1

File tree

1 file changed

+81
-0
lines changed

1 file changed

+81
-0
lines changed
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
//===--- AccessControls.h ---------------------------------------*- C++ -*-===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2025 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 that help control access to APIs.
14+
//
15+
//===----------------------------------------------------------------------===//
16+
17+
#ifndef SWIFT_ACCESSCONTROLS_H
18+
#define SWIFT_ACCESSCONTROLS_H
19+
20+
/// Deprecation warnings
21+
#if defined(__clang__) || defined(__GNUC__)
22+
#if !defined(SWIFT_DEPRECATED)
23+
#define SWIFT_DEPRECATED __attribute__((deprecated))
24+
#endif
25+
#if !defined(SWIFT_DEPRECATED_MSG)
26+
#define SWIFT_DEPRECATED_MSG(...) __attribute__((deprecated(__VA_ARGS__)))
27+
#endif
28+
#else
29+
#if !defined(SWIFT_DEPRECATED)
30+
#define SWIFT_DEPRECATED
31+
#endif
32+
#if !defined(SWIFT_DEPRECATED_MSG)
33+
#define SWIFT_DEPRECATED_MSG(...)
34+
#endif
35+
#endif
36+
37+
38+
/// Unavailable errors
39+
#if defined(__clang__) || defined(__GNUC__)
40+
#if !defined(SWIFT_UNAVAILABLE)
41+
#define SWIFT_UNAVAILABLE __attribute__((unavailable))
42+
#endif
43+
#if !defined(SWIFT_UNAVAILABLE_MSG)
44+
#define SWIFT_UNAVAILABLE_MSG(msg) __attribute__((unavailable(msg)))
45+
#endif
46+
#else
47+
#if !defined(SWIFT_UNAVAILABLE)
48+
#define SWIFT_UNAVAILABLE
49+
#endif
50+
#if !defined(SWIFT_UNAVAILABLE_MSG)
51+
#define SWIFT_UNAVAILABLE_MSG(msg)
52+
#endif
53+
#endif
54+
55+
56+
// Access controls that are only active when included in SILGen sources.
57+
#if defined(SWIFT_INCLUDED_IN_SILGEN_SOURCES)
58+
59+
// Override any prior definitions with these.
60+
#define SWIFT_DEPRECATED_IN_SILGEN SWIFT_DEPRECATED
61+
#define SWIFT_DEPRECATED_IN_SILGEN_MSG(...) SWIFT_DEPRECATED_MSG(__VA_ARGS__)
62+
#define SWIFT_UNAVAILABLE_IN_SILGEN SWIFT_UNAVAILABLE
63+
#define SWIFT_UNAVAILABLE_IN_SILGEN_MSG(MSG) SWIFT_UNAVAILABLE_MSG(MSG)
64+
65+
#else
66+
67+
#if !defined(SWIFT_DEPRECATED_IN_SILGEN)
68+
#define SWIFT_DEPRECATED_IN_SILGEN
69+
#endif
70+
#if !defined(SWIFT_DEPRECATED_IN_SILGEN_MSG)
71+
#define SWIFT_DEPRECATED_IN_SILGEN_MSG(...)
72+
#endif
73+
#if !defined(SWIFT_UNAVAILABLE_IN_SILGEN)
74+
#define SWIFT_UNAVAILABLE_IN_SILGEN
75+
#endif
76+
#if !defined(SWIFT_UNAVAILABLE_IN_SILGEN_MSG)
77+
#define SWIFT_UNAVAILABLE_IN_SILGEN_MSG(MSG)
78+
#endif
79+
#endif // SWIFT_INCLUDED_IN_SILGEN_SOURCES
80+
81+
#endif // SWIFT_ACCESSCONTROLS_H

0 commit comments

Comments
 (0)