diff options
author | Daniel Grumberg <dgrumberg@apple.com> | 2023-03-27 22:12:11 +0100 |
---|---|---|
committer | Daniel Grumberg <dgrumberg@apple.com> | 2023-03-27 22:12:36 +0100 |
commit | 158a431227a876306fe5838936413dd51588d0c6 (patch) | |
tree | c94686d11728bbc0a54c169944861a08c81c70e2 /clang/tools | |
parent | 767aee1de9e98256a62ae8b4c2f84381203613c3 (diff) | |
download | llvm-158a431227a876306fe5838936413dd51588d0c6.tar.gz |
Revert ExtractAPI from https://reviews.llvm.org/D146656
Diffstat (limited to 'clang/tools')
-rw-r--r-- | clang/tools/c-index-test/c-index-test.c | 20 | ||||
-rw-r--r-- | clang/tools/libclang/CXExtractAPI.cpp | 132 |
2 files changed, 33 insertions, 119 deletions
diff --git a/clang/tools/c-index-test/c-index-test.c b/clang/tools/c-index-test/c-index-test.c index f116111fface..448435e83027 100644 --- a/clang/tools/c-index-test/c-index-test.c +++ b/clang/tools/c-index-test/c-index-test.c @@ -3,7 +3,6 @@ #include "clang-c/BuildSystem.h" #include "clang-c/CXCompilationDatabase.h" #include "clang-c/CXErrorCode.h" -#include "clang-c/CXSourceLocation.h" #include "clang-c/CXString.h" #include "clang-c/Documentation.h" #include "clang-c/Index.h" @@ -4882,21 +4881,6 @@ dispose_index: return result; } -static void inspect_single_symbol_sgf_cursor(CXCursor Cursor) { - CXSourceLocation CursorLoc; - CXString SGFData; - const char *SGF; - unsigned line, column; - CursorLoc = clang_getCursorLocation(Cursor); - clang_getSpellingLocation(CursorLoc, 0, &line, &column, 0); - printf("%d:%d: ", line, column); - - SGFData = clang_getSymbolGraphForCursor(Cursor); - SGF = clang_getCString(SGFData); - if (SGF) - printf("%s\n", SGF); -} - /******************************************************************************/ /* Command line processing. */ /******************************************************************************/ @@ -4956,7 +4940,6 @@ static void print_usage(void) { " c-index-test -print-usr-file <file>\n"); fprintf(stderr, " c-index-test -single-symbol-sgfs <symbol filter> {<args>*}\n" - " c-index-test -single-symbol-sgf-at=<site> {<args>*}\n" " c-index-test -single-symbol-sgf-for=<usr> {<args>}*\n"); fprintf(stderr, " c-index-test -write-pch <file> <compiler arguments>\n" @@ -5093,9 +5076,6 @@ int cindextest_main(int argc, const char **argv) { else if (argc > 3 && strcmp(argv[1], "-single-symbol-sgfs") == 0) return perform_test_load_source(argc - 3, argv + 3, argv[2], PrintSingleSymbolSGFs, NULL); - else if (argc > 2 && strstr(argv[1], "-single-symbol-sgf-at=") == argv[1]) - return inspect_cursor_at( - argc, argv, "-single-symbol-sgf-at=", inspect_single_symbol_sgf_cursor); else if (argc > 2 && strstr(argv[1], "-single-symbol-sgf-for=") == argv[1]) return perform_test_single_symbol_sgf(argv[1], argc - 2, argv + 2); diff --git a/clang/tools/libclang/CXExtractAPI.cpp b/clang/tools/libclang/CXExtractAPI.cpp index 9128e891538a..787334ab1bbb 100644 --- a/clang/tools/libclang/CXExtractAPI.cpp +++ b/clang/tools/libclang/CXExtractAPI.cpp @@ -18,7 +18,6 @@ #include "clang-c/Index.h" #include "clang-c/Platform.h" #include "clang/AST/Decl.h" -#include "clang/AST/DeclObjC.h" #include "clang/Basic/TargetInfo.h" #include "clang/ExtractAPI/API.h" #include "clang/ExtractAPI/ExtractAPIVisitor.h" @@ -35,73 +34,13 @@ using namespace clang; using namespace clang::extractapi; -namespace { -struct LibClangExtractAPIVisitor - : ExtractAPIVisitor<LibClangExtractAPIVisitor> { - using Base = ExtractAPIVisitor<LibClangExtractAPIVisitor>; - - LibClangExtractAPIVisitor(ASTContext &Context, APISet &API) - : ExtractAPIVisitor<LibClangExtractAPIVisitor>(Context, API) {} - - const RawComment *fetchRawCommentForDecl(const Decl *D) const { - return Context.getRawCommentForAnyRedecl(D); - } - - // We need to visit implementations as well to ensure that when a user clicks - // on a method defined only within the implementation that we can still - // provide a symbol graph for it. - bool VisitObjCImplementationDecl(const ObjCImplementationDecl *Decl) { - if (!shouldDeclBeIncluded(Decl)) - return true; - - const ObjCInterfaceDecl *Interface = Decl->getClassInterface(); - StringRef Name = Interface->getName(); - StringRef USR = API.recordUSR(Decl); - PresumedLoc Loc = - Context.getSourceManager().getPresumedLoc(Decl->getLocation()); - LinkageInfo Linkage = Decl->getLinkageAndVisibility(); - DocComment Comment; - if (auto *RawComment = fetchRawCommentForDecl(Interface)) - Comment = RawComment->getFormattedLines(Context.getSourceManager(), - Context.getDiagnostics()); - - // Build declaration fragments and sub-heading by generating them for the - // interface. - DeclarationFragments Declaration = - DeclarationFragmentsBuilder::getFragmentsForObjCInterface(Interface); - 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(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()); - - return true; - } -}; -} // namespace - DEFINE_SIMPLE_CONVERSION_FUNCTIONS(APISet, CXAPISet) -static void WalkupFromMostDerivedType(LibClangExtractAPIVisitor &Visitor, - Decl *D); +static void WalkupFromMostDerivedType(ExtractAPIVisitor &Visitor, Decl *D); template <typename DeclTy> static bool WalkupParentContext(DeclContext *Parent, - LibClangExtractAPIVisitor &Visitor) { + ExtractAPIVisitor &Visitor) { if (auto *D = dyn_cast<DeclTy>(Parent)) { WalkupFromMostDerivedType(Visitor, D); return true; @@ -109,8 +48,7 @@ static bool WalkupParentContext(DeclContext *Parent, return false; } -static void WalkupFromMostDerivedType(LibClangExtractAPIVisitor &Visitor, - Decl *D) { +static void WalkupFromMostDerivedType(ExtractAPIVisitor &Visitor, Decl *D) { switch (D->getKind()) { #define ABSTRACT_DECL(DECL) #define DECL(CLASS, BASE) \ @@ -146,7 +84,8 @@ enum CXErrorCode clang_createAPISet(CXTranslationUnit tu, CXAPISet *out_api) { auto Lang = Unit->getInputKind().getLanguage(); APISet *API = new APISet(Ctx.getTargetInfo().getTriple(), Lang, Unit->getMainFileName().str()); - LibClangExtractAPIVisitor Visitor(Ctx, *API); + ExtractAPIVisitor Visitor( + Ctx, [](SourceLocation Loc) { return true; }, *API); for (auto It = Unit->top_level_begin(); It != Unit->top_level_end(); ++It) { Visitor.TraverseDecl(*It); @@ -168,50 +107,45 @@ CXString clang_getSymbolGraphForUSR(const char *usr, CXAPISet api) { } CXString clang_getSymbolGraphForCursor(CXCursor cursor) { - cursor = clang_getCursorReferenced(cursor); CXCursorKind Kind = clang_getCursorKind(cursor); - if (!clang_isDeclaration(Kind)) - return cxstring::createNull(); + if (clang_isDeclaration(Kind)) { + const Decl *D = cxcursor::getCursorDecl(cursor); - const Decl *D = cxcursor::getCursorDecl(cursor); + if (!D) + return cxstring::createNull(); - if (!D) - return cxstring::createNull(); + CXTranslationUnit TU = cxcursor::getCursorTU(cursor); + if (!TU) + return cxstring::createNull(); - CXTranslationUnit TU = cxcursor::getCursorTU(cursor); - if (!TU) - return cxstring::createNull(); + ASTUnit *Unit = cxtu::getASTUnit(TU); - ASTUnit *Unit = cxtu::getASTUnit(TU); + auto &Ctx = Unit->getASTContext(); + auto Lang = Unit->getInputKind().getLanguage(); + APISet API(Ctx.getTargetInfo().getTriple(), Lang, + Unit->getMainFileName().str()); + ExtractAPIVisitor Visitor( + Ctx, [](SourceLocation Loc) { return true; }, API); - auto &Ctx = Unit->getASTContext(); - - auto Lang = Unit->getInputKind().getLanguage(); - APISet API(Ctx.getTargetInfo().getTriple(), Lang, - Unit->getMainFileName().str()); - LibClangExtractAPIVisitor Visitor(Ctx, API); + SmallString<128> USR; + if (index::generateUSRForDecl(D, USR)) + return cxstring::createNull(); - const Decl *CanonicalDecl = D->getCanonicalDecl(); - CanonicalDecl = CanonicalDecl ? CanonicalDecl : D; + WalkupFromMostDerivedType(Visitor, const_cast<Decl *>(D)); + auto *Record = API.findRecordForUSR(USR); - SmallString<128> USR; - if (index::generateUSRForDecl(CanonicalDecl, USR)) - return cxstring::createNull(); + if (!Record) + return cxstring::createNull(); - WalkupFromMostDerivedType(Visitor, const_cast<Decl *>(CanonicalDecl)); - auto *Record = API.findRecordForUSR(USR); - - if (!Record) - return cxstring::createNull(); + for (const auto &Fragment : Record->Declaration.getFragments()) { + if (Fragment.Declaration) + WalkupFromMostDerivedType(Visitor, + const_cast<Decl *>(Fragment.Declaration)); + } - for (const auto &Fragment : Record->Declaration.getFragments()) { - if (Fragment.Declaration) - WalkupFromMostDerivedType(Visitor, - const_cast<Decl *>(Fragment.Declaration)); + if (auto SGF = SymbolGraphSerializer::serializeSingleSymbolSGF(USR, API)) + return GenerateCXStringFromSymbolGraphData(std::move(*SGF)); } - if (auto SGF = SymbolGraphSerializer::serializeSingleSymbolSGF(USR, API)) - return GenerateCXStringFromSymbolGraphData(std::move(*SGF)); - return cxstring::createNull(); } |