aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm-project/clang/lib/ExtractAPI
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2023-09-02 21:17:18 +0000
committerDimitry Andric <dim@FreeBSD.org>2023-12-08 17:34:50 +0000
commit06c3fb2749bda94cb5201f81ffdb8fa6c3161b2e (patch)
tree62f873df87c7c675557a179e0c4c83fe9f3087bc /contrib/llvm-project/clang/lib/ExtractAPI
parentcf037972ea8863e2bab7461d77345367d2c1e054 (diff)
parent7fa27ce4a07f19b07799a767fc29416f3b625afb (diff)
Diffstat (limited to 'contrib/llvm-project/clang/lib/ExtractAPI')
-rw-r--r--contrib/llvm-project/clang/lib/ExtractAPI/API.cpp5
-rw-r--r--contrib/llvm-project/clang/lib/ExtractAPI/APIIgnoresList.cpp31
-rw-r--r--contrib/llvm-project/clang/lib/ExtractAPI/AvailabilityInfo.cpp4
-rw-r--r--contrib/llvm-project/clang/lib/ExtractAPI/DeclarationFragments.cpp57
-rw-r--r--contrib/llvm-project/clang/lib/ExtractAPI/ExtractAPIConsumer.cpp194
-rw-r--r--contrib/llvm-project/clang/lib/ExtractAPI/ExtractAPIVisitor.cpp560
-rw-r--r--contrib/llvm-project/clang/lib/ExtractAPI/Serialization/SerializerBase.cpp19
-rw-r--r--contrib/llvm-project/clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp107
-rw-r--r--contrib/llvm-project/clang/lib/ExtractAPI/TypedefUnderlyingTypeResolver.cpp2
-rw-r--r--contrib/llvm-project/clang/lib/ExtractAPI/TypedefUnderlyingTypeResolver.h48
10 files changed, 271 insertions, 756 deletions
diff --git a/contrib/llvm-project/clang/lib/ExtractAPI/API.cpp b/contrib/llvm-project/clang/lib/ExtractAPI/API.cpp
index 553b7bbe710f..10e79b37de73 100644
--- a/contrib/llvm-project/clang/lib/ExtractAPI/API.cpp
+++ b/contrib/llvm-project/clang/lib/ExtractAPI/API.cpp
@@ -249,10 +249,7 @@ APIRecord *APISet::findRecordForUSR(StringRef USR) const {
if (USR.empty())
return nullptr;
- auto It = USRBasedLookupTable.find(USR);
- if (It != USRBasedLookupTable.end())
- return It->second;
- return nullptr;
+ return USRBasedLookupTable.lookup(USR);
}
StringRef APISet::recordUSR(const Decl *D) {
diff --git a/contrib/llvm-project/clang/lib/ExtractAPI/APIIgnoresList.cpp b/contrib/llvm-project/clang/lib/ExtractAPI/APIIgnoresList.cpp
index 1d65ae2b8e31..d6bbc6692d2b 100644
--- a/contrib/llvm-project/clang/lib/ExtractAPI/APIIgnoresList.cpp
+++ b/contrib/llvm-project/clang/lib/ExtractAPI/APIIgnoresList.cpp
@@ -31,20 +31,29 @@ std::error_code IgnoresFileNotFound::convertToErrorCode() const {
return llvm::inconvertibleErrorCode();
}
-Expected<APIIgnoresList> APIIgnoresList::create(StringRef IgnoresFilePath,
- FileManager &FM) {
- auto BufferOrErr = FM.getBufferForFile(IgnoresFilePath);
- if (!BufferOrErr)
- return make_error<IgnoresFileNotFound>(IgnoresFilePath);
-
- auto Buffer = std::move(BufferOrErr.get());
+Expected<APIIgnoresList>
+APIIgnoresList::create(const FilePathList &IgnoresFilePathList,
+ FileManager &FM) {
SmallVector<StringRef, 32> 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<IgnoresFileNotFound>(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 {
diff --git a/contrib/llvm-project/clang/lib/ExtractAPI/AvailabilityInfo.cpp b/contrib/llvm-project/clang/lib/ExtractAPI/AvailabilityInfo.cpp
index ada64cfb92e6..1df852fdbf93 100644
--- a/contrib/llvm-project/clang/lib/ExtractAPI/AvailabilityInfo.cpp
+++ b/contrib/llvm-project/clang/lib/ExtractAPI/AvailabilityInfo.cpp
@@ -42,8 +42,8 @@ AvailabilitySet::AvailabilitySet(const Decl *Decl) {
Availability->Obsoleted = Attr->getObsoleted();
} else {
Availabilities.emplace_back(Domain, Attr->getIntroduced(),
- Attr->getDeprecated(),
- Attr->getObsoleted());
+ Attr->getDeprecated(), Attr->getObsoleted(),
+ Attr->getUnavailable());
}
}
}
diff --git a/contrib/llvm-project/clang/lib/ExtractAPI/DeclarationFragments.cpp b/contrib/llvm-project/clang/lib/ExtractAPI/DeclarationFragments.cpp
index 12c91c582aa9..1e52f221c798 100644
--- a/contrib/llvm-project/clang/lib/ExtractAPI/DeclarationFragments.cpp
+++ b/contrib/llvm-project/clang/lib/ExtractAPI/DeclarationFragments.cpp
@@ -12,7 +12,7 @@
//===----------------------------------------------------------------------===//
#include "clang/ExtractAPI/DeclarationFragments.h"
-#include "TypedefUnderlyingTypeResolver.h"
+#include "clang/ExtractAPI/TypedefUnderlyingTypeResolver.h"
#include "clang/Index/USRGeneration.h"
#include "llvm/ADT/StringSwitch.h"
@@ -160,14 +160,26 @@ DeclarationFragments DeclarationFragmentsBuilder::getFragmentsForType(
DeclarationFragments Fragments;
// Declaration fragments of a pointer type is the declaration fragments of
- // the pointee type followed by a `*`, except for Objective-C `id` and `Class`
- // pointers, where we do not spell out the `*`.
- if (T->isPointerType() ||
- (T->isObjCObjectPointerType() &&
- !T->getAs<ObjCObjectPointerType>()->isObjCIdOrClassType())) {
+ // the pointee type followed by a `*`,
+ if (T->isPointerType())
return Fragments
.append(getFragmentsForType(T->getPointeeType(), Context, After))
.append(" *", DeclarationFragments::FragmentKind::Text);
+
+ // For Objective-C `id` and `Class` pointers
+ // we do not spell out the `*`.
+ if (T->isObjCObjectPointerType() &&
+ !T->getAs<ObjCObjectPointerType>()->isObjCIdOrClassType()) {
+
+ Fragments.append(getFragmentsForType(T->getPointeeType(), Context, After));
+
+ // id<protocol> is an qualified id type
+ // id<protocol>* is not an qualified id type
+ if (!T->getAs<ObjCObjectPointerType>()->isObjCQualifiedIdType()) {
+ Fragments.append(" *", DeclarationFragments::FragmentKind::Text);
+ }
+
+ return Fragments;
}
// Declaration fragments of a lvalue reference type is the declaration
@@ -243,26 +255,30 @@ DeclarationFragments DeclarationFragmentsBuilder::getFragmentsForType(
return Fragments.append(getFragmentsForType(ET->desugar(), Context, After));
}
- // Everything we care about has been handled now, reduce to the canonical
- // unqualified base type.
- QualType Base = T->getCanonicalTypeUnqualified();
-
- // Render Objective-C `id`/`instancetype` as keywords.
- if (T->isObjCIdType())
- return Fragments.append(Base.getAsString(),
- DeclarationFragments::FragmentKind::Keyword);
-
// If the type is a typedefed type, get the underlying TypedefNameDecl for a
// direct reference to the typedef instead of the wrapped type.
+
+ // 'id' type is a typedef for an ObjCObjectPointerType
+ // we treat it as a typedef
if (const TypedefType *TypedefTy = dyn_cast<TypedefType>(T)) {
const TypedefNameDecl *Decl = TypedefTy->getDecl();
TypedefUnderlyingTypeResolver TypedefResolver(Context);
std::string USR = TypedefResolver.getUSRForType(QualType(T, 0));
+
+ if (T->isObjCIdType()) {
+ return Fragments.append(Decl->getName(),
+ DeclarationFragments::FragmentKind::Keyword);
+ }
+
return Fragments.append(
Decl->getName(), DeclarationFragments::FragmentKind::TypeIdentifier,
USR, TypedefResolver.getUnderlyingTypeDecl(QualType(T, 0)));
}
+ // Everything we care about has been handled now, reduce to the canonical
+ // unqualified base type.
+ QualType Base = T->getCanonicalTypeUnqualified();
+
// If the base type is a TagType (struct/interface/union/class/enum), let's
// get the underlying Decl for better names and USRs.
if (const TagType *TagTy = dyn_cast<TagType>(Base)) {
@@ -441,7 +457,7 @@ DeclarationFragmentsBuilder::getFragmentsForFunction(const FunctionDecl *Func) {
Fragments.append(")", DeclarationFragments::FragmentKind::Text);
// FIXME: Handle exception specifiers: throw, noexcept
- return Fragments;
+ return Fragments.append(";", DeclarationFragments::FragmentKind::Text);
}
DeclarationFragments DeclarationFragmentsBuilder::getFragmentsForEnumConstant(
@@ -470,7 +486,7 @@ DeclarationFragmentsBuilder::getFragmentsForEnum(const EnumDecl *EnumDecl) {
getFragmentsForType(IntegerType, EnumDecl->getASTContext(), After))
.append(std::move(After));
- return Fragments;
+ return Fragments.append(";", DeclarationFragments::FragmentKind::Text);
}
DeclarationFragments
@@ -493,7 +509,8 @@ DeclarationFragmentsBuilder::getFragmentsForStruct(const RecordDecl *Record) {
if (!Record->getName().empty())
Fragments.appendSpace().append(
Record->getName(), DeclarationFragments::FragmentKind::Identifier);
- return Fragments;
+
+ return Fragments.append(";", DeclarationFragments::FragmentKind::Text);
}
DeclarationFragments
@@ -621,7 +638,7 @@ DeclarationFragments DeclarationFragmentsBuilder::getFragmentsForObjCProperty(
// Build the Objective-C property keyword.
Fragments.append("@property", DeclarationFragments::FragmentKind::Keyword);
- const auto Attributes = Property->getPropertyAttributes();
+ const auto Attributes = Property->getPropertyAttributesAsWritten();
// Build the attributes if there is any associated with the property.
if (Attributes != ObjCPropertyAttribute::kind_noattr) {
// No leading comma for the first attribute.
@@ -743,7 +760,7 @@ DeclarationFragments DeclarationFragmentsBuilder::getFragmentsForTypedef(
.appendSpace()
.append(Decl->getName(), DeclarationFragments::FragmentKind::Identifier);
- return Fragments;
+ return Fragments.append(";", DeclarationFragments::FragmentKind::Text);
}
template <typename FunctionT>
diff --git a/contrib/llvm-project/clang/lib/ExtractAPI/ExtractAPIConsumer.cpp b/contrib/llvm-project/clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
index 644845efb819..eb533a934367 100644
--- a/contrib/llvm-project/clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
+++ b/contrib/llvm-project/clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
@@ -12,8 +12,10 @@
///
//===----------------------------------------------------------------------===//
+#include "clang/AST/ASTConcept.h"
#include "clang/AST/ASTConsumer.h"
#include "clang/AST/ASTContext.h"
+#include "clang/AST/DeclObjC.h"
#include "clang/Basic/DiagnosticFrontend.h"
#include "clang/Basic/SourceLocation.h"
#include "clang/Basic/SourceManager.h"
@@ -26,13 +28,16 @@
#include "clang/Frontend/ASTConsumers.h"
#include "clang/Frontend/CompilerInstance.h"
#include "clang/Frontend/FrontendOptions.h"
+#include "clang/Frontend/MultiplexConsumer.h"
#include "clang/Lex/MacroInfo.h"
#include "clang/Lex/PPCallbacks.h"
#include "clang/Lex/Preprocessor.h"
#include "clang/Lex/PreprocessorOptions.h"
#include "llvm/ADT/DenseSet.h"
#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/SmallVector.h"
+#include "llvm/Support/Casting.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/MemoryBuffer.h"
@@ -219,11 +224,48 @@ private:
llvm::DenseSet<const FileEntry *> ExternalFileEntries;
};
+struct BatchExtractAPIVisitor : ExtractAPIVisitor<BatchExtractAPIVisitor> {
+ bool shouldDeclBeIncluded(const Decl *D) const {
+ bool ShouldBeIncluded = true;
+ // Check that we have the definition for redeclarable types.
+ if (auto *TD = llvm::dyn_cast<TagDecl>(D))
+ ShouldBeIncluded = TD->isThisDeclarationADefinition();
+ else if (auto *Interface = llvm::dyn_cast<ObjCInterfaceDecl>(D))
+ ShouldBeIncluded = Interface->isThisDeclarationADefinition();
+ else if (auto *Protocol = llvm::dyn_cast<ObjCProtocolDecl>(D))
+ ShouldBeIncluded = Protocol->isThisDeclarationADefinition();
+
+ ShouldBeIncluded = ShouldBeIncluded && LCF(D->getLocation());
+ return ShouldBeIncluded;
+ }
+
+ BatchExtractAPIVisitor(LocationFileChecker &LCF, ASTContext &Context,
+ APISet &API)
+ : ExtractAPIVisitor<BatchExtractAPIVisitor>(Context, API), LCF(LCF) {}
+
+private:
+ LocationFileChecker &LCF;
+};
+
+class WrappingExtractAPIConsumer : public ASTConsumer {
+public:
+ WrappingExtractAPIConsumer(ASTContext &Context, APISet &API)
+ : Visitor(Context, API) {}
+
+ void HandleTranslationUnit(ASTContext &Context) override {
+ // Use ExtractAPIVisitor to traverse symbol declarations in the context.
+ Visitor.TraverseDecl(Context.getTranslationUnitDecl());
+ }
+
+private:
+ ExtractAPIVisitor<> Visitor;
+};
+
class ExtractAPIConsumer : public ASTConsumer {
public:
ExtractAPIConsumer(ASTContext &Context,
std::unique_ptr<LocationFileChecker> LCF, APISet &API)
- : Visitor(Context, *LCF, API), LCF(std::move(LCF)) {}
+ : Visitor(*LCF, Context, API), LCF(std::move(LCF)) {}
void HandleTranslationUnit(ASTContext &Context) override {
// Use ExtractAPIVisitor to traverse symbol declarations in the context.
@@ -231,15 +273,14 @@ public:
}
private:
- ExtractAPIVisitor Visitor;
+ BatchExtractAPIVisitor Visitor;
std::unique_ptr<LocationFileChecker> LCF;
};
class MacroCallback : public PPCallbacks {
public:
- MacroCallback(const SourceManager &SM, LocationFileChecker &LCF, APISet &API,
- Preprocessor &PP)
- : SM(SM), LCF(LCF), API(API), PP(PP) {}
+ MacroCallback(const SourceManager &SM, APISet &API, Preprocessor &PP)
+ : SM(SM), API(API), PP(PP) {}
void MacroDefined(const Token &MacroNameToken,
const MacroDirective *MD) override {
@@ -279,7 +320,7 @@ public:
if (PM.MD->getMacroInfo()->isUsedForHeaderGuard())
continue;
- if (!LCF(PM.MacroNameToken.getLocation()))
+ if (!shouldMacroBeIncluded(PM))
continue;
StringRef Name = PM.MacroNameToken.getIdentifierInfo()->getName();
@@ -297,7 +338,7 @@ public:
PendingMacros.clear();
}
-private:
+protected:
struct PendingMacro {
Token MacroNameToken;
const MacroDirective *MD;
@@ -306,18 +347,58 @@ private:
: MacroNameToken(MacroNameToken), MD(MD) {}
};
+ virtual bool shouldMacroBeIncluded(const PendingMacro &PM) { return true; }
+
const SourceManager &SM;
- LocationFileChecker &LCF;
APISet &API;
Preprocessor &PP;
llvm::SmallVector<PendingMacro> PendingMacros;
};
+class APIMacroCallback : public MacroCallback {
+public:
+ APIMacroCallback(const SourceManager &SM, APISet &API, Preprocessor &PP,
+ LocationFileChecker &LCF)
+ : MacroCallback(SM, API, PP), LCF(LCF) {}
+
+ bool shouldMacroBeIncluded(const PendingMacro &PM) override {
+ // Do not include macros from external files
+ return LCF(PM.MacroNameToken.getLocation());
+ }
+
+private:
+ LocationFileChecker &LCF;
+};
+
} // namespace
+void ExtractAPIActionBase::ImplEndSourceFileAction() {
+ if (!OS)
+ return;
+
+ // Setup a SymbolGraphSerializer to write out collected API information in
+ // the Symbol Graph format.
+ // FIXME: Make the kind of APISerializer configurable.
+ SymbolGraphSerializer SGSerializer(*API, IgnoresList);
+ SGSerializer.serialize(*OS);
+ OS.reset();
+}
+
+std::unique_ptr<raw_pwrite_stream>
+ExtractAPIAction::CreateOutputFile(CompilerInstance &CI, StringRef InFile) {
+ std::unique_ptr<raw_pwrite_stream> OS;
+ OS = CI.createDefaultOutputFile(/*Binary=*/false, InFile,
+ /*Extension=*/"json",
+ /*RemoveFileOnSignal=*/false);
+ if (!OS)
+ return nullptr;
+ return OS;
+}
+
std::unique_ptr<ASTConsumer>
ExtractAPIAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) {
OS = CreateOutputFile(CI, InFile);
+
if (!OS)
return nullptr;
@@ -331,17 +412,17 @@ ExtractAPIAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) {
auto LCF = std::make_unique<LocationFileChecker>(CI, KnownInputFiles);
- CI.getPreprocessor().addPPCallbacks(std::make_unique<MacroCallback>(
- CI.getSourceManager(), *LCF, *API, CI.getPreprocessor()));
+ CI.getPreprocessor().addPPCallbacks(std::make_unique<APIMacroCallback>(
+ CI.getSourceManager(), *API, CI.getPreprocessor(), *LCF));
// Do not include location in anonymous decls.
PrintingPolicy Policy = CI.getASTContext().getPrintingPolicy();
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) {
@@ -412,23 +493,88 @@ bool ExtractAPIAction::PrepareToExecuteAction(CompilerInstance &CI) {
return true;
}
-void ExtractAPIAction::EndSourceFileAction() {
+void ExtractAPIAction::EndSourceFileAction() { ImplEndSourceFileAction(); }
+
+std::unique_ptr<ASTConsumer>
+WrappingExtractAPIAction::CreateASTConsumer(CompilerInstance &CI,
+ StringRef InFile) {
+ auto OtherConsumer = WrapperFrontendAction::CreateASTConsumer(CI, InFile);
+ if (!OtherConsumer)
+ return nullptr;
+
+ CreatedASTConsumer = true;
+
+ OS = CreateOutputFile(CI, InFile);
if (!OS)
- return;
+ return nullptr;
- // Setup a SymbolGraphSerializer to write out collected API information in
- // the Symbol Graph format.
- // FIXME: Make the kind of APISerializer configurable.
- SymbolGraphSerializer SGSerializer(*API, IgnoresList);
- SGSerializer.serialize(*OS);
- OS.reset();
+ auto ProductName = CI.getFrontendOpts().ProductName;
+
+ // Now that we have enough information about the language options and the
+ // target triple, let's create the APISet before anyone uses it.
+ API = std::make_unique<APISet>(
+ CI.getTarget().getTriple(),
+ CI.getFrontendOpts().Inputs.back().getKind().getLanguage(), ProductName);
+
+ CI.getPreprocessor().addPPCallbacks(std::make_unique<MacroCallback>(
+ CI.getSourceManager(), *API, CI.getPreprocessor()));
+
+ // Do not include location in anonymous decls.
+ PrintingPolicy Policy = CI.getASTContext().getPrintingPolicy();
+ Policy.AnonymousTagLocations = false;
+ CI.getASTContext().setPrintingPolicy(Policy);
+
+ if (!CI.getFrontendOpts().ExtractAPIIgnoresFileList.empty()) {
+ llvm::handleAllErrors(
+ APIIgnoresList::create(CI.getFrontendOpts().ExtractAPIIgnoresFileList,
+ CI.getFileManager())
+ .moveInto(IgnoresList),
+ [&CI](const IgnoresFileNotFound &Err) {
+ CI.getDiagnostics().Report(
+ diag::err_extract_api_ignores_file_not_found)
+ << Err.Path;
+ });
+ }
+
+ auto WrappingConsumer =
+ std::make_unique<WrappingExtractAPIConsumer>(CI.getASTContext(), *API);
+ std::vector<std::unique_ptr<ASTConsumer>> Consumers;
+ Consumers.push_back(std::move(OtherConsumer));
+ Consumers.push_back(std::move(WrappingConsumer));
+
+ return std::make_unique<MultiplexConsumer>(std::move(Consumers));
+}
+
+void WrappingExtractAPIAction::EndSourceFileAction() {
+ // Invoke wrapped action's method.
+ WrapperFrontendAction::EndSourceFileAction();
+
+ if (CreatedASTConsumer) {
+ ImplEndSourceFileAction();
+ }
}
std::unique_ptr<raw_pwrite_stream>
-ExtractAPIAction::CreateOutputFile(CompilerInstance &CI, StringRef InFile) {
- std::unique_ptr<raw_pwrite_stream> OS =
- CI.createDefaultOutputFile(/*Binary=*/false, InFile, /*Extension=*/"json",
- /*RemoveFileOnSignal=*/false);
+WrappingExtractAPIAction::CreateOutputFile(CompilerInstance &CI,
+ StringRef InFile) {
+ std::unique_ptr<raw_pwrite_stream> OS;
+ std::string OutputDir = CI.getFrontendOpts().SymbolGraphOutputDir;
+
+ // The symbol graphs need to be generated as a side effect of regular
+ // compilation so the output should be dumped in the directory provided with
+ // the command line option.
+ llvm::SmallString<128> OutFilePath(OutputDir);
+ auto Seperator = llvm::sys::path::get_separator();
+ auto Infilename = llvm::sys::path::filename(InFile);
+ OutFilePath.append({Seperator, Infilename});
+ llvm::sys::path::replace_extension(OutFilePath, "json");
+ // StringRef outputFilePathref = *OutFilePath;
+
+ // don't use the default output file
+ OS = CI.createOutputFile(/*OutputPath=*/OutFilePath, /*Binary=*/false,
+ /*RemoveFileOnSignal=*/true,
+ /*UseTemporary=*/true,
+ /*CreateMissingDirectories=*/true);
if (!OS)
return nullptr;
return OS;
diff --git a/contrib/llvm-project/clang/lib/ExtractAPI/ExtractAPIVisitor.cpp b/contrib/llvm-project/clang/lib/ExtractAPI/ExtractAPIVisitor.cpp
deleted file mode 100644
index 24260cf89383..000000000000
--- a/contrib/llvm-project/clang/lib/ExtractAPI/ExtractAPIVisitor.cpp
+++ /dev/null
@@ -1,560 +0,0 @@
-//===- ExtractAPI/ExtractAPIVisitor.cpp -------------------------*- 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 implements the ExtractAPIVisitor an ASTVisitor to collect API
-/// information.
-///
-//===----------------------------------------------------------------------===//
-
-#include "clang/ExtractAPI/ExtractAPIVisitor.h"
-
-#include "TypedefUnderlyingTypeResolver.h"
-#include "clang/AST/ASTConsumer.h"
-#include "clang/AST/ASTContext.h"
-#include "clang/AST/Decl.h"
-#include "clang/AST/DeclCXX.h"
-#include "clang/AST/ParentMapContext.h"
-#include "clang/AST/RawCommentList.h"
-#include "clang/Basic/SourceLocation.h"
-#include "clang/Basic/SourceManager.h"
-#include "clang/Basic/TargetInfo.h"
-#include "clang/ExtractAPI/API.h"
-#include "clang/ExtractAPI/AvailabilityInfo.h"
-#include "clang/ExtractAPI/DeclarationFragments.h"
-#include "clang/Frontend/ASTConsumers.h"
-#include "clang/Frontend/FrontendOptions.h"
-#include "llvm/Support/raw_ostream.h"
-
-using namespace clang;
-using namespace extractapi;
-
-namespace {
-
-StringRef getTypedefName(const TagDecl *Decl) {
- if (const auto *TypedefDecl = Decl->getTypedefNameForAnonDecl())
- return TypedefDecl->getName();
-
- return {};
-}
-
-template <class DeclTy>
-bool isInSystemHeader(const ASTContext &Context, const DeclTy *D) {
- return Context.getSourceManager().isInSystemHeader(D->getLocation());
-}
-
-} // namespace
-
-bool ExtractAPIVisitor::VisitVarDecl(const VarDecl *Decl) {
- // skip function parameters.
- if (isa<ParmVarDecl>(Decl))
- return true;
-
- // Skip non-global variables in records (struct/union/class).
- if (Decl->getDeclContext()->isRecord())
- return true;
-
- // Skip local variables inside function or method.
- if (!Decl->isDefinedOutsideFunctionOrMethod())
- return true;
-
- // If this is a template but not specialization or instantiation, skip.
- if (Decl->getASTContext().getTemplateOrSpecializationInfo(Decl) &&
- Decl->getTemplateSpecializationKind() == TSK_Undeclared)
- return true;
-
- if (!LocationChecker(Decl->getLocation()))
- return true;
-
- // Collect symbol information.
- StringRef Name = Decl->getName();
- StringRef USR = API.recordUSR(Decl);
- PresumedLoc Loc =
- Context.getSourceManager().getPresumedLoc(Decl->getLocation());
- LinkageInfo Linkage = Decl->getLinkageAndVisibility();
- DocComment Comment;
- if (auto *RawComment = Context.getRawCommentForDeclNoCache(Decl))
- Comment = RawComment->getFormattedLines(Context.getSourceManager(),
- Context.getDiagnostics());
-
- // Build declaration fragments and sub-heading for the variable.
- DeclarationFragments Declaration =
- DeclarationFragmentsBuilder::getFragmentsForVar(Decl);
- DeclarationFragments SubHeading =
- DeclarationFragmentsBuilder::getSubHeading(Decl);
-
- // Add the global variable record to the API set.
- API.addGlobalVar(Name, USR, Loc, AvailabilitySet(Decl), Linkage, Comment,
- Declaration, SubHeading, isInSystemHeader(Context, Decl));
- return true;
-}
-
-bool ExtractAPIVisitor::VisitFunctionDecl(const FunctionDecl *Decl) {
- if (const auto *Method = dyn_cast<CXXMethodDecl>(Decl)) {
- // Skip member function in class templates.
- if (Method->getParent()->getDescribedClassTemplate() != nullptr)
- return true;
-
- // Skip methods in records.
- for (auto P : Context.getParents(*Method)) {
- if (P.get<CXXRecordDecl>())
- return true;
- }
-
- // Skip ConstructorDecl and DestructorDecl.
- if (isa<CXXConstructorDecl>(Method) || isa<CXXDestructorDecl>(Method))
- return true;
- }
-
- // Skip templated functions.
- switch (Decl->getTemplatedKind()) {
- case FunctionDecl::TK_NonTemplate:
- case FunctionDecl::TK_DependentNonTemplate:
- break;
- case FunctionDecl::TK_MemberSpecialization:
- case FunctionDecl::TK_FunctionTemplateSpecialization:
- if (auto *TemplateInfo = Decl->getTemplateSpecializationInfo()) {
- if (!TemplateInfo->isExplicitInstantiationOrSpecialization())
- return true;
- }
- break;
- case FunctionDecl::TK_FunctionTemplate:
- case FunctionDecl::TK_DependentFunctionTemplateSpecialization:
- return true;
- }
-
- if (!LocationChecker(Decl->getLocation()))
- return true;
-
- // Collect symbol information.
- StringRef Name = Decl->getName();
- StringRef USR = API.recordUSR(Decl);
- PresumedLoc Loc =
- Context.getSourceManager().getPresumedLoc(Decl->getLocation());
- LinkageInfo Linkage = Decl->getLinkageAndVisibility();
- DocComment Comment;
- if (auto *RawComment = Context.getRawCommentForDeclNoCache(Decl))
- Comment = RawComment->getFormattedLines(Context.getSourceManager(),
- Context.getDiagnostics());
-
- // Build declaration fragments, sub-heading, and signature of the function.
- DeclarationFragments Declaration =
- DeclarationFragmentsBuilder::getFragmentsForFunction(Decl);
- DeclarationFragments SubHeading =
- DeclarationFragmentsBuilder::getSubHeading(Decl);
- FunctionSignature Signature =
- DeclarationFragmentsBuilder::getFunctionSignature(Decl);
-
- // Add the function record to the API set.
- API.addGlobalFunction(Name, USR, Loc, AvailabilitySet(Decl), Linkage, Comment,
- Declaration, SubHeading, Signature,
- isInSystemHeader(Context, Decl));
- return true;
-}
-
-bool ExtractAPIVisitor::VisitEnumDecl(const EnumDecl *Decl) {
- if (!Decl->isComplete())
- return true;
-
- // Skip forward declaration.
- if (!Decl->isThisDeclarationADefinition())
- return true;
-
- if (!LocationChecker(Decl->getLocation()))
- return true;
-
- SmallString<128> QualifiedNameBuffer;
- // Collect symbol information.
- StringRef Name = Decl->getName();
- if (Name.empty())
- Name = getTypedefName(Decl);
- if (Name.empty()) {
- llvm::raw_svector_ostream OS(QualifiedNameBuffer);
- Decl->printQualifiedName(OS);
- Name = QualifiedNameBuffer.str();
- }
-
- StringRef USR = API.recordUSR(Decl);
- PresumedLoc Loc =
- Context.getSourceManager().getPresumedLoc(Decl->getLocation());
- DocComment Comment;
- if (auto *RawComment = Context.getRawCommentForDeclNoCache(Decl))
- Comment = RawComment->getFormattedLines(Context.getSourceManager(),
- Context.getDiagnostics());
-
- // Build declaration fragments and sub-heading for the enum.
- DeclarationFragments Declaration =
- DeclarationFragmentsBuilder::getFragmentsForEnum(Decl);
- DeclarationFragments SubHeading =
- DeclarationFragmentsBuilder::getSubHeading(Decl);
-
- EnumRecord *EnumRecord = API.addEnum(
- API.copyString(Name), USR, Loc, AvailabilitySet(Decl), Comment,
- Declaration, SubHeading, isInSystemHeader(Context, Decl));
-
- // Now collect information about the enumerators in this enum.
- recordEnumConstants(EnumRecord, Decl->enumerators());
-
- return true;
-}
-
-bool ExtractAPIVisitor::VisitRecordDecl(const RecordDecl *Decl) {
- if (!Decl->isCompleteDefinition())
- return true;
-
- // Skip C++ structs/classes/unions
- // TODO: support C++ records
- if (isa<CXXRecordDecl>(Decl))
- return true;
-
- if (!LocationChecker(Decl->getLocation()))
- return true;
-
- // Collect symbol information.
- StringRef Name = Decl->getName();
- if (Name.empty())
- Name = getTypedefName(Decl);
- if (Name.empty())
- return true;
-
- StringRef USR = API.recordUSR(Decl);
- PresumedLoc Loc =
- Context.getSourceManager().getPresumedLoc(Decl->getLocation());
- DocComment Comment;
- if (auto *RawComment = Context.getRawCommentForDeclNoCache(Decl))
- Comment = RawComment->getFormattedLines(Context.getSourceManager(),
- Context.getDiagnostics());
-
- // Build declaration fragments and sub-heading for the struct.
- DeclarationFragments Declaration =
- DeclarationFragmentsBuilder::getFragmentsForStruct(Decl);
- DeclarationFragments SubHeading =
- DeclarationFragmentsBuilder::getSubHeading(Decl);
-
- StructRecord *StructRecord =
- API.addStruct(Name, USR, Loc, AvailabilitySet(Decl), Comment, Declaration,
- SubHeading, isInSystemHeader(Context, Decl));
-
- // Now collect information about the fields in this struct.
- recordStructFields(StructRecord, Decl->fields());
-
- return true;
-}
-
-bool ExtractAPIVisitor::VisitObjCInterfaceDecl(const ObjCInterfaceDecl *Decl) {
- // Skip forward declaration for classes (@class)
- if (!Decl->isThisDeclarationADefinition())
- return true;
-
- if (!LocationChecker(Decl->getLocation()))
- return true;
-
- // Collect symbol information.
- StringRef Name = Decl->getName();
- StringRef USR = API.recordUSR(Decl);
- PresumedLoc Loc =
- Context.getSourceManager().getPresumedLoc(Decl->getLocation());
- LinkageInfo Linkage = Decl->getLinkageAndVisibility();
- DocComment Comment;
- if (auto *RawComment = Context.getRawCommentForDeclNoCache(Decl))
- Comment = RawComment->getFormattedLines(Context.getSourceManager(),
- Context.getDiagnostics());
-
- // Build declaration fragments and sub-heading for the interface.
- DeclarationFragments Declaration =
- DeclarationFragmentsBuilder::getFragmentsForObjCInterface(Decl);
- DeclarationFragments SubHeading =
- DeclarationFragmentsBuilder::getSubHeading(Decl);
-
- // Collect super class information.
- SymbolReference SuperClass;
- if (const auto *SuperClassDecl = Decl->getSuperClass()) {
- SuperClass.Name = SuperClassDecl->getObjCRuntimeNameAsString();
- SuperClass.USR = API.recordUSR(SuperClassDecl);
- }
-
- ObjCInterfaceRecord *ObjCInterfaceRecord = API.addObjCInterface(
- Name, USR, Loc, AvailabilitySet(Decl), Linkage, Comment, Declaration,
- SubHeading, SuperClass, isInSystemHeader(Context, Decl));
-
- // Record all methods (selectors). This doesn't include automatically
- // synthesized property methods.
- recordObjCMethods(ObjCInterfaceRecord, Decl->methods());
- recordObjCProperties(ObjCInterfaceRecord, Decl->properties());
- recordObjCInstanceVariables(ObjCInterfaceRecord, Decl->ivars());
- recordObjCProtocols(ObjCInterfaceRecord, Decl->protocols());
-
- return true;
-}
-
-bool ExtractAPIVisitor::VisitObjCProtocolDecl(const ObjCProtocolDecl *Decl) {
- // Skip forward declaration for protocols (@protocol).
- if (!Decl->isThisDeclarationADefinition())
- return true;
-
- if (!LocationChecker(Decl->getLocation()))
- return true;
-
- // Collect symbol information.
- StringRef Name = Decl->getName();
- StringRef USR = API.recordUSR(Decl);
- PresumedLoc Loc =
- Context.getSourceManager().getPresumedLoc(Decl->getLocation());
- DocComment Comment;
- if (auto *RawComment = Context.getRawCommentForDeclNoCache(Decl))
- Comment = RawComment->getFormattedLines(Context.getSourceManager(),
- Context.getDiagnostics());
-
- // Build declaration fragments and sub-heading for the protocol.
- DeclarationFragments Declaration =
- DeclarationFragmentsBuilder::getFragmentsForObjCProtocol(Decl);
- DeclarationFragments SubHeading =
- DeclarationFragmentsBuilder::getSubHeading(Decl);
-
- ObjCProtocolRecord *ObjCProtocolRecord = API.addObjCProtocol(
- Name, USR, Loc, AvailabilitySet(Decl), Comment, Declaration, SubHeading,
- isInSystemHeader(Context, Decl));
-
- recordObjCMethods(ObjCProtocolRecord, Decl->methods());
- recordObjCProperties(ObjCProtocolRecord, Decl->properties());
- recordObjCProtocols(ObjCProtocolRecord, Decl->protocols());
-
- return true;
-}
-
-bool ExtractAPIVisitor::VisitTypedefNameDecl(const TypedefNameDecl *Decl) {
- // Skip ObjC Type Parameter for now.
- if (isa<ObjCTypeParamDecl>(Decl))
- return true;
-
- if (!Decl->isDefinedOutsideFunctionOrMethod())
- return true;
-
- if (!LocationChecker(Decl->getLocation()))
- return true;
-
- PresumedLoc Loc =
- Context.getSourceManager().getPresumedLoc(Decl->getLocation());
- StringRef Name = Decl->getName();
- StringRef USR = API.recordUSR(Decl);
- DocComment Comment;
- if (auto *RawComment = Context.getRawCommentForDeclNoCache(Decl))
- Comment = RawComment->getFormattedLines(Context.getSourceManager(),
- Context.getDiagnostics());
-
- QualType Type = Decl->getUnderlyingType();
- SymbolReference SymRef =
- TypedefUnderlyingTypeResolver(Context).getSymbolReferenceForType(Type,
- API);
-
- API.addTypedef(Name, USR, Loc, AvailabilitySet(Decl), Comment,
- DeclarationFragmentsBuilder::getFragmentsForTypedef(Decl),
- DeclarationFragmentsBuilder::getSubHeading(Decl), SymRef,
- isInSystemHeader(Context, Decl));
-
- return true;
-}
-
-bool ExtractAPIVisitor::VisitObjCCategoryDecl(const ObjCCategoryDecl *Decl) {
- // Collect symbol information.
- StringRef Name = Decl->getName();
- StringRef USR = API.recordUSR(Decl);
- PresumedLoc Loc =
- Context.getSourceManager().getPresumedLoc(Decl->getLocation());
- DocComment Comment;
- if (auto *RawComment = Context.getRawCommentForDeclNoCache(Decl))
- Comment = RawComment->getFormattedLines(Context.getSourceManager(),
- Context.getDiagnostics());
- // Build declaration fragments and sub-heading for the category.
- DeclarationFragments Declaration =
- DeclarationFragmentsBuilder::getFragmentsForObjCCategory(Decl);
- DeclarationFragments SubHeading =
- DeclarationFragmentsBuilder::getSubHeading(Decl);
-
- const ObjCInterfaceDecl *InterfaceDecl = Decl->getClassInterface();
- SymbolReference Interface(InterfaceDecl->getName(),
- API.recordUSR(InterfaceDecl));
-
- ObjCCategoryRecord *ObjCCategoryRecord = API.addObjCCategory(
- Name, USR, Loc, AvailabilitySet(Decl), Comment, Declaration, SubHeading,
- Interface, isInSystemHeader(Context, Decl));
-
- recordObjCMethods(ObjCCategoryRecord, Decl->methods());
- recordObjCProperties(ObjCCategoryRecord, Decl->properties());
- recordObjCInstanceVariables(ObjCCategoryRecord, Decl->ivars());
- recordObjCProtocols(ObjCCategoryRecord, Decl->protocols());
-
- return true;
-}
-
-/// Collect API information for the enum constants and associate with the
-/// parent enum.
-void ExtractAPIVisitor::recordEnumConstants(
- EnumRecord *EnumRecord, const EnumDecl::enumerator_range Constants) {
- for (const auto *Constant : Constants) {
- // Collect symbol information.
- StringRef Name = Constant->getName();
- StringRef USR = API.recordUSR(Constant);
- PresumedLoc Loc =
- Context.getSourceManager().getPresumedLoc(Constant->getLocation());
- DocComment Comment;
- if (auto *RawComment = Context.getRawCommentForDeclNoCache(Constant))
- Comment = RawComment->getFormattedLines(Context.getSourceManager(),
- Context.getDiagnostics());
-
- // Build declaration fragments and sub-heading for the enum constant.
- DeclarationFragments Declaration =
- DeclarationFragmentsBuilder::getFragmentsForEnumConstant(Constant);
- DeclarationFragments SubHeading =
- DeclarationFragmentsBuilder::getSubHeading(Constant);
-
- API.addEnumConstant(EnumRecord, Name, USR, Loc, AvailabilitySet(Constant),
- Comment, Declaration, SubHeading,
- isInSystemHeader(Context, Constant));
- }
-}
-
-/// Collect API information for the struct fields and associate with the
-/// parent struct.
-void ExtractAPIVisitor::recordStructFields(
- StructRecord *StructRecord, const RecordDecl::field_range Fields) {
- for (const auto *Field : Fields) {
- // Collect symbol information.
- StringRef Name = Field->getName();
- StringRef USR = API.recordUSR(Field);
- PresumedLoc Loc =
- Context.getSourceManager().getPresumedLoc(Field->getLocation());
- DocComment Comment;
- if (auto *RawComment = Context.getRawCommentForDeclNoCache(Field))
- Comment = RawComment->getFormattedLines(Context.getSourceManager(),
- Context.getDiagnostics());
-
- // Build declaration fragments and sub-heading for the struct field.
- DeclarationFragments Declaration =
- DeclarationFragmentsBuilder::getFragmentsForField(Field);
- DeclarationFragments SubHeading =
- DeclarationFragmentsBuilder::getSubHeading(Field);
-
- API.addStructField(StructRecord, Name, USR, Loc, AvailabilitySet(Field),
- Comment, Declaration, SubHeading,
- isInSystemHeader(Context, Field));
- }
-}
-
-/// Collect API information for the Objective-C methods and associate with the
-/// parent container.
-void ExtractAPIVisitor::recordObjCMethods(
- ObjCContainerRecord *Container,
- const ObjCContainerDecl::method_range Methods) {
- for (const auto *Method : Methods) {
- // Don't record selectors for properties.
- if (Method->isPropertyAccessor())
- continue;
-
- StringRef Name = API.copyString(Method->getSelector().getAsString());
- StringRef USR = API.recordUSR(Method);
- PresumedLoc Loc =
- Context.getSourceManager().getPresumedLoc(Method->getLocation());
- DocComment Comment;
- if (auto *RawComment = Context.getRawCommentForDeclNoCache(Method))
- Comment = RawComment->getFormattedLines(Context.getSourceManager(),
- Context.getDiagnostics());
-
- // Build declaration fragments, sub-heading, and signature for the method.
- DeclarationFragments Declaration =
- DeclarationFragmentsBuilder::getFragmentsForObjCMethod(Method);
- DeclarationFragments SubHeading =
- DeclarationFragmentsBuilder::getSubHeading(Method);
- FunctionSignature Signature =
- DeclarationFragmentsBuilder::getFunctionSignature(Method);
-
- API.addObjCMethod(Container, Name, USR, Loc, AvailabilitySet(Method),
- Comment, Declaration, SubHeading, Signature,
- Method->isInstanceMethod(),
- isInSystemHeader(Context, Method));
- }
-}
-
-void ExtractAPIVisitor::recordObjCProperties(
- ObjCContainerRecord *Container,
- const ObjCContainerDecl::prop_range Properties) {
- for (const auto *Property : Properties) {
- StringRef Name = Property->getName();
- StringRef USR = API.recordUSR(Property);
- PresumedLoc Loc =
- Context.getSourceManager().getPresumedLoc(Property->getLocation());
- DocComment Comment;
- if (auto *RawComment = Context.getRawCommentForDeclNoCache(Property))
- Comment = RawComment->getFormattedLines(Context.getSourceManager(),
- Context.getDiagnostics());
-
- // Build declaration fragments and sub-heading for the property.
- DeclarationFragments Declaration =
- DeclarationFragmentsBuilder::getFragmentsForObjCProperty(Property);
- DeclarationFragments SubHeading =
- DeclarationFragmentsBuilder::getSubHeading(Property);
-
- StringRef GetterName =
- API.copyString(Property->getGetterName().getAsString());
- StringRef SetterName =
- API.copyString(Property->getSetterName().getAsString());
-
- // Get the attributes for property.
- unsigned Attributes = ObjCPropertyRecord::NoAttr;
- if (Property->getPropertyAttributes() &
- ObjCPropertyAttribute::kind_readonly)
- Attributes |= ObjCPropertyRecord::ReadOnly;
-
- API.addObjCProperty(
- Container, Name, USR, Loc, AvailabilitySet(Property), Comment,
- Declaration, SubHeading,
- static_cast<ObjCPropertyRecord::AttributeKind>(Attributes), GetterName,
- SetterName, Property->isOptional(),
- !(Property->getPropertyAttributes() &
- ObjCPropertyAttribute::kind_class),
- isInSystemHeader(Context, Property));
- }
-}
-
-void ExtractAPIVisitor::recordObjCInstanceVariables(
- ObjCContainerRecord *Container,
- const llvm::iterator_range<
- DeclContext::specific_decl_iterator<ObjCIvarDecl>>
- Ivars) {
- for (const auto *Ivar : Ivars) {
- StringRef Name = Ivar->getName();
- StringRef USR = API.recordUSR(Ivar);
- PresumedLoc Loc =
- Context.getSourceManager().getPresumedLoc(Ivar->getLocation());
- DocComment Comment;
- if (auto *RawComment = Context.getRawCommentForDeclNoCache(Ivar))
- Comment = RawComment->getFormattedLines(Context.getSourceManager(),
- Context.getDiagnostics());
-
- // Build declaration fragments and sub-heading for the instance variable.
- DeclarationFragments Declaration =
- DeclarationFragmentsBuilder::getFragmentsForField(Ivar);
- DeclarationFragments SubHeading =
- DeclarationFragmentsBuilder::getSubHeading(Ivar);
-
- ObjCInstanceVariableRecord::AccessControl Access =
- Ivar->getCanonicalAccessControl();
-
- API.addObjCInstanceVariable(
- Container, Name, USR, Loc, AvailabilitySet(Ivar), Comment, Declaration,
- SubHeading, Access, isInSystemHeader(Context, Ivar));
- }
-}
-
-void ExtractAPIVisitor::recordObjCProtocols(
- ObjCContainerRecord *Container,
- ObjCInterfaceDecl::protocol_range Protocols) {
- for (const auto *Protocol : Protocols)
- Container->Protocols.emplace_back(Protocol->getName(),
- API.recordUSR(Protocol));
-}
diff --git a/contrib/llvm-project/clang/lib/ExtractAPI/Serialization/SerializerBase.cpp b/contrib/llvm-project/clang/lib/ExtractAPI/Serialization/SerializerBase.cpp
deleted file mode 100644
index 71fd25b2b2ab..000000000000
--- a/contrib/llvm-project/clang/lib/ExtractAPI/Serialization/SerializerBase.cpp
+++ /dev/null
@@ -1,19 +0,0 @@
-//===- ExtractAPI/Serialization/SerializerBase.cpp --------------*- 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 implements the APISerializer interface.
-///
-//===----------------------------------------------------------------------===//
-
-#include "clang/ExtractAPI/Serialization/SerializerBase.h"
-#include "llvm/Support/raw_ostream.h"
-
-using namespace clang::extractapi;
-
-void APISerializer::serialize(llvm::raw_ostream &os) {}
diff --git a/contrib/llvm-project/clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp b/contrib/llvm-project/clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
index 01e9b37d2680..534e9288cc71 100644
--- a/contrib/llvm-project/clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
+++ b/contrib/llvm-project/clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
@@ -14,16 +14,11 @@
#include "clang/ExtractAPI/Serialization/SymbolGraphSerializer.h"
#include "clang/Basic/SourceLocation.h"
#include "clang/Basic/Version.h"
-#include "clang/ExtractAPI/API.h"
-#include "clang/ExtractAPI/APIIgnoresList.h"
#include "clang/ExtractAPI/DeclarationFragments.h"
-#include "clang/ExtractAPI/Serialization/SerializerBase.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/STLFunctionalExtras.h"
-#include "llvm/ADT/SmallVector.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/Compiler.h"
-#include "llvm/Support/JSON.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/VersionTuple.h"
#include <optional>
@@ -171,12 +166,16 @@ serializeAvailability(const AvailabilitySet &Availabilities) {
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));
}
@@ -487,6 +486,7 @@ bool generatePathComponents(
SmallVector<PathComponent, 4> ReverseComponenents;
ReverseComponenents.emplace_back(Record.USR, Record.Name, Record.getKind());
const auto *CurrentParent = &Record.ParentInformation;
+ bool FailedToFindParent = false;
while (CurrentParent && !CurrentParent->empty()) {
PathComponent CurrentParentComponent(CurrentParent->ParentUSR,
CurrentParent->ParentName,
@@ -509,8 +509,10 @@ bool generatePathComponents(
// The parent record doesn't exist which means the symbol shouldn't be
// treated as part of the current product.
- if (!ParentRecord)
- return true;
+ if (!ParentRecord) {
+ FailedToFindParent = true;
+ break;
+ }
ReverseComponenents.push_back(std::move(CurrentParentComponent));
CurrentParent = &ParentRecord->ParentInformation;
@@ -519,8 +521,9 @@ bool generatePathComponents(
for (const auto &PC : reverse(ReverseComponenents))
ComponentTransformer(PC);
- return false;
+ return FailedToFindParent;
}
+
Object serializeParentContext(const PathComponent &PC, Language Lang) {
Object ParentContextElem;
ParentContextElem["usr"] = PC.USR;
@@ -533,20 +536,16 @@ template <typename RecordTy>
Array generateParentContexts(const RecordTy &Record, const APISet &API,
Language Lang) {
Array ParentContexts;
- if (generatePathComponents(
- Record, API, [Lang, &ParentContexts](const PathComponent &PC) {
- ParentContexts.push_back(serializeParentContext(PC, Lang));
- }))
- ParentContexts.clear();
- ParentContexts.pop_back();
+ generatePathComponents(
+ Record, API, [Lang, &ParentContexts](const PathComponent &PC) {
+ ParentContexts.push_back(serializeParentContext(PC, Lang));
+ });
return ParentContexts;
}
} // namespace
-void SymbolGraphSerializer::anchor() {}
-
/// Defines the format version emitted by SymbolGraphSerializer.
const VersionTuple SymbolGraphSerializer::FormatVersion{0, 5, 3};
@@ -663,7 +662,7 @@ void SymbolGraphSerializer::serializeRelationship(RelationshipKind Kind,
Relationships.emplace_back(std::move(Relationship));
}
-void SymbolGraphSerializer::serializeGlobalFunctionRecord(
+void SymbolGraphSerializer::visitGlobalFunctionRecord(
const GlobalFunctionRecord &Record) {
auto Obj = serializeAPIRecord(Record);
if (!Obj)
@@ -672,7 +671,7 @@ void SymbolGraphSerializer::serializeGlobalFunctionRecord(
Symbols.emplace_back(std::move(*Obj));
}
-void SymbolGraphSerializer::serializeGlobalVariableRecord(
+void SymbolGraphSerializer::visitGlobalVariableRecord(
const GlobalVariableRecord &Record) {
auto Obj = serializeAPIRecord(Record);
if (!Obj)
@@ -681,7 +680,7 @@ void SymbolGraphSerializer::serializeGlobalVariableRecord(
Symbols.emplace_back(std::move(*Obj));
}
-void SymbolGraphSerializer::serializeEnumRecord(const EnumRecord &Record) {
+void SymbolGraphSerializer::visitEnumRecord(const EnumRecord &Record) {
auto Enum = serializeAPIRecord(Record);
if (!Enum)
return;
@@ -690,7 +689,7 @@ void SymbolGraphSerializer::serializeEnumRecord(const EnumRecord &Record) {
serializeMembers(Record, Record.Constants);
}
-void SymbolGraphSerializer::serializeStructRecord(const StructRecord &Record) {
+void SymbolGraphSerializer::visitStructRecord(const StructRecord &Record) {
auto Struct = serializeAPIRecord(Record);
if (!Struct)
return;
@@ -699,7 +698,7 @@ void SymbolGraphSerializer::serializeStructRecord(const StructRecord &Record) {
serializeMembers(Record, Record.Fields);
}
-void SymbolGraphSerializer::serializeObjCContainerRecord(
+void SymbolGraphSerializer::visitObjCContainerRecord(
const ObjCContainerRecord &Record) {
auto ObjCContainer = serializeAPIRecord(Record);
if (!ObjCContainer)
@@ -736,7 +735,7 @@ void SymbolGraphSerializer::serializeObjCContainerRecord(
}
}
-void SymbolGraphSerializer::serializeMacroDefinitionRecord(
+void SymbolGraphSerializer::visitMacroDefinitionRecord(
const MacroDefinitionRecord &Record) {
auto Macro = serializeAPIRecord(Record);
@@ -751,28 +750,28 @@ void SymbolGraphSerializer::serializeSingleRecord(const APIRecord *Record) {
case APIRecord::RK_Unknown:
llvm_unreachable("Records should have a known kind!");
case APIRecord::RK_GlobalFunction:
- serializeGlobalFunctionRecord(*cast<GlobalFunctionRecord>(Record));
+ visitGlobalFunctionRecord(*cast<GlobalFunctionRecord>(Record));
break;
case APIRecord::RK_GlobalVariable:
- serializeGlobalVariableRecord(*cast<GlobalVariableRecord>(Record));
+ visitGlobalVariableRecord(*cast<GlobalVariableRecord>(Record));
break;
case APIRecord::RK_Enum:
- serializeEnumRecord(*cast<EnumRecord>(Record));
+ visitEnumRecord(*cast<EnumRecord>(Record));
break;
case APIRecord::RK_Struct:
- serializeStructRecord(*cast<StructRecord>(Record));
+ visitStructRecord(*cast<StructRecord>(Record));
break;
case APIRecord::RK_ObjCInterface:
- serializeObjCContainerRecord(*cast<ObjCInterfaceRecord>(Record));
+ visitObjCContainerRecord(*cast<ObjCInterfaceRecord>(Record));
break;
case APIRecord::RK_ObjCProtocol:
- serializeObjCContainerRecord(*cast<ObjCProtocolRecord>(Record));
+ visitObjCContainerRecord(*cast<ObjCProtocolRecord>(Record));
break;
case APIRecord::RK_MacroDefinition:
- serializeMacroDefinitionRecord(*cast<MacroDefinitionRecord>(Record));
+ visitMacroDefinitionRecord(*cast<MacroDefinitionRecord>(Record));
break;
case APIRecord::RK_Typedef:
- serializeTypedefRecord(*cast<TypedefRecord>(Record));
+ visitTypedefRecord(*cast<TypedefRecord>(Record));
break;
default:
if (auto Obj = serializeAPIRecord(*Record)) {
@@ -786,8 +785,7 @@ void SymbolGraphSerializer::serializeSingleRecord(const APIRecord *Record) {
}
}
-void SymbolGraphSerializer::serializeTypedefRecord(
- const TypedefRecord &Record) {
+void SymbolGraphSerializer::visitTypedefRecord(const TypedefRecord &Record) {
// Typedefs of anonymous types have their entries unified with the underlying
// type.
bool ShouldDrop = Record.UnderlyingType.Name.empty();
@@ -807,35 +805,7 @@ void SymbolGraphSerializer::serializeTypedefRecord(
}
Object SymbolGraphSerializer::serialize() {
- // Serialize global variables in the API set.
- for (const auto &GlobalVar : API.getGlobalVariables())
- serializeGlobalVariableRecord(*GlobalVar.second);
-
- for (const auto &GlobalFunction : API.getGlobalFunctions())
- serializeGlobalFunctionRecord(*GlobalFunction.second);
-
- // Serialize enum records in the API set.
- for (const auto &Enum : API.getEnums())
- serializeEnumRecord(*Enum.second);
-
- // Serialize struct records in the API set.
- for (const auto &Struct : API.getStructs())
- serializeStructRecord(*Struct.second);
-
- // Serialize Objective-C interface records in the API set.
- for (const auto &ObjCInterface : API.getObjCInterfaces())
- serializeObjCContainerRecord(*ObjCInterface.second);
-
- // Serialize Objective-C protocol records in the API set.
- for (const auto &ObjCProtocol : API.getObjCProtocols())
- serializeObjCContainerRecord(*ObjCProtocol.second);
-
- for (const auto &Macro : API.getMacros())
- serializeMacroDefinitionRecord(*Macro.second);
-
- for (const auto &Typedef : API.getTypedefs())
- serializeTypedefRecord(*Typedef.second);
-
+ traverseAPISet();
return serializeCurrentGraph();
}
@@ -865,6 +835,9 @@ SymbolGraphSerializer::serializeSingleSymbolSGF(StringRef USR,
if (!Record)
return {};
+ if (isa<ObjCCategoryRecord>(Record))
+ return {};
+
Object Root;
APIIgnoresList EmptyIgnores;
SymbolGraphSerializer Serializer(API, EmptyIgnores,
diff --git a/contrib/llvm-project/clang/lib/ExtractAPI/TypedefUnderlyingTypeResolver.cpp b/contrib/llvm-project/clang/lib/ExtractAPI/TypedefUnderlyingTypeResolver.cpp
index 3da2424ea726..3a5f62c9b2e6 100644
--- a/contrib/llvm-project/clang/lib/ExtractAPI/TypedefUnderlyingTypeResolver.cpp
+++ b/contrib/llvm-project/clang/lib/ExtractAPI/TypedefUnderlyingTypeResolver.cpp
@@ -11,7 +11,7 @@
///
//===----------------------------------------------------------------------===//
-#include "TypedefUnderlyingTypeResolver.h"
+#include "clang/ExtractAPI/TypedefUnderlyingTypeResolver.h"
#include "clang/Index/USRGeneration.h"
using namespace clang;
diff --git a/contrib/llvm-project/clang/lib/ExtractAPI/TypedefUnderlyingTypeResolver.h b/contrib/llvm-project/clang/lib/ExtractAPI/TypedefUnderlyingTypeResolver.h
deleted file mode 100644
index 54aa11c354c0..000000000000
--- a/contrib/llvm-project/clang/lib/ExtractAPI/TypedefUnderlyingTypeResolver.h
+++ /dev/null
@@ -1,48 +0,0 @@
-//===- ExtractAPI/TypedefUnderlyingTypeResolver.h ---------------*- 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 UnderlyingTypeResolver which is a helper type for
-/// resolving the undelrying type for a given QualType and exposing that
-/// information in various forms.
-///
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_CLANG_UNDERLYING_TYPE_RESOLVER_H
-#define LLVM_CLANG_UNDERLYING_TYPE_RESOLVER_H
-
-#include "clang/AST/ASTContext.h"
-#include "clang/AST/Decl.h"
-#include "clang/ExtractAPI/API.h"
-
-#include <string>
-
-namespace clang {
-namespace extractapi {
-
-struct TypedefUnderlyingTypeResolver {
- /// Gets the underlying type declaration.
- const NamedDecl *getUnderlyingTypeDecl(QualType Type) const;
-
- /// Get a SymbolReference for the given type.
- SymbolReference getSymbolReferenceForType(QualType Type, APISet &API) const;
-
- /// Get a USR for the given type.
- std::string getUSRForType(QualType Type) const;
-
- explicit TypedefUnderlyingTypeResolver(ASTContext &Context)
- : Context(Context) {}
-
-private:
- ASTContext &Context;
-};
-
-} // namespace extractapi
-} // namespace clang
-
-#endif // LLVM_CLANG_UNDERLYING_TYPE_RESOLVER_H