Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[clang] Move AvailabilityInfo into AST library #81897

Merged
merged 1 commit into from
Feb 16, 2024

Conversation

cyndyishida
Copy link
Member

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.

@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Feb 15, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Feb 15, 2024

@llvm/pr-subscribers-clang

Author: Cyndy Ishida (cyndyishida)

Changes

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 --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

Previously this class was only used by ExtractAPI, but it will soon also
be needed by InstallAPI. This patch should not change availbility
behavior but just centralizes the information next to what already is
captured about availability for ast traversal.
/// 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;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are 32 chars required?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fear I may have misunderstood your question, I give alternative answers.

  • There is not a default template argument for SmallString
  • For why I picked 32, 31 characters is the longest string value under inputs and outputs for mapping platform availability

Copy link
Collaborator

@ributzka ributzka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@cyndyishida cyndyishida merged commit e606dc1 into llvm:main Feb 16, 2024
3 of 4 checks passed
@cyndyishida cyndyishida deleted the MoveAvailabilityInfo branch February 16, 2024 01:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants