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 "clang/AST/Decl.h" 19 #include "llvm/ADT/SmallVector.h" 20 #include "llvm/Support/Error.h" 21 #include "llvm/Support/VersionTuple.h" 22 #include "llvm/Support/raw_ostream.h" 23 24 using llvm::VersionTuple; 25 26 namespace clang { 27 namespace extractapi { 28 29 /// Stores availability attributes of a symbol in a given domain. 30 struct AvailabilityInfo { 31 /// The domain for which this availability info item applies 32 std::string Domain; 33 VersionTuple Introduced; 34 VersionTuple Deprecated; 35 VersionTuple Obsoleted; 36 bool Unavailable; 37 38 AvailabilityInfo() = default; 39 40 AvailabilityInfo(StringRef Domain, VersionTuple I, VersionTuple D, 41 VersionTuple O, bool U) 42 : Domain(Domain), Introduced(I), Deprecated(D), Obsoleted(O), 43 Unavailable(U) {} 44 }; 45 46 class AvailabilitySet { 47 private: 48 using AvailabilityList = llvm::SmallVector<AvailabilityInfo, 4>; 49 AvailabilityList Availabilities; 50 51 bool UnconditionallyDeprecated = false; 52 bool UnconditionallyUnavailable = false; 53 54 public: 55 AvailabilitySet(const Decl *Decl); 56 AvailabilitySet() = default; 57 58 AvailabilityList::const_iterator begin() const { 59 return Availabilities.begin(); 60 } 61 62 AvailabilityList::const_iterator end() const { return Availabilities.end(); } 63 64 /// Check if the symbol is unconditionally deprecated. 65 /// 66 /// i.e. \code __attribute__((deprecated)) \endcode 67 bool isUnconditionallyDeprecated() const { return UnconditionallyDeprecated; } 68 69 /// Check if the symbol is unconditionally unavailable. 70 /// 71 /// i.e. \code __attribute__((unavailable)) \endcode 72 bool isUnconditionallyUnavailable() const { 73 return UnconditionallyUnavailable; 74 } 75 76 /// Determine if this AvailabilitySet represents default availability. 77 bool isDefault() const { return Availabilities.empty(); } 78 }; 79 80 } // namespace extractapi 81 } // namespace clang 82 83 #endif // LLVM_CLANG_EXTRACTAPI_AVAILABILITY_INFO_H 84