clang  19.0.0git
Availability.h
Go to the documentation of this file.
1 //===--- Availability.h - Classes for availability --------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This files defines some classes that implement availability checking.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_CLANG_AST_AVAILABILITY_H
14 #define LLVM_CLANG_AST_AVAILABILITY_H
15 
17 #include "llvm/ADT/SmallString.h"
18 #include "llvm/ADT/StringRef.h"
19 #include "llvm/Support/VersionTuple.h"
20 
21 namespace clang {
22 
23 /// One specifier in an @available expression.
24 ///
25 /// \code
26 /// @available(macos 10.10, *)
27 /// \endcode
28 ///
29 /// Here, 'macos 10.10' and '*' both map to an instance of this type.
30 ///
32  /// Represents the version that this specifier requires. If the host OS
33  /// version is greater than or equal to Version, the @available will evaluate
34  /// to true.
35  VersionTuple Version;
36 
37  /// Name of the platform that Version corresponds to.
38  StringRef Platform;
39 
40  SourceLocation BeginLoc, EndLoc;
41 
42 public:
43  AvailabilitySpec(VersionTuple Version, StringRef Platform,
44  SourceLocation BeginLoc, SourceLocation EndLoc)
45  : Version(Version), Platform(Platform), BeginLoc(BeginLoc),
46  EndLoc(EndLoc) {}
47 
48  /// This constructor is used when representing the '*' case.
50  : BeginLoc(StarLoc), EndLoc(StarLoc) {}
51 
52  VersionTuple getVersion() const { return Version; }
53  StringRef getPlatform() const { return Platform; }
54  SourceLocation getBeginLoc() const { return BeginLoc; }
55  SourceLocation getEndLoc() const { return EndLoc; }
56 
57  /// Returns true when this represents the '*' case.
58  bool isOtherPlatformSpec() const { return Version.empty(); }
59 };
60 
61 class Decl;
62 
63 /// Storage of availability attributes for a declaration.
65  /// The domain is the platform for which this availability info applies to.
67  VersionTuple Introduced;
68  VersionTuple Deprecated;
69  VersionTuple Obsoleted;
70  bool Unavailable = false;
73 
74  AvailabilityInfo() = default;
75 
76  /// Determine if this AvailabilityInfo represents the default availability.
77  bool isDefault() const { return *this == AvailabilityInfo(); }
78 
79  /// Check if the symbol has been obsoleted.
80  bool isObsoleted() const { return !Obsoleted.empty(); }
81 
82  /// Check if the symbol is unavailable unconditionally or
83  /// on the active platform and os version.
84  bool isUnavailable() const {
86  }
87 
88  /// Check if the symbol is unconditionally deprecated.
89  ///
90  /// i.e. \code __attribute__((deprecated)) \endcode
92 
93  /// Check if the symbol is unconditionally unavailable.
94  ///
95  /// i.e. \code __attribute__((unavailable)) \endcode
98  }
99 
100  AvailabilityInfo(StringRef Domain, VersionTuple I, VersionTuple D,
101  VersionTuple O, bool U, bool UD, bool UU)
105 
106  friend bool operator==(const AvailabilityInfo &Lhs,
107  const AvailabilityInfo &Rhs);
108 
109 public:
110  static AvailabilityInfo createFromDecl(const Decl *Decl);
111 };
112 
113 inline bool operator==(const AvailabilityInfo &Lhs,
114  const AvailabilityInfo &Rhs) {
115  return std::tie(Lhs.Introduced, Lhs.Deprecated, Lhs.Obsoleted,
118  std::tie(Rhs.Introduced, Rhs.Deprecated, Rhs.Obsoleted,
121 }
122 
123 } // end namespace clang
124 
125 #endif
Defines the clang::SourceLocation class and associated facilities.
One specifier in an @available expression.
Definition: Availability.h:31
bool isOtherPlatformSpec() const
Returns true when this represents the '*' case.
Definition: Availability.h:58
AvailabilitySpec(VersionTuple Version, StringRef Platform, SourceLocation BeginLoc, SourceLocation EndLoc)
Definition: Availability.h:43
StringRef getPlatform() const
Definition: Availability.h:53
AvailabilitySpec(SourceLocation StarLoc)
This constructor is used when representing the '*' case.
Definition: Availability.h:49
SourceLocation getBeginLoc() const
Definition: Availability.h:54
VersionTuple getVersion() const
Definition: Availability.h:52
SourceLocation getEndLoc() const
Definition: Availability.h:55
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:86
Encodes a location in the source.
The JSON file list parser is used to communicate input to InstallAPI.
bool operator==(const CallGraphNode::CallRecord &LHS, const CallGraphNode::CallRecord &RHS)
Definition: CallGraph.h:223
Storage of availability attributes for a declaration.
Definition: Availability.h:64
bool isUnconditionallyDeprecated() const
Check if the symbol is unconditionally deprecated.
Definition: Availability.h:91
llvm::SmallString< 32 > Domain
The domain is the platform for which this availability info applies to.
Definition: Availability.h:66
VersionTuple Deprecated
Definition: Availability.h:68
bool isDefault() const
Determine if this AvailabilityInfo represents the default availability.
Definition: Availability.h:77
bool isUnavailable() const
Check if the symbol is unavailable unconditionally or on the active platform and os version.
Definition: Availability.h:84
bool isObsoleted() const
Check if the symbol has been obsoleted.
Definition: Availability.h:80
friend bool operator==(const AvailabilityInfo &Lhs, const AvailabilityInfo &Rhs)
Definition: Availability.h:113
static AvailabilityInfo createFromDecl(const Decl *Decl)
VersionTuple Introduced
Definition: Availability.h:67
AvailabilityInfo(StringRef Domain, VersionTuple I, VersionTuple D, VersionTuple O, bool U, bool UD, bool UU)
Definition: Availability.h:100
bool isUnconditionallyUnavailable() const
Check if the symbol is unconditionally unavailable.
Definition: Availability.h:96
VersionTuple Obsoleted
Definition: Availability.h:69