[llvm-branch-commits] [cfe-branch] r120662 - in /cfe/branches/Apple/whitney: include/clang-c/Index.h tools/libclang/CIndex.cpp tools/libclang/libclang.darwin.exports tools/libclang/libclang.exports

Daniel Dunbar daniel at zuster.org
Wed Dec 1 18:52:05 PST 2010


Author: ddunbar
Date: Wed Dec  1 20:52:05 2010
New Revision: 120662

URL: http://llvm.org/viewvc/llvm-project?rev=120662&view=rev
Log:
Merge r119874:
--
Author: Douglas Gregor <dgregor at apple.com>
Date:   Fri Nov 19 23:44:15 2010 +0000

    Implement clang_getCanonicalCursor() in libclang, which does the obvious thing.

Modified:
    cfe/branches/Apple/whitney/include/clang-c/Index.h
    cfe/branches/Apple/whitney/tools/libclang/CIndex.cpp
    cfe/branches/Apple/whitney/tools/libclang/libclang.darwin.exports
    cfe/branches/Apple/whitney/tools/libclang/libclang.exports

Modified: cfe/branches/Apple/whitney/include/clang-c/Index.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/include/clang-c/Index.h?rev=120662&r1=120661&r2=120662&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/include/clang-c/Index.h (original)
+++ cfe/branches/Apple/whitney/include/clang-c/Index.h Wed Dec  1 20:52:05 2010
@@ -2071,6 +2071,32 @@
 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);
+
+/**
  * @}
  */
 

Modified: cfe/branches/Apple/whitney/tools/libclang/CIndex.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/tools/libclang/CIndex.cpp?rev=120662&r1=120661&r2=120662&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/tools/libclang/CIndex.cpp (original)
+++ cfe/branches/Apple/whitney/tools/libclang/CIndex.cpp Wed Dec  1 20:52:05 2010
@@ -3717,6 +3717,16 @@
   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;

Modified: cfe/branches/Apple/whitney/tools/libclang/libclang.darwin.exports
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/tools/libclang/libclang.darwin.exports?rev=120662&r1=120661&r2=120662&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/tools/libclang/libclang.darwin.exports (original)
+++ cfe/branches/Apple/whitney/tools/libclang/libclang.darwin.exports Wed Dec  1 20:52:05 2010
@@ -32,6 +32,7 @@
 _clang_formatDiagnostic
 _clang_getCString
 _clang_getCXXAccessSpecifier
+_clang_getCanonicalCursor
 _clang_getCanonicalType
 _clang_getClangVersion
 _clang_getCompletionAvailability

Modified: cfe/branches/Apple/whitney/tools/libclang/libclang.exports
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/tools/libclang/libclang.exports?rev=120662&r1=120661&r2=120662&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/tools/libclang/libclang.exports (original)
+++ cfe/branches/Apple/whitney/tools/libclang/libclang.exports Wed Dec  1 20:52:05 2010
@@ -32,6 +32,7 @@
 clang_formatDiagnostic
 clang_getCString
 clang_getCXXAccessSpecifier
+clang_getCanonicalCursor
 clang_getCanonicalType
 clang_getClangVersion
 clang_getCompletionAvailability





More information about the llvm-branch-commits mailing list