================ @@ -8955,6 +8960,36 @@ unsigned clang_Cursor_isExternalSymbol(CXCursor C, CXString *language, return 0; } +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 BinaryOperator *BinOp = dyn_cast<BinaryOperator>(D)) { + switch (BinOp->getOpcode()) { + default: + return CX_BO_Invalid; +#define BINARY_OPERATION(Name, Spelling) \ + case BO_##Name: \ + return CX_BO_##Name; +#include "clang/AST/OperationKinds.def" + } + } + + return CX_BO_Invalid; +} + +CXString clang_Cursor_getBinaryOpcodeStr(enum CX_BinaryOperatorKind Op) { + if (Op > CX_BO_LAST) { + return cxstring::createEmpty(); + } + + return cxstring::createDup( + BinaryOperator::getOpcodeStr(static_cast<BinaryOperatorKind>(Op - 1))); ---------------- AaronBallman wrote:
It'd be good to add a comment here explaining why `- 1`. https://github.com/llvm/llvm-project/pull/98489 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits