[clang] [clang] Move `AvailabilityInfo` into AST library (PR #81897)

via cfe-commits cfe-commits at lists.llvm.org
Thu Feb 15 10:43:13 PST 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Cyndy Ishida (cyndyishida)

<details>
<summary>Changes</summary>

Previously this class was only used by ExtractAPI, but it will soon also be needed by InstallAPI. This patch should not change availability behavior but just centralizes the information next to what already is captured about availability for AST traversal.

---
Full diff: https://github.com/llvm/llvm-project/pull/81897.diff


7 Files Affected:

- (modified) clang/include/clang/AST/Availability.h (+51) 
- (modified) clang/include/clang/ExtractAPI/API.h (+1-1) 
- (removed) clang/include/clang/ExtractAPI/AvailabilityInfo.h (-76) 
- (modified) clang/include/clang/ExtractAPI/ExtractAPIVisitor.h (+1-1) 
- (renamed) clang/lib/AST/Availability.cpp (+17-4) 
- (modified) clang/lib/AST/CMakeLists.txt (+1) 
- (modified) clang/lib/ExtractAPI/CMakeLists.txt (-1) 


``````````diff
diff --git a/clang/include/clang/AST/Availability.h b/clang/include/clang/AST/Availability.h
index 527fc4b59a5f4d..ff0018b0452dda 100644
--- a/clang/include/clang/AST/Availability.h
+++ b/clang/include/clang/AST/Availability.h
@@ -57,6 +57,57 @@ class AvailabilitySpec {
   bool isOtherPlatformSpec() const { return Version.empty(); }
 };
 
+class Decl;
+
+/// Storage of availability attributes for a declaration.
+struct AvailabilityInfo {
+  /// The domain for which this availability info item applies.
+  std::string Domain;
+  VersionTuple Introduced;
+  VersionTuple Deprecated;
+  VersionTuple Obsoleted;
+  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 unconditionally deprecated.
+  ///
+  /// i.e. \code __attribute__((deprecated)) \endcode
+  bool isUnconditionallyDeprecated() const { return UnconditionallyDeprecated; }
+
+  /// Check if the symbol is unconditionally unavailable.
+  ///
+  /// i.e. \code __attribute__((unavailable)) \endcode
+  bool isUnconditionallyUnavailable() const {
+    return UnconditionallyUnavailable;
+  }
+
+  AvailabilityInfo(StringRef Domain, VersionTuple I, VersionTuple D,
+                   VersionTuple O, bool UD, bool UU)
+      : Domain(Domain), Introduced(I), Deprecated(D), Obsoleted(O),
+        UnconditionallyDeprecated(UD), UnconditionallyUnavailable(UU) {}
+
+  friend bool operator==(const AvailabilityInfo &Lhs,
+                         const AvailabilityInfo &Rhs);
+
+public:
+  static AvailabilityInfo createFromDecl(const Decl *Decl);
+};
+
+inline bool operator==(const AvailabilityInfo &Lhs,
+                       const AvailabilityInfo &Rhs) {
+  return std::tie(Lhs.Introduced, Lhs.Deprecated, Lhs.Obsoleted,
+                  Lhs.UnconditionallyDeprecated,
+                  Lhs.UnconditionallyUnavailable) ==
+         std::tie(Rhs.Introduced, Rhs.Deprecated, Rhs.Obsoleted,
+                  Rhs.UnconditionallyDeprecated,
+                  Rhs.UnconditionallyUnavailable);
+}
+
 } // end namespace clang
 
 #endif
diff --git a/clang/include/clang/ExtractAPI/API.h b/clang/include/clang/ExtractAPI/API.h
index 0a0f1bd1e95f7f..b220db294101d8 100644
--- a/clang/include/clang/ExtractAPI/API.h
+++ b/clang/include/clang/ExtractAPI/API.h
@@ -18,12 +18,12 @@
 #ifndef LLVM_CLANG_EXTRACTAPI_API_H
 #define LLVM_CLANG_EXTRACTAPI_API_H
 
+#include "clang/AST/Availability.h"
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclObjC.h"
 #include "clang/AST/RawCommentList.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/Specifiers.h"
-#include "clang/ExtractAPI/AvailabilityInfo.h"
 #include "clang/ExtractAPI/DeclarationFragments.h"
 #include "llvm/ADT/MapVector.h"
 #include "llvm/ADT/StringRef.h"
diff --git a/clang/include/clang/ExtractAPI/AvailabilityInfo.h b/clang/include/clang/ExtractAPI/AvailabilityInfo.h
deleted file mode 100644
index 3b8d6f46ed56d2..00000000000000
--- a/clang/include/clang/ExtractAPI/AvailabilityInfo.h
+++ /dev/null
@@ -1,76 +0,0 @@
-//===- ExtractAPI/AvailabilityInfo.h - Availability Info --------*- C++ -*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-///
-/// \file
-/// This file defines the AvailabilityInfo struct that collects availability
-/// attributes of a symbol.
-///
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_CLANG_EXTRACTAPI_AVAILABILITY_INFO_H
-#define LLVM_CLANG_EXTRACTAPI_AVAILABILITY_INFO_H
-
-#include "clang/AST/Decl.h"
-#include "llvm/Support/Error.h"
-#include "llvm/Support/VersionTuple.h"
-#include "llvm/Support/raw_ostream.h"
-
-namespace clang {
-namespace extractapi {
-
-/// Stores availability attributes of a symbol.
-struct AvailabilityInfo {
-  /// The domain for which this availability info item applies
-  std::string Domain;
-  VersionTuple Introduced;
-  VersionTuple Deprecated;
-  VersionTuple Obsoleted;
-  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 unconditionally deprecated.
-  ///
-  /// i.e. \code __attribute__((deprecated)) \endcode
-  bool isUnconditionallyDeprecated() const { return UnconditionallyDeprecated; }
-  /// Check if the symbol is unconditionally unavailable.
-  ///
-  /// i.e. \code __attribute__((unavailable)) \endcode
-  bool isUnconditionallyUnavailable() const {
-    return UnconditionallyUnavailable;
-  }
-
-  AvailabilityInfo(StringRef Domain, VersionTuple I, VersionTuple D,
-                   VersionTuple O, bool UD, bool UU)
-      : Domain(Domain), Introduced(I), Deprecated(D), Obsoleted(O),
-        UnconditionallyDeprecated(UD), UnconditionallyUnavailable(UU) {}
-
-  friend bool operator==(const AvailabilityInfo &Lhs,
-                         const AvailabilityInfo &Rhs);
-
-public:
-  static AvailabilityInfo createFromDecl(const Decl *Decl);
-};
-
-inline bool operator==(const AvailabilityInfo &Lhs,
-                       const AvailabilityInfo &Rhs) {
-  return std::tie(Lhs.Introduced, Lhs.Deprecated, Lhs.Obsoleted,
-                  Lhs.UnconditionallyDeprecated,
-                  Lhs.UnconditionallyUnavailable) ==
-         std::tie(Rhs.Introduced, Rhs.Deprecated, Rhs.Obsoleted,
-                  Rhs.UnconditionallyDeprecated,
-                  Rhs.UnconditionallyUnavailable);
-}
-
-} // namespace extractapi
-} // namespace clang
-
-#endif // LLVM_CLANG_EXTRACTAPI_AVAILABILITY_INFO_H
diff --git a/clang/include/clang/ExtractAPI/ExtractAPIVisitor.h b/clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
index ac6f4e313540c8..e1c3e41c750d40 100644
--- a/clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
+++ b/clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
@@ -14,12 +14,12 @@
 #ifndef LLVM_CLANG_EXTRACTAPI_EXTRACT_API_VISITOR_H
 #define LLVM_CLANG_EXTRACTAPI_EXTRACT_API_VISITOR_H
 
+#include "clang/AST/Availability.h"
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclCXX.h"
 #include "clang/AST/DeclTemplate.h"
 #include "clang/Basic/OperatorKinds.h"
 #include "clang/Basic/Specifiers.h"
-#include "clang/ExtractAPI/AvailabilityInfo.h"
 #include "clang/ExtractAPI/DeclarationFragments.h"
 #include "llvm/ADT/FunctionExtras.h"
 
diff --git a/clang/lib/ExtractAPI/AvailabilityInfo.cpp b/clang/lib/AST/Availability.cpp
similarity index 63%
rename from clang/lib/ExtractAPI/AvailabilityInfo.cpp
rename to clang/lib/AST/Availability.cpp
index 18e4d16b45bb64..d0054e37e4dcd2 100644
--- a/clang/lib/ExtractAPI/AvailabilityInfo.cpp
+++ b/clang/lib/AST/Availability.cpp
@@ -1,11 +1,22 @@
-#include "clang/ExtractAPI/AvailabilityInfo.h"
+//===- Availability.cpp --------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This file implements the Availability information for Decls.
+//
+//===----------------------------------------------------------------------===//
+
+#include "clang/AST/Availability.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/Attr.h"
+#include "clang/AST/Decl.h"
 #include "clang/Basic/TargetInfo.h"
-#include "llvm/ADT/STLExtras.h"
 
-using namespace clang::extractapi;
-using namespace llvm;
+namespace clang {
 
 AvailabilityInfo AvailabilityInfo::createFromDecl(const Decl *Decl) {
   ASTContext &Context = Decl->getASTContext();
@@ -33,3 +44,5 @@ AvailabilityInfo AvailabilityInfo::createFromDecl(const Decl *Decl) {
   }
   return Availability;
 }
+
+} // namespace clang
diff --git a/clang/lib/AST/CMakeLists.txt b/clang/lib/AST/CMakeLists.txt
index 49dcf2e4da3e77..d793c3ed0410a8 100644
--- a/clang/lib/AST/CMakeLists.txt
+++ b/clang/lib/AST/CMakeLists.txt
@@ -32,6 +32,7 @@ add_clang_library(clangAST
   ASTTypeTraits.cpp
   AttrDocTable.cpp
   AttrImpl.cpp
+  Availability.cpp
   Comment.cpp
   CommentBriefParser.cpp
   CommentCommandTraits.cpp
diff --git a/clang/lib/ExtractAPI/CMakeLists.txt b/clang/lib/ExtractAPI/CMakeLists.txt
index b43fe742478ce2..2b6a5b7273f554 100644
--- a/clang/lib/ExtractAPI/CMakeLists.txt
+++ b/clang/lib/ExtractAPI/CMakeLists.txt
@@ -6,7 +6,6 @@ set(LLVM_LINK_COMPONENTS
 add_clang_library(clangExtractAPI
   API.cpp
   APIIgnoresList.cpp
-  AvailabilityInfo.cpp
   ExtractAPIConsumer.cpp
   DeclarationFragments.cpp
   Serialization/SymbolGraphSerializer.cpp

``````````

</details>


https://github.com/llvm/llvm-project/pull/81897


More information about the cfe-commits mailing list