Skip to content

Remove duplicate API #132776

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions clang/bindings/python/clang/cindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -1887,7 +1887,7 @@ def binary_operator(self):
"""

if not hasattr(self, "_binopcode"):
self._binopcode = conf.lib.clang_Cursor_getBinaryOpcode(self)
self._binopcode = conf.lib.clang_getCursorBinaryOperatorKind(self)

return BinaryOperator.from_id(self._binopcode)

Expand Down Expand Up @@ -4097,7 +4097,7 @@ def set_property(self, property, value):
("clang_Cursor_getTemplateArgumentType", [Cursor, c_uint], Type),
("clang_Cursor_getTemplateArgumentValue", [Cursor, c_uint], c_longlong),
("clang_Cursor_getTemplateArgumentUnsignedValue", [Cursor, c_uint], c_ulonglong),
("clang_Cursor_getBinaryOpcode", [Cursor], c_int),
("clang_getCursorBinaryOperatorKind", [Cursor], c_int),
("clang_Cursor_getBriefCommentText", [Cursor], _CXString),
("clang_Cursor_getRawCommentText", [Cursor], _CXString),
("clang_Cursor_getOffsetOfField", [Cursor], c_longlong),
Expand Down
4 changes: 4 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -799,6 +799,10 @@ libclang
- Fixed a buffer overflow in ``CXString`` implementation. The fix may result in
increased memory allocation.

- Deprecate ``clang_Cursor_GetBinaryOpcode`` and ``clang_Cursor_getBinaryOpcodeStr``
implementations, which are duplicates of ``clang_getCursorBinaryOperatorKind``
and ``clang_getBinaryOperatorKindSpelling`` respectively.

Code Completion
---------------

Expand Down
73 changes: 39 additions & 34 deletions clang/include/clang-c/Index.h
Original file line number Diff line number Diff line change
Expand Up @@ -3882,12 +3882,16 @@ enum CX_BinaryOperatorKind {

/**
* \brief Returns the operator code for the binary operator.
*
* @deprecated: use clang_getCursorBinaryOperatorKind instead.
*/
CINDEX_LINKAGE enum CX_BinaryOperatorKind
clang_Cursor_getBinaryOpcode(CXCursor C);

/**
* \brief Returns a string containing the spelling of the binary operator.
*
* @deprecated: use clang_getBinaryOperatorKindSpelling instead
*/
CINDEX_LINKAGE CXString
clang_Cursor_getBinaryOpcodeStr(enum CX_BinaryOperatorKind Op);
Expand Down Expand Up @@ -6683,73 +6687,74 @@ CINDEX_LINKAGE unsigned clang_visitCXXMethods(CXType T, CXFieldVisitor visitor,
*/
enum CXBinaryOperatorKind {
/** This value describes cursors which are not binary operators. */
CXBinaryOperator_Invalid,
CXBinaryOperator_Invalid = 0,
/** C++ Pointer - to - member operator. */
CXBinaryOperator_PtrMemD,
CXBinaryOperator_PtrMemD = 1,
/** C++ Pointer - to - member operator. */
CXBinaryOperator_PtrMemI,
CXBinaryOperator_PtrMemI = 2,
/** Multiplication operator. */
CXBinaryOperator_Mul,
CXBinaryOperator_Mul = 3,
/** Division operator. */
CXBinaryOperator_Div,
CXBinaryOperator_Div = 4,
/** Remainder operator. */
CXBinaryOperator_Rem,
CXBinaryOperator_Rem = 5,
/** Addition operator. */
CXBinaryOperator_Add,
CXBinaryOperator_Add = 6,
/** Subtraction operator. */
CXBinaryOperator_Sub,
CXBinaryOperator_Sub = 7,
/** Bitwise shift left operator. */
CXBinaryOperator_Shl,
CXBinaryOperator_Shl = 8,
/** Bitwise shift right operator. */
CXBinaryOperator_Shr,
CXBinaryOperator_Shr = 9,
/** C++ three-way comparison (spaceship) operator. */
CXBinaryOperator_Cmp,
CXBinaryOperator_Cmp = 10,
/** Less than operator. */
CXBinaryOperator_LT,
CXBinaryOperator_LT = 11,
/** Greater than operator. */
CXBinaryOperator_GT,
CXBinaryOperator_GT = 12,
/** Less or equal operator. */
CXBinaryOperator_LE,
CXBinaryOperator_LE = 13,
/** Greater or equal operator. */
CXBinaryOperator_GE,
CXBinaryOperator_GE = 14,
/** Equal operator. */
CXBinaryOperator_EQ,
CXBinaryOperator_EQ = 15,
/** Not equal operator. */
CXBinaryOperator_NE,
CXBinaryOperator_NE = 16,
/** Bitwise AND operator. */
CXBinaryOperator_And,
CXBinaryOperator_And = 17,
/** Bitwise XOR operator. */
CXBinaryOperator_Xor,
CXBinaryOperator_Xor = 18,
/** Bitwise OR operator. */
CXBinaryOperator_Or,
CXBinaryOperator_Or = 19,
/** Logical AND operator. */
CXBinaryOperator_LAnd,
CXBinaryOperator_LAnd = 20,
/** Logical OR operator. */
CXBinaryOperator_LOr,
CXBinaryOperator_LOr = 21,
/** Assignment operator. */
CXBinaryOperator_Assign,
CXBinaryOperator_Assign = 22,
/** Multiplication assignment operator. */
CXBinaryOperator_MulAssign,
CXBinaryOperator_MulAssign = 23,
/** Division assignment operator. */
CXBinaryOperator_DivAssign,
CXBinaryOperator_DivAssign = 24,
/** Remainder assignment operator. */
CXBinaryOperator_RemAssign,
CXBinaryOperator_RemAssign = 25,
/** Addition assignment operator. */
CXBinaryOperator_AddAssign,
CXBinaryOperator_AddAssign = 26,
/** Subtraction assignment operator. */
CXBinaryOperator_SubAssign,
CXBinaryOperator_SubAssign = 27,
/** Bitwise shift left assignment operator. */
CXBinaryOperator_ShlAssign,
CXBinaryOperator_ShlAssign = 28,
/** Bitwise shift right assignment operator. */
CXBinaryOperator_ShrAssign,
CXBinaryOperator_ShrAssign = 29,
/** Bitwise AND assignment operator. */
CXBinaryOperator_AndAssign,
CXBinaryOperator_AndAssign = 30,
/** Bitwise XOR assignment operator. */
CXBinaryOperator_XorAssign,
CXBinaryOperator_XorAssign = 31,
/** Bitwise OR assignment operator. */
CXBinaryOperator_OrAssign,
CXBinaryOperator_OrAssign = 32,
/** Comma operator. */
CXBinaryOperator_Comma
CXBinaryOperator_Comma = 33,
CXBinaryOperator_Last = CXBinaryOperator_Comma
};

/**
Expand Down
6 changes: 3 additions & 3 deletions clang/tools/c-index-test/c-index-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -1863,14 +1863,14 @@ static enum CXChildVisitResult PrintTypeSize(CXCursor cursor, CXCursor p,
static enum CXChildVisitResult PrintBinOps(CXCursor C, CXCursor p,
CXClientData d) {
enum CXCursorKind ck = clang_getCursorKind(C);
enum CX_BinaryOperatorKind bok;
enum CXBinaryOperatorKind bok;
CXString opstr;
if (ck != CXCursor_BinaryOperator && ck != CXCursor_CompoundAssignOperator)
return CXChildVisit_Recurse;

PrintCursor(C, NULL);
bok = clang_Cursor_getBinaryOpcode(C);
opstr = clang_Cursor_getBinaryOpcodeStr(bok);
bok = clang_getCursorBinaryOperatorKind(C);
opstr = clang_getBinaryOperatorKindSpelling(bok);
printf(" BinOp=%s %d\n", clang_getCString(opstr), bok);
clang_disposeString(opstr);
return CXChildVisit_Recurse;
Expand Down
35 changes: 10 additions & 25 deletions clang/tools/libclang/CIndex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5441,7 +5441,8 @@ CXString clang_getCursorSpelling(CXCursor C) {

if (C.kind == CXCursor_BinaryOperator ||
C.kind == CXCursor_CompoundAssignOperator) {
return clang_Cursor_getBinaryOpcodeStr(clang_Cursor_getBinaryOpcode(C));
return clang_getBinaryOperatorKindSpelling(
clang_getCursorBinaryOperatorKind(C));
}

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

enum CX_BinaryOperatorKind clang_Cursor_getBinaryOpcode(CXCursor C) {
if (C.kind != CXCursor_BinaryOperator &&
C.kind != CXCursor_CompoundAssignOperator) {
return CX_BO_Invalid;
}

const Expr *D = getCursorExpr(C);
if (const auto *BinOp = dyn_cast<BinaryOperator>(D)) {
switch (BinOp->getOpcode()) {
#define BINARY_OPERATION(Name, Spelling) \
case BO_##Name: \
return CX_BO_##Name;
#include "clang/AST/OperationKinds.def"
}
}

return CX_BO_Invalid;
return static_cast<CX_BinaryOperatorKind>(
clang_getCursorBinaryOperatorKind(C));
}

CXString clang_Cursor_getBinaryOpcodeStr(enum CX_BinaryOperatorKind Op) {
if (Op > CX_BO_LAST)
return cxstring::createEmpty();

return cxstring::createDup(
// BinaryOperator::getOpcodeStr has no case for CX_BO_Invalid,
// so subtract 1
BinaryOperator::getOpcodeStr(static_cast<BinaryOperatorKind>(Op - 1)));
return clang_getBinaryOperatorKindSpelling(
static_cast<CXBinaryOperatorKind>(Op));
}

CXSourceRange clang_Cursor_getCommentRange(CXCursor C) {
Expand Down Expand Up @@ -10110,7 +10092,10 @@ cxindex::Logger::~Logger() {
}

CXString clang_getBinaryOperatorKindSpelling(enum CXBinaryOperatorKind kind) {
return cxstring::createRef(
if (kind > CXBinaryOperator_Last)
return cxstring::createEmpty();

return cxstring::createDup(
BinaryOperator::getOpcodeStr(static_cast<BinaryOperatorKind>(kind - 1)));
}

Expand Down