Pretty straight-forward.

---
 bindings/python/clang/cindex.py             |   12 ++++++++++++
 bindings/python/tests/cindex/test_cursor.py |    1 +
 2 files changed, 13 insertions(+), 0 deletions(-)
diff --git a/bindings/python/clang/cindex.py b/bindings/python/clang/cindex.py
index e385ca2..4c9f96d 100644
--- a/bindings/python/clang/cindex.py
+++ b/bindings/python/clang/cindex.py
@@ -964,16 +964,24 @@ class Cursor(Structure):
         """
         Retrieve the type (if any) of of the entity pointed at by the
         cursor.
         """
         if not hasattr(self, '_type'):
             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."""
 
         # FIXME: Expose iteration from CIndex, PR6125.
         def visitor(child, parent, children):
             # FIXME: Document this assertion in API.
             # FIXME: There should just be an isNull method.
             assert child != Cursor_null()
@@ -1730,16 +1738,20 @@ Cursor_def = lib.clang_getCursorDefinition
 Cursor_def.argtypes = [Cursor]
 Cursor_def.restype = Cursor
 Cursor_def.errcheck = Cursor.from_result
 
 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
 Cursor_spelling.errcheck = _CXString.from_result
 
 Cursor_displayname = lib.clang_getCursorDisplayName
 Cursor_displayname.argtypes = [Cursor]
 Cursor_displayname.restype = _CXString
diff --git a/bindings/python/tests/cindex/test_cursor.py b/bindings/python/tests/cindex/test_cursor.py
index 3dde891..efcede9 100644
--- a/bindings/python/tests/cindex/test_cursor.py
+++ b/bindings/python/tests/cindex/test_cursor.py
@@ -37,16 +37,17 @@ def test_get_children():
     assert len(tu_nodes) == 3
 
     assert tu_nodes[0].kind == CursorKind.STRUCT_DECL
     assert tu_nodes[0].spelling == 's0'
     assert tu_nodes[0].is_definition() == True
     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
     assert s0_nodes[0].kind == CursorKind.FIELD_DECL
     assert s0_nodes[0].spelling == 'a'
     assert s0_nodes[0].type.kind == TypeKind.INT
     assert s0_nodes[1].kind == CursorKind.FIELD_DECL
     assert s0_nodes[1].spelling == 'b'
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to