[clang] Add retrieval of unary operator spelling and python bindings (PR #219983)

Vlad Serebrennikov via cfe-commits cfe-commits at lists.llvm.org
Sun Sep 13 09:44:50 PDT 2026


================
@@ -986,6 +987,54 @@ def test_binop(self):
             c = get_cursor(tu, op)
             assert c.binary_operator == typ
 
+    def test_unaryop(self):
+        tu = get_tu(
+            """
+                void func(void) {
+                int a = 0;
+                a++;
+                ++a;
+                a--;
+                --a;
+                *(&a);
+                +a;
+                -a;
+                !a;
+                ~a;
+                float _Complex b;
+                __real b;
+                __imag b;
+                __extension__ a;
+            }""",
+            lang="cpp",
+        )
+
+        operators = {
+            "&": UnaryOperator.AddrOf,
+            "*": UnaryOperator.Deref,
+            "+": UnaryOperator.Plus,
+            "-": UnaryOperator.Minus,
+            "~": UnaryOperator.Not,
+            "!": UnaryOperator.LNot,
+            "__real": UnaryOperator.Real,
+            "__imag": UnaryOperator.Imag,
+            "__extension__": UnaryOperator.Extension,
+        }
+
+        for op, typ in operators.items():
+            c = get_cursor(tu, op)
+            assert c.unary_operator == typ
+
+        shoulds = (
+            UnaryOperator.PostInc,
+            UnaryOperator.PreInc,
+            UnaryOperator.PostDec,
+            UnaryOperator.PreDec,
+        )
+        haves = list(next(tu.cursor.get_children()).get_children())[1:]
----------------
Endilll wrote:

Agreed

https://github.com/llvm/llvm-project/pull/219983


More information about the cfe-commits mailing list