Page MenuHomePhabricator

Allow getting template args for ClassTemplateSpecializations
ClosedPublic

Authored by anderslanglands on Sep 22 2022, 1:01 AM.

Details

Summary

Modifies clang_Cursor_getNumTemplateArguments() and friends to work on Struct, Class and ClassTemplatePartialSpecialization decls as well as functions

Diff Detail

Event Timeline

Herald added a project: Restricted Project. · View Herald TranscriptSep 22 2022, 1:01 AM
anderslanglands requested review of this revision.Sep 22 2022, 1:01 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 22 2022, 1:01 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript

Hello again, this generalizes the template argument functionality to operate on cursor kinds other than functions.

I could use some help creating a test for this. On my previous patch I was able to just copy/paste and modify an existing test, but from a quick scan of the current tests I can't see how I'd modify one of them to test this functionality.

Updating doc comments to reflect new functionality

Mostly nits from me (FWIW, we use auto when the type is explicitly spelled out in the initialization and we don't usually use else after an unconditional return as a matter of coding style.) In terms of the test coverage, I would probably make a new test modeled after https://github.com/llvm/llvm-project/blob/main/clang/test/Index/cxx14-lambdas.cpp.

clang/include/clang-c/Index.h
3594–3596

Since we're in the area already...

clang/tools/libclang/CXCursor.cpp
1357

CXCursor_StructDecl is interesting -- does that only get used in C or will it also show up in C++? If it's C-only, we can drop that bit.

1372–1373
1379–1388
1404

Same question here about struct decl as above.

1410–1417
1439–1455
anderslanglands marked 7 inline comments as done.

Add testing, address style notes

I ended up modifying c-index-test to print out the template arguments in the same way it does for FunctionDecl, which ends up working all cases in the existing test suite. The only other thing I added was a specific case in index-templates.cpp to check whether it catches StructDecl too (it does).

clang/tools/libclang/CXCursor.cpp
1357

It does. I added a case to index-templates.cpp that tests for this.

aaron.ballman accepted this revision.Sep 23 2022, 6:54 AM

LGTM! I can fix up the minor nit with the release note formatting when I land on your behalf.

clang/docs/ReleaseNotes.rst
429–430
This revision is now accepted and ready to land.Sep 23 2022, 6:54 AM