]> granicus.if.org Git - clang/commitdiff
Implement a simple hash function for libclang cursors
authorDouglas Gregor <dgregor@apple.com>
Sat, 20 Nov 2010 00:09:34 +0000 (00:09 +0000)
committerDouglas Gregor <dgregor@apple.com>
Sat, 20 Nov 2010 00:09:34 +0000 (00:09 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@119876 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang-c/Index.h
tools/libclang/CIndex.cpp
tools/libclang/libclang.darwin.exports
tools/libclang/libclang.exports

index ebe74e2d2fc511aaf5ef571bf03eb43746d6f40f..d7a4b602bb5794a517fe9cddd7a59d4b03ff533b 100644 (file)
@@ -1350,6 +1350,11 @@ CINDEX_LINKAGE CXCursor clang_getTranslationUnitCursor(CXTranslationUnit);
  */
 CINDEX_LINKAGE unsigned clang_equalCursors(CXCursor, CXCursor);
 
+/**
+ * \brief Compute a hash value for the given cursor.
+ */
+CINDEX_LINKAGE unsigned clang_hashCursor(CXCursor);
+  
 /**
  * \brief Retrieve the kind of the given cursor.
  */
index 9116667ec74a37178ea79687d7804a17bd396c04..2eb2096fc9ee839eebccf1f8485dd7e189532e03 100644 (file)
@@ -3137,6 +3137,15 @@ unsigned clang_equalCursors(CXCursor X, CXCursor Y) {
   return X == Y;
 }
 
+unsigned clang_hashCursor(CXCursor C) {
+  unsigned Index = 0;
+  if (clang_isExpression(C.kind) || clang_isStatement(C.kind))
+    Index = 1;
+  
+  return llvm::DenseMapInfo<std::pair<unsigned, void*> >::getHashValue(
+                                        std::make_pair(C.kind, C.data[Index]));
+}
+
 unsigned clang_isInvalid(enum CXCursorKind K) {
   return K >= CXCursor_FirstInvalid && K <= CXCursor_LastInvalid;
 }
index e132f7f9aab17e3f893c7f1fe65357cc9a265971..936ad464511e38ea2cf546874065f585e88bd01b 100644 (file)
@@ -102,6 +102,7 @@ _clang_getTranslationUnitCursor
 _clang_getTranslationUnitSpelling
 _clang_getTypeDeclaration
 _clang_getTypeKindSpelling
+_clang_hashCursor
 _clang_isCursorDefinition
 _clang_isDeclaration
 _clang_isExpression
index fce89ca87bc06fe1e541a6922b31d0d13940657a..de770eea454b5e907d04f4fdbb7eab835937695f 100644 (file)
@@ -102,6 +102,7 @@ clang_getTranslationUnitCursor
 clang_getTranslationUnitSpelling
 clang_getTypeDeclaration
 clang_getTypeKindSpelling
+clang_hashCursor
 clang_isCursorDefinition
 clang_isDeclaration
 clang_isExpression