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/Support/Error.h"
20#include "llvm/Support/VersionTuple.h"
21#include "llvm/Support/raw_ostream.h"
22
23namespace clang {
24namespace extractapi {
25
26/// Stores availability attributes of a symbol.
27struct AvailabilityInfo {
28 /// The domain for which this availability info item applies
29 std::string Domain;
30 VersionTuple Introduced;
31 VersionTuple Deprecated;
32 VersionTuple Obsoleted;
33 bool UnconditionallyDeprecated = false;
34 bool UnconditionallyUnavailable = false;
35
36 AvailabilityInfo() = default;
37
38 /// Determine if this AvailabilityInfo represents the default availability.
39 bool isDefault() const { return *this == AvailabilityInfo(); }
40 /// Check if the symbol is unconditionally deprecated.
41 ///
42 /// i.e. \code __attribute__((deprecated)) \endcode
43 bool isUnconditionallyDeprecated() const { return UnconditionallyDeprecated; }
44 /// Check if the symbol is unconditionally unavailable.
45 ///
46 /// i.e. \code __attribute__((unavailable)) \endcode
47 bool isUnconditionallyUnavailable() const {
48 return UnconditionallyUnavailable;
49 }
50
51 AvailabilityInfo(StringRef Domain, VersionTuple I, VersionTuple D,
52 VersionTuple O, bool UD, bool UU)
53 : Domain(Domain), Introduced(I), Deprecated(D), Obsoleted(O),
54 UnconditionallyDeprecated(UD), UnconditionallyUnavailable(UU) {}
55
56 friend bool operator==(const AvailabilityInfo &Lhs,
57 const AvailabilityInfo &Rhs);
58
59public:
60 static AvailabilityInfo createFromDecl(const Decl *Decl);
61};
62
63inline bool operator==(const AvailabilityInfo &Lhs,
64 const AvailabilityInfo &Rhs) {
65 return std::tie(args: Lhs.Introduced, args: Lhs.Deprecated, args: Lhs.Obsoleted,
66 args: Lhs.UnconditionallyDeprecated,
67 args: Lhs.UnconditionallyUnavailable) ==
68 std::tie(args: Rhs.Introduced, args: Rhs.Deprecated, args: Rhs.Obsoleted,
69 args: Rhs.UnconditionallyDeprecated,
70 args: Rhs.UnconditionallyUnavailable);
71}
72
73} // namespace extractapi
74} // namespace clang
75
76#endif // LLVM_CLANG_EXTRACTAPI_AVAILABILITY_INFO_H
77

source code of clang/include/clang/ExtractAPI/AvailabilityInfo.h