aboutsummaryrefslogtreecommitdiff
path: root/clang/tools/c-index-test/c-index-test.c
diff options
context:
space:
mode:
authorThomas Wucher <30866545+thomaswucher@users.noreply.github.com>2024-07-15 15:17:28 +0200
committerGitHub <noreply@github.com>2024-07-15 09:17:28 -0400
commita972a394afcb276abb3029d0f2753d4403e379c2 (patch)
tree117adb17513a6d40e76ad0f02341306fb13e64f0 /clang/tools/c-index-test/c-index-test.c
parent1af3a89a4b384cbc5a6b111a0f7756085de818cd (diff)
downloadllvm-a972a394afcb276abb3029d0f2753d4403e379c2.zip
llvm-a972a394afcb276abb3029d0f2753d4403e379c2.tar.gz
llvm-a972a394afcb276abb3029d0f2753d4403e379c2.tar.bz2
Retrieve BinaryOperator::getOpcode and BinaryOperator::getOpcodeStr via libclang and its python interface (#98489)
This is a rework of patch [D10833](https://reviews.llvm.org/D10833) previously posted on LLVM Phabricator by arthurp in 2015. It allows to retrieve the type of binary operator via libclangs python bindings. I did clean up the changes, removed unrelated changes and rebased the changeset to the latest main branch. As this is my first contribution to the LLVM project, let me know if any required tests or documentation are missing.
Diffstat (limited to 'clang/tools/c-index-test/c-index-test.c')
-rw-r--r--clang/tools/c-index-test/c-index-test.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/clang/tools/c-index-test/c-index-test.c b/clang/tools/c-index-test/c-index-test.c
index e078e9b..46016c1 100644
--- a/clang/tools/c-index-test/c-index-test.c
+++ b/clang/tools/c-index-test/c-index-test.c
@@ -1840,6 +1840,22 @@ static enum CXChildVisitResult PrintTypeSize(CXCursor cursor, CXCursor p,
return CXChildVisit_Recurse;
}
+static enum CXChildVisitResult PrintBinOps(CXCursor C, CXCursor p,
+ CXClientData d) {
+ enum CXCursorKind ck = clang_getCursorKind(C);
+ enum CX_BinaryOperatorKind 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);
+ printf(" BinOp=%s %d\n", clang_getCString(opstr), bok);
+
+ return CXChildVisit_Recurse;
+}
+
/******************************************************************************/
/* Mangling testing. */
/******************************************************************************/
@@ -5098,6 +5114,8 @@ int cindextest_main(int argc, const char **argv) {
else if (argc > 2 && strcmp(argv[1], "-test-print-bitwidth") == 0)
return perform_test_load_source(argc - 2, argv + 2, "all",
PrintBitWidth, 0);
+ else if (argc > 2 && strcmp(argv[1], "-test-print-binops") == 0)
+ return perform_test_load_source(argc - 2, argv + 2, "all", PrintBinOps, 0);
else if (argc > 2 && strcmp(argv[1], "-test-print-mangle") == 0)
return perform_test_load_tu(argv[2], "all", NULL, PrintMangledName, NULL);
else if (argc > 2 && strcmp(argv[1], "-test-print-manglings") == 0)