Add new libclang hooks for CXCursorSet, a
DenseMap-backed hashtable for doing client-side
management of CXCursors within a set.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@121318 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/tools/libclang/CXCursor.cpp b/tools/libclang/CXCursor.cpp
index 9d485f8..26cb2d2 100644
--- a/tools/libclang/CXCursor.cpp
+++ b/tools/libclang/CXCursor.cpp
@@ -493,3 +493,68 @@
return ((uintptr_t) (C.data[1])) != 0;
}
+//===----------------------------------------------------------------------===//
+// CXCursorSet.
+//===----------------------------------------------------------------------===//
+
+typedef llvm::DenseMap<CXCursor, unsigned> CXCursorSet_Impl;
+
+static inline CXCursorSet packCXCursorSet(CXCursorSet_Impl *setImpl) {
+ return (CXCursorSet) setImpl;
+}
+static inline CXCursorSet_Impl *unpackCXCursorSet(CXCursorSet set) {
+ return (CXCursorSet_Impl*) set;
+}
+namespace llvm {
+template<> class llvm::DenseMapInfo<CXCursor> {
+public:
+ static inline CXCursor getEmptyKey() {
+ return MakeCXCursorInvalid(CXCursor_InvalidFile);
+ }
+ static inline CXCursor getTombstoneKey() {
+ return MakeCXCursorInvalid(CXCursor_NoDeclFound);
+ }
+ static inline unsigned getHashValue(const CXCursor &cursor) {
+ return llvm::DenseMapInfo<std::pair<void*,void*> >
+ ::getHashValue(std::make_pair(cursor.data[0], cursor.data[1]));
+ }
+ static inline bool isEqual(const CXCursor &x, const CXCursor &y) {
+ return x.kind == y.kind &&
+ x.data[0] == y.data[0] &&
+ x.data[1] == y.data[1];
+ }
+};
+}
+
+extern "C" {
+CXCursorSet clang_createCXCursorSet() {
+ return packCXCursorSet(new CXCursorSet_Impl());
+}
+
+void clang_disposeCXCursorSet(CXCursorSet set) {
+ delete unpackCXCursorSet(set);
+}
+
+unsigned clang_CXCursorSet_contains(CXCursorSet set, CXCursor cursor) {
+ CXCursorSet_Impl *setImpl = unpackCXCursorSet(set);
+ if (!setImpl)
+ return 0;
+ return setImpl->find(cursor) == setImpl->end();
+}
+
+unsigned clang_CXCurorSet_insert(CXCursorSet set, CXCursor cursor) {
+ // Do not insert invalid cursors into the set.
+ if (cursor.kind >= CXCursor_FirstInvalid &&
+ cursor.kind <= CXCursor_LastInvalid)
+ return 1;
+
+ CXCursorSet_Impl *setImpl = unpackCXCursorSet(set);
+ if (!setImpl)
+ return 1;
+ unsigned &entry = (*setImpl)[cursor];
+ unsigned flag = entry == 0 ? 1 : 0;
+ entry = 1;
+ return flag;
+}
+} // end: extern "C"
+
diff --git a/tools/libclang/libclang.darwin.exports b/tools/libclang/libclang.darwin.exports
index 936ad46..33a0f83 100644
--- a/tools/libclang/libclang.darwin.exports
+++ b/tools/libclang/libclang.darwin.exports
@@ -1,3 +1,5 @@
+_clang_CXCursorSet_contains
+_clang_CXCursorSet_insert
_clang_CXXMethod_isStatic
_clang_annotateTokens
_clang_codeCompleteAt
@@ -9,6 +11,7 @@
_clang_constructUSR_ObjCMethod
_clang_constructUSR_ObjCProperty
_clang_constructUSR_ObjCProtocol
+_clang_createCXCursorSet
_clang_createIndex
_clang_createTranslationUnit
_clang_createTranslationUnitFromSourceFile
@@ -17,6 +20,7 @@
_clang_defaultEditingTranslationUnitOptions
_clang_defaultReparseOptions
_clang_defaultSaveOptions
+_clang_disposeCXCursorSet
_clang_disposeCodeCompleteResults
_clang_disposeDiagnostic
_clang_disposeIndex
@@ -25,10 +29,10 @@
_clang_disposeTokens
_clang_disposeTranslationUnit
_clang_enableStackTraces
-_clang_executeOnThread
_clang_equalCursors
_clang_equalLocations
_clang_equalTypes
+_clang_executeOnThread
_clang_formatDiagnostic
_clang_getCString
_clang_getCXXAccessSpecifier
@@ -120,3 +124,4 @@
_clang_sortCodeCompletionResults
_clang_tokenize
_clang_visitChildren
+_clang_visitChildrenWithBlock
diff --git a/tools/libclang/libclang.exports b/tools/libclang/libclang.exports
index de770ee..d966b66 100644
--- a/tools/libclang/libclang.exports
+++ b/tools/libclang/libclang.exports
@@ -1,3 +1,5 @@
+clang_CXCursorSet_contains
+clang_CXCursorSet_insert
clang_CXXMethod_isStatic
clang_annotateTokens
clang_codeCompleteAt
@@ -9,6 +11,7 @@
clang_constructUSR_ObjCMethod
clang_constructUSR_ObjCProperty
clang_constructUSR_ObjCProtocol
+clang_createCXCursorSet
clang_createIndex
clang_createTranslationUnit
clang_createTranslationUnitFromSourceFile
@@ -17,6 +20,7 @@
clang_defaultEditingTranslationUnitOptions
clang_defaultReparseOptions
clang_defaultSaveOptions
+clang_disposeCXCursorSet
clang_disposeCodeCompleteResults
clang_disposeDiagnostic
clang_disposeIndex
@@ -25,10 +29,10 @@
clang_disposeTokens
clang_disposeTranslationUnit
clang_enableStackTraces
-clang_executeOnThread
clang_equalCursors
clang_equalLocations
clang_equalTypes
+clang_executeOnThread
clang_formatDiagnostic
clang_getCString
clang_getCXXAccessSpecifier