1 //===- ExtractAPI/AvailabilityInfo.h - Availability Info --------*- 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 /// \file
10 /// This file defines the AvailabilityInfo struct that collects availability
11 /// attributes of a symbol.
12 ///
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef LLVM_CLANG_EXTRACTAPI_AVAILABILITY_INFO_H
16 #define LLVM_CLANG_EXTRACTAPI_AVAILABILITY_INFO_H
17 
18 #include "llvm/Support/Error.h"
19 #include "llvm/Support/VersionTuple.h"
20 #include "llvm/Support/raw_ostream.h"
21 
22 using llvm::VersionTuple;
23 
24 namespace clang {
25 namespace extractapi {
26 
27 /// Stores availability attributes of a symbol.
28 struct AvailabilityInfo {
29   VersionTuple Introduced;
30   VersionTuple Deprecated;
31   VersionTuple Obsoleted;
32   bool Unavailable{false};
33   bool UnconditionallyDeprecated{false};
34   bool UnconditionallyUnavailable{false};
35 
36   /// Determine if this AvailabilityInfo represents the default availability.
37   bool isDefault() const { return *this == AvailabilityInfo(); }
38 
39   /// Check if the symbol is unavailable.
40   bool isUnavailable() const { return Unavailable; }
41 
42   /// Check if the symbol is unconditionally deprecated.
43   ///
44   /// i.e. \code __attribute__((deprecated)) \endcode
45   bool isUnconditionallyDeprecated() const { return UnconditionallyDeprecated; }
46 
47   /// Check if the symbol is unconditionally unavailable.
48   ///
49   /// i.e. \code __attribute__((unavailable)) \endcode
50   bool isUnconditionallyUnavailable() const {
51     return UnconditionallyUnavailable;
52   }
53 
54   AvailabilityInfo() = default;
55 
56   AvailabilityInfo(VersionTuple I, VersionTuple D, VersionTuple O, bool U,
57                    bool UD, bool UU)
58       : Introduced(I), Deprecated(D), Obsoleted(O), Unavailable(U),
59         UnconditionallyDeprecated(UD), UnconditionallyUnavailable(UU) {}
60 
61   friend bool operator==(const AvailabilityInfo &Lhs,
62                          const AvailabilityInfo &Rhs);
63 };
64 
65 inline bool operator==(const AvailabilityInfo &Lhs,
66                        const AvailabilityInfo &Rhs) {
67   return std::tie(Lhs.Introduced, Lhs.Deprecated, Lhs.Obsoleted,
68                   Lhs.Unavailable, Lhs.UnconditionallyDeprecated,
69                   Lhs.UnconditionallyUnavailable) ==
70          std::tie(Rhs.Introduced, Rhs.Deprecated, Rhs.Obsoleted,
71                   Rhs.Unavailable, Rhs.UnconditionallyDeprecated,
72                   Rhs.UnconditionallyUnavailable);
73 }
74 
75 } // namespace extractapi
76 } // namespace clang
77 
78 #endif // LLVM_CLANG_EXTRACTAPI_AVAILABILITY_INFO_H
79