[PATCH] D144940: [clang][ExtractAPI] Handle platform specific unavailability correctly

Ankur Saini via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Feb 27 21:11:24 PST 2023


Arsenic created this revision.
Herald added a reviewer: ributzka.
Herald added a project: All.
Arsenic edited the summary of this revision.
Arsenic added reviewers: dang, zixuw.
Arsenic published this revision for review.
Arsenic added inline comments.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.


================
Comment at: clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp:546
+      Record, API, [Lang, &ParentContexts](const PathComponent &PC) {
+        ParentContexts.push_back(serializeParentContext(PC, Lang));
+      });
----------------
These changes seems to have added by clang-format. 
Is there a way to not let clang format edit the code that I haven't touched ?


This Patch gives ExtractAPI the ability to emit correct availability information for symbols marked as unavailable on a specific platform ( PR#60954 )


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D144940

Files:
  clang/include/clang/ExtractAPI/AvailabilityInfo.h
  clang/lib/ExtractAPI/AvailabilityInfo.cpp
  clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp


Index: clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
===================================================================
--- clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
+++ clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
@@ -171,12 +171,16 @@
   for (const auto &AvailInfo : Availabilities) {
     Object Availability;
     Availability["domain"] = AvailInfo.Domain;
-    serializeObject(Availability, "introducedVersion",
-                    serializeSemanticVersion(AvailInfo.Introduced));
-    serializeObject(Availability, "deprecatedVersion",
-                    serializeSemanticVersion(AvailInfo.Deprecated));
-    serializeObject(Availability, "obsoletedVersion",
-                    serializeSemanticVersion(AvailInfo.Obsoleted));
+    if (AvailInfo.Unavailable)
+      Availability["isUnconditionallyUnavailable"] = true;
+    else {
+      serializeObject(Availability, "introducedVersion",
+                      serializeSemanticVersion(AvailInfo.Introduced));
+      serializeObject(Availability, "deprecatedVersion",
+                      serializeSemanticVersion(AvailInfo.Deprecated));
+      serializeObject(Availability, "obsoletedVersion",
+                      serializeSemanticVersion(AvailInfo.Obsoleted));
+    }
     AvailabilityArray.emplace_back(std::move(Availability));
   }
 
@@ -537,11 +541,10 @@
 Array generateParentContexts(const RecordTy &Record, const APISet &API,
                              Language Lang) {
   Array ParentContexts;
-  generatePathComponents(Record, API,
-                         [Lang, &ParentContexts](const PathComponent &PC) {
-                           ParentContexts.push_back(
-                               serializeParentContext(PC, Lang));
-                         });
+  generatePathComponents(
+      Record, API, [Lang, &ParentContexts](const PathComponent &PC) {
+        ParentContexts.push_back(serializeParentContext(PC, Lang));
+      });
 
   // The last component would be the record itself so let's remove it.
   if (!ParentContexts.empty())
Index: clang/lib/ExtractAPI/AvailabilityInfo.cpp
===================================================================
--- clang/lib/ExtractAPI/AvailabilityInfo.cpp
+++ clang/lib/ExtractAPI/AvailabilityInfo.cpp
@@ -42,8 +42,8 @@
           Availability->Obsoleted = Attr->getObsoleted();
       } else {
         Availabilities.emplace_back(Domain, Attr->getIntroduced(),
-                                    Attr->getDeprecated(),
-                                    Attr->getObsoleted());
+                                    Attr->getDeprecated(), Attr->getObsoleted(),
+                                    Attr->getUnavailable());
       }
     }
   }
Index: clang/include/clang/ExtractAPI/AvailabilityInfo.h
===================================================================
--- clang/include/clang/ExtractAPI/AvailabilityInfo.h
+++ clang/include/clang/ExtractAPI/AvailabilityInfo.h
@@ -33,17 +33,19 @@
   VersionTuple Introduced;
   VersionTuple Deprecated;
   VersionTuple Obsoleted;
+  bool Unavailable;
 
   AvailabilityInfo() = default;
 
   AvailabilityInfo(StringRef Domain, VersionTuple I, VersionTuple D,
-                   VersionTuple O)
-      : Domain(Domain), Introduced(I), Deprecated(D), Obsoleted(O) {}
+                   VersionTuple O, bool U)
+      : Domain(Domain), Introduced(I), Deprecated(D), Obsoleted(O),
+        Unavailable(U) {}
 };
 
 class AvailabilitySet {
 private:
-  using AvailabilityList = llvm::SmallVector<AvailabilityInfo, 4>;
+  using AvailabilityList = llvm::SmallVector<AvailabilityInfo, 5>;
   AvailabilityList Availabilities;
 
   bool UnconditionallyDeprecated = false;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D144940.501011.patch
Type: text/x-patch
Size: 3698 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230228/d7260186/attachment.bin>


More information about the cfe-commits mailing list