llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang Author: Daniel Grumberg (daniel-grumberg) <details> <summary>Changes</summary> rdar://127732562 --- Full diff: https://github.com/llvm/llvm-project/pull/91466.diff 3 Files Affected: - (modified) clang/include/clang/ExtractAPI/API.h (+4-2) - (modified) clang/include/clang/ExtractAPI/ExtractAPIVisitor.h (+14-9) - (modified) clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp (+2-2) ``````````diff diff --git a/clang/include/clang/ExtractAPI/API.h b/clang/include/clang/ExtractAPI/API.h index d323e1668a72b..d2341f004c52f 100644 --- a/clang/include/clang/ExtractAPI/API.h +++ b/clang/include/clang/ExtractAPI/API.h @@ -266,6 +266,7 @@ struct APIRecord { AccessControl Access; + RecordKind KindForDisplay; private: const RecordKind Kind; friend class RecordContext; @@ -277,6 +278,7 @@ struct APIRecord { APIRecord *getNextInContext() const { return NextInContext; } RecordKind getKind() const { return Kind; } + RecordKind getKindForDisplay() const { return KindForDisplay; } static APIRecord *castFromRecordContext(const RecordContext *Ctx); static RecordContext *castToRecordContext(const APIRecord *Record); @@ -293,10 +295,10 @@ struct APIRecord { Availability(std::move(Availability)), Linkage(Linkage), Comment(Comment), Declaration(Declaration), SubHeading(SubHeading), IsFromSystemHeader(IsFromSystemHeader), Access(std::move(Access)), - Kind(Kind) {} + KindForDisplay(Kind), Kind(Kind) {} APIRecord(RecordKind Kind, StringRef USR, StringRef Name) - : USR(USR), Name(Name), Kind(Kind) {} + : USR(USR), Name(Name), KindForDisplay(Kind), Kind(Kind) {} // Pure virtual destructor to make APIRecord abstract virtual ~APIRecord() = 0; diff --git a/clang/include/clang/ExtractAPI/ExtractAPIVisitor.h b/clang/include/clang/ExtractAPI/ExtractAPIVisitor.h index 97cc457ea2a92..482a81f750a76 100644 --- a/clang/include/clang/ExtractAPI/ExtractAPIVisitor.h +++ b/clang/include/clang/ExtractAPI/ExtractAPIVisitor.h @@ -194,6 +194,15 @@ class ExtractAPIVisitorBase : public RecursiveASTVisitor<Derived> { return Bases; } + APIRecord::RecordKind getKindForDisplay(const CXXRecordDecl *Decl) { + if (Decl->isUnion()) + return APIRecord::RK_Union; + if (Decl->isStruct()) + return APIRecord::RK_Struct; + + return APIRecord::RK_CXXClass; + } + StringRef getOwningModuleName(const Decl &D) { if (auto *OwningModule = D.getImportedOwningModule()) return OwningModule->Name; @@ -599,13 +608,6 @@ bool ExtractAPIVisitorBase<Derived>::VisitCXXRecordDecl( DeclarationFragments SubHeading = DeclarationFragmentsBuilder::getSubHeading(Decl); - APIRecord::RecordKind Kind; - if (Decl->isUnion()) - Kind = APIRecord::RecordKind::RK_Union; - else if (Decl->isStruct()) - Kind = APIRecord::RecordKind::RK_Struct; - else - Kind = APIRecord::RecordKind::RK_CXXClass; auto Access = DeclarationFragmentsBuilder::getAccessControl(Decl); CXXClassRecord *Record; @@ -619,13 +621,15 @@ bool ExtractAPIVisitorBase<Derived>::VisitCXXRecordDecl( AvailabilityInfo::createFromDecl(Decl), Comment, Declaration, SubHeading, Template(Decl->getDescribedClassTemplate()), Access, isInSystemHeader(Decl)); - } else + } else { Record = API.createRecord<CXXClassRecord>( USR, Name, createHierarchyInformationForDecl(*Decl), Loc, AvailabilityInfo::createFromDecl(Decl), Comment, Declaration, - SubHeading, Kind, Access, isInSystemHeader(Decl), + SubHeading, APIRecord::RecordKind::RK_CXXClass, Access, isInSystemHeader(Decl), isEmbeddedInVarDeclarator(*Decl)); + } + Record->KindForDisplay = getKindForDisplay(Decl); Record->Bases = getBases(Decl); return true; @@ -849,6 +853,7 @@ bool ExtractAPIVisitorBase<Derived>:: Template(Decl), DeclarationFragmentsBuilder::getAccessControl(Decl), isInSystemHeader(Decl)); + CTPSR->KindForDisplay = getKindForDisplay(Decl); CTPSR->Bases = getBases(Decl); return true; diff --git a/clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp b/clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp index 34278b5d40c42..952deccded07d 100644 --- a/clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp +++ b/clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp @@ -514,7 +514,7 @@ Object serializeSymbolKind(APIRecord::RecordKind RK, Language Lang) { /// which is prefixed by the source language name, useful for tooling to parse /// the kind, and a \c displayName for rendering human-readable names. Object serializeSymbolKind(const APIRecord &Record, Language Lang) { - return serializeSymbolKind(Record.getKind(), Lang); + return serializeSymbolKind(Record.KindForDisplay, Lang); } /// Serialize the function signature field, as specified by the @@ -592,7 +592,7 @@ Array generateParentContexts(const SmallVectorImpl<SymbolReference> &Parents, Elem["name"] = Parent.Name; if (Parent.Record) Elem["kind"] = - serializeSymbolKind(Parent.Record->getKind(), Lang)["identifier"]; + serializeSymbolKind(Parent.Record->KindForDisplay, Lang)["identifier"]; else Elem["kind"] = serializeSymbolKind(APIRecord::RK_Unknown, Lang)["identifier"]; `````````` </details> https://github.com/llvm/llvm-project/pull/91466 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits