aboutsummaryrefslogtreecommitdiff
path: root/clang/unittests/libclang/LibclangTest.cpp
diff options
context:
space:
mode:
authorMineGame159 <petulko08@gmail.com>2023-06-09 10:01:43 -0400
committerAaron Ballman <aaron@aaronballman.com>2023-06-09 10:01:43 -0400
commit7fbc9de4553666a189b0529ca04e1d9966c0d4f8 (patch)
treebbe15e91f17eed89299f97a074afb3aaa33440e5 /clang/unittests/libclang/LibclangTest.cpp
parent621507ce20ad8eef2986be2712631165e53b7d91 (diff)
downloadllvm-7fbc9de4553666a189b0529ca04e1d9966c0d4f8.zip
llvm-7fbc9de4553666a189b0529ca04e1d9966c0d4f8.tar.gz
llvm-7fbc9de4553666a189b0529ca04e1d9966c0d4f8.tar.bz2
[libclang] Add CXBinaryOperatorKind and CXUnaryOperatorKind
Adds 2 new functions to the C libclang api for retrieving operator kinds for binary and unary operators from cursors. Also adds 2 functions for retrieving the spelling of the new enums. Fixes https://github.com/llvm/llvm-project/issues/29138 Differential Revision: https://reviews.llvm.org/D150910
Diffstat (limited to 'clang/unittests/libclang/LibclangTest.cpp')
-rw-r--r--clang/unittests/libclang/LibclangTest.cpp34
1 files changed, 34 insertions, 0 deletions
diff --git a/clang/unittests/libclang/LibclangTest.cpp b/clang/unittests/libclang/LibclangTest.cpp
index ca762eb..f85a72b 100644
--- a/clang/unittests/libclang/LibclangTest.cpp
+++ b/clang/unittests/libclang/LibclangTest.cpp
@@ -1138,6 +1138,40 @@ void Class1::fun() {}
"class ns1::Class1");
}
+TEST_F(LibclangParseTest, BinaryOperator) {
+ std::string Main = "main.cpp";
+ WriteFile(Main, "int foo() { return 5 + 9; }");
+ ClangTU = clang_parseTranslationUnit(Index, Main.c_str(), nullptr, 0, nullptr,
+ 0, TUFlags);
+
+ Traverse([](CXCursor cursor, CXCursor parent) -> CXChildVisitResult {
+ if (cursor.kind == CXCursor_BinaryOperator) {
+ EXPECT_EQ(clang_getCursorBinaryOperatorKind(cursor),
+ CXBinaryOperator_Add);
+ return CXChildVisit_Break;
+ }
+
+ return CXChildVisit_Recurse;
+ });
+}
+
+TEST_F(LibclangParseTest, UnaryOperator) {
+ std::string Main = "main.cpp";
+ WriteFile(Main, "int foo() { int a = 5; return a++; }");
+ ClangTU = clang_parseTranslationUnit(Index, Main.c_str(), nullptr, 0, nullptr,
+ 0, TUFlags);
+
+ Traverse([](CXCursor cursor, CXCursor parent) -> CXChildVisitResult {
+ if (cursor.kind == CXCursor_UnaryOperator) {
+ EXPECT_EQ(clang_getCursorUnaryOperatorKind(cursor),
+ CXUnaryOperator_PostInc);
+ return CXChildVisit_Break;
+ }
+
+ return CXChildVisit_Recurse;
+ });
+}
+
class LibclangRewriteTest : public LibclangParseTest {
public:
CXRewriter Rew = nullptr;