-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[clang][ExtractAPI] combine typedef records if the underlying type's name is underscored #125964
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
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// RUN: rm -rf %t | ||
// RUN: %clang_cc1 -extract-api --pretty-sgf --emit-sgf-symbol-labels-for-testing \ | ||
// RUN: --product-name=TypedefChain -triple arm64-apple-macosx -x c-header %s -o %t/typedefchain-c.symbols.json -verify | ||
// RUN: %clang_cc1 -extract-api --pretty-sgf --emit-sgf-symbol-labels-for-testing \ | ||
// RUN: --product-name=TypedefChain -triple arm64-apple-macosx -x c++-header %s -o %t/typedefchain-cxx.symbols.json -verify | ||
|
||
// RUN: FileCheck %s --input-file %t/typedefchain-c.symbols.json --check-prefix MYSTRUCT | ||
// RUN: FileCheck %s --input-file %t/typedefchain-cxx.symbols.json --check-prefix MYSTRUCT | ||
typedef struct _MyStruct { } MyStruct; | ||
|
||
// MYSTRUCT-LABEL: "!testLabel": "c:@S@_MyStruct" | ||
// MYSTRUCT: "accessLevel": "public", | ||
// MYSTRUCT: "declarationFragments": [ | ||
// MYSTRUCT-NEXT: { | ||
// MYSTRUCT-NEXT: "kind": "keyword", | ||
// MYSTRUCT-NEXT: "spelling": "typedef" | ||
// MYSTRUCT-NEXT: }, | ||
// MYSTRUCT-NEXT: { | ||
// MYSTRUCT-NEXT: "kind": "text", | ||
// MYSTRUCT-NEXT: "spelling": " " | ||
// MYSTRUCT-NEXT: }, | ||
// MYSTRUCT-NEXT: { | ||
// MYSTRUCT-NEXT: "kind": "keyword", | ||
// MYSTRUCT-NEXT: "spelling": "struct" | ||
// MYSTRUCT-NEXT: }, | ||
// MYSTRUCT-NEXT: { | ||
// MYSTRUCT-NEXT: "kind": "text", | ||
// MYSTRUCT-NEXT: "spelling": " " | ||
// MYSTRUCT-NEXT: }, | ||
// MYSTRUCT-NEXT: { | ||
// MYSTRUCT-NEXT: "kind": "identifier", | ||
// MYSTRUCT-NEXT: "spelling": "_MyStruct" | ||
// MYSTRUCT-NEXT: }, | ||
// MYSTRUCT-NEXT: { | ||
// MYSTRUCT-NEXT: "kind": "text", | ||
// MYSTRUCT-NEXT: "spelling": " { ... } " | ||
// MYSTRUCT-NEXT: }, | ||
// MYSTRUCT-NEXT: { | ||
// MYSTRUCT-NEXT: "kind": "identifier", | ||
// MYSTRUCT-NEXT: "spelling": "MyStruct" | ||
// MYSTRUCT-NEXT: }, | ||
// MYSTRUCT-NEXT: { | ||
// MYSTRUCT-NEXT: "kind": "text", | ||
// MYSTRUCT-NEXT: "spelling": ";" | ||
// MYSTRUCT-NEXT: } | ||
// MYSTRUCT-NEXT: ], | ||
// MYSTRUCT: "kind": { | ||
// MYSTRUCT-NEXT: "displayName": "Structure", | ||
// MYSTRUCT-NEXT: "identifier": "c{{(\+\+)?}}.struct" | ||
// MYSTRUCT: "names": { | ||
// MYSTRUCT-NEXT: "navigator": [ | ||
// MYSTRUCT-NEXT: { | ||
// MYSTRUCT-NEXT: "kind": "identifier", | ||
// MYSTRUCT-NEXT: "spelling": "MyStruct" | ||
// MYSTRUCT-NEXT: } | ||
// MYSTRUCT-NEXT: ], | ||
// MYSTRUCT-NEXT: "subHeading": [ | ||
// MYSTRUCT-NEXT: { | ||
// MYSTRUCT-NEXT: "kind": "identifier", | ||
// MYSTRUCT-NEXT: "spelling": "MyStruct" | ||
// MYSTRUCT-NEXT: } | ||
// MYSTRUCT-NEXT: ], | ||
// MYSTRUCT-NEXT: "title": "MyStruct" | ||
// MYSTRUCT-NEXT: }, | ||
// MYSTRUCT: "pathComponents": [ | ||
// MYSTRUCT-NEXT: "MyStruct" | ||
// MYSTRUCT-NEXT: ] | ||
|
||
// expected-no-diagnostics |
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.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it worth catching a
typedef
of atypedef
that also begins with an underscore?5
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is already limiting itself to underlying types which (1) are "tag decls", i.e. structs/classes/enums/unions, and (2) whose definitions are "embedded in a declarator", which AFAIK means that it's not going to catch typedefs of typedefs to begin with.
Now, I recently implemented logic in the Swift compiler to catch the same situation i mentioned in the PR description, but in that PR i took a more general approach and folded together "public type aliases of types that are being hidden (e.g. underscored)". However, the Swift symbol graph generator didn't have its own notion of "folding decls together" yet, since in the average case the Swift Clang Importer already handles that, whereas here in Clang we were already handling
typedef struct
unification. (I also didn't go recursive in the Swift PR, but the nondeterministic ordering of AST walking could make that even more complicated! 😵💫)I'm inclined to hold off on going recursive for now, and come back later if we need to handle
typedef _HiddenTypedef PublicTypedef
in this kind of way. I could see this becoming even more complicated in this kind of situation, to avoid revealing too many implementation details in an ostensibly public symbol graph rendering.