Skip to content

Commit a2b5449

Browse files
committed
Remove duplicate API
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.
1 parent 1f96788 commit a2b5449

File tree

6 files changed

+50
-129
lines changed

6 files changed

+50
-129
lines changed

clang/bindings/python/clang/cindex.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1876,7 +1876,7 @@ def binary_operator(self):
18761876
"""
18771877

18781878
if not hasattr(self, "_binopcode"):
1879-
self._binopcode = conf.lib.clang_Cursor_getBinaryOpcode(self)
1879+
self._binopcode = conf.lib.clang_getCursorBinaryOperatorKind(self)
18801880

18811881
return BinaryOperator.from_id(self._binopcode)
18821882

@@ -4043,7 +4043,7 @@ def set_property(self, property, value):
40434043
("clang_Cursor_getTemplateArgumentType", [Cursor, c_uint], Type),
40444044
("clang_Cursor_getTemplateArgumentValue", [Cursor, c_uint], c_longlong),
40454045
("clang_Cursor_getTemplateArgumentUnsignedValue", [Cursor, c_uint], c_ulonglong),
4046-
("clang_Cursor_getBinaryOpcode", [Cursor], c_int),
4046+
("clang_getCursorBinaryOperatorKind", [Cursor], c_int),
40474047
("clang_Cursor_getBriefCommentText", [Cursor], _CXString),
40484048
("clang_Cursor_getRawCommentText", [Cursor], _CXString),
40494049
("clang_Cursor_getOffsetOfField", [Cursor], c_longlong),

clang/docs/ReleaseNotes.rst

+4
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,10 @@ libclang
483483
- Fixed a buffer overflow in ``CXString`` implementation. The fix may result in
484484
increased memory allocation.
485485

486+
- Remove ``clang_Cursor_GetBinaryOpcode`` and ``clang_Cursor_getBinaryOpcodeStr``
487+
implementations, which were duplicates of ``clang_getCursorBinaryOperatorKind``
488+
and ``clang_getBinaryOperatorKindSpelling`` respectively.
489+
486490
Code Completion
487491
---------------
488492

clang/include/clang-c/Index.h

+35-87
Original file line numberDiff line numberDiff line change
@@ -3839,59 +3839,6 @@ enum CX_StorageClass {
38393839
CX_SC_Register
38403840
};
38413841

3842-
/**
3843-
* Represents a specific kind of binary operator which can appear at a cursor.
3844-
*/
3845-
enum CX_BinaryOperatorKind {
3846-
CX_BO_Invalid = 0,
3847-
CX_BO_PtrMemD = 1,
3848-
CX_BO_PtrMemI = 2,
3849-
CX_BO_Mul = 3,
3850-
CX_BO_Div = 4,
3851-
CX_BO_Rem = 5,
3852-
CX_BO_Add = 6,
3853-
CX_BO_Sub = 7,
3854-
CX_BO_Shl = 8,
3855-
CX_BO_Shr = 9,
3856-
CX_BO_Cmp = 10,
3857-
CX_BO_LT = 11,
3858-
CX_BO_GT = 12,
3859-
CX_BO_LE = 13,
3860-
CX_BO_GE = 14,
3861-
CX_BO_EQ = 15,
3862-
CX_BO_NE = 16,
3863-
CX_BO_And = 17,
3864-
CX_BO_Xor = 18,
3865-
CX_BO_Or = 19,
3866-
CX_BO_LAnd = 20,
3867-
CX_BO_LOr = 21,
3868-
CX_BO_Assign = 22,
3869-
CX_BO_MulAssign = 23,
3870-
CX_BO_DivAssign = 24,
3871-
CX_BO_RemAssign = 25,
3872-
CX_BO_AddAssign = 26,
3873-
CX_BO_SubAssign = 27,
3874-
CX_BO_ShlAssign = 28,
3875-
CX_BO_ShrAssign = 29,
3876-
CX_BO_AndAssign = 30,
3877-
CX_BO_XorAssign = 31,
3878-
CX_BO_OrAssign = 32,
3879-
CX_BO_Comma = 33,
3880-
CX_BO_LAST = CX_BO_Comma
3881-
};
3882-
3883-
/**
3884-
* \brief Returns the operator code for the binary operator.
3885-
*/
3886-
CINDEX_LINKAGE enum CX_BinaryOperatorKind
3887-
clang_Cursor_getBinaryOpcode(CXCursor C);
3888-
3889-
/**
3890-
* \brief Returns a string containing the spelling of the binary operator.
3891-
*/
3892-
CINDEX_LINKAGE CXString
3893-
clang_Cursor_getBinaryOpcodeStr(enum CX_BinaryOperatorKind Op);
3894-
38953842
/**
38963843
* Returns the storage class for a function or variable declaration.
38973844
*
@@ -6671,73 +6618,74 @@ CINDEX_LINKAGE unsigned clang_visitCXXMethods(CXType T, CXFieldVisitor visitor,
66716618
*/
66726619
enum CXBinaryOperatorKind {
66736620
/** This value describes cursors which are not binary operators. */
6674-
CXBinaryOperator_Invalid,
6621+
CXBinaryOperator_Invalid = 0,
66756622
/** C++ Pointer - to - member operator. */
6676-
CXBinaryOperator_PtrMemD,
6623+
CXBinaryOperator_PtrMemD = 1,
66776624
/** C++ Pointer - to - member operator. */
6678-
CXBinaryOperator_PtrMemI,
6625+
CXBinaryOperator_PtrMemI = 2,
66796626
/** Multiplication operator. */
6680-
CXBinaryOperator_Mul,
6627+
CXBinaryOperator_Mul = 3,
66816628
/** Division operator. */
6682-
CXBinaryOperator_Div,
6629+
CXBinaryOperator_Div = 4,
66836630
/** Remainder operator. */
6684-
CXBinaryOperator_Rem,
6631+
CXBinaryOperator_Rem = 5,
66856632
/** Addition operator. */
6686-
CXBinaryOperator_Add,
6633+
CXBinaryOperator_Add = 6,
66876634
/** Subtraction operator. */
6688-
CXBinaryOperator_Sub,
6635+
CXBinaryOperator_Sub = 7,
66896636
/** Bitwise shift left operator. */
6690-
CXBinaryOperator_Shl,
6637+
CXBinaryOperator_Shl = 8,
66916638
/** Bitwise shift right operator. */
6692-
CXBinaryOperator_Shr,
6639+
CXBinaryOperator_Shr = 9,
66936640
/** C++ three-way comparison (spaceship) operator. */
6694-
CXBinaryOperator_Cmp,
6641+
CXBinaryOperator_Cmp = 10,
66956642
/** Less than operator. */
6696-
CXBinaryOperator_LT,
6643+
CXBinaryOperator_LT = 11,
66976644
/** Greater than operator. */
6698-
CXBinaryOperator_GT,
6645+
CXBinaryOperator_GT = 12,
66996646
/** Less or equal operator. */
6700-
CXBinaryOperator_LE,
6647+
CXBinaryOperator_LE = 13,
67016648
/** Greater or equal operator. */
6702-
CXBinaryOperator_GE,
6649+
CXBinaryOperator_GE = 14,
67036650
/** Equal operator. */
6704-
CXBinaryOperator_EQ,
6651+
CXBinaryOperator_EQ = 15,
67056652
/** Not equal operator. */
6706-
CXBinaryOperator_NE,
6653+
CXBinaryOperator_NE = 16,
67076654
/** Bitwise AND operator. */
6708-
CXBinaryOperator_And,
6655+
CXBinaryOperator_And = 17,
67096656
/** Bitwise XOR operator. */
6710-
CXBinaryOperator_Xor,
6657+
CXBinaryOperator_Xor = 18,
67116658
/** Bitwise OR operator. */
6712-
CXBinaryOperator_Or,
6659+
CXBinaryOperator_Or = 19,
67136660
/** Logical AND operator. */
6714-
CXBinaryOperator_LAnd,
6661+
CXBinaryOperator_LAnd = 20,
67156662
/** Logical OR operator. */
6716-
CXBinaryOperator_LOr,
6663+
CXBinaryOperator_LOr = 21,
67176664
/** Assignment operator. */
6718-
CXBinaryOperator_Assign,
6665+
CXBinaryOperator_Assign = 22,
67196666
/** Multiplication assignment operator. */
6720-
CXBinaryOperator_MulAssign,
6667+
CXBinaryOperator_MulAssign = 23,
67216668
/** Division assignment operator. */
6722-
CXBinaryOperator_DivAssign,
6669+
CXBinaryOperator_DivAssign = 24,
67236670
/** Remainder assignment operator. */
6724-
CXBinaryOperator_RemAssign,
6671+
CXBinaryOperator_RemAssign = 25,
67256672
/** Addition assignment operator. */
6726-
CXBinaryOperator_AddAssign,
6673+
CXBinaryOperator_AddAssign = 26,
67276674
/** Subtraction assignment operator. */
6728-
CXBinaryOperator_SubAssign,
6675+
CXBinaryOperator_SubAssign = 27,
67296676
/** Bitwise shift left assignment operator. */
6730-
CXBinaryOperator_ShlAssign,
6677+
CXBinaryOperator_ShlAssign = 28,
67316678
/** Bitwise shift right assignment operator. */
6732-
CXBinaryOperator_ShrAssign,
6679+
CXBinaryOperator_ShrAssign = 29,
67336680
/** Bitwise AND assignment operator. */
6734-
CXBinaryOperator_AndAssign,
6681+
CXBinaryOperator_AndAssign = 30,
67356682
/** Bitwise XOR assignment operator. */
6736-
CXBinaryOperator_XorAssign,
6683+
CXBinaryOperator_XorAssign = 31,
67376684
/** Bitwise OR assignment operator. */
6738-
CXBinaryOperator_OrAssign,
6685+
CXBinaryOperator_OrAssign = 32,
67396686
/** Comma operator. */
6740-
CXBinaryOperator_Comma
6687+
CXBinaryOperator_Comma = 33,
6688+
CXBinaryOperator_Last = CXBinaryOperator_Comma
67416689
};
67426690

67436691
/**

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

+3-3
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

+6-31
Original file line numberDiff line numberDiff line change
@@ -5442,7 +5442,8 @@ CXString clang_getCursorSpelling(CXCursor C) {
54425442

54435443
if (C.kind == CXCursor_BinaryOperator ||
54445444
C.kind == CXCursor_CompoundAssignOperator) {
5445-
return clang_Cursor_getBinaryOpcodeStr(clang_Cursor_getBinaryOpcode(C));
5445+
return clang_getBinaryOperatorKindSpelling(
5446+
clang_getCursorBinaryOperatorKind(C));
54465447
}
54475448

54485449
const Decl *D = getDeclFromExpr(getCursorExpr(C));
@@ -9210,35 +9211,6 @@ unsigned clang_Cursor_isExternalSymbol(CXCursor C, CXString *language,
92109211
return 0;
92119212
}
92129213

9213-
enum CX_BinaryOperatorKind clang_Cursor_getBinaryOpcode(CXCursor C) {
9214-
if (C.kind != CXCursor_BinaryOperator &&
9215-
C.kind != CXCursor_CompoundAssignOperator) {
9216-
return CX_BO_Invalid;
9217-
}
9218-
9219-
const Expr *D = getCursorExpr(C);
9220-
if (const auto *BinOp = dyn_cast<BinaryOperator>(D)) {
9221-
switch (BinOp->getOpcode()) {
9222-
#define BINARY_OPERATION(Name, Spelling) \
9223-
case BO_##Name: \
9224-
return CX_BO_##Name;
9225-
#include "clang/AST/OperationKinds.def"
9226-
}
9227-
}
9228-
9229-
return CX_BO_Invalid;
9230-
}
9231-
9232-
CXString clang_Cursor_getBinaryOpcodeStr(enum CX_BinaryOperatorKind Op) {
9233-
if (Op > CX_BO_LAST)
9234-
return cxstring::createEmpty();
9235-
9236-
return cxstring::createDup(
9237-
// BinaryOperator::getOpcodeStr has no case for CX_BO_Invalid,
9238-
// so subtract 1
9239-
BinaryOperator::getOpcodeStr(static_cast<BinaryOperatorKind>(Op - 1)));
9240-
}
9241-
92429214
CXSourceRange clang_Cursor_getCommentRange(CXCursor C) {
92439215
if (!clang_isDeclaration(C.kind))
92449216
return clang_getNullRange();
@@ -10111,7 +10083,10 @@ cxindex::Logger::~Logger() {
1011110083
}
1011210084

1011310085
CXString clang_getBinaryOperatorKindSpelling(enum CXBinaryOperatorKind kind) {
10114-
return cxstring::createRef(
10086+
if (kind > CXBinaryOperator_Last)
10087+
return cxstring::createEmpty();
10088+
10089+
return cxstring::createDup(
1011510090
BinaryOperator::getOpcodeStr(static_cast<BinaryOperatorKind>(kind - 1)));
1011610091
}
1011710092

clang/tools/libclang/libclang.map

-6
Original file line numberDiff line numberDiff line change
@@ -423,12 +423,6 @@ LLVM_17 {
423423
clang_getCursorUnaryOperatorKind;
424424
};
425425

426-
LLVM_19 {
427-
global:
428-
clang_Cursor_getBinaryOpcode;
429-
clang_Cursor_getBinaryOpcodeStr;
430-
};
431-
432426
LLVM_20 {
433427
global:
434428
clang_getOffsetOfBase;

0 commit comments

Comments
 (0)