query-selector-visibility.patch 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. commit 865b9340996f9f9d04b73b187248737dc6fd845e
  2. Author: Michael Wu <mwu@mozilla.com>
  3. Date: Mon Sep 14 17:47:21 2015 -0400
  4. Add support for querying the visibility of a cursor
  5. diff --git a/clang/include/clang-c/Index.h b/clang/include/clang-c/Index.h
  6. index fad9cfa..311bfcb 100644
  7. --- a/clang/include/clang-c/Index.h
  8. +++ b/clang/include/clang-c/Index.h
  9. @@ -2440,6 +2440,24 @@ enum CXLinkageKind {
  10. CINDEX_LINKAGE enum CXLinkageKind clang_getCursorLinkage(CXCursor cursor);
  11. /**
  12. + * \brief Describe the visibility of the entity referred to by a cursor.
  13. + */
  14. +enum CXVisibilityKind {
  15. + /** \brief This value indicates that no visibility information is available
  16. + * for a provided CXCursor. */
  17. + CXVisibility_Invalid,
  18. +
  19. + /** \brief Symbol not seen by the linker. */
  20. + CXVisibility_Hidden,
  21. + /** \brief Symbol seen by the linker but resolves to a symbol inside this object. */
  22. + CXVisibility_Protected,
  23. + /** \brief Symbol seen by the linker and acts like a normal symbol. */
  24. + CXVisibility_Default,
  25. +};
  26. +
  27. +CINDEX_LINKAGE enum CXVisibilityKind clang_getCursorVisibility(CXCursor cursor);
  28. +
  29. +/**
  30. * \brief Determine the availability of the entity that this cursor refers to,
  31. * taking the current target platform into account.
  32. *
  33. diff --git a/clang/tools/libclang/CIndex.cpp b/clang/tools/libclang/CIndex.cpp
  34. index 8225a6c..9fa18d3 100644
  35. --- a/clang/tools/libclang/CIndex.cpp
  36. +++ b/clang/tools/libclang/CIndex.cpp
  37. @@ -6361,6 +6361,27 @@ CXLinkageKind clang_getCursorLinkage(CXCursor cursor) {
  38. } // end: extern "C"
  39. //===----------------------------------------------------------------------===//
  40. +// Operations for querying visibility of a cursor.
  41. +//===----------------------------------------------------------------------===//
  42. +
  43. +extern "C" {
  44. +CXVisibilityKind clang_getCursorVisibility(CXCursor cursor) {
  45. + if (!clang_isDeclaration(cursor.kind))
  46. + return CXVisibility_Invalid;
  47. +
  48. + const Decl *D = cxcursor::getCursorDecl(cursor);
  49. + if (const NamedDecl *ND = dyn_cast_or_null<NamedDecl>(D))
  50. + switch (ND->getVisibility()) {
  51. + case HiddenVisibility: return CXVisibility_Hidden;
  52. + case ProtectedVisibility: return CXVisibility_Protected;
  53. + case DefaultVisibility: return CXVisibility_Default;
  54. + };
  55. +
  56. + return CXVisibility_Invalid;
  57. +}
  58. +} // end: extern "C"
  59. +
  60. +//===----------------------------------------------------------------------===//
  61. // Operations for querying language of a cursor.
  62. //===----------------------------------------------------------------------===//
  63. diff --git a/clang/tools/libclang/libclang.exports b/clang/tools/libclang/libclang.exports
  64. index f6a7175..a919a8e 100644
  65. --- a/clang/tools/libclang/libclang.exports
  66. +++ b/clang/tools/libclang/libclang.exports
  67. @@ -173,6 +173,7 @@ clang_getCursorSemanticParent
  68. clang_getCursorSpelling
  69. clang_getCursorType
  70. clang_getCursorUSR
  71. +clang_getCursorVisibility
  72. clang_getDeclObjCTypeEncoding
  73. clang_getDefinitionSpellingAndExtent
  74. clang_getDiagnostic