Skip to content

Commit 7895f31

Browse files
[clang][ExtractAPI] Reland ExtractAPI for libclang improvements
This relands the changes that were originally introduced by: - https://reviews.llvm.org/D146656 - https://reviews.llvm.org/D147138 This also fixes the leak that led to these changes being reverted Differential Revision: https://reviews.llvm.org/D147234
1 parent 2a753e0 commit 7895f31

File tree

12 files changed

+842
-709
lines changed

12 files changed

+842
-709
lines changed

clang/include/clang/ExtractAPI/ExtractAPIVisitor.h

Lines changed: 592 additions & 12 deletions
Large diffs are not rendered by default.

clang/lib/ExtractAPI/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ add_clang_library(clangExtractAPI
77
APIIgnoresList.cpp
88
AvailabilityInfo.cpp
99
ExtractAPIConsumer.cpp
10-
ExtractAPIVisitor.cpp
1110
DeclarationFragments.cpp
1211
Serialization/SerializerBase.cpp
1312
Serialization/SymbolGraphSerializer.cpp

clang/lib/ExtractAPI/DeclarationFragments.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
//===----------------------------------------------------------------------===//
1313

1414
#include "clang/ExtractAPI/DeclarationFragments.h"
15-
#include "TypedefUnderlyingTypeResolver.h"
15+
#include "clang/ExtractAPI/TypedefUnderlyingTypeResolver.h"
1616
#include "clang/Index/USRGeneration.h"
1717
#include "llvm/ADT/StringSwitch.h"
1818

clang/lib/ExtractAPI/ExtractAPIConsumer.cpp

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@
1212
///
1313
//===----------------------------------------------------------------------===//
1414

15+
#include "clang/AST/ASTConcept.h"
1516
#include "clang/AST/ASTConsumer.h"
1617
#include "clang/AST/ASTContext.h"
18+
#include "clang/AST/DeclObjC.h"
1719
#include "clang/Basic/DiagnosticFrontend.h"
1820
#include "clang/Basic/SourceLocation.h"
1921
#include "clang/Basic/SourceManager.h"
@@ -33,6 +35,7 @@
3335
#include "llvm/ADT/DenseSet.h"
3436
#include "llvm/ADT/STLExtras.h"
3537
#include "llvm/ADT/SmallVector.h"
38+
#include "llvm/Support/Casting.h"
3639
#include "llvm/Support/Error.h"
3740
#include "llvm/Support/FileSystem.h"
3841
#include "llvm/Support/MemoryBuffer.h"
@@ -218,19 +221,42 @@ struct LocationFileChecker {
218221
llvm::DenseSet<const FileEntry *> ExternalFileEntries;
219222
};
220223

224+
struct BatchExtractAPIVisitor : ExtractAPIVisitor<BatchExtractAPIVisitor> {
225+
bool shouldDeclBeIncluded(const Decl *D) const {
226+
bool ShouldBeIncluded = true;
227+
// Check that we have the definition for redeclarable types.
228+
if (auto *TD = llvm::dyn_cast<TagDecl>(D))
229+
ShouldBeIncluded = TD->isThisDeclarationADefinition();
230+
else if (auto *Interface = llvm::dyn_cast<ObjCInterfaceDecl>(D))
231+
ShouldBeIncluded = Interface->isThisDeclarationADefinition();
232+
else if (auto *Protocol = llvm::dyn_cast<ObjCProtocolDecl>(D))
233+
ShouldBeIncluded = Protocol->isThisDeclarationADefinition();
234+
235+
ShouldBeIncluded = ShouldBeIncluded && LCF(D->getLocation());
236+
return ShouldBeIncluded;
237+
}
238+
239+
BatchExtractAPIVisitor(LocationFileChecker &LCF, ASTContext &Context,
240+
APISet &API)
241+
: ExtractAPIVisitor<BatchExtractAPIVisitor>(Context, API), LCF(LCF) {}
242+
243+
private:
244+
LocationFileChecker &LCF;
245+
};
246+
221247
class ExtractAPIConsumer : public ASTConsumer {
222248
public:
223249
ExtractAPIConsumer(ASTContext &Context,
224250
std::unique_ptr<LocationFileChecker> LCF, APISet &API)
225-
: Visitor(Context, *LCF, API), LCF(std::move(LCF)) {}
251+
: Visitor(*LCF, Context, API), LCF(std::move(LCF)) {}
226252

227253
void HandleTranslationUnit(ASTContext &Context) override {
228254
// Use ExtractAPIVisitor to traverse symbol declarations in the context.
229255
Visitor.TraverseDecl(Context.getTranslationUnitDecl());
230256
}
231257

232258
private:
233-
ExtractAPIVisitor Visitor;
259+
BatchExtractAPIVisitor Visitor;
234260
std::unique_ptr<LocationFileChecker> LCF;
235261
};
236262

0 commit comments

Comments
 (0)