mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2025-05-15 02:16:40 +00:00

This Patch gives ExtractAPI the ability to emit correct availability information for symbols marked as unavailable on a specific platform ( PR#60954 ) Reviewed By: dang Differential Revision: https://reviews.llvm.org/D144940
51 lines
1.8 KiB
C++
51 lines
1.8 KiB
C++
#include "clang/ExtractAPI/AvailabilityInfo.h"
|
|
#include "clang/AST/Attr.h"
|
|
#include "llvm/ADT/STLExtras.h"
|
|
|
|
using namespace clang;
|
|
using namespace extractapi;
|
|
|
|
AvailabilitySet::AvailabilitySet(const Decl *Decl) {
|
|
// Collect availability attributes from all redeclrations.
|
|
for (const auto *RD : Decl->redecls()) {
|
|
if (const auto *A = RD->getAttr<UnavailableAttr>()) {
|
|
if (!A->isImplicit()) {
|
|
this->Availabilities.clear();
|
|
UnconditionallyUnavailable = true;
|
|
}
|
|
}
|
|
|
|
if (const auto *A = RD->getAttr<DeprecatedAttr>()) {
|
|
if (!A->isImplicit()) {
|
|
this->Availabilities.clear();
|
|
UnconditionallyDeprecated = true;
|
|
}
|
|
}
|
|
|
|
for (const auto *Attr : RD->specific_attrs<AvailabilityAttr>()) {
|
|
StringRef Domain = Attr->getPlatform()->getName();
|
|
auto *Availability =
|
|
llvm::find_if(Availabilities, [Domain](const AvailabilityInfo &Info) {
|
|
return Domain.equals(Info.Domain);
|
|
});
|
|
if (Availability != Availabilities.end()) {
|
|
// Get the highest introduced version for all redeclarations.
|
|
if (Availability->Introduced < Attr->getIntroduced())
|
|
Availability->Introduced = Attr->getIntroduced();
|
|
|
|
// Get the lowest deprecated version for all redeclarations.
|
|
if (Availability->Deprecated > Attr->getDeprecated())
|
|
Availability->Deprecated = Attr->getDeprecated();
|
|
|
|
// Get the lowest obsoleted version for all redeclarations.
|
|
if (Availability->Obsoleted > Attr->getObsoleted())
|
|
Availability->Obsoleted = Attr->getObsoleted();
|
|
} else {
|
|
Availabilities.emplace_back(Domain, Attr->getIntroduced(),
|
|
Attr->getDeprecated(), Attr->getObsoleted(),
|
|
Attr->getUnavailable());
|
|
}
|
|
}
|
|
}
|
|
}
|