]> granicus.if.org Git - clang/commitdiff
Implement clang_getCanonicalCursor() in libclang, which does the obvious thing.
authorDouglas Gregor <dgregor@apple.com>
Fri, 19 Nov 2010 23:44:15 +0000 (23:44 +0000)
committerDouglas Gregor <dgregor@apple.com>
Fri, 19 Nov 2010 23:44:15 +0000 (23:44 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@119874 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 2fc408973542cfcbe94e8726abda05af259db5e4..ebe74e2d2fc511aaf5ef571bf03eb43746d6f40f 100644 (file)
@@ -2074,6 +2074,32 @@ CINDEX_LINKAGE CXCursor clang_getCursorDefinition(CXCursor);
  */
 CINDEX_LINKAGE unsigned clang_isCursorDefinition(CXCursor);
 
+/**
+ * \brief Retrieve the canonical cursor corresponding to the given cursor.
+ *
+ * In the C family of languages, many kinds of entities can be declared several
+ * times within a single translation unit. For example, a structure type can
+ * be forward-declared (possibly multiple times) and later defined:
+ *
+ * \code
+ * struct X;
+ * struct X;
+ * struct X {
+ *   int member;
+ * };
+ * \endcode
+ *
+ * The declarations and the definition of \c X are represented by three 
+ * different cursors, all of which are declarations of the same underlying 
+ * entity. One of these cursor is considered the "canonical" cursor, which
+ * is effectively the representative for the underlying entity. One can 
+ * determine if two cursors are declarations of the same underlying entity by
+ * comparing their canonical cursors.
+ *
+ * \returns The canonical cursor for the entity referred to by the given cursor.
+ */
+CINDEX_LINKAGE CXCursor clang_getCanonicalCursor(CXCursor);
+
 /**
  * @}
  */
index 9137172daf88e12663545b6b685b2231b7265fdf..9116667ec74a37178ea79687d7804a17bd396c04 100644 (file)
@@ -3717,6 +3717,16 @@ unsigned clang_isCursorDefinition(CXCursor C) {
   return clang_getCursorDefinition(C) == C;
 }
 
+CXCursor clang_getCanonicalCursor(CXCursor C) {
+  if (!clang_isDeclaration(C.kind))
+    return C;
+  
+  if (Decl *D = getCursorDecl(C))
+    return MakeCXCursor(D->getCanonicalDecl(), getCursorTU(C));
+  
+  return C;
+}
+  
 unsigned clang_getNumOverloadedDecls(CXCursor C) {
   if (C.kind != CXCursor_OverloadedDeclRef)
     return 0;
index 5e8abf25333b2eca331122df67ee8e4181d2e995..e132f7f9aab17e3f893c7f1fe65357cc9a265971 100644 (file)
@@ -32,6 +32,7 @@ _clang_equalTypes
 _clang_formatDiagnostic
 _clang_getCString
 _clang_getCXXAccessSpecifier
+_clang_getCanonicalCursor
 _clang_getCanonicalType
 _clang_getClangVersion
 _clang_getCompletionAvailability
index ca9a9d1016dde5ccd7b9c8bbbfda9e88f5b740a4..fce89ca87bc06fe1e541a6922b31d0d13940657a 100644 (file)
@@ -32,6 +32,7 @@ clang_equalTypes
 clang_formatDiagnostic
 clang_getCString
 clang_getCXXAccessSpecifier
+clang_getCanonicalCursor
 clang_getCanonicalType
 clang_getClangVersion
 clang_getCompletionAvailability