Skip to content

Commit e47b5ee

Browse files
Jugst3rGeorgeARM
authored andcommitted
Remove duplicate API (llvm#132776)
And adapt the existing code to account for the comments made when introducing the duplicate API. Note that this introduces a retro-incompatibility with LLVM 19. cc @sebastianpoeplau
1 parent f368197 commit e47b5ee

File tree

5 files changed

+58
-64
lines changed

5 files changed

+58
-64
lines changed

clang/bindings/python/clang/cindex.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1887,7 +1887,7 @@ def binary_operator(self):
18871887
"""
18881888

18891889
if not hasattr(self, "_binopcode"):
1890-
self._binopcode = conf.lib.clang_Cursor_getBinaryOpcode(self)
1890+
self._binopcode = conf.lib.clang_getCursorBinaryOperatorKind(self)
18911891

18921892
return BinaryOperator.from_id(self._binopcode)
18931893

@@ -4097,7 +4097,7 @@ def set_property(self, property, value):
40974097
("clang_Cursor_getTemplateArgumentType", [Cursor, c_uint], Type),
40984098
("clang_Cursor_getTemplateArgumentValue", [Cursor, c_uint], c_longlong),
40994099
("clang_Cursor_getTemplateArgumentUnsignedValue", [Cursor, c_uint], c_ulonglong),
4100-
("clang_Cursor_getBinaryOpcode", [Cursor], c_int),
4100+
("clang_getCursorBinaryOperatorKind", [Cursor], c_int),
41014101
("clang_Cursor_getBriefCommentText", [Cursor], _CXString),
41024102
("clang_Cursor_getRawCommentText", [Cursor], _CXString),
41034103
("clang_Cursor_getOffsetOfField", [Cursor], c_longlong),

clang/docs/ReleaseNotes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -799,6 +799,10 @@ libclang
799799
- Fixed a buffer overflow in ``CXString`` implementation. The fix may result in
800800
increased memory allocation.
801801

802+
- Deprecate ``clang_Cursor_GetBinaryOpcode`` and ``clang_Cursor_getBinaryOpcodeStr``
803+
implementations, which are duplicates of ``clang_getCursorBinaryOperatorKind``
804+
and ``clang_getBinaryOperatorKindSpelling`` respectively.
805+
802806
Code Completion
803807
---------------
804808

clang/include/clang-c/Index.h

Lines changed: 39 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3882,12 +3882,16 @@ enum CX_BinaryOperatorKind {
38823882

38833883
/**
38843884
* \brief Returns the operator code for the binary operator.
3885+
*
3886+
* @deprecated: use clang_getCursorBinaryOperatorKind instead.
38853887
*/
38863888
CINDEX_LINKAGE enum CX_BinaryOperatorKind
38873889
clang_Cursor_getBinaryOpcode(CXCursor C);
38883890

38893891
/**
38903892
* \brief Returns a string containing the spelling of the binary operator.
3893+
*
3894+
* @deprecated: use clang_getBinaryOperatorKindSpelling instead
38913895
*/
38923896
CINDEX_LINKAGE CXString
38933897
clang_Cursor_getBinaryOpcodeStr(enum CX_BinaryOperatorKind Op);
@@ -6683,73 +6687,74 @@ CINDEX_LINKAGE unsigned clang_visitCXXMethods(CXType T, CXFieldVisitor visitor,
66836687
*/
66846688
enum CXBinaryOperatorKind {
66856689
/** This value describes cursors which are not binary operators. */
6686-
CXBinaryOperator_Invalid,
6690+
CXBinaryOperator_Invalid = 0,
66876691
/** C++ Pointer - to - member operator. */
6688-
CXBinaryOperator_PtrMemD,
6692+
CXBinaryOperator_PtrMemD = 1,
66896693
/** C++ Pointer - to - member operator. */
6690-
CXBinaryOperator_PtrMemI,
6694+
CXBinaryOperator_PtrMemI = 2,
66916695
/** Multiplication operator. */
6692-
CXBinaryOperator_Mul,
6696+
CXBinaryOperator_Mul = 3,
66936697
/** Division operator. */
6694-
CXBinaryOperator_Div,
6698+
CXBinaryOperator_Div = 4,
66956699
/** Remainder operator. */
6696-
CXBinaryOperator_Rem,
6700+
CXBinaryOperator_Rem = 5,
66976701
/** Addition operator. */
6698-
CXBinaryOperator_Add,
6702+
CXBinaryOperator_Add = 6,
66996703
/** Subtraction operator. */
6700-
CXBinaryOperator_Sub,
6704+
CXBinaryOperator_Sub = 7,
67016705
/** Bitwise shift left operator. */
6702-
CXBinaryOperator_Shl,
6706+
CXBinaryOperator_Shl = 8,
67036707
/** Bitwise shift right operator. */
6704-
CXBinaryOperator_Shr,
6708+
CXBinaryOperator_Shr = 9,
67056709
/** C++ three-way comparison (spaceship) operator. */
6706-
CXBinaryOperator_Cmp,
6710+
CXBinaryOperator_Cmp = 10,
67076711
/** Less than operator. */
6708-
CXBinaryOperator_LT,
6712+
CXBinaryOperator_LT = 11,
67096713
/** Greater than operator. */
6710-
CXBinaryOperator_GT,
6714+
CXBinaryOperator_GT = 12,
67116715
/** Less or equal operator. */
6712-
CXBinaryOperator_LE,
6716+
CXBinaryOperator_LE = 13,
67136717
/** Greater or equal operator. */
6714-
CXBinaryOperator_GE,
6718+
CXBinaryOperator_GE = 14,
67156719
/** Equal operator. */
6716-
CXBinaryOperator_EQ,
6720+
CXBinaryOperator_EQ = 15,
67176721
/** Not equal operator. */
6718-
CXBinaryOperator_NE,
6722+
CXBinaryOperator_NE = 16,
67196723
/** Bitwise AND operator. */
6720-
CXBinaryOperator_And,
6724+
CXBinaryOperator_And = 17,
67216725
/** Bitwise XOR operator. */
6722-
CXBinaryOperator_Xor,
6726+
CXBinaryOperator_Xor = 18,
67236727
/** Bitwise OR operator. */
6724-
CXBinaryOperator_Or,
6728+
CXBinaryOperator_Or = 19,
67256729
/** Logical AND operator. */
6726-
CXBinaryOperator_LAnd,
6730+
CXBinaryOperator_LAnd = 20,
67276731
/** Logical OR operator. */
6728-
CXBinaryOperator_LOr,
6732+
CXBinaryOperator_LOr = 21,
67296733
/** Assignment operator. */
6730-
CXBinaryOperator_Assign,
6734+
CXBinaryOperator_Assign = 22,
67316735
/** Multiplication assignment operator. */
6732-
CXBinaryOperator_MulAssign,
6736+
CXBinaryOperator_MulAssign = 23,
67336737
/** Division assignment operator. */
6734-
CXBinaryOperator_DivAssign,
6738+
CXBinaryOperator_DivAssign = 24,
67356739
/** Remainder assignment operator. */
6736-
CXBinaryOperator_RemAssign,
6740+
CXBinaryOperator_RemAssign = 25,
67376741
/** Addition assignment operator. */
6738-
CXBinaryOperator_AddAssign,
6742+
CXBinaryOperator_AddAssign = 26,
67396743
/** Subtraction assignment operator. */
6740-
CXBinaryOperator_SubAssign,
6744+
CXBinaryOperator_SubAssign = 27,
67416745
/** Bitwise shift left assignment operator. */
6742-
CXBinaryOperator_ShlAssign,
6746+
CXBinaryOperator_ShlAssign = 28,
67436747
/** Bitwise shift right assignment operator. */
6744-
CXBinaryOperator_ShrAssign,
6748+
CXBinaryOperator_ShrAssign = 29,
67456749
/** Bitwise AND assignment operator. */
6746-
CXBinaryOperator_AndAssign,
6750+
CXBinaryOperator_AndAssign = 30,
67476751
/** Bitwise XOR assignment operator. */
6748-
CXBinaryOperator_XorAssign,
6752+
CXBinaryOperator_XorAssign = 31,
67496753
/** Bitwise OR assignment operator. */
6750-
CXBinaryOperator_OrAssign,
6754+
CXBinaryOperator_OrAssign = 32,
67516755
/** Comma operator. */
6752-
CXBinaryOperator_Comma
6756+
CXBinaryOperator_Comma = 33,
6757+
CXBinaryOperator_Last = CXBinaryOperator_Comma
67536758
};
67546759

67556760
/**

clang/tools/c-index-test/c-index-test.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1863,14 +1863,14 @@ static enum CXChildVisitResult PrintTypeSize(CXCursor cursor, CXCursor p,
18631863
static enum CXChildVisitResult PrintBinOps(CXCursor C, CXCursor p,
18641864
CXClientData d) {
18651865
enum CXCursorKind ck = clang_getCursorKind(C);
1866-
enum CX_BinaryOperatorKind bok;
1866+
enum CXBinaryOperatorKind bok;
18671867
CXString opstr;
18681868
if (ck != CXCursor_BinaryOperator && ck != CXCursor_CompoundAssignOperator)
18691869
return CXChildVisit_Recurse;
18701870

18711871
PrintCursor(C, NULL);
1872-
bok = clang_Cursor_getBinaryOpcode(C);
1873-
opstr = clang_Cursor_getBinaryOpcodeStr(bok);
1872+
bok = clang_getCursorBinaryOperatorKind(C);
1873+
opstr = clang_getBinaryOperatorKindSpelling(bok);
18741874
printf(" BinOp=%s %d\n", clang_getCString(opstr), bok);
18751875
clang_disposeString(opstr);
18761876
return CXChildVisit_Recurse;

clang/tools/libclang/CIndex.cpp

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5441,7 +5441,8 @@ CXString clang_getCursorSpelling(CXCursor C) {
54415441

54425442
if (C.kind == CXCursor_BinaryOperator ||
54435443
C.kind == CXCursor_CompoundAssignOperator) {
5444-
return clang_Cursor_getBinaryOpcodeStr(clang_Cursor_getBinaryOpcode(C));
5444+
return clang_getBinaryOperatorKindSpelling(
5445+
clang_getCursorBinaryOperatorKind(C));
54455446
}
54465447

54475448
const Decl *D = getDeclFromExpr(getCursorExpr(C));
@@ -9210,32 +9211,13 @@ unsigned clang_Cursor_isExternalSymbol(CXCursor C, CXString *language,
92109211
}
92119212

92129213
enum CX_BinaryOperatorKind clang_Cursor_getBinaryOpcode(CXCursor C) {
9213-
if (C.kind != CXCursor_BinaryOperator &&
9214-
C.kind != CXCursor_CompoundAssignOperator) {
9215-
return CX_BO_Invalid;
9216-
}
9217-
9218-
const Expr *D = getCursorExpr(C);
9219-
if (const auto *BinOp = dyn_cast<BinaryOperator>(D)) {
9220-
switch (BinOp->getOpcode()) {
9221-
#define BINARY_OPERATION(Name, Spelling) \
9222-
case BO_##Name: \
9223-
return CX_BO_##Name;
9224-
#include "clang/AST/OperationKinds.def"
9225-
}
9226-
}
9227-
9228-
return CX_BO_Invalid;
9214+
return static_cast<CX_BinaryOperatorKind>(
9215+
clang_getCursorBinaryOperatorKind(C));
92299216
}
92309217

92319218
CXString clang_Cursor_getBinaryOpcodeStr(enum CX_BinaryOperatorKind Op) {
9232-
if (Op > CX_BO_LAST)
9233-
return cxstring::createEmpty();
9234-
9235-
return cxstring::createDup(
9236-
// BinaryOperator::getOpcodeStr has no case for CX_BO_Invalid,
9237-
// so subtract 1
9238-
BinaryOperator::getOpcodeStr(static_cast<BinaryOperatorKind>(Op - 1)));
9219+
return clang_getBinaryOperatorKindSpelling(
9220+
static_cast<CXBinaryOperatorKind>(Op));
92399221
}
92409222

92419223
CXSourceRange clang_Cursor_getCommentRange(CXCursor C) {
@@ -10110,7 +10092,10 @@ cxindex::Logger::~Logger() {
1011010092
}
1011110093

1011210094
CXString clang_getBinaryOperatorKindSpelling(enum CXBinaryOperatorKind kind) {
10113-
return cxstring::createRef(
10095+
if (kind > CXBinaryOperator_Last)
10096+
return cxstring::createEmpty();
10097+
10098+
return cxstring::createDup(
1011410099
BinaryOperator::getOpcodeStr(static_cast<BinaryOperatorKind>(kind - 1)));
1011510100
}
1011610101

0 commit comments

Comments
 (0)