]> granicus.if.org Git - clang/commitdiff
[clang.py] Implement Cursor.is_static_method
authorGregory Szorc <gregory.szorc@gmail.com>
Sat, 9 Jun 2012 16:21:34 +0000 (16:21 +0000)
committerGregory Szorc <gregory.szorc@gmail.com>
Sat, 9 Jun 2012 16:21:34 +0000 (16:21 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@158277 91177308-0d34-0410-b5e6-96231b3b80d8

bindings/python/clang/cindex.py
bindings/python/tests/cindex/test_cursor.py

index 257b7aeb19f19515d353a0fb80e0be1a68234950..7a637112a25179d9a45a65c12fe38fd7e0445542 100644 (file)
@@ -949,6 +949,12 @@ class Cursor(Structure):
         """
         return Cursor_is_def(self)
 
+    def is_static_method(self):
+        """Returns True if the cursor refers to a C++ member function or member
+        function template that is declared 'static'.
+        """
+        return Cursor_is_static_method(self)
+
     def get_definition(self):
         """
         If the cursor is a reference to a declaration or a declaration of
@@ -2176,6 +2182,10 @@ Cursor_is_def = lib.clang_isCursorDefinition
 Cursor_is_def.argtypes = [Cursor]
 Cursor_is_def.restype = bool
 
+Cursor_is_static_method = lib.clang_CXXMethod_isStatic
+Cursor_is_static_method.argtypes = [Cursor]
+Cursor_is_static_method.restype = bool
+
 Cursor_def = lib.clang_getCursorDefinition
 Cursor_def.argtypes = [Cursor]
 Cursor_def.restype = Cursor
index 9a37d2ff1b35956a0effab5e13b5d335a341ed6c..979838b21c7db3264daef9bc636de2e372a7bbaf 100644 (file)
@@ -102,6 +102,22 @@ def test_canonical():
     assert len(cursors) == 3
     assert cursors[1].canonical == cursors[2].canonical
 
+def test_is_static_method():
+    """Ensure Cursor.is_static_method works."""
+
+    source = 'class X { static void foo(); void bar(); };'
+    tu = get_tu(source, lang='cpp')
+
+    cls = get_cursor(tu, 'X')
+    foo = get_cursor(tu, 'foo')
+    bar = get_cursor(tu, 'bar')
+    assert cls is not None
+    assert foo is not None
+    assert bar is not None
+
+    assert foo.is_static_method()
+    assert not bar.is_static_method()
+
 def test_underlying_type():
     tu = get_tu('typedef int foo;')
     typedef = get_cursor(tu, 'foo')