]> granicus.if.org Git - clang/commitdiff
[clang.py] Implement Cursor.hash
authorTobias Grosser <grosser@fim.uni-passau.de>
Sun, 5 Feb 2012 11:42:03 +0000 (11:42 +0000)
committerTobias Grosser <grosser@fim.uni-passau.de>
Sun, 5 Feb 2012 11:42:03 +0000 (11:42 +0000)
Contributed by: Gregory Szorc <gregory.szorc@gmail.com>

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@149826 91177308-0d34-0410-b5e6-96231b3b80d8

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

index e385ca2893e57dd568f8e1dd5e2edbaf47ecade6..4c9f96ddb38447a236f50dffe0ad645085a3c2e4 100644 (file)
@@ -969,6 +969,14 @@ class Cursor(Structure):
             self._type = Cursor_type(self)
         return self._type
 
+    @property
+    def hash(self):
+        """Returns a hash of the cursor as an int."""
+        if not hasattr(self, '_hash'):
+            self._hash = Cursor_hash(self)
+
+        return self._hash
+
     def get_children(self):
         """Return an iterator for accessing the children of this cursor."""
 
@@ -1735,6 +1743,10 @@ Cursor_eq = lib.clang_equalCursors
 Cursor_eq.argtypes = [Cursor, Cursor]
 Cursor_eq.restype = c_uint
 
+Cursor_hash = lib.clang_hashCursor
+Cursor_hash.argtypes = [Cursor]
+Cursor_hash.restype = c_uint
+
 Cursor_spelling = lib.clang_getCursorSpelling
 Cursor_spelling.argtypes = [Cursor]
 Cursor_spelling.restype = _CXString
index 3dde891a9c264814ccc69550529b27bfa34c3cce..efcede9015405421514f6610adb3310801ac9b75 100644 (file)
@@ -42,6 +42,7 @@ def test_get_children():
     assert tu_nodes[0].location.file.name == 't.c'
     assert tu_nodes[0].location.line == 4
     assert tu_nodes[0].location.column == 8
+    assert tu_nodes[0].hash > 0
 
     s0_nodes = list(tu_nodes[0].get_children())
     assert len(s0_nodes) == 2