r246931 - Index: expose visibility attribute
Saleem Abdulrasool via cfe-commits
cfe-commits at lists.llvm.org
Sat Sep 5 11:53:43 PDT 2015
Author: compnerd
Date: Sat Sep 5 13:53:43 2015
New Revision: 246931
URL: http://llvm.org/viewvc/llvm-project?rev=246931&view=rev
Log:
Index: expose visibility attribute
Expose the previously unexposed visibility attribute via the python and C
bindings.
Added:
cfe/trunk/test/Index/visibility.c
Modified:
cfe/trunk/bindings/python/clang/cindex.py
cfe/trunk/include/clang-c/Index.h
cfe/trunk/tools/libclang/CIndex.cpp
cfe/trunk/tools/libclang/CXCursor.cpp
Modified: cfe/trunk/bindings/python/clang/cindex.py
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/bindings/python/clang/cindex.py?rev=246931&r1=246930&r2=246931&view=diff
==============================================================================
--- cfe/trunk/bindings/python/clang/cindex.py (original)
+++ cfe/trunk/bindings/python/clang/cindex.py Sat Sep 5 13:53:43 2015
@@ -1100,6 +1100,8 @@ CursorKind.CUDAGLOBAL_ATTR = CursorKind(
CursorKind.CUDAHOST_ATTR = CursorKind(415)
CursorKind.CUDASHARED_ATTR = CursorKind(416)
+CursorKind.VISIBILITY_ATTR = CursorKind(417)
+
###
# Preprocessing
CursorKind.PREPROCESSING_DIRECTIVE = CursorKind(500)
Modified: cfe/trunk/include/clang-c/Index.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang-c/Index.h?rev=246931&r1=246930&r2=246931&view=diff
==============================================================================
--- cfe/trunk/include/clang-c/Index.h (original)
+++ cfe/trunk/include/clang-c/Index.h Sat Sep 5 13:53:43 2015
@@ -32,7 +32,7 @@
* compatible, thus CINDEX_VERSION_MAJOR is expected to remain stable.
*/
#define CINDEX_VERSION_MAJOR 0
-#define CINDEX_VERSION_MINOR 30
+#define CINDEX_VERSION_MINOR 31
#define CINDEX_VERSION_ENCODE(major, minor) ( \
((major) * 10000) \
@@ -2279,7 +2279,8 @@ enum CXCursorKind {
CXCursor_CUDAGlobalAttr = 414,
CXCursor_CUDAHostAttr = 415,
CXCursor_CUDASharedAttr = 416,
- CXCursor_LastAttr = CXCursor_CUDASharedAttr,
+ CXCursor_VisibilityAttr = 417,
+ CXCursor_LastAttr = CXCursor_VisibilityAttr,
/* Preprocessing */
CXCursor_PreprocessingDirective = 500,
Added: cfe/trunk/test/Index/visibility.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/visibility.c?rev=246931&view=auto
==============================================================================
--- cfe/trunk/test/Index/visibility.c (added)
+++ cfe/trunk/test/Index/visibility.c Sat Sep 5 13:53:43 2015
@@ -0,0 +1,13 @@
+// RUN: c-index-test -index-file %s -target i686-pc-linux \
+// RUN: | FileCheck %s -check-prefix CHECK -check-prefix CHECK-LINUX
+// RUN: c-index-test -index-file -Wno-unsupported-visibility %s -target i386-darwin \
+// RUN: | FileCheck %s -check-prefix CHECK -check-prefix CHECK-DARWIN
+
+void __attribute__ (( visibility("default") )) default_visibility();
+// CHECK: <attribute>: attribute(visibility)=default
+void __attribute__ (( visibility("hidden") )) hidden_visibility();
+// CHECK: <attribute>: attribute(visibility)=hidden
+void __attribute__ (( visibility("protected") )) protected_visibility();
+// CHECK-LINUX: <attribute>: attribute(visibility)=protected
+// CHECK-DARWIN: <attribute>: attribute(visibility)=default
+
Modified: cfe/trunk/tools/libclang/CIndex.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=246931&r1=246930&r2=246931&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CIndex.cpp (original)
+++ cfe/trunk/tools/libclang/CIndex.cpp Sat Sep 5 13:53:43 2015
@@ -3756,6 +3756,19 @@ CXString clang_getCursorSpelling(CXCurso
return cxstring::createRef("packed");
}
+ if (C.kind == CXCursor_VisibilityAttr) {
+ const VisibilityAttr *AA = cast<VisibilityAttr>(cxcursor::getCursorAttr(C));
+ switch (AA->getVisibility()) {
+ case VisibilityAttr::VisibilityType::Default:
+ return cxstring::createRef("default");
+ case VisibilityAttr::VisibilityType::Hidden:
+ return cxstring::createRef("hidden");
+ case VisibilityAttr::VisibilityType::Protected:
+ return cxstring::createRef("protected");
+ }
+ llvm_unreachable("unknown visibility type");
+ }
+
return cxstring::createEmpty();
}
@@ -4237,6 +4250,8 @@ CXString clang_getCursorKindSpelling(enu
return cxstring::createRef("attribute(host)");
case CXCursor_CUDASharedAttr:
return cxstring::createRef("attribute(shared)");
+ case CXCursor_VisibilityAttr:
+ return cxstring::createRef("attribute(visibility)");
case CXCursor_PreprocessingDirective:
return cxstring::createRef("preprocessing directive");
case CXCursor_MacroDefinition:
Modified: cfe/trunk/tools/libclang/CXCursor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CXCursor.cpp?rev=246931&r1=246930&r2=246931&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CXCursor.cpp (original)
+++ cfe/trunk/tools/libclang/CXCursor.cpp Sat Sep 5 13:53:43 2015
@@ -58,6 +58,7 @@ static CXCursorKind GetCursorKind(const
case attr::CUDAGlobal: return CXCursor_CUDAGlobalAttr;
case attr::CUDAHost: return CXCursor_CUDAHostAttr;
case attr::CUDAShared: return CXCursor_CUDASharedAttr;
+ case attr::Visibility: return CXCursor_VisibilityAttr;
}
return CXCursor_UnexposedAttr;
More information about the cfe-commits
mailing list