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

via cfe-commits cfe-commits at lists.llvm.org
Thu Feb 15 17:14:58 PST 2024


Author: Cyndy Ishida
Date: 2024-02-15T17:14:54-08:00
New Revision: e606dc1dafead794f92a677fd92b2ea8e5a3fb4f

URL: https://github.com/llvm/llvm-project/commit/e606dc1dafead794f92a677fd92b2ea8e5a3fb4f
DIFF: https://github.com/llvm/llvm-project/commit/e606dc1dafead794f92a677fd92b2ea8e5a3fb4f.diff

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

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.

Added: 
    clang/lib/AST/Availability.cpp

Modified: 
    clang/include/clang/AST/Availability.h
    clang/include/clang/ExtractAPI/API.h
    clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
    clang/lib/AST/CMakeLists.txt
    clang/lib/ExtractAPI/CMakeLists.txt

Removed: 
    clang/include/clang/ExtractAPI/AvailabilityInfo.h
    clang/lib/ExtractAPI/AvailabilityInfo.cpp


################################################################################
diff  --git a/clang/include/clang/AST/Availability.h b/clang/include/clang/AST/Availability.h
index 527fc4b59a5f4d..ae3acbeffe7f18 100644
--- a/clang/include/clang/AST/Availability.h
+++ b/clang/include/clang/AST/Availability.h
@@ -14,6 +14,7 @@
 #define LLVM_CLANG_AST_AVAILABILITY_H
 
 #include "clang/Basic/SourceLocation.h"
+#include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/VersionTuple.h"
 
@@ -57,6 +58,57 @@ class AvailabilitySpec {
   bool isOtherPlatformSpec() const { return Version.empty(); }
 };
 
+class Decl;
+
+/// Storage of availability attributes for a declaration.
+struct AvailabilityInfo {
+  /// The domain is the platform for which this availability info applies to.
+  llvm::SmallString<32> 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


        


More information about the cfe-commits mailing list