[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
Thu May 9 09:36:19 PDT 2024
https://github.com/daniel-grumberg updated https://github.com/llvm/llvm-project/pull/91466
>From a8c7763ed5f36e4faeba5eece2827b2dec010734 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
rdar://127732562
---
clang/include/clang/ExtractAPI/API.h | 7 ++++--
.../clang/ExtractAPI/ExtractAPIVisitor.h | 25 +++++++++++--------
.../Serialization/SymbolGraphSerializer.cpp | 6 ++---
3 files changed, 23 insertions(+), 15 deletions(-)
diff --git a/clang/include/clang/ExtractAPI/API.h b/clang/include/clang/ExtractAPI/API.h
index d323e1668a72..bf291074fd06 100644
--- a/clang/include/clang/ExtractAPI/API.h
+++ b/clang/include/clang/ExtractAPI/API.h
@@ -266,6 +266,8 @@ struct APIRecord {
AccessControl Access;
+ RecordKind KindForDisplay;
+
private:
const RecordKind Kind;
friend class RecordContext;
@@ -277,6 +279,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 +296,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 97cc457ea2a9..8ccebe457ed5 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),
- isEmbeddedInVarDeclarator(*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 34278b5d40c4..c16d4623f115 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
@@ -591,8 +591,8 @@ Array generateParentContexts(const SmallVectorImpl<SymbolReference> &Parents,
Elem["usr"] = Parent.USR;
Elem["name"] = Parent.Name;
if (Parent.Record)
- Elem["kind"] =
- serializeSymbolKind(Parent.Record->getKind(), Lang)["identifier"];
+ Elem["kind"] = serializeSymbolKind(Parent.Record->KindForDisplay,
+ Lang)["identifier"];
else
Elem["kind"] =
serializeSymbolKind(APIRecord::RK_Unknown, Lang)["identifier"];
More information about the cfe-commits
mailing list