Skip to content

Commit 33fa40c

Browse files
authoredOct 2, 2024··
[clang][ExtractAPI] Generate subheading for typedef'd anonymous types (#110689)
When an anonymous type has a typedef we normally use the typedef's name in places where we expect a named identifier in the symbol graph. This extends this logic to apply to subheadings. rdar://136690614
1 parent e6bf48d commit 33fa40c

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed
 

‎clang/lib/ExtractAPI/DeclarationFragments.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -1621,6 +1621,9 @@ DeclarationFragmentsBuilder::getSubHeading(const NamedDecl *Decl) {
16211621
cast<CXXMethodDecl>(Decl)->isOverloadedOperator()) {
16221622
Fragments.append(Decl->getNameAsString(),
16231623
DeclarationFragments::FragmentKind::Identifier);
1624+
} else if (isa<TagDecl>(Decl) &&
1625+
cast<TagDecl>(Decl)->getTypedefNameForAnonDecl()) {
1626+
return getSubHeading(cast<TagDecl>(Decl)->getTypedefNameForAnonDecl());
16241627
} else if (Decl->getIdentifier()) {
16251628
Fragments.append(Decl->getName(),
16261629
DeclarationFragments::FragmentKind::Identifier);

‎clang/test/ExtractAPI/typedef_anonymous_record.c

+30-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,21 @@ typedef struct { } MyStruct;
3535
// MYSTRUCT: "kind": {
3636
// MYSTRUCT-NEXT: "displayName": "Structure",
3737
// MYSTRUCT-NEXT: "identifier": "c.struct"
38-
// MYSTRUCT: "title": "MyStruct"
38+
// MYSTRUCT: "names": {
39+
// MYSTRUCT-NEXT: "navigator": [
40+
// MYSTRUCT-NEXT: {
41+
// MYSTRUCT-NEXT: "kind": "identifier",
42+
// MYSTRUCT-NEXT: "spelling": "MyStruct"
43+
// MYSTRUCT-NEXT: }
44+
// MYSTRUCT-NEXT: ],
45+
// MYSTRUCT-NEXT: "subHeading": [
46+
// MYSTRUCT-NEXT: {
47+
// MYSTRUCT-NEXT: "kind": "identifier",
48+
// MYSTRUCT-NEXT: "spelling": "MyStruct"
49+
// MYSTRUCT-NEXT: }
50+
// MYSTRUCT-NEXT: ],
51+
// MYSTRUCT-NEXT: "title": "MyStruct"
52+
// MYSTRUCT-NEXT: },
3953
// MYSTRUCT: "pathComponents": [
4054
// MYSTRUCT-NEXT: "MyStruct"
4155
// MYSTRUCT-NEXT: ]
@@ -111,7 +125,21 @@ typedef enum { Case } MyEnum;
111125
// MYENUM: "kind": {
112126
// MYENUM-NEXT: "displayName": "Enumeration",
113127
// MYENUM-NEXT: "identifier": "c.enum"
114-
// MYENUM: "title": "MyEnum"
128+
// MYENUM: "names": {
129+
// MYENUM-NEXT: "navigator": [
130+
// MYENUM-NEXT: {
131+
// MYENUM-NEXT: "kind": "identifier",
132+
// MYENUM-NEXT: "spelling": "MyEnum"
133+
// MYENUM-NEXT: }
134+
// MYENUM-NEXT: ],
135+
// MYENUM-NEXT: "subHeading": [
136+
// MYENUM-NEXT: {
137+
// MYENUM-NEXT: "kind": "identifier",
138+
// MYENUM-NEXT: "spelling": "MyEnum"
139+
// MYENUM-NEXT: }
140+
// MYENUM-NEXT: ],
141+
// MYENUM-NEXT: "title": "MyEnum"
142+
// MYENUM-NEXT: },
115143

116144
// CASE-LABEL: "!testLabel": "c:@EA@MyEnum@Case"
117145
// CASE: "pathComponents": [

0 commit comments

Comments
 (0)
Please sign in to comment.