[PATCH] D158646: [clang-tools-extra][ExtractAPI] create clang-symbolgraph-merger

2023-09-10 Thread Ankur Saini via Phabricator via cfe-commits
Arsenic added a comment.

In D158646#4639599 , @dang wrote:

> As per https://discourse.llvm.org/t/pull-request-migration-schedule/71595 we 
> should move this review to GitHub to make sure we don't lose track of it.

The patch has been moved to GitHub ( 
https://github.com/llvm/llvm-project/pull/65894 )


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D158646/new/

https://reviews.llvm.org/D158646

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D157810: [clang][ExtractAPI] Create extractapi::RecordLocation

2023-08-26 Thread Ankur Saini via Phabricator via cfe-commits
Arsenic updated this revision to Diff 553730.
Arsenic added a comment.

Fix minor typo is comments

- Move creation of DocComment in it's own seperate function
- Update the Underlying DataType used by RecordLocation
- Update the patch to account for new C++ APIRecords


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157810/new/

https://reviews.llvm.org/D157810

Files:
  clang/include/clang/ExtractAPI/API.h
  clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
  clang/lib/ExtractAPI/API.cpp
  clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
  clang/tools/libclang/CXExtractAPI.cpp

Index: clang/tools/libclang/CXExtractAPI.cpp
===
--- clang/tools/libclang/CXExtractAPI.cpp
+++ clang/tools/libclang/CXExtractAPI.cpp
@@ -61,9 +61,12 @@
 Context.getSourceManager().getPresumedLoc(Decl->getLocation());
 LinkageInfo Linkage = Decl->getLinkageAndVisibility();
 DocComment Comment;
-if (auto *RawComment = fetchRawCommentForDecl(Interface))
-  Comment = RawComment->getFormattedLines(Context.getSourceManager(),
-  Context.getDiagnostics());
+if (auto *RawComment = fetchRawCommentForDecl(Interface)) {
+  auto RawCommentVec = RawComment->getFormattedLines(
+  Context.getSourceManager(), Context.getDiagnostics());
+  std::copy(RawCommentVec.begin(), RawCommentVec.end(),
+std::back_inserter(Comment));
+}
 
 // Build declaration fragments and sub-heading by generating them for the
 // interface.
Index: clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
===
--- clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
+++ clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
@@ -14,6 +14,7 @@
 #include "clang/ExtractAPI/Serialization/SymbolGraphSerializer.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/Version.h"
+#include "clang/ExtractAPI/API.h"
 #include "clang/ExtractAPI/DeclarationFragments.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/STLFunctionalExtras.h"
@@ -105,8 +106,7 @@
 }
 
 /// Serialize a source position.
-Object serializeSourcePosition(const PresumedLoc &Loc) {
-  assert(Loc.isValid() && "invalid source position");
+Object serializeSourcePosition(const RecordLocation &Loc) {
 
   Object SourcePosition;
   SourcePosition["line"] = Loc.getLine();
@@ -120,7 +120,7 @@
 /// \param Loc The presumed location to serialize.
 /// \param IncludeFileURI If true, include the file path of \p Loc as a URI.
 /// Defaults to false.
-Object serializeSourceLocation(const PresumedLoc &Loc,
+Object serializeSourceLocation(const RecordLocation &Loc,
bool IncludeFileURI = false) {
   Object SourceLocation;
   serializeObject(SourceLocation, "position", serializeSourcePosition(Loc));
@@ -136,8 +136,8 @@
 }
 
 /// Serialize a source range with begin and end locations.
-Object serializeSourceRange(const PresumedLoc &BeginLoc,
-const PresumedLoc &EndLoc) {
+Object serializeSourceRange(const RecordLocation &BeginLoc,
+const RecordLocation &EndLoc) {
   Object SourceRange;
   serializeObject(SourceRange, "start", serializeSourcePosition(BeginLoc));
   serializeObject(SourceRange, "end", serializeSourcePosition(EndLoc));
Index: clang/lib/ExtractAPI/API.cpp
===
--- clang/lib/ExtractAPI/API.cpp
+++ clang/lib/ExtractAPI/API.cpp
@@ -46,7 +46,7 @@
 
 NamespaceRecord *
 APISet::addNamespace(APIRecord *Parent, StringRef Name, StringRef USR,
- PresumedLoc Loc, AvailabilitySet Availability,
+ RecordLocation Loc, AvailabilitySet Availability,
  LinkageInfo Linkage, const DocComment &Comment,
  DeclarationFragments Declaration,
  DeclarationFragments SubHeading, bool IsFromSystemHeader) {
@@ -61,7 +61,7 @@
 }
 
 GlobalVariableRecord *
-APISet::addGlobalVar(StringRef Name, StringRef USR, PresumedLoc Loc,
+APISet::addGlobalVar(StringRef Name, StringRef USR, RecordLocation Loc,
  AvailabilitySet Availabilities, LinkageInfo Linkage,
  const DocComment &Comment, DeclarationFragments Fragments,
  DeclarationFragments SubHeading, bool IsFromSystemHeader) {
@@ -71,7 +71,7 @@
 }
 
 GlobalVariableTemplateRecord *APISet::addGlobalVariableTemplate(
-StringRef Name, StringRef USR, PresumedLoc Loc,
+StringRef Name, StringRef USR, RecordLocation Loc,
 AvailabilitySet Availability, LinkageInfo Linkage,
 const DocComment &Comment, DeclarationFragments Declaration,
 DeclarationFragments SubHeading, Template Template,
@@ -83,7 +83,7 @@
 }
 
 GlobalFunctionRecord *APISet::addGlobalFunction(
-Strin

[PATCH] D158646: [clang-tools-extra][ExtractAPI] create clang-symbolgraph-merger

2023-08-23 Thread Ankur Saini via Phabricator via cfe-commits
Arsenic created this revision.
Arsenic added a reviewer: dang.
Arsenic added projects: All, clang-tools-extra.
Herald added a reviewer: ributzka.
Arsenic requested review of this revision.

Create a clang tool to merge all the JSON symbolgraph emited by 
--emit-symbol-graph or -extract-api options into one unified JSON symbolgraph 
file.


https://reviews.llvm.org/D158646

Files:
  clang-tools-extra/CMakeLists.txt
  clang-tools-extra/clang-symbolgraph-merger/CMakeLists.txt
  
clang-tools-extra/clang-symbolgraph-merger/include/clang-symbolgraph-merger/SymbolGraph.h
  
clang-tools-extra/clang-symbolgraph-merger/include/clang-symbolgraph-merger/SymbolGraphMerger.h
  
clang-tools-extra/clang-symbolgraph-merger/include/clang-symbolgraph-merger/SymbolGraphVisitor.h
  clang-tools-extra/clang-symbolgraph-merger/lib/CMakeLists.txt
  clang-tools-extra/clang-symbolgraph-merger/lib/SymbolGraph.cpp
  clang-tools-extra/clang-symbolgraph-merger/lib/SymbolGraphMerger.cpp
  clang-tools-extra/clang-symbolgraph-merger/tool/CMakeLists.txt
  clang-tools-extra/clang-symbolgraph-merger/tool/SymbolGraphMergerMain.cpp
  clang/include/clang/ExtractAPI/AvailabilityInfo.h

Index: clang/include/clang/ExtractAPI/AvailabilityInfo.h
===
--- clang/include/clang/ExtractAPI/AvailabilityInfo.h
+++ clang/include/clang/ExtractAPI/AvailabilityInfo.h
@@ -53,6 +53,12 @@
 
 public:
   AvailabilitySet(const Decl *Decl);
+  AvailabilitySet(AvailabilityList &List,
+  bool UnconditionallyDeprecated = false,
+  bool UnconditionallyUnavailable = false)
+  : Availabilities(List),
+UnconditionallyDeprecated(UnconditionallyDeprecated),
+UnconditionallyUnavailable(UnconditionallyUnavailable) {}
   AvailabilitySet() = default;
 
   AvailabilityList::const_iterator begin() const {
Index: clang-tools-extra/clang-symbolgraph-merger/tool/SymbolGraphMergerMain.cpp
===
--- /dev/null
+++ clang-tools-extra/clang-symbolgraph-merger/tool/SymbolGraphMergerMain.cpp
@@ -0,0 +1,125 @@
+#include "clang-symbolgraph-merger/SymbolGraphMerger.h"
+#include "clang-symbolgraph-merger/SymbolGraphVisitor.h"
+#include "clang/ExtractAPI/Serialization/SymbolGraphSerializer.h"
+#include "clang/Tooling/CommonOptionsParser.h"
+#include "clang/Tooling/Execution.h"
+#include "clang/Tooling/Tooling.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/Path.h"
+#include "llvm/Support/Signals.h"
+#include "llvm/Support/raw_ostream.h"
+#include 
+#include 
+
+using namespace clang::tooling;
+using namespace llvm;
+using namespace sgmerger;
+
+namespace {
+
+bool collectSymbolGraphs(StringRef SGDirectory,
+ SmallVector &SymbolGraphs) {
+  std::error_code Error;
+  for (sys::fs::directory_iterator I(SGDirectory, Error), End; I != End;
+   I.increment(Error)) {
+if (Error)
+  return false;
+std::string File(I->path());
+llvm::ErrorOr Status = I->status();
+if (!Status)
+  return false;
+sys::fs::file_type Type = Status->type();
+// If the file is a directory, ignore the name and recurse.
+if (Type == sys::fs::file_type::directory_file) {
+  if (!collectSymbolGraphs(File, SymbolGraphs))
+return false;
+  continue;
+}
+
+// Ignore all the non json files
+if (!sys::path::extension(File).equals(".json"))
+  continue;
+
+// Read the Symbol Graph from the file
+int FileFD;
+if (auto OpenError = sys::fs::openFileForRead(File, FileFD))
+  return false;
+
+llvm::SmallString<256> Payload;
+if (auto ReadError = sys::fs::readNativeFileToEOF(FileFD, Payload))
+  return false;
+
+SymbolGraphs.emplace_back(SymbolGraph(Payload));
+llvm::sys::fs::closeFile(FileFD);
+  }
+  return true;
+}
+
+} // namespace
+
+static cl::extrahelp CommonHelp(CommonOptionsParser::HelpMessage);
+// TODO: add more help text
+// static cl::extrahelp MoreHelp("\nMore help text...\n");
+
+static cl::OptionCategory
+SymbolGraphMergerCategory("clang-symbolgraph-merger options");
+
+static cl::opt ProjectName("project-name",
+cl::desc("Name of project."),
+cl::cat(SymbolGraphMergerCategory),
+cl::init(""));
+
+static cl::opt
+OutFile("o", cl::desc("File for outputing generated Symbol Graph."),
+cl::cat(SymbolGraphMergerCategory), cl::value_desc("filepath"),
+cl::init("output"));
+
+static cl::opt
+InputDir(cl::Positional, cl::Required, cl::cat(SymbolGraphMergerCategory),
+ cl::value_desc("filepath"),
+ cl::desc("Input directory containing all the SymbolGraphs"));
+
+int main(int argc, const char **argv) {
+  llvm::sys::PrintStackTraceOnError

[PATCH] D157810: [clang][ExtractAPI] Create extractapi::RecordLocation

2023-08-23 Thread Ankur Saini via Phabricator via cfe-commits
Arsenic updated this revision to Diff 552794.
Arsenic added a comment.

- Create function to directly get DocComments from Decl


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157810/new/

https://reviews.llvm.org/D157810

Files:
  clang/include/clang/ExtractAPI/API.h
  clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
  clang/lib/ExtractAPI/API.cpp
  clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
  clang/tools/libclang/CXExtractAPI.cpp

Index: clang/tools/libclang/CXExtractAPI.cpp
===
--- clang/tools/libclang/CXExtractAPI.cpp
+++ clang/tools/libclang/CXExtractAPI.cpp
@@ -61,9 +61,12 @@
 Context.getSourceManager().getPresumedLoc(Decl->getLocation());
 LinkageInfo Linkage = Decl->getLinkageAndVisibility();
 DocComment Comment;
-if (auto *RawComment = fetchRawCommentForDecl(Interface))
-  Comment = RawComment->getFormattedLines(Context.getSourceManager(),
-  Context.getDiagnostics());
+if (auto *RawComment = fetchRawCommentForDecl(Interface)) {
+  auto RawCommentVec = RawComment->getFormattedLines(
+  Context.getSourceManager(), Context.getDiagnostics());
+  std::copy(RawCommentVec.begin(), RawCommentVec.end(),
+std::back_inserter(Comment));
+}
 
 // Build declaration fragments and sub-heading by generating them for the
 // interface.
Index: clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
===
--- clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
+++ clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
@@ -14,6 +14,7 @@
 #include "clang/ExtractAPI/Serialization/SymbolGraphSerializer.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/Version.h"
+#include "clang/ExtractAPI/API.h"
 #include "clang/ExtractAPI/DeclarationFragments.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/STLFunctionalExtras.h"
@@ -105,8 +106,7 @@
 }
 
 /// Serialize a source position.
-Object serializeSourcePosition(const PresumedLoc &Loc) {
-  assert(Loc.isValid() && "invalid source position");
+Object serializeSourcePosition(const RecordLocation &Loc) {
 
   Object SourcePosition;
   SourcePosition["line"] = Loc.getLine();
@@ -120,7 +120,7 @@
 /// \param Loc The presumed location to serialize.
 /// \param IncludeFileURI If true, include the file path of \p Loc as a URI.
 /// Defaults to false.
-Object serializeSourceLocation(const PresumedLoc &Loc,
+Object serializeSourceLocation(const RecordLocation &Loc,
bool IncludeFileURI = false) {
   Object SourceLocation;
   serializeObject(SourceLocation, "position", serializeSourcePosition(Loc));
@@ -136,8 +136,8 @@
 }
 
 /// Serialize a source range with begin and end locations.
-Object serializeSourceRange(const PresumedLoc &BeginLoc,
-const PresumedLoc &EndLoc) {
+Object serializeSourceRange(const RecordLocation &BeginLoc,
+const RecordLocation &EndLoc) {
   Object SourceRange;
   serializeObject(SourceRange, "start", serializeSourcePosition(BeginLoc));
   serializeObject(SourceRange, "end", serializeSourcePosition(EndLoc));
Index: clang/lib/ExtractAPI/API.cpp
===
--- clang/lib/ExtractAPI/API.cpp
+++ clang/lib/ExtractAPI/API.cpp
@@ -46,7 +46,7 @@
 
 NamespaceRecord *
 APISet::addNamespace(APIRecord *Parent, StringRef Name, StringRef USR,
- PresumedLoc Loc, AvailabilitySet Availability,
+ RecordLocation Loc, AvailabilitySet Availability,
  LinkageInfo Linkage, const DocComment &Comment,
  DeclarationFragments Declaration,
  DeclarationFragments SubHeading, bool IsFromSystemHeader) {
@@ -61,7 +61,7 @@
 }
 
 GlobalVariableRecord *
-APISet::addGlobalVar(StringRef Name, StringRef USR, PresumedLoc Loc,
+APISet::addGlobalVar(StringRef Name, StringRef USR, RecordLocation Loc,
  AvailabilitySet Availabilities, LinkageInfo Linkage,
  const DocComment &Comment, DeclarationFragments Fragments,
  DeclarationFragments SubHeading, bool IsFromSystemHeader) {
@@ -71,7 +71,7 @@
 }
 
 GlobalVariableTemplateRecord *APISet::addGlobalVariableTemplate(
-StringRef Name, StringRef USR, PresumedLoc Loc,
+StringRef Name, StringRef USR, RecordLocation Loc,
 AvailabilitySet Availability, LinkageInfo Linkage,
 const DocComment &Comment, DeclarationFragments Declaration,
 DeclarationFragments SubHeading, Template Template,
@@ -83,7 +83,7 @@
 }
 
 GlobalFunctionRecord *APISet::addGlobalFunction(
-StringRef Name, StringRef USR, PresumedLoc Loc,
+StringRef Name, StringRef USR, RecordLocation Loc,
 AvailabilitySet Availabilities, LinkageInfo Linkage,
 const DocComment &

[PATCH] D157810: [clang][ExtractAPI] Create extractapi::RecordLocation

2023-08-13 Thread Ankur Saini via Phabricator via cfe-commits
Arsenic updated this revision to Diff 549691.
Arsenic added a comment.

Fix minor typo in code comments


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157810/new/

https://reviews.llvm.org/D157810

Files:
  clang/include/clang/ExtractAPI/API.h
  clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
  clang/lib/ExtractAPI/API.cpp
  clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
  clang/tools/libclang/CXExtractAPI.cpp

Index: clang/tools/libclang/CXExtractAPI.cpp
===
--- clang/tools/libclang/CXExtractAPI.cpp
+++ clang/tools/libclang/CXExtractAPI.cpp
@@ -61,9 +61,12 @@
 Context.getSourceManager().getPresumedLoc(Decl->getLocation());
 LinkageInfo Linkage = Decl->getLinkageAndVisibility();
 DocComment Comment;
-if (auto *RawComment = fetchRawCommentForDecl(Interface))
-  Comment = RawComment->getFormattedLines(Context.getSourceManager(),
-  Context.getDiagnostics());
+if (auto *RawComment = fetchRawCommentForDecl(Interface)) {
+  auto RawCommentVec = RawComment->getFormattedLines(
+  Context.getSourceManager(), Context.getDiagnostics());
+  std::copy(RawCommentVec.begin(), RawCommentVec.end(),
+std::back_inserter(Comment));
+}
 
 // Build declaration fragments and sub-heading by generating them for the
 // interface.
Index: clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
===
--- clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
+++ clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
@@ -14,6 +14,7 @@
 #include "clang/ExtractAPI/Serialization/SymbolGraphSerializer.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/Version.h"
+#include "clang/ExtractAPI/API.h"
 #include "clang/ExtractAPI/DeclarationFragments.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/STLFunctionalExtras.h"
@@ -105,7 +106,7 @@
 }
 
 /// Serialize a source position.
-Object serializeSourcePosition(const PresumedLoc &Loc) {
+Object serializeSourcePosition(const RecordLocation &Loc) {
   assert(Loc.isValid() && "invalid source position");
 
   Object SourcePosition;
@@ -120,7 +121,7 @@
 /// \param Loc The presumed location to serialize.
 /// \param IncludeFileURI If true, include the file path of \p Loc as a URI.
 /// Defaults to false.
-Object serializeSourceLocation(const PresumedLoc &Loc,
+Object serializeSourceLocation(const RecordLocation &Loc,
bool IncludeFileURI = false) {
   Object SourceLocation;
   serializeObject(SourceLocation, "position", serializeSourcePosition(Loc));
@@ -136,8 +137,8 @@
 }
 
 /// Serialize a source range with begin and end locations.
-Object serializeSourceRange(const PresumedLoc &BeginLoc,
-const PresumedLoc &EndLoc) {
+Object serializeSourceRange(const RecordLocation &BeginLoc,
+const RecordLocation &EndLoc) {
   Object SourceRange;
   serializeObject(SourceRange, "start", serializeSourcePosition(BeginLoc));
   serializeObject(SourceRange, "end", serializeSourcePosition(EndLoc));
Index: clang/lib/ExtractAPI/API.cpp
===
--- clang/lib/ExtractAPI/API.cpp
+++ clang/lib/ExtractAPI/API.cpp
@@ -45,7 +45,7 @@
 } // namespace
 
 GlobalVariableRecord *
-APISet::addGlobalVar(StringRef Name, StringRef USR, PresumedLoc Loc,
+APISet::addGlobalVar(StringRef Name, StringRef USR, RecordLocation Loc,
  AvailabilitySet Availabilities, LinkageInfo Linkage,
  const DocComment &Comment, DeclarationFragments Fragments,
  DeclarationFragments SubHeading, bool IsFromSystemHeader) {
@@ -55,7 +55,7 @@
 }
 
 GlobalFunctionRecord *APISet::addGlobalFunction(
-StringRef Name, StringRef USR, PresumedLoc Loc,
+StringRef Name, StringRef USR, RecordLocation Loc,
 AvailabilitySet Availabilities, LinkageInfo Linkage,
 const DocComment &Comment, DeclarationFragments Fragments,
 DeclarationFragments SubHeading, FunctionSignature Signature,
@@ -67,7 +67,7 @@
 }
 
 EnumConstantRecord *APISet::addEnumConstant(EnumRecord *Enum, StringRef Name,
-StringRef USR, PresumedLoc Loc,
+StringRef USR, RecordLocation Loc,
 AvailabilitySet Availabilities,
 const DocComment &Comment,
 DeclarationFragments Declaration,
@@ -82,7 +82,7 @@
   return Enum->Constants.emplace_back(std::move(Record)).get();
 }
 
-EnumRecord *APISet::addEnum(StringRef Name, StringRef USR, PresumedLoc Loc,
+EnumRecord *APISet::addEnum(StringRef Name, StringRef USR, RecordLocation Loc,

[PATCH] D157810: [clang][ExtractAPI] Create extractapi::RecordLocation

2023-08-13 Thread Ankur Saini via Phabricator via cfe-commits
Arsenic created this revision.
Arsenic added a reviewer: dang.
Herald added a reviewer: ributzka.
Herald added a project: All.
Arsenic requested review of this revision.
Herald added subscribers: cfe-commits, wangpc.
Herald added a project: clang.

Create and use extractapi::RecordLocation instead of conventional
clang::PresumedLoc to track the location of an APIRecord, this reduces
the dependency of APISet on SourceManager and would help if someone
wants to create APISet from JSON Serialized SymbolGraph.

These changes also add extractapi::CommentLine which is similar to
RawComment::CommentLine but use RecordLocation instead of PresumedLoc.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157810

Files:
  clang/include/clang/ExtractAPI/API.h
  clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
  clang/lib/ExtractAPI/API.cpp
  clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
  clang/tools/libclang/CXExtractAPI.cpp

Index: clang/tools/libclang/CXExtractAPI.cpp
===
--- clang/tools/libclang/CXExtractAPI.cpp
+++ clang/tools/libclang/CXExtractAPI.cpp
@@ -61,9 +61,12 @@
 Context.getSourceManager().getPresumedLoc(Decl->getLocation());
 LinkageInfo Linkage = Decl->getLinkageAndVisibility();
 DocComment Comment;
-if (auto *RawComment = fetchRawCommentForDecl(Interface))
-  Comment = RawComment->getFormattedLines(Context.getSourceManager(),
-  Context.getDiagnostics());
+if (auto *RawComment = fetchRawCommentForDecl(Interface)) {
+  auto RawCommentVec = RawComment->getFormattedLines(
+  Context.getSourceManager(), Context.getDiagnostics());
+  std::copy(RawCommentVec.begin(), RawCommentVec.end(),
+std::back_inserter(Comment));
+}
 
 // Build declaration fragments and sub-heading by generating them for the
 // interface.
Index: clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
===
--- clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
+++ clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
@@ -14,6 +14,7 @@
 #include "clang/ExtractAPI/Serialization/SymbolGraphSerializer.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/Version.h"
+#include "clang/ExtractAPI/API.h"
 #include "clang/ExtractAPI/DeclarationFragments.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/STLFunctionalExtras.h"
@@ -105,7 +106,7 @@
 }
 
 /// Serialize a source position.
-Object serializeSourcePosition(const PresumedLoc &Loc) {
+Object serializeSourcePosition(const RecordLocation &Loc) {
   assert(Loc.isValid() && "invalid source position");
 
   Object SourcePosition;
@@ -120,7 +121,7 @@
 /// \param Loc The presumed location to serialize.
 /// \param IncludeFileURI If true, include the file path of \p Loc as a URI.
 /// Defaults to false.
-Object serializeSourceLocation(const PresumedLoc &Loc,
+Object serializeSourceLocation(const RecordLocation &Loc,
bool IncludeFileURI = false) {
   Object SourceLocation;
   serializeObject(SourceLocation, "position", serializeSourcePosition(Loc));
@@ -136,8 +137,8 @@
 }
 
 /// Serialize a source range with begin and end locations.
-Object serializeSourceRange(const PresumedLoc &BeginLoc,
-const PresumedLoc &EndLoc) {
+Object serializeSourceRange(const RecordLocation &BeginLoc,
+const RecordLocation &EndLoc) {
   Object SourceRange;
   serializeObject(SourceRange, "start", serializeSourcePosition(BeginLoc));
   serializeObject(SourceRange, "end", serializeSourcePosition(EndLoc));
Index: clang/lib/ExtractAPI/API.cpp
===
--- clang/lib/ExtractAPI/API.cpp
+++ clang/lib/ExtractAPI/API.cpp
@@ -45,7 +45,7 @@
 } // namespace
 
 GlobalVariableRecord *
-APISet::addGlobalVar(StringRef Name, StringRef USR, PresumedLoc Loc,
+APISet::addGlobalVar(StringRef Name, StringRef USR, RecordLocation Loc,
  AvailabilitySet Availabilities, LinkageInfo Linkage,
  const DocComment &Comment, DeclarationFragments Fragments,
  DeclarationFragments SubHeading, bool IsFromSystemHeader) {
@@ -55,7 +55,7 @@
 }
 
 GlobalFunctionRecord *APISet::addGlobalFunction(
-StringRef Name, StringRef USR, PresumedLoc Loc,
+StringRef Name, StringRef USR, RecordLocation Loc,
 AvailabilitySet Availabilities, LinkageInfo Linkage,
 const DocComment &Comment, DeclarationFragments Fragments,
 DeclarationFragments SubHeading, FunctionSignature Signature,
@@ -67,7 +67,7 @@
 }
 
 EnumConstantRecord *APISet::addEnumConstant(EnumRecord *Enum, StringRef Name,
-StringRef USR, PresumedLoc Loc,
+StringRef USR, RecordLocation Loc,
  

[PATCH] D152356: [clang][ExtractAPI] Add --emit-symbol-graph option

2023-07-03 Thread Ankur Saini via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG8e9145e43142: [clang][ExtractAPI] Add --emit-symbol-graph 
option (authored by Arsenic).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152356/new/

https://reviews.llvm.org/D152356

Files:
  clang/include/clang/Driver/Options.td
  clang/include/clang/ExtractAPI/ExtractAPIActionBase.h
  clang/include/clang/ExtractAPI/FrontendActions.h
  clang/include/clang/Frontend/FrontendOptions.h
  clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
  clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
  clang/test/ExtractAPI/emit-symbol-graph/multi_file.c
  clang/test/ExtractAPI/emit-symbol-graph/single_file.c

Index: clang/test/ExtractAPI/emit-symbol-graph/single_file.c
===
--- /dev/null
+++ clang/test/ExtractAPI/emit-symbol-graph/single_file.c
@@ -0,0 +1,213 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: split-file %s %t
+// RUN: sed -e "s@INPUT_DIR@%{/t:regex_replacement}@g" \
+// RUN: %t/reference.output.json.in >> %t/reference.output.json
+// RUN: %clang_cc1 %t/main.c --emit-symbol-graph=%t/SymbolGraphs --product-name=basicfile -triple=x86_64-apple-macosx12.0.0
+
+// Generator version is not consistent across test runs, normalize it.
+// RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
+// RUN: %t/SymbolGraphs/main.json >> %t/output-normalized.json
+// RUN: diff %t/reference.output.json %t/output-normalized.json
+
+// CHECK-NOT: error:
+// CHECK-NOT: warning:
+
+//--- main.c
+#define TESTMACRO1 2
+#define TESTMARCRO2 5
+
+int main ()
+{
+  return 0;
+}
+
+
+//--- reference.output.json.in
+{
+  "metadata": {
+"formatVersion": {
+  "major": 0,
+  "minor": 5,
+  "patch": 3
+},
+"generator": "?"
+  },
+  "module": {
+"name": "basicfile",
+"platform": {
+  "architecture": "x86_64",
+  "operatingSystem": {
+"name": "macosx"
+  },
+  "vendor": "apple"
+}
+  },
+  "relationships": [],
+  "symbols": [
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "typeIdentifier",
+  "preciseIdentifier": "c:I",
+  "spelling": "int"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "main"
+},
+{
+  "kind": "text",
+  "spelling": "();"
+}
+  ],
+  "functionSignature": {
+"returns": [
+  {
+"kind": "typeIdentifier",
+"preciseIdentifier": "c:I",
+"spelling": "int"
+  }
+]
+  },
+  "identifier": {
+"interfaceLanguage": "c",
+"precise": "c:@F@main"
+  },
+  "kind": {
+"displayName": "Function",
+"identifier": "c.func"
+  },
+  "location": {
+"position": {
+  "character": 5,
+  "line": 4
+},
+"uri": "file://INPUT_DIR/main.c"
+  },
+  "names": {
+"navigator": [
+  {
+"kind": "identifier",
+"spelling": "main"
+  }
+],
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "main"
+  }
+],
+"title": "main"
+  },
+  "pathComponents": [
+"main"
+  ]
+},
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "#define"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "TESTMACRO1"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "c",
+"precise": "c:main.c@8@macro@TESTMACRO1"
+  },
+  "kind": {
+"displayName": "Macro",
+"identifier": "c.macro"
+  },
+  "location": {
+"position": {
+  "character": 9,
+  "line": 1
+},
+"uri": "file://INPUT_DIR/main.c"
+  },
+  "names": {
+"navigator": [
+  {
+"kind": "identifier",
+"spelling": "TESTMACRO1"
+  }
+],
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "TESTMACRO1"
+  }
+],
+"title": "TESTMACRO1"
+  },
+  "pathComponents": [
+"TESTMACRO1"
+  ]
+},
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "#define"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "TESTMARCRO2"
+}
+  ],
+  "identifier": {
+"i

[PATCH] D152356: [clang][ExtractAPI] Add --emit-symbol-graph option

2023-06-28 Thread Ankur Saini via Phabricator via cfe-commits
Arsenic updated this revision to Diff 535630.
Arsenic added a comment.

Changes majorly include fixing issues pointed out by review comments :

- Remove WrappingExtractAPIAction::prepareToExecuteAction()
- Move knownInputFiles from Base action to ExtractAPIFrontendAction
- Fix naming of MacroCallback and symbolGraphConsumer
- Fix minor typos
- Remove BasicExtractAPIVisitor, directly use ExtractAPIVisitor instead


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152356/new/

https://reviews.llvm.org/D152356

Files:
  clang/include/clang/Driver/Options.td
  clang/include/clang/ExtractAPI/ExtractAPIActionBase.h
  clang/include/clang/ExtractAPI/FrontendActions.h
  clang/include/clang/Frontend/FrontendOptions.h
  clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
  clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
  clang/test/ExtractAPI/emit-symbol-graph/multi_file.c
  clang/test/ExtractAPI/emit-symbol-graph/single_file.c

Index: clang/test/ExtractAPI/emit-symbol-graph/single_file.c
===
--- /dev/null
+++ clang/test/ExtractAPI/emit-symbol-graph/single_file.c
@@ -0,0 +1,213 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: split-file %s %t
+// RUN: sed -e "s@INPUT_DIR@%{/t:regex_replacement}@g" \
+// RUN: %t/reference.output.json.in >> %t/reference.output.json
+// RUN: %clang_cc1 %t/main.c --emit-symbol-graph=%t/SymbolGraphs --product-name=basicfile -triple=x86_64-apple-macosx12.0.0
+
+// Generator version is not consistent across test runs, normalize it.
+// RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
+// RUN: %t/SymbolGraphs/main.json >> %t/output-normalized.json
+// RUN: diff %t/reference.output.json %t/output-normalized.json
+
+// CHECK-NOT: error:
+// CHECK-NOT: warning:
+
+//--- main.c
+#define TESTMACRO1 2
+#define TESTMARCRO2 5
+
+int main ()
+{
+  return 0;
+}
+
+
+//--- reference.output.json.in
+{
+  "metadata": {
+"formatVersion": {
+  "major": 0,
+  "minor": 5,
+  "patch": 3
+},
+"generator": "?"
+  },
+  "module": {
+"name": "basicfile",
+"platform": {
+  "architecture": "x86_64",
+  "operatingSystem": {
+"name": "macosx"
+  },
+  "vendor": "apple"
+}
+  },
+  "relationships": [],
+  "symbols": [
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "typeIdentifier",
+  "preciseIdentifier": "c:I",
+  "spelling": "int"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "main"
+},
+{
+  "kind": "text",
+  "spelling": "();"
+}
+  ],
+  "functionSignature": {
+"returns": [
+  {
+"kind": "typeIdentifier",
+"preciseIdentifier": "c:I",
+"spelling": "int"
+  }
+]
+  },
+  "identifier": {
+"interfaceLanguage": "c",
+"precise": "c:@F@main"
+  },
+  "kind": {
+"displayName": "Function",
+"identifier": "c.func"
+  },
+  "location": {
+"position": {
+  "character": 5,
+  "line": 4
+},
+"uri": "file://INPUT_DIR/main.c"
+  },
+  "names": {
+"navigator": [
+  {
+"kind": "identifier",
+"spelling": "main"
+  }
+],
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "main"
+  }
+],
+"title": "main"
+  },
+  "pathComponents": [
+"main"
+  ]
+},
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "#define"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "TESTMACRO1"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "c",
+"precise": "c:main.c@8@macro@TESTMACRO1"
+  },
+  "kind": {
+"displayName": "Macro",
+"identifier": "c.macro"
+  },
+  "location": {
+"position": {
+  "character": 9,
+  "line": 1
+},
+"uri": "file://INPUT_DIR/main.c"
+  },
+  "names": {
+"navigator": [
+  {
+"kind": "identifier",
+"spelling": "TESTMACRO1"
+  }
+],
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "TESTMACRO1"
+  }
+],
+"title": "TESTMACRO1"
+  },
+  "pathComponents": [
+"TESTMACRO1"
+  ]
+},
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "#define"
+},
+{
+  "kind": "tex

[PATCH] D152356: [clang][ExtractAPI] Add --emit-symbol-graph option

2023-06-16 Thread Ankur Saini via Phabricator via cfe-commits
Arsenic created this revision.
Arsenic added a reviewer: dang.
Herald added a reviewer: ributzka.
Herald added a project: All.
Arsenic updated this revision to Diff 529841.
Arsenic added a comment.
Arsenic marked 5 inline comments as done.
Arsenic updated this revision to Diff 532145.
Arsenic updated this revision to Diff 532148.
Arsenic published this revision for review.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

- now "--emit-symbol-garph" should emit all the symbols (even the ones external 
to the input files)
- update tests accordingly
- did changes as suggested in the last review


Arsenic added a comment.

- move ExtractAPIBase to it's own seperate file
- remove ExtractAPIBase::CreateExtractAPIConsumer(), consumer generation is now 
managed by the derived class.
- New BasicExtractAPIVisitor for including all the decls when visiting AST ( 
used by WrappingExtractAPIVisitor )
- New SymbolGraphConsumer for more general symbol graph generation ( emmit all 
the symbols )
- Refactor MacroCallBack for more general case
- New APIMacroCallBack for cases where symbol graph is generated for API 
information of a library ( filter out symbols from external files )


Arsenic added a comment.

remove unnecessary includes from ExtractAPIActionBase.h




Comment at: clang/include/clang/ExtractAPI/FrontendActions.h:21
 #include "clang/Frontend/FrontendAction.h"
+#include "clang/Frontend/MultiplexConsumer.h"
 

Is this include needed here? If not it should go in the cpp file



Comment at: clang/include/clang/ExtractAPI/FrontendActions.h:111
+  /// craeted or not
+  bool createdASTConsumer = false;
+





Comment at: clang/lib/ExtractAPI/ExtractAPIConsumer.cpp:402
+  std::string OutputDir = CI.getFrontendOpts().SymbolGraphOutputDir;
+  if (OutputDir.empty())
+OS = CI.createDefaultOutputFile(/*Binary=*/false, InFile,

I am not sure if the base class is the best place to put this logic in. Maybe 
it would make sense to have a separate implementation for the two derived 
classes.



Comment at: clang/lib/ExtractAPI/ExtractAPIConsumer.cpp:523
+  StringRef FilePath = FIF.getFile();
+  if (auto RelativeName = getRelativeIncludeName(CI, FilePath, &IsQuoted))
+KnownInputFiles.emplace_back(

I am not sure this does exactly what we want from this. We are hoping to get 
symbols that come from project headers here as well. I think that this would 
constrain the visitor to only record symbols that came from the input files 
themselves.



Comment at: clang/test/ExtractAPI/emit-symbol-graph/multi_file.c:8
+// RUN: %t/reference.test.json.in >> %t/reference.test.json
+// RUN: %clang %t/test.c %t/main.c -Xclang --emit-symbol-graph=%t/SymbolGraphs 
-Xclang --product-name=multifile_hello_world -Xclang 
-triple=x86_64-apple-macosx12.0.0
+

I was a bit confused as to whether call the front end or the entire driver so 
currently I have created 2 different tests one for each. 

I called the driver here because it saved me an extra step of linking the 
standard library here.



Comment at: clang/test/ExtractAPI/emit-symbol-graph/multi_file.c:8
+// RUN: %t/reference.test.json.in >> %t/reference.test.json
+// RUN: %clang %t/test.c %t/main.c -Xclang --emit-symbol-graph=%t/SymbolGraphs 
-Xclang --product-name=multifile_hello_world -Xclang 
-triple=x86_64-apple-macosx12.0.0
+

Arsenic wrote:
> I was a bit confused as to whether call the front end or the entire driver so 
> currently I have created 2 different tests one for each. 
> 
> I called the driver here because it saved me an extra step of linking the 
> standard library here.
> I was a bit confused as to whether call the front end or the entire driver so 
> currently I have created 2 different tests one for each. 
> 
> I called the driver here because it saved me an extra step of linking the 
> standard library here.

The current tests only test if the generated symbol-graphs are correct or not, 
and does not check if the output file was generated or not, What would be a 
good way to test for the regular output file. 
Should we only test for their existence of the output files or something else 
also.



Comment at: clang/test/ExtractAPI/emit-symbol-graph/multi_file.c:8
+// RUN: %t/reference.test.json.in >> %t/reference.test.json
+// RUN: %clang %t/test.c %t/main.c -Xclang --emit-symbol-graph=%t/SymbolGraphs 
-Xclang --product-name=multifile_hello_world -Xclang 
-triple=x86_64-apple-macosx12.0.0
+

Arsenic wrote:
> Arsenic wrote:
> > I was a bit confused as to whether call the front end or the entire driver 
> > so currently I have created 2 different tests one for each. 
> > 
> > I called the driver here because it saved me an extra step of linking the 
> > standard library here.
> > I was a bit confused as to whether ca

[PATCH] D145869: [clang][ExtractAPI] Add multiple file support to --extract-api-ignores

2023-03-13 Thread Ankur Saini via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG58825d2cf947: [clang][ExtractAPI] Add multiple file support 
to --extract-api-ignores (authored by Arsenic).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D145869/new/

https://reviews.llvm.org/D145869

Files:
  clang/include/clang/Driver/Options.td
  clang/include/clang/ExtractAPI/APIIgnoresList.h
  clang/include/clang/Frontend/FrontendOptions.h
  clang/lib/ExtractAPI/APIIgnoresList.cpp
  clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
  clang/test/ExtractAPI/ignored-symbols-multifile.c

Index: clang/test/ExtractAPI/ignored-symbols-multifile.c
===
--- /dev/null
+++ clang/test/ExtractAPI/ignored-symbols-multifile.c
@@ -0,0 +1,44 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: %clang_cc1 -extract-api -triple arm64-apple-macosx \
+// RUN:   --extract-api-ignores=%t/ignores-list1,%t/ignores-list2,%t/ignores-list3 \
+// RUN:   -x c-header %t/input.h -verify -o - | FileCheck %t/input.h
+
+//--- input.h
+#define IGNORED_6_FILE1 6
+#define IGNORED_2_FILE1 2
+#define IGNORED_5_FILE1 5
+
+#define IGNORED_4_FILE2 4
+#define IGNORED_3_FILE2 3
+
+typedef double IGNORED_1_FILE3;
+typedef int IGNORED_7_FILE3;
+
+typedef float NonIgnored;
+
+// CHECK-NOT: IGNORED_6_FILE1
+// CHECK-NOT: IGNORED_2_FILE1
+// CHECK-NOT: IGNORED_5_FILE1
+
+// CHECK-NOT: IGNORED_4_FILE2
+// CHECK-NOT: IGNORED_3_FILE2
+
+// CHECK-NOT: IGNORED_1_FILE3
+// CHECK-NOT: IGNORED_7_FILE3
+// CHECK: NonIgnored
+
+// expected-no-diagnostics
+
+//--- ignores-list1
+IGNORED_6_FILE1
+IGNORED_2_FILE1
+IGNORED_5_FILE1
+
+//--- ignores-list2
+IGNORED_4_FILE2
+IGNORED_3_FILE2
+
+//--- ignores-list3
+IGNORED_1_FILE3
+IGNORED_7_FILE3
Index: clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
===
--- clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
+++ clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
@@ -339,9 +339,9 @@
   Policy.AnonymousTagLocations = false;
   CI.getASTContext().setPrintingPolicy(Policy);
 
-  if (!CI.getFrontendOpts().ExtractAPIIgnoresFile.empty()) {
+  if (!CI.getFrontendOpts().ExtractAPIIgnoresFileList.empty()) {
 llvm::handleAllErrors(
-APIIgnoresList::create(CI.getFrontendOpts().ExtractAPIIgnoresFile,
+APIIgnoresList::create(CI.getFrontendOpts().ExtractAPIIgnoresFileList,
CI.getFileManager())
 .moveInto(IgnoresList),
 [&CI](const IgnoresFileNotFound &Err) {
Index: clang/lib/ExtractAPI/APIIgnoresList.cpp
===
--- clang/lib/ExtractAPI/APIIgnoresList.cpp
+++ clang/lib/ExtractAPI/APIIgnoresList.cpp
@@ -31,20 +31,29 @@
   return llvm::inconvertibleErrorCode();
 }
 
-Expected APIIgnoresList::create(StringRef IgnoresFilePath,
-FileManager &FM) {
-  auto BufferOrErr = FM.getBufferForFile(IgnoresFilePath);
-  if (!BufferOrErr)
-return make_error(IgnoresFilePath);
-
-  auto Buffer = std::move(BufferOrErr.get());
+Expected
+APIIgnoresList::create(const FilePathList &IgnoresFilePathList,
+   FileManager &FM) {
   SmallVector Lines;
-  Buffer->getBuffer().split(Lines, '\n', /*MaxSplit*/ -1, /*KeepEmpty*/ false);
-  // Symbol names don't have spaces in them, let's just remove these in case the
-  // input is slighlty malformed.
+  BufferList symbolBufferList;
+
+  for (const auto &CurrentIgnoresFilePath : IgnoresFilePathList) {
+auto BufferOrErr = FM.getBufferForFile(CurrentIgnoresFilePath);
+
+if (!BufferOrErr)
+  return make_error(CurrentIgnoresFilePath);
+
+auto Buffer = std::move(BufferOrErr.get());
+Buffer->getBuffer().split(Lines, '\n', /*MaxSplit*/ -1,
+  /*KeepEmpty*/ false);
+symbolBufferList.push_back(std::move(Buffer));
+  }
+
+  // Symbol names don't have spaces in them, let's just remove these in case
+  // the input is slighlty malformed.
   transform(Lines, Lines.begin(), [](StringRef Line) { return Line.trim(); });
   sort(Lines);
-  return APIIgnoresList(std::move(Lines), std::move(Buffer));
+  return APIIgnoresList(std::move(Lines), std::move(symbolBufferList));
 }
 
 bool APIIgnoresList::shouldIgnore(StringRef SymbolName) const {
Index: clang/include/clang/Frontend/FrontendOptions.h
===
--- clang/include/clang/Frontend/FrontendOptions.h
+++ clang/include/clang/Frontend/FrontendOptions.h
@@ -453,8 +453,9 @@
   std::string ProductName;
 
   // Currently this is only used as part of the `-extract-api` action.
-  /// The file providing a list of APIs to ignore when extracting documentation
-  std::string ExtractAPIIgnoresFile;
+  // A comma seperated list of files providing a list of APIs to
+  // ignore when extrac

[PATCH] D145869: [clang][ExtractAPI] Add multiple file support to --extract-api-ignores

2023-03-13 Thread Ankur Saini via Phabricator via cfe-commits
Arsenic updated this revision to Diff 504594.
Arsenic added a comment.

fix test


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D145869/new/

https://reviews.llvm.org/D145869

Files:
  clang/include/clang/Driver/Options.td
  clang/include/clang/ExtractAPI/APIIgnoresList.h
  clang/include/clang/Frontend/FrontendOptions.h
  clang/lib/ExtractAPI/APIIgnoresList.cpp
  clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
  clang/test/ExtractAPI/ignored-symbols-multifile.c

Index: clang/test/ExtractAPI/ignored-symbols-multifile.c
===
--- /dev/null
+++ clang/test/ExtractAPI/ignored-symbols-multifile.c
@@ -0,0 +1,44 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: %clang_cc1 -extract-api -triple arm64-apple-macosx \
+// RUN:   --extract-api-ignores=%t/ignores-list1,%t/ignores-list2,%t/ignores-list3 \
+// RUN:   -x c-header %t/input.h -verify -o - | FileCheck %t/input.h
+
+//--- input.h
+#define IGNORED_6_FILE1 6
+#define IGNORED_2_FILE1 2
+#define IGNORED_5_FILE1 5
+
+#define IGNORED_4_FILE2 4
+#define IGNORED_3_FILE2 3
+
+typedef double IGNORED_1_FILE3;
+typedef int IGNORED_7_FILE3;
+
+typedef float NonIgnored;
+
+// CHECK-NOT: IGNORED_6_FILE1
+// CHECK-NOT: IGNORED_2_FILE1
+// CHECK-NOT: IGNORED_5_FILE1
+
+// CHECK-NOT: IGNORED_4_FILE2
+// CHECK-NOT: IGNORED_3_FILE2
+
+// CHECK-NOT: IGNORED_1_FILE3
+// CHECK-NOT: IGNORED_7_FILE3
+// CHECK: NonIgnored
+
+// expected-no-diagnostics
+
+//--- ignores-list1
+IGNORED_6_FILE1
+IGNORED_2_FILE1
+IGNORED_5_FILE1
+
+//--- ignores-list2
+IGNORED_4_FILE2
+IGNORED_3_FILE2
+
+//--- ignores-list3
+IGNORED_1_FILE3
+IGNORED_7_FILE3
Index: clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
===
--- clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
+++ clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
@@ -339,9 +339,9 @@
   Policy.AnonymousTagLocations = false;
   CI.getASTContext().setPrintingPolicy(Policy);
 
-  if (!CI.getFrontendOpts().ExtractAPIIgnoresFile.empty()) {
+  if (!CI.getFrontendOpts().ExtractAPIIgnoresFileList.empty()) {
 llvm::handleAllErrors(
-APIIgnoresList::create(CI.getFrontendOpts().ExtractAPIIgnoresFile,
+APIIgnoresList::create(CI.getFrontendOpts().ExtractAPIIgnoresFileList,
CI.getFileManager())
 .moveInto(IgnoresList),
 [&CI](const IgnoresFileNotFound &Err) {
Index: clang/lib/ExtractAPI/APIIgnoresList.cpp
===
--- clang/lib/ExtractAPI/APIIgnoresList.cpp
+++ clang/lib/ExtractAPI/APIIgnoresList.cpp
@@ -31,20 +31,29 @@
   return llvm::inconvertibleErrorCode();
 }
 
-Expected APIIgnoresList::create(StringRef IgnoresFilePath,
-FileManager &FM) {
-  auto BufferOrErr = FM.getBufferForFile(IgnoresFilePath);
-  if (!BufferOrErr)
-return make_error(IgnoresFilePath);
-
-  auto Buffer = std::move(BufferOrErr.get());
+Expected
+APIIgnoresList::create(const FilePathList &IgnoresFilePathList,
+   FileManager &FM) {
   SmallVector Lines;
-  Buffer->getBuffer().split(Lines, '\n', /*MaxSplit*/ -1, /*KeepEmpty*/ false);
-  // Symbol names don't have spaces in them, let's just remove these in case the
-  // input is slighlty malformed.
+  BufferList symbolBufferList;
+
+  for (const auto &CurrentIgnoresFilePath : IgnoresFilePathList) {
+auto BufferOrErr = FM.getBufferForFile(CurrentIgnoresFilePath);
+
+if (!BufferOrErr)
+  return make_error(CurrentIgnoresFilePath);
+
+auto Buffer = std::move(BufferOrErr.get());
+Buffer->getBuffer().split(Lines, '\n', /*MaxSplit*/ -1,
+  /*KeepEmpty*/ false);
+symbolBufferList.push_back(std::move(Buffer));
+  }
+
+  // Symbol names don't have spaces in them, let's just remove these in case
+  // the input is slighlty malformed.
   transform(Lines, Lines.begin(), [](StringRef Line) { return Line.trim(); });
   sort(Lines);
-  return APIIgnoresList(std::move(Lines), std::move(Buffer));
+  return APIIgnoresList(std::move(Lines), std::move(symbolBufferList));
 }
 
 bool APIIgnoresList::shouldIgnore(StringRef SymbolName) const {
Index: clang/include/clang/Frontend/FrontendOptions.h
===
--- clang/include/clang/Frontend/FrontendOptions.h
+++ clang/include/clang/Frontend/FrontendOptions.h
@@ -453,8 +453,9 @@
   std::string ProductName;
 
   // Currently this is only used as part of the `-extract-api` action.
-  /// The file providing a list of APIs to ignore when extracting documentation
-  std::string ExtractAPIIgnoresFile;
+  // A comma seperated list of files providing a list of APIs to
+  // ignore when extracting documentation.
+  std::vector ExtractAPIIgnoresFileList;
 
   /// Args to pass to the plugins
   std::map> PluginArgs;
Index: clang/include/clang/ExtractAPI/APIIgnoresList

[PATCH] D145869: [clang][ExtractAPI] Add multiple file support to --extract-api-ignores

2023-03-13 Thread Ankur Saini via Phabricator via cfe-commits
Arsenic updated this revision to Diff 504590.
Arsenic added a comment.

Update clang/test/ExtractAPI/ignored-symbols-multifile.c :
Shuffle the order of ignored symbols in test to check the sorting behaviour of 
APIIgnoresList


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D145869/new/

https://reviews.llvm.org/D145869

Files:
  clang/include/clang/Driver/Options.td
  clang/include/clang/ExtractAPI/APIIgnoresList.h
  clang/include/clang/Frontend/FrontendOptions.h
  clang/lib/ExtractAPI/APIIgnoresList.cpp
  clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
  clang/test/ExtractAPI/ignored-symbols-multifile.c

Index: clang/test/ExtractAPI/ignored-symbols-multifile.c
===
--- /dev/null
+++ clang/test/ExtractAPI/ignored-symbols-multifile.c
@@ -0,0 +1,44 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: %clang_cc1 -extract-api -triple arm64-apple-macosx \
+// RUN:   --extract-api-ignores=%t/ignores-list1,%t/ignores-list2,%t/ignores-list3 \
+// RUN:   -x c-header %t/input.h -verify -o - | FileCheck %t/input.h
+
+//--- input.h
+#define IGNORED_6_FILE1 6
+#define IGNORED_2_FILE1 2
+#define IGNORED_5_FILE1 5
+
+#define IGNORED_4_FILE2 4
+#define IGNORED_3_FILE2 3
+
+typedef double IGNORED_1_FILE3;
+typedef int IGNORED_7_FILE3;
+
+typedef float NonIgnored;
+
+// CHECK-NOT: IGNORED_1_FILE1
+// CHECK-NOT: IGNORED_2_FILE1
+// CHECK-NOT: IGNORED_3_FILE1
+
+// CHECK-NOT: IGNORED_4_FILE2
+// CHECK-NOT: IGNORED_5_FILE2
+
+// CHECK-NOT: IGNORED_1_FILE3
+// CHECK-NOT: IGNORED_7_FILE3
+// CHECK: NonIgnored
+
+// expected-no-diagnostics
+
+//--- ignores-list1
+IGNORED_6_FILE1
+IGNORED_2_FILE1
+IGNORED_5_FILE1
+
+//--- ignores-list2
+IGNORED_4_FILE2
+IGNORED_3_FILE2
+
+//--- ignores-list3
+IGNORED_1_FILE3
+IGNORED_7_FILE3
Index: clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
===
--- clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
+++ clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
@@ -339,9 +339,9 @@
   Policy.AnonymousTagLocations = false;
   CI.getASTContext().setPrintingPolicy(Policy);
 
-  if (!CI.getFrontendOpts().ExtractAPIIgnoresFile.empty()) {
+  if (!CI.getFrontendOpts().ExtractAPIIgnoresFileList.empty()) {
 llvm::handleAllErrors(
-APIIgnoresList::create(CI.getFrontendOpts().ExtractAPIIgnoresFile,
+APIIgnoresList::create(CI.getFrontendOpts().ExtractAPIIgnoresFileList,
CI.getFileManager())
 .moveInto(IgnoresList),
 [&CI](const IgnoresFileNotFound &Err) {
Index: clang/lib/ExtractAPI/APIIgnoresList.cpp
===
--- clang/lib/ExtractAPI/APIIgnoresList.cpp
+++ clang/lib/ExtractAPI/APIIgnoresList.cpp
@@ -31,20 +31,29 @@
   return llvm::inconvertibleErrorCode();
 }
 
-Expected APIIgnoresList::create(StringRef IgnoresFilePath,
-FileManager &FM) {
-  auto BufferOrErr = FM.getBufferForFile(IgnoresFilePath);
-  if (!BufferOrErr)
-return make_error(IgnoresFilePath);
-
-  auto Buffer = std::move(BufferOrErr.get());
+Expected
+APIIgnoresList::create(const FilePathList &IgnoresFilePathList,
+   FileManager &FM) {
   SmallVector Lines;
-  Buffer->getBuffer().split(Lines, '\n', /*MaxSplit*/ -1, /*KeepEmpty*/ false);
-  // Symbol names don't have spaces in them, let's just remove these in case the
-  // input is slighlty malformed.
+  BufferList symbolBufferList;
+
+  for (const auto &CurrentIgnoresFilePath : IgnoresFilePathList) {
+auto BufferOrErr = FM.getBufferForFile(CurrentIgnoresFilePath);
+
+if (!BufferOrErr)
+  return make_error(CurrentIgnoresFilePath);
+
+auto Buffer = std::move(BufferOrErr.get());
+Buffer->getBuffer().split(Lines, '\n', /*MaxSplit*/ -1,
+  /*KeepEmpty*/ false);
+symbolBufferList.push_back(std::move(Buffer));
+  }
+
+  // Symbol names don't have spaces in them, let's just remove these in case
+  // the input is slighlty malformed.
   transform(Lines, Lines.begin(), [](StringRef Line) { return Line.trim(); });
   sort(Lines);
-  return APIIgnoresList(std::move(Lines), std::move(Buffer));
+  return APIIgnoresList(std::move(Lines), std::move(symbolBufferList));
 }
 
 bool APIIgnoresList::shouldIgnore(StringRef SymbolName) const {
Index: clang/include/clang/Frontend/FrontendOptions.h
===
--- clang/include/clang/Frontend/FrontendOptions.h
+++ clang/include/clang/Frontend/FrontendOptions.h
@@ -453,8 +453,9 @@
   std::string ProductName;
 
   // Currently this is only used as part of the `-extract-api` action.
-  /// The file providing a list of APIs to ignore when extracting documentation
-  std::string ExtractAPIIgnoresFile;
+  // A comma seperated list of files providing a list of APIs to
+  // ignore when extracting documentation.
+  std::vec

[PATCH] D145869: [clang][ExtractAPI] Add multiple file support to --extract-api-ignores

2023-03-12 Thread Ankur Saini via Phabricator via cfe-commits
Arsenic created this revision.
Herald added a reviewer: ributzka.
Herald added a project: All.
Arsenic requested review of this revision.
Herald added a reviewer: dang.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

- Modify -extract-api-ignores command line option to accept multiple arguments
- Update APIIgnoresList to operate on a file list instead of a single file
- Add new test verifying the functionality
- fix #61242 on GitHub issue tracker


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D145869

Files:
  clang/include/clang/Driver/Options.td
  clang/include/clang/ExtractAPI/APIIgnoresList.h
  clang/include/clang/Frontend/FrontendOptions.h
  clang/lib/ExtractAPI/APIIgnoresList.cpp
  clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
  clang/test/ExtractAPI/ignored-symbols-multifile.c

Index: clang/test/ExtractAPI/ignored-symbols-multifile.c
===
--- /dev/null
+++ clang/test/ExtractAPI/ignored-symbols-multifile.c
@@ -0,0 +1,44 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: %clang_cc1 -extract-api -triple arm64-apple-macosx \
+// RUN:   --extract-api-ignores=%t/ignores-list1,%t/ignores-list2,%t/ignores-list3 \
+// RUN:   -x c-header %t/input.h -verify -o - | FileCheck %t/input.h
+
+//--- input.h
+#define IGNORED_FILE1_1 1
+#define IGNORED_FILE1_2 2
+#define IGNORED_FILE1_3 3
+
+#define IGNORED_FILE2_4 4
+#define IGNORED_FILE2_5 5
+
+typedef double IGNORED_FILE3_6;
+typedef int IGNORED_FILE3_7;
+
+typedef float NonIgnored;
+
+// CHECK-NOT: IGNORED_FILE1_1
+// CHECK-NOT: IGNORED_FILE1_2
+// CHECK-NOT: IGNORED_FILE1_3
+
+// CHECK-NOT: IGNORED_FILE2_4
+// CHECK-NOT: IGNORED_FILE2_5
+
+// CHECK-NOT: IGNORED_FILE3_6
+// CHECK-NOT: IGNORED_FILE3_7
+// CHECK: NonIgnored
+
+// expected-no-diagnostics
+
+//--- ignores-list1
+IGNORED_FILE1_1
+IGNORED_FILE1_2
+IGNORED_FILE1_3
+
+//--- ignores-list2
+IGNORED_FILE2_4
+IGNORED_FILE2_5
+
+//--- ignores-list3
+IGNORED_FILE3_6
+IGNORED_FILE3_7
Index: clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
===
--- clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
+++ clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
@@ -339,9 +339,9 @@
   Policy.AnonymousTagLocations = false;
   CI.getASTContext().setPrintingPolicy(Policy);
 
-  if (!CI.getFrontendOpts().ExtractAPIIgnoresFile.empty()) {
+  if (!CI.getFrontendOpts().ExtractAPIIgnoresFileList.empty()) {
 llvm::handleAllErrors(
-APIIgnoresList::create(CI.getFrontendOpts().ExtractAPIIgnoresFile,
+APIIgnoresList::create(CI.getFrontendOpts().ExtractAPIIgnoresFileList,
CI.getFileManager())
 .moveInto(IgnoresList),
 [&CI](const IgnoresFileNotFound &Err) {
Index: clang/lib/ExtractAPI/APIIgnoresList.cpp
===
--- clang/lib/ExtractAPI/APIIgnoresList.cpp
+++ clang/lib/ExtractAPI/APIIgnoresList.cpp
@@ -31,20 +31,29 @@
   return llvm::inconvertibleErrorCode();
 }
 
-Expected APIIgnoresList::create(StringRef IgnoresFilePath,
-FileManager &FM) {
-  auto BufferOrErr = FM.getBufferForFile(IgnoresFilePath);
-  if (!BufferOrErr)
-return make_error(IgnoresFilePath);
-
-  auto Buffer = std::move(BufferOrErr.get());
+Expected
+APIIgnoresList::create(const FilePathList &IgnoresFilePathList,
+   FileManager &FM) {
   SmallVector Lines;
-  Buffer->getBuffer().split(Lines, '\n', /*MaxSplit*/ -1, /*KeepEmpty*/ false);
-  // Symbol names don't have spaces in them, let's just remove these in case the
-  // input is slighlty malformed.
+  BufferList symbolBufferList;
+
+  for (const auto &CurrentIgnoresFilePath : IgnoresFilePathList) {
+auto BufferOrErr = FM.getBufferForFile(CurrentIgnoresFilePath);
+
+if (!BufferOrErr)
+  return make_error(CurrentIgnoresFilePath);
+
+auto Buffer = std::move(BufferOrErr.get());
+Buffer->getBuffer().split(Lines, '\n', /*MaxSplit*/ -1,
+  /*KeepEmpty*/ false);
+symbolBufferList.push_back(std::move(Buffer));
+  }
+
+  // Symbol names don't have spaces in them, let's just remove these in case
+  // the input is slighlty malformed.
   transform(Lines, Lines.begin(), [](StringRef Line) { return Line.trim(); });
   sort(Lines);
-  return APIIgnoresList(std::move(Lines), std::move(Buffer));
+  return APIIgnoresList(std::move(Lines), std::move(symbolBufferList));
 }
 
 bool APIIgnoresList::shouldIgnore(StringRef SymbolName) const {
Index: clang/include/clang/Frontend/FrontendOptions.h
===
--- clang/include/clang/Frontend/FrontendOptions.h
+++ clang/include/clang/Frontend/FrontendOptions.h
@@ -453,8 +453,9 @@
   std::string ProductName;
 
   // Currently this is only used as part of the `-extract-api` action.
-  /// The file providing a list of APIs to ignore when ex

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

2023-02-28 Thread Ankur Saini via Phabricator via cfe-commits
Arsenic abandoned this revision.
Arsenic added a comment.

duplicate of https://reviews.llvm.org/D144940


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D144964/new/

https://reviews.llvm.org/D144964

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2023-02-28 Thread Ankur Saini via Phabricator via cfe-commits
Arsenic updated this revision to Diff 501148.
Arsenic added a comment.

Add test to check platform specific unavailability

The update also remove the useless changes that were introduced by
using clang format on the entire file instead of current commit.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D144940/new/

https://reviews.llvm.org/D144940

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


Index: clang/test/ExtractAPI/availability.c
===
--- clang/test/ExtractAPI/availability.c
+++ clang/test/ExtractAPI/availability.c
@@ -26,6 +26,9 @@
 void f(void) __attribute__((unavailable)) __attribute__((availability(macos, 
introduced=11.0)));
 
 void d(void) __attribute__((availability(tvos, introduced=15.0)));
+
+void e(void) __attribute__((availability(tvos, unavailable)));
+
 ///expected-no-diagnostics
 
 //--- reference.output.json.in
@@ -391,6 +394,10 @@
 "minor": 0,
 "patch": 0
   }
+},
+{
+  "domain": "tvos",
+  "isUnconditionallyUnavailable": true
 }
   ],
   "declarationFragments": [
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));
   }
 
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,12 +33,14 @@
   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 {


Index: clang/test/ExtractAPI/availability.c
===
--- clang/test/ExtractAPI/availability.c
+++ clang/test/ExtractAPI/availability.c
@@ -26,6 +26,9 @@
 void f(void) __attribute__((unavailable)) __attribute__((availability(macos, introduced=11.0)));
 
 void d(void) __attribute__((availability(tvos, introduced=15.0)));
+
+void e(void) __attribute__((availability(tvos, unavailable)));
+
 ///expected-no-diagnostics
 
 //--- reference.output.json.in
@@ -391,6 +394,10 @@
 "minor": 0,
 "patch": 0
   }
+},
+{
+  "domain": "tvos",
+  "isUnconditionallyUnavailable": true
 }
   ],
   "declarationFragments": [
Index: clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
===
--- cla

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

2023-02-28 Thread Ankur Saini via Phabricator via cfe-commits
Arsenic created this revision.
Herald added a reviewer: ributzka.
Herald added a project: All.
Arsenic requested review of this revision.
Herald added a reviewer: dang.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

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

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


Index: clang/test/ExtractAPI/availability.c
===
--- clang/test/ExtractAPI/availability.c
+++ clang/test/ExtractAPI/availability.c
@@ -26,6 +26,9 @@
 void f(void) __attribute__((unavailable)) __attribute__((availability(macos, 
introduced=11.0)));
 
 void d(void) __attribute__((availability(tvos, introduced=15.0)));
+
+void e(void) __attribute__((availability(tvos, unavailable)));
+
 ///expected-no-diagnostics
 
 //--- reference.output.json.in
@@ -391,6 +394,10 @@
 "minor": 0,
 "patch": 0
   }
+},
+{
+  "domain": "tvos",
+  "isUnconditionallyUnavailable": true
 }
   ],
   "declarationFragments": [
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));
   }
 
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,12 +33,14 @@
   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 {


Index: clang/test/ExtractAPI/availability.c
===
--- clang/test/ExtractAPI/availability.c
+++ clang/test/ExtractAPI/availability.c
@@ -26,6 +26,9 @@
 void f(void) __attribute__((unavailable)) __attribute__((availability(macos, introduced=11.0)));
 
 void d(void) __attribute__((availability(tvos, introduced=15.0)));
+
+void e(void) __attribute__((availability(tvos, unavailable)));
+
 ///expected-no-diagnostics
 
 //--- reference.output.json.in
@@ -391,6 +394,10 @@
 "minor": 0,
 "patch": 0
   }
+},
+{
+  "domain": "tvos",
+  "isUnconditionallyUnavailable": true
 }
   ],
   "declarationFragments": [
Index: clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
==

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

2023-02-28 Thread Ankur Saini via Phabricator via cfe-commits
Arsenic added a comment.

In D144940#4158020 , @dang wrote:

> Nice! glad to see this getting fixed. You should add a lit test to ensure we 
> don't regress this behavior in the future.

I see a test checking for availability attribute already exists ( 
`clang/test/ExtractAPI/availability.c` ) would it be better if I update it with 
another function having a platform specific unavailability attribute or should 
I create a new test file ?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D144940/new/

https://reviews.llvm.org/D144940

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2023-02-27 Thread Ankur Saini via Phabricator via cfe-commits
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;
+  using AvailabilityList = llvm::SmallVector;
   AvailabilityList Availabilities;
 
   bool UnconditionallyDeprecated = false;


Index: clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
===
--- clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
+++ clang/lib/ExtractAP