Adds 2 new functions to the C libclang api for retrieving operator kinds for binary and unary operators from cursors. Also adds 2 functions for retrieving the spelling of the new enums. This differential implements #29138.
Details
- Reviewers
aaron.ballman vedgy ayzhao collinbaker jcranmer diseraluca abdulras - Group Reviewers
Restricted Project Restricted Project - Commits
- rG7fbc9de45536: [libclang] Add CXBinaryOperatorKind and CXUnaryOperatorKind
Diff Detail
Event Timeline
Thank you for the additions! This should have some amount of test coverage added to clang/unittests/libclang/LibclangTest.cpp and a release note.
clang/tools/libclang/CIndex.cpp | ||
---|---|---|
9611 | Instead of implementing this manually, I think this should do: return cxstring::createRef(BinaryOperator::getOpcodeStr(kind - 1)); (Similar for unary operators, may need casts to compile properly). | |
9688 | Please spell out the type. | |
9690–9694 | Similar for unary operators. |
I kinda thought the undefined reference error is just something I broke on my machine but guess not. Don't really know what can cause it since it can link to other functions from there and the function exists.
I suspect the reason for the failed build is that you haven't updated clang/tools/libclang/libclang.map. Also CINDEX_VERSION_MINOR in clang/include/clang-c/Index.h needs to be incremented, unless it has been incremented in the targeted LLVM release version already. See e.g. cc929590ad305f0d068709c7c7999f5fc6118dc9.
I have added the new functions into the file and now it successfully compiles the test. (but fails when running it - EDIT: guess I broke my dev env somehow)
Also checked and made sure that CINDEX_VERSION_MINOR was already incremented in LLVM 17.
Another thing I am not sure is which naming convention I should be using. Some functions in the C api use clang_getCursorBinaryOperatorKind and others clang_Cursor_getBinaryOperatorKind.
The style you're using currently is fine.
clang/docs/ReleaseNotes.rst | ||
---|---|---|
720 | ||
clang/tools/libclang/CIndex.cpp | ||
9620–9624 | Sorry, I was unclear before. :-) Our style guide is to not use auto unless the type is spelled out explicitly in the RHS of the assignment (basically, use auto when it lets you avoid repeating the type name). So these uses with dyn_cast (and friends) should use auto, while a call like getCursorExpr() should spell out the type explicitly. | |
9640 | ||
clang/unittests/libclang/LibclangTest.cpp | ||
1143 | ||
1160 |
LGTM! Do you need me to commit on your behalf? If so, what name and email address would you like me to use for patch attribution?
Yeah, this is my first contribution, thanks. My name can be MineGame159 and email petulko08@gmail.com.