|
12 | 12 | ///
|
13 | 13 | //===----------------------------------------------------------------------===//
|
14 | 14 |
|
| 15 | +#include "clang/AST/ASTConcept.h" |
15 | 16 | #include "clang/AST/ASTConsumer.h"
|
16 | 17 | #include "clang/AST/ASTContext.h"
|
| 18 | +#include "clang/AST/DeclObjC.h" |
17 | 19 | #include "clang/Basic/DiagnosticFrontend.h"
|
18 | 20 | #include "clang/Basic/SourceLocation.h"
|
19 | 21 | #include "clang/Basic/SourceManager.h"
|
|
33 | 35 | #include "llvm/ADT/DenseSet.h"
|
34 | 36 | #include "llvm/ADT/STLExtras.h"
|
35 | 37 | #include "llvm/ADT/SmallVector.h"
|
| 38 | +#include "llvm/Support/Casting.h" |
36 | 39 | #include "llvm/Support/Error.h"
|
37 | 40 | #include "llvm/Support/FileSystem.h"
|
38 | 41 | #include "llvm/Support/MemoryBuffer.h"
|
@@ -218,19 +221,42 @@ struct LocationFileChecker {
|
218 | 221 | llvm::DenseSet<const FileEntry *> ExternalFileEntries;
|
219 | 222 | };
|
220 | 223 |
|
| 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 | + |
221 | 247 | class ExtractAPIConsumer : public ASTConsumer {
|
222 | 248 | public:
|
223 | 249 | ExtractAPIConsumer(ASTContext &Context,
|
224 | 250 | 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)) {} |
226 | 252 |
|
227 | 253 | void HandleTranslationUnit(ASTContext &Context) override {
|
228 | 254 | // Use ExtractAPIVisitor to traverse symbol declarations in the context.
|
229 | 255 | Visitor.TraverseDecl(Context.getTranslationUnitDecl());
|
230 | 256 | }
|
231 | 257 |
|
232 | 258 | private:
|
233 |
| - ExtractAPIVisitor Visitor; |
| 259 | + BatchExtractAPIVisitor Visitor; |
234 | 260 | std::unique_ptr<LocationFileChecker> LCF;
|
235 | 261 | };
|
236 | 262 |
|
|
0 commit comments