Index: clang/include/clang-c/Index.h =================================================================== --- clang/include/clang-c/Index.h +++ clang/include/clang-c/Index.h @@ -2940,6 +2940,26 @@ CINDEX_LINKAGE void clang_disposeCXPlatformAvailability(CXPlatformAvailability *availability); +/** + * If cursor refers to a variable declaration and it has initializer returns + * cursor referring to the initializer otherwise return null cursor. + */ +CINDEX_LINKAGE CXCursor clang_getVarDeclInitializer(CXCursor cursor); + +/** + * If cursor refers to a variable declaration that has global storage returns 1. + * If cursor refers to a variable declaration that doesn't have global storage + * returns 0. Otherwise returns -1. + */ +CINDEX_LINKAGE int clang_hasVarDeclGlobalStorage(CXCursor cursor); + +/** + * If cursor refers to a variable declaration that has external storage + * returns 1. If cursor refers to a variable declaration that doesn't have + * external storage returns 0. Otherwise returns -1. + */ +CINDEX_LINKAGE int clang_hasVarDeclExternalStorage(CXCursor cursor); + /** * Describe the "language" of the entity referred to by a cursor. */ Index: clang/tools/libclang/CIndex.cpp =================================================================== --- clang/tools/libclang/CIndex.cpp +++ clang/tools/libclang/CIndex.cpp @@ -8897,6 +8897,42 @@ clang_disposeCXTUResourceUsage(Usage); } +CXCursor clang_getVarDeclInitializer(CXCursor cursor) { + const Decl *const D = getCursorDecl(cursor); + if (!D) + return clang_getNullCursor(); + const auto *const VD = dyn_cast(D); + if (!VD) + return clang_getNullCursor(); + const Expr *const Init = VD->getInit(); + if (!Init) + return clang_getNullCursor(); + + return cxcursor::MakeCXCursor(Init, VD, cxcursor::getCursorTU(cursor)); +} + +int clang_hasVarDeclGlobalStorage(CXCursor cursor) { + const Decl *const D = getCursorDecl(cursor); + if (!D) + return -1; + const auto *const VD = dyn_cast(D); + if (!VD) + return -1; + + return VD->hasGlobalStorage(); +} + +int clang_hasVarDeclExternalStorage(CXCursor cursor) { + const Decl *const D = getCursorDecl(cursor); + if (!D) + return -1; + const auto *const VD = dyn_cast(D); + if (!VD) + return -1; + + return VD->hasExternalStorage(); +} + //===----------------------------------------------------------------------===// // Misc. utility functions. //===----------------------------------------------------------------------===// Index: clang/tools/libclang/libclang.exports =================================================================== --- clang/tools/libclang/libclang.exports +++ clang/tools/libclang/libclang.exports @@ -382,3 +382,6 @@ clang_PrintingPolicy_dispose clang_install_aborting_llvm_fatal_error_handler clang_uninstall_llvm_fatal_error_handler +clang_getVarDeclInitializer +clang_hasVarDeclGlobalStorage +clang_hasVarDeclExternalStorage \ No newline at end of file