clang  19.0.0git
Availability.cpp
Go to the documentation of this file.
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 
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
Defines the clang::ASTContext interface.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:185
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:86
ASTContext & getASTContext() const LLVM_READONLY
Definition: DeclBase.cpp:501
redecl_range redecls() const
Returns an iterator range for all the redeclarations of the same decl.
Definition: DeclBase.h:1039
Defines the clang::TargetInfo interface.
The JSON file list parser is used to communicate input to InstallAPI.
Storage of availability attributes for a declaration.
Definition: Availability.h:64
static AvailabilityInfo createFromDecl(const Decl *Decl)