Skip to content

Commit e606dc1

Browse files
authored
[clang] Move AvailabilityInfo into AST library (#81897)
Previously this class was only used by ExtractAPI, but it will soon also be needed by InstallAPI. This patch should not change availability behavior but just centralizes the information next to what already is captured about availability for AST traversal.
1 parent cc23574 commit e606dc1

File tree

7 files changed

+72
-83
lines changed

7 files changed

+72
-83
lines changed

clang/include/clang/AST/Availability.h

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#define LLVM_CLANG_AST_AVAILABILITY_H
1515

1616
#include "clang/Basic/SourceLocation.h"
17+
#include "llvm/ADT/SmallString.h"
1718
#include "llvm/ADT/StringRef.h"
1819
#include "llvm/Support/VersionTuple.h"
1920

@@ -57,6 +58,57 @@ class AvailabilitySpec {
5758
bool isOtherPlatformSpec() const { return Version.empty(); }
5859
};
5960

61+
class Decl;
62+
63+
/// Storage of availability attributes for a declaration.
64+
struct AvailabilityInfo {
65+
/// The domain is the platform for which this availability info applies to.
66+
llvm::SmallString<32> Domain;
67+
VersionTuple Introduced;
68+
VersionTuple Deprecated;
69+
VersionTuple Obsoleted;
70+
bool UnconditionallyDeprecated = false;
71+
bool UnconditionallyUnavailable = false;
72+
73+
AvailabilityInfo() = default;
74+
75+
/// Determine if this AvailabilityInfo represents the default availability.
76+
bool isDefault() const { return *this == AvailabilityInfo(); }
77+
78+
/// Check if the symbol is unconditionally deprecated.
79+
///
80+
/// i.e. \code __attribute__((deprecated)) \endcode
81+
bool isUnconditionallyDeprecated() const { return UnconditionallyDeprecated; }
82+
83+
/// Check if the symbol is unconditionally unavailable.
84+
///
85+
/// i.e. \code __attribute__((unavailable)) \endcode
86+
bool isUnconditionallyUnavailable() const {
87+
return UnconditionallyUnavailable;
88+
}
89+
90+
AvailabilityInfo(StringRef Domain, VersionTuple I, VersionTuple D,
91+
VersionTuple O, bool UD, bool UU)
92+
: Domain(Domain), Introduced(I), Deprecated(D), Obsoleted(O),
93+
UnconditionallyDeprecated(UD), UnconditionallyUnavailable(UU) {}
94+
95+
friend bool operator==(const AvailabilityInfo &Lhs,
96+
const AvailabilityInfo &Rhs);
97+
98+
public:
99+
static AvailabilityInfo createFromDecl(const Decl *Decl);
100+
};
101+
102+
inline bool operator==(const AvailabilityInfo &Lhs,
103+
const AvailabilityInfo &Rhs) {
104+
return std::tie(Lhs.Introduced, Lhs.Deprecated, Lhs.Obsoleted,
105+
Lhs.UnconditionallyDeprecated,
106+
Lhs.UnconditionallyUnavailable) ==
107+
std::tie(Rhs.Introduced, Rhs.Deprecated, Rhs.Obsoleted,
108+
Rhs.UnconditionallyDeprecated,
109+
Rhs.UnconditionallyUnavailable);
110+
}
111+
60112
} // end namespace clang
61113

62114
#endif

clang/include/clang/ExtractAPI/API.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@
1818
#ifndef LLVM_CLANG_EXTRACTAPI_API_H
1919
#define LLVM_CLANG_EXTRACTAPI_API_H
2020

21+
#include "clang/AST/Availability.h"
2122
#include "clang/AST/Decl.h"
2223
#include "clang/AST/DeclObjC.h"
2324
#include "clang/AST/RawCommentList.h"
2425
#include "clang/Basic/SourceLocation.h"
2526
#include "clang/Basic/Specifiers.h"
26-
#include "clang/ExtractAPI/AvailabilityInfo.h"
2727
#include "clang/ExtractAPI/DeclarationFragments.h"
2828
#include "llvm/ADT/MapVector.h"
2929
#include "llvm/ADT/StringRef.h"

clang/include/clang/ExtractAPI/AvailabilityInfo.h

Lines changed: 0 additions & 76 deletions
This file was deleted.

clang/include/clang/ExtractAPI/ExtractAPIVisitor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414
#ifndef LLVM_CLANG_EXTRACTAPI_EXTRACT_API_VISITOR_H
1515
#define LLVM_CLANG_EXTRACTAPI_EXTRACT_API_VISITOR_H
1616

17+
#include "clang/AST/Availability.h"
1718
#include "clang/AST/Decl.h"
1819
#include "clang/AST/DeclCXX.h"
1920
#include "clang/AST/DeclTemplate.h"
2021
#include "clang/Basic/OperatorKinds.h"
2122
#include "clang/Basic/Specifiers.h"
22-
#include "clang/ExtractAPI/AvailabilityInfo.h"
2323
#include "clang/ExtractAPI/DeclarationFragments.h"
2424
#include "llvm/ADT/FunctionExtras.h"
2525

clang/lib/ExtractAPI/AvailabilityInfo.cpp renamed to clang/lib/AST/Availability.cpp

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
1-
#include "clang/ExtractAPI/AvailabilityInfo.h"
1+
//===- Availability.cpp --------------------------------------------------===//
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 file implements the Availability information for Decls.
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#include "clang/AST/Availability.h"
214
#include "clang/AST/ASTContext.h"
315
#include "clang/AST/Attr.h"
16+
#include "clang/AST/Decl.h"
417
#include "clang/Basic/TargetInfo.h"
5-
#include "llvm/ADT/STLExtras.h"
618

7-
using namespace clang::extractapi;
8-
using namespace llvm;
19+
namespace clang {
920

1021
AvailabilityInfo AvailabilityInfo::createFromDecl(const Decl *Decl) {
1122
ASTContext &Context = Decl->getASTContext();
@@ -33,3 +44,5 @@ AvailabilityInfo AvailabilityInfo::createFromDecl(const Decl *Decl) {
3344
}
3445
return Availability;
3546
}
47+
48+
} // namespace clang

clang/lib/AST/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ add_clang_library(clangAST
3232
ASTTypeTraits.cpp
3333
AttrDocTable.cpp
3434
AttrImpl.cpp
35+
Availability.cpp
3536
Comment.cpp
3637
CommentBriefParser.cpp
3738
CommentCommandTraits.cpp

clang/lib/ExtractAPI/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ set(LLVM_LINK_COMPONENTS
66
add_clang_library(clangExtractAPI
77
API.cpp
88
APIIgnoresList.cpp
9-
AvailabilityInfo.cpp
109
ExtractAPIConsumer.cpp
1110
DeclarationFragments.cpp
1211
Serialization/SymbolGraphSerializer.cpp

0 commit comments

Comments
 (0)