summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEhsan Akhgari <ehsan.akhgari@gmail.com>2016-05-31 15:55:51 +0000
committerEhsan Akhgari <ehsan.akhgari@gmail.com>2016-05-31 15:55:51 +0000
commitb743de7fb9dcd66815d66dc52874ee25c7c8f8cc (patch)
tree4e218b0f0a4bc109d7168277c04d7fcbd239f9c1
parent3a562e6f703a0eaeee7db3674baf7876ed954f91 (diff)
downloadbcm5719-llvm-b743de7fb9dcd66815d66dc52874ee25c7c8f8cc.tar.gz
bcm5719-llvm-b743de7fb9dcd66815d66dc52874ee25c7c8f8cc.zip
clang-c: Add the clang_getCursorVisibility() API
This patch adds an API for querying the visibility of the entity referred to by a cursor. Patch by Michael Wu <mwu@mozilla.com>. llvm-svn: 271292
-rw-r--r--clang/include/clang-c/Index.h26
-rw-r--r--clang/test/Index/symbol-visibility.c7
-rw-r--r--clang/tools/c-index-test/c-index-test.c30
-rw-r--r--clang/tools/libclang/CIndex.cpp21
-rw-r--r--clang/tools/libclang/libclang.exports1
5 files changed, 85 insertions, 0 deletions
diff --git a/clang/include/clang-c/Index.h b/clang/include/clang-c/Index.h
index 790effea1d7..dbcd0c8840f 100644
--- a/clang/include/clang-c/Index.h
+++ b/clang/include/clang-c/Index.h
@@ -2516,6 +2516,32 @@ enum CXLinkageKind {
*/
CINDEX_LINKAGE enum CXLinkageKind clang_getCursorLinkage(CXCursor cursor);
+enum CXVisibilityKind {
+ /** \brief This value indicates that no visibility information is available
+ * for a provided CXCursor. */
+ CXVisibility_Invalid,
+
+ /** \brief Symbol not seen by the linker. */
+ CXVisibility_Hidden,
+ /** \brief Symbol seen by the linker but resolves to a symbol inside this object. */
+ CXVisibility_Protected,
+ /** \brief Symbol seen by the linker and acts like a normal symbol. */
+ CXVisibility_Default
+};
+
+/**
+ * \brief Describe the visibility of the entity referred to by a cursor.
+ *
+ * This returns the default visibility if not explicitly specified by
+ * a visibility attribute. The default visibility may be changed by
+ * commandline arguments.
+ *
+ * \param cursor The cursor to query.
+ *
+ * \returns The visibility of the cursor.
+ */
+CINDEX_LINKAGE enum CXVisibilityKind clang_getCursorVisibility(CXCursor cursor);
+
/**
* \brief Determine the availability of the entity that this cursor refers to,
* taking the current target platform into account.
diff --git a/clang/test/Index/symbol-visibility.c b/clang/test/Index/symbol-visibility.c
new file mode 100644
index 00000000000..014e80f8187
--- /dev/null
+++ b/clang/test/Index/symbol-visibility.c
@@ -0,0 +1,7 @@
+// RUN: c-index-test -test-print-visibility %s | FileCheck %s
+
+__attribute__ ((visibility ("default"))) void foo1();
+__attribute__ ((visibility ("hidden"))) void foo2();
+
+// CHECK: FunctionDecl=foo1:3:47visibility=Default
+// CHECK: FunctionDecl=foo2:4:46visibility=Hidden
diff --git a/clang/tools/c-index-test/c-index-test.c b/clang/tools/c-index-test/c-index-test.c
index 838c38a7b28..802140a350f 100644
--- a/clang/tools/c-index-test/c-index-test.c
+++ b/clang/tools/c-index-test/c-index-test.c
@@ -1265,6 +1265,32 @@ static enum CXChildVisitResult PrintLinkage(CXCursor cursor, CXCursor p,
}
/******************************************************************************/
+/* Visibility testing. */
+/******************************************************************************/
+
+static enum CXChildVisitResult PrintVisibility(CXCursor cursor, CXCursor p,
+ CXClientData d) {
+ const char *visibility = 0;
+
+ if (clang_isInvalid(clang_getCursorKind(cursor)))
+ return CXChildVisit_Recurse;
+
+ switch (clang_getCursorVisibility(cursor)) {
+ case CXVisibility_Invalid: break;
+ case CXVisibility_Hidden: visibility = "Hidden"; break;
+ case CXVisibility_Protected: visibility = "Protected"; break;
+ case CXVisibility_Default: visibility = "Default"; break;
+ }
+
+ if (visibility) {
+ PrintCursor(cursor, NULL);
+ printf("visibility=%s\n", visibility);
+ }
+
+ return CXChildVisit_Recurse;
+}
+
+/******************************************************************************/
/* Typekind testing. */
/******************************************************************************/
@@ -4240,6 +4266,7 @@ static void print_usage(void) {
" c-index-test -test-inclusion-stack-tu <AST file>\n");
fprintf(stderr,
" c-index-test -test-print-linkage-source {<args>}*\n"
+ " c-index-test -test-print-visibility {<args>}*\n"
" c-index-test -test-print-type {<args>}*\n"
" c-index-test -test-print-type-size {<args>}*\n"
" c-index-test -test-print-bitwidth {<args>}*\n"
@@ -4334,6 +4361,9 @@ int cindextest_main(int argc, const char **argv) {
else if (argc > 2 && strcmp(argv[1], "-test-print-linkage-source") == 0)
return perform_test_load_source(argc - 2, argv + 2, "all", PrintLinkage,
NULL);
+ else if (argc > 2 && strcmp(argv[1], "-test-print-visibility") == 0)
+ return perform_test_load_source(argc - 2, argv + 2, "all", PrintVisibility,
+ NULL);
else if (argc > 2 && strcmp(argv[1], "-test-print-type") == 0)
return perform_test_load_source(argc - 2, argv + 2, "all",
PrintType, 0);
diff --git a/clang/tools/libclang/CIndex.cpp b/clang/tools/libclang/CIndex.cpp
index 1aeb3a6397e..78df3ce264c 100644
--- a/clang/tools/libclang/CIndex.cpp
+++ b/clang/tools/libclang/CIndex.cpp
@@ -6817,6 +6817,27 @@ CXLinkageKind clang_getCursorLinkage(CXCursor cursor) {
} // end: extern "C"
//===----------------------------------------------------------------------===//
+// Operations for querying visibility of a cursor.
+//===----------------------------------------------------------------------===//
+
+extern "C" {
+CXVisibilityKind clang_getCursorVisibility(CXCursor cursor) {
+ if (!clang_isDeclaration(cursor.kind))
+ return CXVisibility_Invalid;
+
+ const Decl *D = cxcursor::getCursorDecl(cursor);
+ if (const NamedDecl *ND = dyn_cast_or_null<NamedDecl>(D))
+ switch (ND->getVisibility()) {
+ case HiddenVisibility: return CXVisibility_Hidden;
+ case ProtectedVisibility: return CXVisibility_Protected;
+ case DefaultVisibility: return CXVisibility_Default;
+ };
+
+ return CXVisibility_Invalid;
+}
+} // end: extern "C"
+
+//===----------------------------------------------------------------------===//
// Operations for querying language of a cursor.
//===----------------------------------------------------------------------===//
diff --git a/clang/tools/libclang/libclang.exports b/clang/tools/libclang/libclang.exports
index c4e781dbed8..c8fe0a21d09 100644
--- a/clang/tools/libclang/libclang.exports
+++ b/clang/tools/libclang/libclang.exports
@@ -182,6 +182,7 @@ clang_getCursorSemanticParent
clang_getCursorSpelling
clang_getCursorType
clang_getCursorUSR
+clang_getCursorVisibility
clang_getDeclObjCTypeEncoding
clang_getDefinitionSpellingAndExtent
clang_getDiagnostic
OpenPOWER on IntegriCloud