]> granicus.if.org Git - clang/commitdiff
Add clang_getCursorLinkage(), which returns the
authorTed Kremenek <kremenek@apple.com>
Wed, 3 Mar 2010 06:36:57 +0000 (06:36 +0000)
committerTed Kremenek <kremenek@apple.com>
Wed, 3 Mar 2010 06:36:57 +0000 (06:36 +0000)
underlying linkage for the entity referred to by a
CXCursor.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@97646 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang-c/Index.h
tools/CIndex/CIndex.cpp

index c1238e5d88e7c445463dc619dbb7a15fbec7d44a..7bc290d88f4ef8194bf9314d55d069d2df39faee 100644 (file)
@@ -888,6 +888,32 @@ CINDEX_LINKAGE unsigned clang_isInvalid(enum CXCursorKind);
  */
 CINDEX_LINKAGE unsigned clang_isTranslationUnit(enum CXCursorKind);
 
+/**
+ * \brief Describe the linkage of the entity referred to by a cursor.
+ */
+enum CXLinkageKind {
+  /** \brief This value indicates that no linkage information is available
+   * for a provided CXCursor. */
+  CXLinkage_Invalid,
+  /**
+   * \brief This is the linkage for variables, parameters, and so on that
+   *  have automatic storage.  This covers normal (non-extern) local variables.
+   */
+  CXLinkage_NoLinkage,
+  /** \brief This is the linkage for static variables and static functions. */
+  CXLinkage_Internal,
+  /** \brief This is the linkage for entities with external linkage that live
+   * in C++ anonymous namespaces.*/
+  CXLinkage_UniqueExternal,
+  /** \brief This is the linkage for entities with true, external linkage. */
+  CXLinkage_External
+};
+
+/**
+ * \brief Determine the linkage of the entity referred to be a given cursor.
+ */
+CINDEX_LINKAGE enum CXLinkageKind clang_getCursorLinkage(CXCursor cursor);
+
 /**
  * @}
  */
index e13dddfcad580592d80e99d52c482413e323dc1a..6fc7b530307da13dbd92a68b7c0580edcd7a34ee 100644 (file)
@@ -2209,6 +2209,25 @@ void clang_disposeTokens(CXTranslationUnit TU,
 
 } // end: extern "C"
 
+//===----------------------------------------------------------------------===//
+// Operations for querying linkage of a cursor.
+//===----------------------------------------------------------------------===//
+
+extern "C" {
+CXLinkageKind clang_getCursorLinkage(CXCursor cursor) {
+  Decl *D = cxcursor::getCursorDecl(cursor);
+  if (NamedDecl *ND = dyn_cast_or_null<NamedDecl>(D))
+    switch (ND->getLinkage()) {
+      case NoLinkage: return CXLinkage_NoLinkage;
+      case InternalLinkage: return CXLinkage_Internal;
+      case UniqueExternalLinkage: return CXLinkage_UniqueExternal;
+      case ExternalLinkage: return CXLinkage_External;
+    };
+
+  return CXLinkage_Invalid;
+}
+} // end: extern "C"
+
 //===----------------------------------------------------------------------===//
 // CXString Operations.
 //===----------------------------------------------------------------------===//