clang: lib/AST/Availability.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
18
19namespace {
20
21
22struct AvailabilitySet {
23 bool UnconditionallyDeprecated = false;
24 bool UnconditionallyUnavailable = false;
25
26 void insert(clang::AvailabilityInfo &&Availability) {
27 auto *Found = getForPlatform(Availability.Domain);
28 if (Found)
29 Found->mergeWith(std::move(Availability));
30 else
31 Availabilities.emplace_back(std::move(Availability));
32 }
33
34 clang::AvailabilityInfo *getForPlatform(llvm::StringRef Domain) {
35 auto *It = llvm::find_if(Availabilities,
36 [Domain](const clang::AvailabilityInfo &Info) {
38 });
39 return It == Availabilities.end() ? nullptr : It;
40 }
41
42private:
43 llvm::SmallVectorclang::AvailabilityInfo Availabilities;
44};
45
46static void createInfoForDecl(const clang::Decl *Decl,
47 AvailabilitySet &Availabilities) {
48
49 for (const auto *RD : Decl->redecls()) {
50 for (const auto *A : RD->specific_attrsclang::AvailabilityAttr()) {
52 A->getPlatform()->getName(), A->getIntroduced(), A->getDeprecated(),
53 A->getObsoleted(), A->getUnavailable(), false, false));
54 }
55
56 if (const auto *A = RD->getAttrclang::UnavailableAttr())
57 if (!A->isImplicit())
58 Availabilities.UnconditionallyUnavailable = true;
59
60 if (const auto *A = RD->getAttrclang::DeprecatedAttr())
61 if (!A->isImplicit())
62 Availabilities.UnconditionallyDeprecated = true;
63 }
64}
65
66}
67
69
72 return;
73
76
80
82
83
84
85
88 else
90
93 else
95}
96
98 AvailabilitySet Availabilities;
99
100
101 for (const auto *Ctx = D; Ctx;
102 Ctx = llvm::cast_or_null(Ctx->getDeclContext()))
103 createInfoForDecl(Ctx, Availabilities);
104
105 if (auto *Avail = Availabilities.getForPlatform(
107 Avail->UnconditionallyDeprecated = Availabilities.UnconditionallyDeprecated;
108 Avail->UnconditionallyUnavailable =
109 Availabilities.UnconditionallyUnavailable;
110 return std::move(*Avail);
111 }
112
116 return Avail;
117}
118
119}
Defines the clang::ASTContext interface.
const TargetInfo & getTargetInfo() const
Decl - This represents one declaration (or definition), e.g.
ASTContext & getASTContext() const LLVM_READONLY
StringRef getPlatformName() const
Retrieve the name of the platform as it is used in the availability attribute.
Defines the clang::TargetInfo interface.
std::variant< struct RequiresDecl, struct HeaderDecl, struct UmbrellaDirDecl, struct ModuleDecl, struct ExcludeDecl, struct ExportDecl, struct ExportAsDecl, struct ExternModuleDecl, struct UseDecl, struct LinkDecl, struct ConfigMacrosDecl, struct ConflictDecl > Decl
All declarations that can appear in a module declaration.
The JSON file list parser is used to communicate input to InstallAPI.
nullptr
This class represents a compute construct, representing a 'Kind' of ‘parallel’, 'serial',...
@ Other
Other implicit parameter.
Storage of availability attributes for a declaration.
llvm::SmallString< 32 > Domain
The domain is the platform for which this availability info applies to.
AvailabilityInfo()=default
bool isDefault() const
Determine if this AvailabilityInfo represents the default availability.
void mergeWith(AvailabilityInfo Other)
Augments the existing information with additional constraints provided by Other.
Definition Availability.cpp:70
bool UnconditionallyDeprecated
static AvailabilityInfo createFromDecl(const Decl *Decl)
Definition Availability.cpp:97
bool UnconditionallyUnavailable