[clang] [clang][ExtractAPI] Distinguish between record kind for display and for RTTI (PR #91466)
Daniel Grumberg via cfe-commits
cfe-commits at lists.llvm.org
Wed May 8 05:27:03 PDT 2024
https://github.com/daniel-grumberg created https://github.com/llvm/llvm-project/pull/91466
rdar://127732562
>From d1118a8552d84e044cd0f22cd8b46e5e65b43cae Mon Sep 17 00:00:00 2001
From: Daniel Grumberg <dgrumberg at apple.com>
Date: Wed, 8 May 2024 11:55:15 +0100
Subject: [PATCH] [clang][ExtractAPI] Distinguish between record kind for
display and for RTTI
---
clang/include/clang/ExtractAPI/API.h | 6 +++--
.../clang/ExtractAPI/ExtractAPIVisitor.h | 23 +++++++++++--------
.../Serialization/SymbolGraphSerializer.cpp | 4 ++--
3 files changed, 20 insertions(+), 13 deletions(-)
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"];
More information about the cfe-commits
mailing list