Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:36:29

0001 //===--- Availability.h - Classes for availability --------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 //
0009 // This files defines some classes that implement availability checking.
0010 //
0011 //===----------------------------------------------------------------------===//
0012 
0013 #ifndef LLVM_CLANG_AST_AVAILABILITY_H
0014 #define LLVM_CLANG_AST_AVAILABILITY_H
0015 
0016 #include "clang/Basic/SourceLocation.h"
0017 #include "llvm/ADT/SmallString.h"
0018 #include "llvm/ADT/StringRef.h"
0019 #include "llvm/Support/VersionTuple.h"
0020 
0021 namespace clang {
0022 
0023 /// One specifier in an @available expression.
0024 ///
0025 /// \code
0026 ///   @available(macos 10.10, *)
0027 /// \endcode
0028 ///
0029 /// Here, 'macos 10.10' and '*' both map to an instance of this type.
0030 ///
0031 class AvailabilitySpec {
0032   /// Represents the version that this specifier requires. If the host OS
0033   /// version is greater than or equal to Version, the @available will evaluate
0034   /// to true.
0035   VersionTuple Version;
0036 
0037   /// Name of the platform that Version corresponds to.
0038   StringRef Platform;
0039 
0040   SourceLocation BeginLoc, EndLoc;
0041 
0042 public:
0043   AvailabilitySpec(VersionTuple Version, StringRef Platform,
0044                    SourceLocation BeginLoc, SourceLocation EndLoc)
0045       : Version(Version), Platform(Platform), BeginLoc(BeginLoc),
0046         EndLoc(EndLoc) {}
0047 
0048   /// This constructor is used when representing the '*' case.
0049   AvailabilitySpec(SourceLocation StarLoc)
0050       : BeginLoc(StarLoc), EndLoc(StarLoc) {}
0051 
0052   VersionTuple getVersion() const { return Version; }
0053   StringRef getPlatform() const { return Platform; }
0054   SourceLocation getBeginLoc() const { return BeginLoc; }
0055   SourceLocation getEndLoc() const { return EndLoc; }
0056 
0057   /// Returns true when this represents the '*' case.
0058   bool isOtherPlatformSpec() const { return Version.empty(); }
0059 };
0060 
0061 class Decl;
0062 
0063 /// Storage of availability attributes for a declaration.
0064 struct AvailabilityInfo {
0065   /// The domain is the platform for which this availability info applies to.
0066   llvm::SmallString<32> Domain;
0067   VersionTuple Introduced;
0068   VersionTuple Deprecated;
0069   VersionTuple Obsoleted;
0070   bool Unavailable = false;
0071   bool UnconditionallyDeprecated = false;
0072   bool UnconditionallyUnavailable = false;
0073 
0074   AvailabilityInfo() = default;
0075 
0076   /// Determine if this AvailabilityInfo represents the default availability.
0077   bool isDefault() const { return *this == AvailabilityInfo(); }
0078 
0079   /// Check if the symbol has been obsoleted.
0080   bool isObsoleted() const { return !Obsoleted.empty(); }
0081 
0082   /// Check if the symbol is unavailable unconditionally or
0083   /// on the active platform and os version.
0084   bool isUnavailable() const {
0085     return Unavailable || isUnconditionallyUnavailable();
0086   }
0087 
0088   /// Check if the symbol is unconditionally deprecated.
0089   ///
0090   /// i.e. \code __attribute__((deprecated)) \endcode
0091   bool isUnconditionallyDeprecated() const { return UnconditionallyDeprecated; }
0092 
0093   /// Check if the symbol is unconditionally unavailable.
0094   ///
0095   /// i.e. \code __attribute__((unavailable)) \endcode
0096   bool isUnconditionallyUnavailable() const {
0097     return UnconditionallyUnavailable;
0098   }
0099 
0100   /// Augments the existing information with additional constraints provided by
0101   /// \c Other.
0102   void mergeWith(AvailabilityInfo Other);
0103 
0104   AvailabilityInfo(StringRef Domain, VersionTuple I, VersionTuple D,
0105                    VersionTuple O, bool U, bool UD, bool UU)
0106       : Domain(Domain), Introduced(I), Deprecated(D), Obsoleted(O),
0107         Unavailable(U), UnconditionallyDeprecated(UD),
0108         UnconditionallyUnavailable(UU) {}
0109 
0110   friend bool operator==(const AvailabilityInfo &Lhs,
0111                          const AvailabilityInfo &Rhs);
0112 
0113 public:
0114   static AvailabilityInfo createFromDecl(const Decl *Decl);
0115 };
0116 
0117 inline bool operator==(const AvailabilityInfo &Lhs,
0118                        const AvailabilityInfo &Rhs) {
0119   return std::tie(Lhs.Introduced, Lhs.Deprecated, Lhs.Obsoleted,
0120                   Lhs.Unavailable, Lhs.UnconditionallyDeprecated,
0121                   Lhs.UnconditionallyUnavailable) ==
0122          std::tie(Rhs.Introduced, Rhs.Deprecated, Rhs.Obsoleted,
0123                   Rhs.Unavailable, Rhs.UnconditionallyDeprecated,
0124                   Rhs.UnconditionallyUnavailable);
0125 }
0126 
0127 } // end namespace clang
0128 
0129 #endif