-
Notifications
You must be signed in to change notification settings - Fork 13.4k
[clang][ExtractAPI] Distinguish between record kind for display and for RTTI #91466
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
daniel-grumberg
merged 1 commit into
llvm:main
from
daniel-grumberg:extract-api-display-kind
May 13, 2024
Merged
[clang][ExtractAPI] Distinguish between record kind for display and for RTTI #91466
daniel-grumberg
merged 1 commit into
llvm:main
from
daniel-grumberg:extract-api-display-kind
May 13, 2024
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@llvm/pr-subscribers-clang Author: Daniel Grumberg (daniel-grumberg) Changesrdar://127732562 Full diff: https://github.com/llvm/llvm-project/pull/91466.diff 3 Files Affected:
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"];
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
QuietMisdreavus
approved these changes
May 9, 2024
…or RTTI rdar://127732562
d1118a8
to
a8c7763
Compare
daniel-grumberg
added a commit
to daniel-grumberg/llvm-project
that referenced
this pull request
May 24, 2024
…or RTTI (llvm#91466) rdar://127732562
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
rdar://127732562