Skip to content

Commit

Permalink
Merge pull request #8634 from daniel-grumberg/cherry-picks/swift/6.0/…
Browse files Browse the repository at this point in the history
…05c1447
  • Loading branch information
fredriss authored May 13, 2024
2 parents 8583cc1 + 0af98c9 commit 2b4062f
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 457 deletions.
17 changes: 13 additions & 4 deletions clang/include/clang/ExtractAPI/AvailabilityInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,21 @@ struct AvailabilityInfo {
VersionTuple Introduced;
VersionTuple Deprecated;
VersionTuple Obsoleted;
bool Unavailable = false;
bool UnconditionallyDeprecated = false;
bool UnconditionallyUnavailable = false;

AvailabilityInfo() = default;

/// Determine if this AvailabilityInfo represents the default availability.
bool isDefault() const { return *this == AvailabilityInfo(); }

/// Check if the symbol is unavailable unconditionally or
/// on the active platform and os version.
bool isUnavailable() const {
return Unavailable || isUnconditionallyUnavailable();
}

/// Check if the symbol is unconditionally deprecated.
///
/// i.e. \code __attribute__((deprecated)) \endcode
Expand All @@ -49,9 +57,10 @@ struct AvailabilityInfo {
}

AvailabilityInfo(StringRef Domain, VersionTuple I, VersionTuple D,
VersionTuple O, bool UD, bool UU)
VersionTuple O, bool U, bool UD, bool UU)
: Domain(Domain), Introduced(I), Deprecated(D), Obsoleted(O),
UnconditionallyDeprecated(UD), UnconditionallyUnavailable(UU) {}
Unavailable(U), UnconditionallyDeprecated(UD),
UnconditionallyUnavailable(UU) {}

friend bool operator==(const AvailabilityInfo &Lhs,
const AvailabilityInfo &Rhs);
Expand All @@ -63,10 +72,10 @@ struct AvailabilityInfo {
inline bool operator==(const AvailabilityInfo &Lhs,
const AvailabilityInfo &Rhs) {
return std::tie(Lhs.Introduced, Lhs.Deprecated, Lhs.Obsoleted,
Lhs.UnconditionallyDeprecated,
Lhs.Unavailable, Lhs.UnconditionallyDeprecated,
Lhs.UnconditionallyUnavailable) ==
std::tie(Rhs.Introduced, Rhs.Deprecated, Rhs.Obsoleted,
Rhs.UnconditionallyDeprecated,
Rhs.Unavailable, Rhs.UnconditionallyDeprecated,
Rhs.UnconditionallyUnavailable);
}

Expand Down
6 changes: 3 additions & 3 deletions clang/lib/ExtractAPI/AvailabilityInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ AvailabilityInfo AvailabilityInfo::createFromDecl(const Decl *Decl) {
for (const auto *A : RD->specific_attrs<AvailabilityAttr>()) {
if (A->getPlatform()->getName() != PlatformName)
continue;
Availability =
AvailabilityInfo(A->getPlatform()->getName(), A->getIntroduced(),
A->getDeprecated(), A->getObsoleted(), false, false);
Availability = AvailabilityInfo(
A->getPlatform()->getName(), A->getIntroduced(), A->getDeprecated(),
A->getObsoleted(), A->getUnavailable(), false, false);
break;
}

Expand Down
28 changes: 15 additions & 13 deletions clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,27 +164,29 @@ std::optional<Array> serializeAvailability(const AvailabilityInfo &Avail) {
if (Avail.isDefault())
return std::nullopt;

Object Availability;
Array AvailabilityArray;
Availability["domain"] = Avail.Domain;
serializeObject(Availability, "introduced",
serializeSemanticVersion(Avail.Introduced));
serializeObject(Availability, "deprecated",
serializeSemanticVersion(Avail.Deprecated));
serializeObject(Availability, "obsoleted",
serializeSemanticVersion(Avail.Obsoleted));

if (Avail.isUnconditionallyDeprecated()) {
Object UnconditionallyDeprecated;
UnconditionallyDeprecated["domain"] = "*";
UnconditionallyDeprecated["isUnconditionallyDeprecated"] = true;
AvailabilityArray.emplace_back(std::move(UnconditionallyDeprecated));
}
if (Avail.isUnconditionallyUnavailable()) {
Object UnconditionallyUnavailable;
UnconditionallyUnavailable["domain"] = "*";
UnconditionallyUnavailable["isUnconditionallyUnavailable"] = true;
AvailabilityArray.emplace_back(std::move(UnconditionallyUnavailable));
Object Availability;

Availability["domain"] = Avail.Domain;

if (Avail.isUnavailable()) {
Availability["isUnconditionallyUnavailable"] = true;
} else {
serializeObject(Availability, "introduced",
serializeSemanticVersion(Avail.Introduced));
serializeObject(Availability, "deprecated",
serializeSemanticVersion(Avail.Deprecated));
serializeObject(Availability, "obsoleted",
serializeSemanticVersion(Avail.Obsoleted));
}

AvailabilityArray.emplace_back(std::move(Availability));
return AvailabilityArray;
}
Expand Down
Loading

0 comments on commit 2b4062f

Please sign in to comment.