[cfe-commits] r150936 - in /cfe/trunk/bindings/python: clang/cindex.py tests/cindex/test_type.py

Gregory Szorc gregory.szorc at gmail.com
Sun Feb 19 10:28:34 PST 2012


Author: gps
Date: Sun Feb 19 12:28:33 2012
New Revision: 150936

URL: http://llvm.org/viewvc/llvm-project?rev=150936&view=rev
Log:
[clang.py] Implement Type.is_function_variadic

Modified:
    cfe/trunk/bindings/python/clang/cindex.py
    cfe/trunk/bindings/python/tests/cindex/test_type.py

Modified: cfe/trunk/bindings/python/clang/cindex.py
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/bindings/python/clang/cindex.py?rev=150936&r1=150935&r2=150936&view=diff
==============================================================================
--- cfe/trunk/bindings/python/clang/cindex.py (original)
+++ cfe/trunk/bindings/python/clang/cindex.py Sun Feb 19 12:28:33 2012
@@ -1205,6 +1205,12 @@
         """
         return Type_is_restrict_qualified(self)
 
+    def is_function_variadic(self):
+        """Determine whether this function Type is a variadic function type."""
+        assert self.kind == TypeKind.FUNCTIONPROTO
+
+        return Type_is_variadic(self)
+
     def is_pod(self):
         """Determine whether this Type represents plain old data (POD)."""
         return Type_is_pod(self)
@@ -1893,6 +1899,10 @@
 Type_is_pod.argtypes = [Type]
 Type_is_pod.restype = bool
 
+Type_is_variadic = lib.clang_isFunctionTypeVariadic
+Type_is_variadic.argtypes = [Type]
+Type_is_variadic.restype = bool
+
 Type_get_pointee = lib.clang_getPointeeType
 Type_get_pointee.argtypes = [Type]
 Type_get_pointee.restype = Type

Modified: cfe/trunk/bindings/python/tests/cindex/test_type.py
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/bindings/python/tests/cindex/test_type.py?rev=150936&r1=150935&r2=150936&view=diff
==============================================================================
--- cfe/trunk/bindings/python/tests/cindex/test_type.py (original)
+++ cfe/trunk/bindings/python/tests/cindex/test_type.py Sun Feb 19 12:28:33 2012
@@ -1,7 +1,6 @@
 from clang.cindex import CursorKind
 from clang.cindex import Index
 from clang.cindex import TypeKind
-from nose.tools import ok_
 from nose.tools import raises
 
 kInput = """\
@@ -21,9 +20,18 @@
 
 """
 
-def test_a_struct():
+def get_tu(source=kInput, lang='c'):
+    name = 't.c'
+    if lang == 'cpp':
+        name = 't.cpp'
+
     index = Index.create()
-    tu = index.parse('t.c', unsaved_files = [('t.c',kInput)])
+    tu = index.parse(name, unsaved_files=[(name, source)])
+    assert tu is not None
+    return tu
+
+def test_a_struct():
+    tu = get_tu(kInput)
 
     for n in tu.cursor.get_children():
         if n.spelling == 'teststruct':
@@ -86,8 +94,7 @@
 };
 """
 def testConstantArray():
-    index = Index.create()
-    tu = index.parse('t.c', unsaved_files = [('t.c',constarrayInput)])
+    tu = get_tu(constarrayInput)
 
     for n in tu.cursor.get_children():
         if n.spelling == 'teststruct':
@@ -103,9 +110,7 @@
         assert False, "Didn't find teststruct??"
 
 def test_is_pod():
-    index = Index.create()
-    tu = index.parse('t.c', unsaved_files=[('t.c', 'int i; void f();')])
-    assert tu is not None
+    tu = get_tu('int i; void f();')
     i, f = None, None
 
     for cursor in tu.cursor.get_children():
@@ -120,24 +125,48 @@
     assert i.type.is_pod()
     assert not f.type.is_pod()
 
-def test_element_type():
-    index = Index.create()
-    tu = index.parse('t.c', unsaved_files=[('t.c', 'int i[5];')])
-    assert tu is not None
+def test_function_variadic():
+    """Ensure Type.is_function_variadic works."""
+
+    source ="""
+#include <stdarg.h>
 
+void foo(int a, ...);
+void bar(int a, int b);
+"""
+
+    tu = get_tu(source)
+    foo, bar = None, None
+    for cursor in tu.cursor.get_children():
+        if cursor.spelling == 'foo':
+            foo = cursor
+        elif cursor.spelling == 'bar':
+            bar = cursor
+
+    assert foo is not None
+    assert bar is not None
+
+    assert isinstance(foo.type.is_function_variadic(), bool)
+    assert foo.type.is_function_variadic()
+    assert not bar.type.is_function_variadic()
+
+def test_element_type():
+    tu = get_tu('int i[5];')
+    i = None
     for cursor in tu.cursor.get_children():
         if cursor.spelling == 'i':
             i = cursor
             break
 
+    assert i is not None
+
     assert i.type.kind == TypeKind.CONSTANTARRAY
     assert i.type.element_type.kind == TypeKind.INT
 
 @raises(Exception)
 def test_invalid_element_type():
     """Ensure Type.element_type raises if type doesn't have elements."""
-    index = Index.create()
-    tu = index.parse('t.c', unsaved_files=[('t.c', 'int i;')])
+    tu = get_tu('int i;')
 
     i = None
     for cursor in tu.cursor.get_children():
@@ -145,13 +174,11 @@
             i = cursor
             break
 
-    ok_(i is not None)
+    assert i is not None
     i.element_type
 
 def test_element_count():
-    index = Index.create()
-    tu = index.parse('t.c', unsaved_files=[('t.c', 'int i[5]; int j;')])
-    assert tu is not None
+    tu = get_tu('int i[5]; int j;')
 
     for cursor in tu.cursor.get_children():
         if cursor.spelling == 'i':





More information about the cfe-commits mailing list