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" 14 #include "clang/AST/ASTContext.h" 15 #include "clang/AST/Attr.h" 16 #include "clang/AST/Decl.h" 17 #include "clang/Basic/TargetInfo.h" 18 19 namespace clang { 20 21 AvailabilityInfo AvailabilityInfo::createFromDecl(const Decl *Decl) { 22 ASTContext &Context = Decl->getASTContext(); 23 StringRef PlatformName = Context.getTargetInfo().getPlatformName(); 24 AvailabilityInfo Availability; 25 26 // Collect availability attributes from all redeclarations. 27 for (const auto *RD : Decl->redecls()) { 28 for (const auto *A : RD->specific_attrs<AvailabilityAttr>()) { 29 if (A->getPlatform()->getName() != PlatformName) 30 continue; 31 Availability = AvailabilityInfo( 32 A->getPlatform()->getName(), A->getIntroduced(), A->getDeprecated(), 33 A->getObsoleted(), A->getUnavailable(), false, false); 34 break; 35 } 36 37 if (const auto *A = RD->getAttr<UnavailableAttr>()) 38 if (!A->isImplicit()) 39 Availability.UnconditionallyUnavailable = true; 40 41 if (const auto *A = RD->getAttr<DeprecatedAttr>()) 42 if (!A->isImplicit()) 43 Availability.UnconditionallyDeprecated = true; 44 } 45 return Availability; 46 } 47 48 } // namespace clang 49