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

Tobias Grosser grosser at fim.uni-passau.de
Sun Feb 5 03:42:04 PST 2012


Author: grosser
Date: Sun Feb  5 05:42:03 2012
New Revision: 149826

URL: http://llvm.org/viewvc/llvm-project?rev=149826&view=rev
Log:
[clang.py] Implement Cursor.hash

Contributed by: Gregory Szorc <gregory.szorc at gmail.com>

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

Modified: cfe/trunk/bindings/python/clang/cindex.py
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/bindings/python/clang/cindex.py?rev=149826&r1=149825&r2=149826&view=diff
==============================================================================
--- cfe/trunk/bindings/python/clang/cindex.py (original)
+++ cfe/trunk/bindings/python/clang/cindex.py Sun Feb  5 05:42:03 2012
@@ -969,6 +969,14 @@
             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.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

Modified: cfe/trunk/bindings/python/tests/cindex/test_cursor.py
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/bindings/python/tests/cindex/test_cursor.py?rev=149826&r1=149825&r2=149826&view=diff
==============================================================================
--- cfe/trunk/bindings/python/tests/cindex/test_cursor.py (original)
+++ cfe/trunk/bindings/python/tests/cindex/test_cursor.py Sun Feb  5 05:42:03 2012
@@ -42,6 +42,7 @@
     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





More information about the cfe-commits mailing list