This is an archive of the discontinued LLVM Phabricator instance.

[clang-doc] Add typedef/using information.
ClosedPublic

Authored by brettw on Sep 21 2022, 9:18 AM.

Details

Summary

Read typedef and "using" type alias declarations and serialize into the internal structures. Emit this information in the YAML output. The HTML and MD generators are unchanged.

Separate out the logic to create the parent namespace or record object and insert the newly created child into it. This logic was previously duplicated for every "info" type and is now shared.

To help this, a struct containing the child vectors was separated out so children can be added generically and without having too many templates.

A small change was made to populateParentNamespaces() to allow using types that aren't themselves DeclContexts (typedefs are the first example of this).

Diff Detail

Event Timeline

brettw created this revision.Sep 21 2022, 9:18 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 21 2022, 9:18 AM
Herald added a subscriber: arphaman. · View Herald Transcript
brettw requested review of this revision.Sep 21 2022, 9:18 AM

Can we also add support for some of these changes to the other backends? I'm fine w/ us delaying that a bit, and tackling those in separate patches, but we shouldn't let one backend get wildly ahead of the others.

clang-tools-extra/clang-doc/BitcodeReader.cpp
540

nit: can we avoid unrelated changes to whitespace here and elsewhere in the patch?

clang-tools-extra/clang-doc/Representation.h
280

It seems a bit odd to use inheritance here on a type w/ public fields, and no methods. do you think using composition would improve the situation?

I'm fine w/ it if we think this is the simpler/more maintainable solution, but given that we don't have any methods in this case I'm unsure if there's much benefit.

clang-tools-extra/clang-doc/Serialize.cpp
449

Is this guaranteed to always execute at least once? can't getDeclContext() return null?

If there's some invariant that D is non null, then this code should probably have an assert.

632

Won't this deref the moved from unique_ptr?

https://en.cppreference.com/w/cpp/language/eval_order

In list-initialization, every value computation and side effect of a given initializer clause is sequenced before every value computation and side effect associated with any initializer clause that follows it in the brace-enclosed comma-separated list of initializers.

Under that reading, the move should always happen first. If it happens to still work, I think it's just luck in the implementation.

brettw updated this revision to Diff 462313.Sep 22 2022, 3:16 PM
brettw added inline comments.Sep 22 2022, 3:20 PM
clang-tools-extra/clang-doc/BitcodeReader.cpp
540

I did this on purpose. There were 8 variants of AddChild and I added two more. It became difficult to find the right one so I grouped them with comments for each group. This may be difficult to see in the side-by-side but it's much nicer in an editor.

clang-tools-extra/clang-doc/Representation.h
280

I don't have a strong opinion. I changed to composition.

clang-tools-extra/clang-doc/Serialize.cpp
632

Thanks, nice catch.

paulkirth accepted this revision.Sep 22 2022, 3:41 PM
paulkirth added inline comments.
clang-tools-extra/clang-doc/BitcodeReader.cpp
540

That's reasonable. Opening the full context, I see what you're going for.

This revision is now accepted and ready to land.Sep 22 2022, 3:41 PM
haowei accepted this revision.Sep 26 2022, 4:03 PM
This revision was automatically updated to reflect the committed changes.

This causes failures with -Werror such as: https://lab.llvm.org/buildbot/#/builders/57/builds/22322
Please fix or revert.

clang-tools-extra/clang-doc/Representation.h
45

There are at least a couple of switch statements where this enumerator isn't covered.
Examples:

clang-tools-extra/clang-doc/HTMLGenerator.cpp:847:11:
clang-tools-extra/clang-doc/MDGenerator.cpp:327:15
clang-tools-extra/clang-doc/MDGenerator.cpp:365:11

This causes failures with -Werror such as: https://lab.llvm.org/buildbot/#/builders/57/builds/22322
Please fix or revert.

Thanks for reporting this. I reverted this change.

brettw updated this revision to Diff 466858.Oct 11 2022, 10:39 AM

Fixed -Wall issues.

brettw reopened this revision.Oct 11 2022, 10:40 AM

New patch up to fix warnings that caused the revert.

This revision is now accepted and ready to land.Oct 11 2022, 10:40 AM

The premerge check is failing, because it can't apply the patch. Often this just means you need to rebase, so can you try rebasing your change and reuploading?

Also, do you have commit access? you've made enough changes that its appropriate to request, which should make landing your changes easier.

This revision was automatically updated to reflect the committed changes.