[cfe-commits] r121318 - in /cfe/trunk: include/clang-c/Index.h tools/libclang/CXCursor.cpp tools/libclang/libclang.darwin.exports tools/libclang/libclang.exports
Ted Kremenek
kremenek at apple.com
Wed Dec 8 15:43:14 PST 2010
Author: kremenek
Date: Wed Dec 8 17:43:14 2010
New Revision: 121318
URL: http://llvm.org/viewvc/llvm-project?rev=121318&view=rev
Log:
Add new libclang hooks for CXCursorSet, a
DenseMap-backed hashtable for doing client-side
management of CXCursors within a set.
Modified:
cfe/trunk/include/clang-c/Index.h
cfe/trunk/tools/libclang/CXCursor.cpp
cfe/trunk/tools/libclang/libclang.darwin.exports
cfe/trunk/tools/libclang/libclang.exports
Modified: cfe/trunk/include/clang-c/Index.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang-c/Index.h?rev=121318&r1=121317&r2=121318&view=diff
==============================================================================
--- cfe/trunk/include/clang-c/Index.h (original)
+++ cfe/trunk/include/clang-c/Index.h Wed Dec 8 17:43:14 2010
@@ -1460,7 +1460,38 @@
*/
CINDEX_LINKAGE enum CXLanguageKind clang_getCursorLanguage(CXCursor cursor);
-
+
+/**
+ * \brief A fast container representing a set of CXCursors.
+ */
+typedef struct CXCursorSetImpl *CXCursorSet;
+
+/**
+ * \brief Creates an empty CXCursorSet.
+ */
+CINDEX_LINKAGE CXCursorSet clang_createCXCursorSet();
+
+/**
+ * \brief Disposes a CXCursorSet and releases its associated memory.
+ */
+CINDEX_LINKAGE void clang_disposeCXCursorSet(CXCursorSet cset);
+
+/**
+ * \brief Queries a CXCursorSet to see if it contains a specific CXCursor.
+ *
+ * \returns non-zero if the set contains the specified cursor.
+*/
+CINDEX_LINKAGE unsigned clang_CXCursorSet_contains(CXCursorSet cset,
+ CXCursor cursor);
+
+/**
+ * \brief Inserts a CXCursor into a CXCursorSet.
+ *
+ * \returns zero if the CXCursor was already in the set, and non-zero otherwise.
+*/
+CINDEX_LINKAGE unsigned clang_CXCursorSet_insert(CXCursorSet cset,
+ CXCursor cursor);
+
/**
* \brief Determine the semantic parent of the given cursor.
*
Modified: cfe/trunk/tools/libclang/CXCursor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CXCursor.cpp?rev=121318&r1=121317&r2=121318&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CXCursor.cpp (original)
+++ cfe/trunk/tools/libclang/CXCursor.cpp Wed Dec 8 17:43:14 2010
@@ -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"
+
Modified: cfe/trunk/tools/libclang/libclang.darwin.exports
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/libclang.darwin.exports?rev=121318&r1=121317&r2=121318&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/libclang.darwin.exports (original)
+++ cfe/trunk/tools/libclang/libclang.darwin.exports Wed Dec 8 17:43:14 2010
@@ -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
Modified: cfe/trunk/tools/libclang/libclang.exports
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/libclang.exports?rev=121318&r1=121317&r2=121318&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/libclang.exports (original)
+++ cfe/trunk/tools/libclang/libclang.exports Wed Dec 8 17:43:14 2010
@@ -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
More information about the cfe-commits
mailing list