AvailabilityInfo.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #include "clang/ExtractAPI/AvailabilityInfo.h"
  2. #include "clang/AST/Attr.h"
  3. #include "llvm/ADT/STLExtras.h"
  4. using namespace clang;
  5. using namespace extractapi;
  6. AvailabilitySet::AvailabilitySet(const Decl *Decl) {
  7. // Collect availability attributes from all redeclrations.
  8. for (const auto *RD : Decl->redecls()) {
  9. if (const auto *A = RD->getAttr<UnavailableAttr>()) {
  10. if (!A->isImplicit()) {
  11. this->Availabilities.clear();
  12. UnconditionallyUnavailable = true;
  13. }
  14. }
  15. if (const auto *A = RD->getAttr<DeprecatedAttr>()) {
  16. if (!A->isImplicit()) {
  17. this->Availabilities.clear();
  18. UnconditionallyDeprecated = true;
  19. }
  20. }
  21. for (const auto *Attr : RD->specific_attrs<AvailabilityAttr>()) {
  22. StringRef Domain = Attr->getPlatform()->getName();
  23. auto *Availability =
  24. llvm::find_if(Availabilities, [Domain](const AvailabilityInfo &Info) {
  25. return Domain.equals(Info.Domain);
  26. });
  27. if (Availability != Availabilities.end()) {
  28. // Get the highest introduced version for all redeclarations.
  29. if (Availability->Introduced < Attr->getIntroduced())
  30. Availability->Introduced = Attr->getIntroduced();
  31. // Get the lowest deprecated version for all redeclarations.
  32. if (Availability->Deprecated > Attr->getDeprecated())
  33. Availability->Deprecated = Attr->getDeprecated();
  34. // Get the lowest obsoleted version for all redeclarations.
  35. if (Availability->Obsoleted > Attr->getObsoleted())
  36. Availability->Obsoleted = Attr->getObsoleted();
  37. } else {
  38. Availabilities.emplace_back(Domain, Attr->getIntroduced(),
  39. Attr->getDeprecated(),
  40. Attr->getObsoleted());
  41. }
  42. }
  43. }
  44. }