]> granicus.if.org Git - clang/commitdiff
[libclang] python: expose a few functions, patch by Loïc Jaquemet!
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Thu, 3 Oct 2013 16:19:27 +0000 (16:19 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Thu, 3 Oct 2013 16:19:27 +0000 (16:19 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@191907 91177308-0d34-0410-b5e6-96231b3b80d8

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

index be65ebe39a54612268f34b00d6cf59d7f62010d4..5710d7fe28eab9e8a689106039bc33149070cdb6 100644 (file)
@@ -1316,6 +1316,16 @@ class Cursor(Structure):
 
         return self._referenced
 
+    @property
+    def brief_comment(self):
+        """Returns the brief comment text associated with that Cursor"""
+        return conf.lib.clang_Cursor_getBriefCommentText(self)
+    
+    @property
+    def raw_comment(self):
+        """Returns the raw comment text associated with that Cursor"""
+        return conf.lib.clang_Cursor_getRawCommentText(self)
+
     def get_arguments(self):
         """Return an iterator for accessing the arguments of this cursor."""
         num_args = conf.lib.clang_Cursor_getNumArguments(self)
@@ -1687,6 +1697,11 @@ class Type(Structure):
         """
         return conf.lib.clang_Type_getOffsetOf(self, c_char_p(fieldname))
 
+    @property
+    def spelling(self):
+        """Retrieve the spelling of this Type."""
+        return conf.lib.clang_getTypeSpelling(self)
+
     def __eq__(self, other):
         if type(other) != type(self):
             return False
@@ -3026,6 +3041,11 @@ functionList = [
    _CXString,
    _CXString.from_result),
 
+  ("clang_getTypeSpelling",
+   [Type],
+   _CXString,
+   _CXString.from_result),
+
   ("clang_hashCursor",
    [Cursor],
    c_uint),
@@ -3130,6 +3150,16 @@ functionList = [
    [Cursor],
    bool),
 
+  ("clang_Cursor_getBriefCommentText",
+   [Cursor],
+   _CXString,
+   _CXString.from_result),
+
+  ("clang_Cursor_getRawCommentText",
+   [Cursor],
+   _CXString,
+   _CXString.from_result),
+
   ("clang_Type_getAlignOf",
    [Type],
    c_longlong),
index 62968d6285f98dabfd12841b4ce31ab8a49a58e1..a02c06fe5a13f817973da5643898c78e77cc40f3 100644 (file)
@@ -132,6 +132,22 @@ def test_equal():
     assert a.type != None
     assert a.type != 'foo'
 
+def test_type_spelling():
+    """Ensure Type.spelling works."""
+    tu = get_tu('int c[5]; int i[]; int x; int v[x];')
+    c = get_cursor(tu, 'c')
+    i = get_cursor(tu, 'i')
+    x = get_cursor(tu, 'x')
+    v = get_cursor(tu, 'v')
+    assert c is not None
+    assert i is not None
+    assert x is not None
+    assert v is not None
+    assert c.type.spelling == "int [5]"
+    assert i.type.spelling == "int []"
+    assert x.type.spelling == "int"
+    assert v.type.spelling == "int [x]"
+
 def test_typekind_spelling():
     """Ensure TypeKind.spelling works."""
     tu = get_tu('int a;')