Implement a simple hash function for libclang cursors
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@119876 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/clang-c/Index.h b/include/clang-c/Index.h
index ebe74e2..d7a4b60 100644
--- a/include/clang-c/Index.h
+++ b/include/clang-c/Index.h
@@ -1351,6 +1351,11 @@
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.
*/
CINDEX_LINKAGE enum CXCursorKind clang_getCursorKind(CXCursor);
diff --git a/tools/libclang/CIndex.cpp b/tools/libclang/CIndex.cpp
index 9116667..2eb2096 100644
--- a/tools/libclang/CIndex.cpp
+++ b/tools/libclang/CIndex.cpp
@@ -3137,6 +3137,15 @@
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;
}
diff --git a/tools/libclang/libclang.darwin.exports b/tools/libclang/libclang.darwin.exports
index e132f7f..936ad46 100644
--- a/tools/libclang/libclang.darwin.exports
+++ b/tools/libclang/libclang.darwin.exports
@@ -102,6 +102,7 @@
_clang_getTranslationUnitSpelling
_clang_getTypeDeclaration
_clang_getTypeKindSpelling
+_clang_hashCursor
_clang_isCursorDefinition
_clang_isDeclaration
_clang_isExpression
diff --git a/tools/libclang/libclang.exports b/tools/libclang/libclang.exports
index fce89ca..de770ee 100644
--- a/tools/libclang/libclang.exports
+++ b/tools/libclang/libclang.exports
@@ -102,6 +102,7 @@
clang_getTranslationUnitSpelling
clang_getTypeDeclaration
clang_getTypeKindSpelling
+clang_hashCursor
clang_isCursorDefinition
clang_isDeclaration
clang_isExpression