[PATCH] D42893: [libclang] Add clang_File_tryGetRealPathName
This revision was automatically updated to reflect the committed changes. Closed by commit rL329515: [libclang] Add clang_File_tryGetRealPathName (authored by MaskRay, committed by ). Herald added a subscriber: llvm-commits. Changed prior to commit: https://reviews.llvm.org/D42893?vs=141496=141511#toc Repository: rL LLVM https://reviews.llvm.org/D42893 Files: cfe/trunk/include/clang-c/Index.h cfe/trunk/tools/libclang/CIndex.cpp cfe/trunk/tools/libclang/libclang.exports cfe/trunk/unittests/libclang/LibclangTest.cpp Index: cfe/trunk/unittests/libclang/LibclangTest.cpp === --- cfe/trunk/unittests/libclang/LibclangTest.cpp +++ cfe/trunk/unittests/libclang/LibclangTest.cpp @@ -482,6 +482,21 @@ } }; +TEST_F(LibclangReparseTest, FileName) { + std::string CppName = "main.cpp"; + WriteFile(CppName, "int main() {}"); + ClangTU = clang_parseTranslationUnit(Index, CppName.c_str(), nullptr, 0, + nullptr, 0, TUFlags); + CXFile cxf = clang_getFile(ClangTU, CppName.c_str()); + + CXString cxname = clang_getFileName(cxf); + ASSERT_TRUE(strstr(clang_getCString(cxname), CppName.c_str())); + clang_disposeString(cxname); + + cxname = clang_File_tryGetRealPathName(cxf); + ASSERT_TRUE(strstr(clang_getCString(cxname), CppName.c_str())); + clang_disposeString(cxname); +} TEST_F(LibclangReparseTest, Reparse) { const char *HeaderTop = "#ifndef H\n#define H\nstruct Foo { int bar;"; Index: cfe/trunk/tools/libclang/CIndex.cpp === --- cfe/trunk/tools/libclang/CIndex.cpp +++ cfe/trunk/tools/libclang/CIndex.cpp @@ -4249,6 +4249,14 @@ return FEnt1->getUniqueID() == FEnt2->getUniqueID(); } +CXString clang_File_tryGetRealPathName(CXFile SFile) { + if (!SFile) +return cxstring::createNull(); + + FileEntry *FEnt = static_cast(SFile); + return cxstring::createRef(FEnt->tryGetRealPathName()); +} + //===--===// // CXCursor Operations. //===--===// Index: cfe/trunk/tools/libclang/libclang.exports === --- cfe/trunk/tools/libclang/libclang.exports +++ cfe/trunk/tools/libclang/libclang.exports @@ -46,6 +46,7 @@ clang_Cursor_getModule clang_Cursor_getStorageClass clang_File_isEqual +clang_File_tryGetRealPathName clang_Module_getASTFile clang_Module_getParent clang_Module_getName Index: cfe/trunk/include/clang-c/Index.h === --- cfe/trunk/include/clang-c/Index.h +++ cfe/trunk/include/clang-c/Index.h @@ -425,6 +425,13 @@ CINDEX_LINKAGE int clang_File_isEqual(CXFile file1, CXFile file2); /** + * \brief Returns the real path name of \c file. + * + * An empty string may be returned. Use \c clang_getFileName() in that case. + */ +CINDEX_LINKAGE CXString clang_File_tryGetRealPathName(CXFile file); + +/** * @} */ Index: cfe/trunk/unittests/libclang/LibclangTest.cpp === --- cfe/trunk/unittests/libclang/LibclangTest.cpp +++ cfe/trunk/unittests/libclang/LibclangTest.cpp @@ -482,6 +482,21 @@ } }; +TEST_F(LibclangReparseTest, FileName) { + std::string CppName = "main.cpp"; + WriteFile(CppName, "int main() {}"); + ClangTU = clang_parseTranslationUnit(Index, CppName.c_str(), nullptr, 0, + nullptr, 0, TUFlags); + CXFile cxf = clang_getFile(ClangTU, CppName.c_str()); + + CXString cxname = clang_getFileName(cxf); + ASSERT_TRUE(strstr(clang_getCString(cxname), CppName.c_str())); + clang_disposeString(cxname); + + cxname = clang_File_tryGetRealPathName(cxf); + ASSERT_TRUE(strstr(clang_getCString(cxname), CppName.c_str())); + clang_disposeString(cxname); +} TEST_F(LibclangReparseTest, Reparse) { const char *HeaderTop = "#ifndef H\n#define H\nstruct Foo { int bar;"; Index: cfe/trunk/tools/libclang/CIndex.cpp === --- cfe/trunk/tools/libclang/CIndex.cpp +++ cfe/trunk/tools/libclang/CIndex.cpp @@ -4249,6 +4249,14 @@ return FEnt1->getUniqueID() == FEnt2->getUniqueID(); } +CXString clang_File_tryGetRealPathName(CXFile SFile) { + if (!SFile) +return cxstring::createNull(); + + FileEntry *FEnt = static_cast(SFile); + return cxstring::createRef(FEnt->tryGetRealPathName()); +} + //===--===// // CXCursor Operations. //===--===// Index: cfe/trunk/tools/libclang/libclang.exports === --- cfe/trunk/tools/libclang/libclang.exports +++ cfe/trunk/tools/libclang/libclang.exports @@ -46,6 +46,7 @@
[PATCH] D42893: [libclang] Add clang_File_tryGetRealPathName
MaskRay added a comment. Done. ninja -C ~/Dev/llvm/debug unittests/libclang/libclangTests ~/Dev/llvm/debug/tools/clang/unittests/libclang/libclangTests Repository: rC Clang https://reviews.llvm.org/D42893 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D42893: [libclang] Add clang_File_tryGetRealPathName
MaskRay updated this revision to Diff 141496. MaskRay added a comment. Add unittests/libclang/LibclangTest.cpp test Repository: rC Clang https://reviews.llvm.org/D42893 Files: include/clang-c/Index.h tools/libclang/CIndex.cpp tools/libclang/libclang.exports unittests/libclang/LibclangTest.cpp Index: unittests/libclang/LibclangTest.cpp === --- unittests/libclang/LibclangTest.cpp +++ unittests/libclang/LibclangTest.cpp @@ -482,6 +482,21 @@ } }; +TEST_F(LibclangReparseTest, FileName) { + std::string CppName = "main.cpp"; + WriteFile(CppName, "int main() {}"); + ClangTU = clang_parseTranslationUnit(Index, CppName.c_str(), nullptr, 0, + nullptr, 0, TUFlags); + CXFile cxf = clang_getFile(ClangTU, CppName.c_str()); + + CXString cxname = clang_getFileName(cxf); + ASSERT_TRUE(strstr(clang_getCString(cxname), CppName.c_str())); + clang_disposeString(cxname); + + cxname = clang_File_tryGetRealPathName(cxf); + ASSERT_TRUE(strstr(clang_getCString(cxname), CppName.c_str())); + clang_disposeString(cxname); +} TEST_F(LibclangReparseTest, Reparse) { const char *HeaderTop = "#ifndef H\n#define H\nstruct Foo { int bar;"; Index: tools/libclang/libclang.exports === --- tools/libclang/libclang.exports +++ tools/libclang/libclang.exports @@ -46,6 +46,7 @@ clang_Cursor_getModule clang_Cursor_getStorageClass clang_File_isEqual +clang_File_tryGetRealPathName clang_Module_getASTFile clang_Module_getParent clang_Module_getName Index: tools/libclang/CIndex.cpp === --- tools/libclang/CIndex.cpp +++ tools/libclang/CIndex.cpp @@ -4249,6 +4249,14 @@ return FEnt1->getUniqueID() == FEnt2->getUniqueID(); } +CXString clang_File_tryGetRealPathName(CXFile SFile) { + if (!SFile) +return cxstring::createNull(); + + FileEntry *FEnt = static_cast(SFile); + return cxstring::createRef(FEnt->tryGetRealPathName()); +} + //===--===// // CXCursor Operations. //===--===// Index: include/clang-c/Index.h === --- include/clang-c/Index.h +++ include/clang-c/Index.h @@ -424,6 +424,13 @@ */ CINDEX_LINKAGE int clang_File_isEqual(CXFile file1, CXFile file2); +/** + * \brief Returns the real path name of \c file. + * + * An empty string may be returned. Use \c clang_getFileName() in that case. + */ +CINDEX_LINKAGE CXString clang_File_tryGetRealPathName(CXFile file); + /** * @} */ Index: unittests/libclang/LibclangTest.cpp === --- unittests/libclang/LibclangTest.cpp +++ unittests/libclang/LibclangTest.cpp @@ -482,6 +482,21 @@ } }; +TEST_F(LibclangReparseTest, FileName) { + std::string CppName = "main.cpp"; + WriteFile(CppName, "int main() {}"); + ClangTU = clang_parseTranslationUnit(Index, CppName.c_str(), nullptr, 0, + nullptr, 0, TUFlags); + CXFile cxf = clang_getFile(ClangTU, CppName.c_str()); + + CXString cxname = clang_getFileName(cxf); + ASSERT_TRUE(strstr(clang_getCString(cxname), CppName.c_str())); + clang_disposeString(cxname); + + cxname = clang_File_tryGetRealPathName(cxf); + ASSERT_TRUE(strstr(clang_getCString(cxname), CppName.c_str())); + clang_disposeString(cxname); +} TEST_F(LibclangReparseTest, Reparse) { const char *HeaderTop = "#ifndef H\n#define H\nstruct Foo { int bar;"; Index: tools/libclang/libclang.exports === --- tools/libclang/libclang.exports +++ tools/libclang/libclang.exports @@ -46,6 +46,7 @@ clang_Cursor_getModule clang_Cursor_getStorageClass clang_File_isEqual +clang_File_tryGetRealPathName clang_Module_getASTFile clang_Module_getParent clang_Module_getName Index: tools/libclang/CIndex.cpp === --- tools/libclang/CIndex.cpp +++ tools/libclang/CIndex.cpp @@ -4249,6 +4249,14 @@ return FEnt1->getUniqueID() == FEnt2->getUniqueID(); } +CXString clang_File_tryGetRealPathName(CXFile SFile) { + if (!SFile) +return cxstring::createNull(); + + FileEntry *FEnt = static_cast(SFile); + return cxstring::createRef(FEnt->tryGetRealPathName()); +} + //===--===// // CXCursor Operations. //===--===// Index: include/clang-c/Index.h === --- include/clang-c/Index.h +++ include/clang-c/Index.h @@ -424,6 +424,13 @@ */ CINDEX_LINKAGE int clang_File_isEqual(CXFile file1, CXFile file2); +/** + *
[PATCH] D42893: [libclang] Add clang_File_tryGetRealPathName
MaskRay updated this revision to Diff 141492. MaskRay added a comment. Rebase Repository: rC Clang https://reviews.llvm.org/D42893 Files: include/clang-c/Index.h tools/libclang/CIndex.cpp tools/libclang/libclang.exports Index: tools/libclang/libclang.exports === --- tools/libclang/libclang.exports +++ tools/libclang/libclang.exports @@ -46,6 +46,7 @@ clang_Cursor_getModule clang_Cursor_getStorageClass clang_File_isEqual +clang_File_tryGetRealPathName clang_Module_getASTFile clang_Module_getParent clang_Module_getName Index: tools/libclang/CIndex.cpp === --- tools/libclang/CIndex.cpp +++ tools/libclang/CIndex.cpp @@ -4249,6 +4249,14 @@ return FEnt1->getUniqueID() == FEnt2->getUniqueID(); } +CXString clang_File_tryGetRealPathName(CXFile SFile) { + if (!SFile) +return cxstring::createNull(); + + FileEntry *FEnt = static_cast(SFile); + return cxstring::createRef(FEnt->tryGetRealPathName()); +} + //===--===// // CXCursor Operations. //===--===// Index: include/clang-c/Index.h === --- include/clang-c/Index.h +++ include/clang-c/Index.h @@ -424,6 +424,13 @@ */ CINDEX_LINKAGE int clang_File_isEqual(CXFile file1, CXFile file2); +/** + * \brief Returns the real path name of \c file. + * + * An empty string may be returned. Use \c clang_getFileName() in that case. + */ +CINDEX_LINKAGE CXString clang_File_tryGetRealPathName(CXFile file); + /** * @} */ Index: tools/libclang/libclang.exports === --- tools/libclang/libclang.exports +++ tools/libclang/libclang.exports @@ -46,6 +46,7 @@ clang_Cursor_getModule clang_Cursor_getStorageClass clang_File_isEqual +clang_File_tryGetRealPathName clang_Module_getASTFile clang_Module_getParent clang_Module_getName Index: tools/libclang/CIndex.cpp === --- tools/libclang/CIndex.cpp +++ tools/libclang/CIndex.cpp @@ -4249,6 +4249,14 @@ return FEnt1->getUniqueID() == FEnt2->getUniqueID(); } +CXString clang_File_tryGetRealPathName(CXFile SFile) { + if (!SFile) +return cxstring::createNull(); + + FileEntry *FEnt = static_cast(SFile); + return cxstring::createRef(FEnt->tryGetRealPathName()); +} + //===--===// // CXCursor Operations. //===--===// Index: include/clang-c/Index.h === --- include/clang-c/Index.h +++ include/clang-c/Index.h @@ -424,6 +424,13 @@ */ CINDEX_LINKAGE int clang_File_isEqual(CXFile file1, CXFile file2); +/** + * \brief Returns the real path name of \c file. + * + * An empty string may be returned. Use \c clang_getFileName() in that case. + */ +CINDEX_LINKAGE CXString clang_File_tryGetRealPathName(CXFile file); + /** * @} */ ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D42893: [libclang] Add clang_File_tryGetRealPathName
jbcoe added a comment. Tests for libclang are in clang/unittests/libclang/LibclangTest.cpp Given the surgical nature of this change I hope it will be quick to add a test. Repository: rC Clang https://reviews.llvm.org/D42893 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D42893: [libclang] Add clang_File_tryGetRealPathName
jbcoe added a comment. I’ll see if I can find a suitable location for a test. Repository: rC Clang https://reviews.llvm.org/D42893 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D42893: [libclang] Add clang_File_tryGetRealPathName
MaskRay added a comment. There is no unittest but I have verified with a C++ language server on Arch Linux. Without using this function, cquery/ccls will not be able to index system header files because of excessive .. in the path returned by clang_getFileName. Repository: rC Clang https://reviews.llvm.org/D42893 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D42893: [libclang] Add clang_File_tryGetRealPathName
MaskRay added a comment. In https://reviews.llvm.org/D42893#1053754, @jbcoe wrote: > Can you add some simple tests? Where should I add tests? I cannot find tests for other clang_File_* functions. Repository: rC Clang https://reviews.llvm.org/D42893 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D42893: [libclang] Add clang_File_tryGetRealPathName
jbcoe requested changes to this revision. jbcoe added a comment. This revision now requires changes to proceed. Can you add some simple tests? Repository: rC Clang https://reviews.llvm.org/D42893 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D42893: [libclang] Add clang_File_tryGetRealPathName
MaskRay added a comment. Ping Repository: rC Clang https://reviews.llvm.org/D42893 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D42893: [libclang] Add clang_File_tryGetRealPathName
MaskRay added a comment. ping Repository: rC Clang https://reviews.llvm.org/D42893 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D42893: [libclang] Add clang_File_tryGetRealPathName
MaskRay added a comment. On Arch Linux, `../lib64/gcc/x86_64-pc-linux-gnu/7.2.1/../../../../include/c++/7.2.1` (Name) resolves to a path that requires leading path components (`/usr/include`), this kind of resembles jailbreak. Repository: rC Clang https://reviews.llvm.org/D42893 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D42893: [libclang] Add clang_File_tryGetRealPathName
MaskRay updated this revision to Diff 132774. MaskRay added a comment. Increase CINDEX_VERSION_MINOR Repository: rC Clang https://reviews.llvm.org/D42893 Files: include/clang-c/Index.h tools/libclang/CIndex.cpp tools/libclang/libclang.exports Index: tools/libclang/libclang.exports === --- tools/libclang/libclang.exports +++ tools/libclang/libclang.exports @@ -46,6 +46,7 @@ clang_Cursor_getModule clang_Cursor_getStorageClass clang_File_isEqual +clang_File_tryGetRealPathName clang_Module_getASTFile clang_Module_getParent clang_Module_getName Index: tools/libclang/CIndex.cpp === --- tools/libclang/CIndex.cpp +++ tools/libclang/CIndex.cpp @@ -4249,6 +4249,14 @@ return FEnt1->getUniqueID() == FEnt2->getUniqueID(); } +CXString clang_File_tryGetRealPathName(CXFile SFile) { + if (!SFile) +return cxstring::createNull(); + + FileEntry *FEnt = static_cast(SFile); + return cxstring::createRef(FEnt->tryGetRealPathName()); +} + //===--===// // CXCursor Operations. //===--===// Index: include/clang-c/Index.h === --- include/clang-c/Index.h +++ include/clang-c/Index.h @@ -32,7 +32,7 @@ * compatible, thus CINDEX_VERSION_MAJOR is expected to remain stable. */ #define CINDEX_VERSION_MAJOR 0 -#define CINDEX_VERSION_MINOR 47 +#define CINDEX_VERSION_MINOR 48 #define CINDEX_VERSION_ENCODE(major, minor) ( \ ((major) * 1) \ @@ -424,6 +424,13 @@ */ CINDEX_LINKAGE int clang_File_isEqual(CXFile file1, CXFile file2); +/** + * \brief Returns the real path name of \c file. + * + * An empty string may be returned. Use \c clang_getFileName() in that case. + */ +CINDEX_LINKAGE CXString clang_File_tryGetRealPathName(CXFile file); + /** * @} */ Index: tools/libclang/libclang.exports === --- tools/libclang/libclang.exports +++ tools/libclang/libclang.exports @@ -46,6 +46,7 @@ clang_Cursor_getModule clang_Cursor_getStorageClass clang_File_isEqual +clang_File_tryGetRealPathName clang_Module_getASTFile clang_Module_getParent clang_Module_getName Index: tools/libclang/CIndex.cpp === --- tools/libclang/CIndex.cpp +++ tools/libclang/CIndex.cpp @@ -4249,6 +4249,14 @@ return FEnt1->getUniqueID() == FEnt2->getUniqueID(); } +CXString clang_File_tryGetRealPathName(CXFile SFile) { + if (!SFile) +return cxstring::createNull(); + + FileEntry *FEnt = static_cast(SFile); + return cxstring::createRef(FEnt->tryGetRealPathName()); +} + //===--===// // CXCursor Operations. //===--===// Index: include/clang-c/Index.h === --- include/clang-c/Index.h +++ include/clang-c/Index.h @@ -32,7 +32,7 @@ * compatible, thus CINDEX_VERSION_MAJOR is expected to remain stable. */ #define CINDEX_VERSION_MAJOR 0 -#define CINDEX_VERSION_MINOR 47 +#define CINDEX_VERSION_MINOR 48 #define CINDEX_VERSION_ENCODE(major, minor) ( \ ((major) * 1) \ @@ -424,6 +424,13 @@ */ CINDEX_LINKAGE int clang_File_isEqual(CXFile file1, CXFile file2); +/** + * \brief Returns the real path name of \c file. + * + * An empty string may be returned. Use \c clang_getFileName() in that case. + */ +CINDEX_LINKAGE CXString clang_File_tryGetRealPathName(CXFile file); + /** * @} */ ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D42893: [libclang] Add clang_File_tryGetRealPathName
MaskRay updated this revision to Diff 132775. MaskRay added a comment. description Repository: rC Clang https://reviews.llvm.org/D42893 Files: include/clang-c/Index.h tools/libclang/CIndex.cpp tools/libclang/libclang.exports Index: tools/libclang/libclang.exports === --- tools/libclang/libclang.exports +++ tools/libclang/libclang.exports @@ -46,6 +46,7 @@ clang_Cursor_getModule clang_Cursor_getStorageClass clang_File_isEqual +clang_File_tryGetRealPathName clang_Module_getASTFile clang_Module_getParent clang_Module_getName Index: tools/libclang/CIndex.cpp === --- tools/libclang/CIndex.cpp +++ tools/libclang/CIndex.cpp @@ -4249,6 +4249,14 @@ return FEnt1->getUniqueID() == FEnt2->getUniqueID(); } +CXString clang_File_tryGetRealPathName(CXFile SFile) { + if (!SFile) +return cxstring::createNull(); + + FileEntry *FEnt = static_cast(SFile); + return cxstring::createRef(FEnt->tryGetRealPathName()); +} + //===--===// // CXCursor Operations. //===--===// Index: include/clang-c/Index.h === --- include/clang-c/Index.h +++ include/clang-c/Index.h @@ -32,7 +32,7 @@ * compatible, thus CINDEX_VERSION_MAJOR is expected to remain stable. */ #define CINDEX_VERSION_MAJOR 0 -#define CINDEX_VERSION_MINOR 47 +#define CINDEX_VERSION_MINOR 48 #define CINDEX_VERSION_ENCODE(major, minor) ( \ ((major) * 1) \ @@ -424,6 +424,13 @@ */ CINDEX_LINKAGE int clang_File_isEqual(CXFile file1, CXFile file2); +/** + * \brief Returns the real path name of \c file. + * + * An empty string may be returned. Use \c clang_getFileName() in that case. + */ +CINDEX_LINKAGE CXString clang_File_tryGetRealPathName(CXFile file); + /** * @} */ Index: tools/libclang/libclang.exports === --- tools/libclang/libclang.exports +++ tools/libclang/libclang.exports @@ -46,6 +46,7 @@ clang_Cursor_getModule clang_Cursor_getStorageClass clang_File_isEqual +clang_File_tryGetRealPathName clang_Module_getASTFile clang_Module_getParent clang_Module_getName Index: tools/libclang/CIndex.cpp === --- tools/libclang/CIndex.cpp +++ tools/libclang/CIndex.cpp @@ -4249,6 +4249,14 @@ return FEnt1->getUniqueID() == FEnt2->getUniqueID(); } +CXString clang_File_tryGetRealPathName(CXFile SFile) { + if (!SFile) +return cxstring::createNull(); + + FileEntry *FEnt = static_cast(SFile); + return cxstring::createRef(FEnt->tryGetRealPathName()); +} + //===--===// // CXCursor Operations. //===--===// Index: include/clang-c/Index.h === --- include/clang-c/Index.h +++ include/clang-c/Index.h @@ -32,7 +32,7 @@ * compatible, thus CINDEX_VERSION_MAJOR is expected to remain stable. */ #define CINDEX_VERSION_MAJOR 0 -#define CINDEX_VERSION_MINOR 47 +#define CINDEX_VERSION_MINOR 48 #define CINDEX_VERSION_ENCODE(major, minor) ( \ ((major) * 1) \ @@ -424,6 +424,13 @@ */ CINDEX_LINKAGE int clang_File_isEqual(CXFile file1, CXFile file2); +/** + * \brief Returns the real path name of \c file. + * + * An empty string may be returned. Use \c clang_getFileName() in that case. + */ +CINDEX_LINKAGE CXString clang_File_tryGetRealPathName(CXFile file); + /** * @} */ ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D42893: [libclang] Add clang_File_tryGetRealPathName
MaskRay updated this revision to Diff 132773. MaskRay added a comment. description Repository: rC Clang https://reviews.llvm.org/D42893 Files: include/clang-c/Index.h tools/libclang/CIndex.cpp tools/libclang/libclang.exports Index: tools/libclang/libclang.exports === --- tools/libclang/libclang.exports +++ tools/libclang/libclang.exports @@ -46,6 +46,7 @@ clang_Cursor_getModule clang_Cursor_getStorageClass clang_File_isEqual +clang_File_tryGetRealPathName clang_Module_getASTFile clang_Module_getParent clang_Module_getName Index: tools/libclang/CIndex.cpp === --- tools/libclang/CIndex.cpp +++ tools/libclang/CIndex.cpp @@ -4249,6 +4249,14 @@ return FEnt1->getUniqueID() == FEnt2->getUniqueID(); } +CXString clang_File_tryGetRealPathName(CXFile SFile) { + if (!SFile) +return cxstring::createNull(); + + FileEntry *FEnt = static_cast(SFile); + return cxstring::createRef(FEnt->tryGetRealPathName()); +} + //===--===// // CXCursor Operations. //===--===// Index: include/clang-c/Index.h === --- include/clang-c/Index.h +++ include/clang-c/Index.h @@ -424,6 +424,13 @@ */ CINDEX_LINKAGE int clang_File_isEqual(CXFile file1, CXFile file2); +/** + * \brief Returns the real path name of \c file. + * + * An empty string may be returned. Use \c clang_getFileName() in that case. + */ +CINDEX_LINKAGE CXString clang_File_tryGetRealPathName(CXFile file); + /** * @} */ Index: tools/libclang/libclang.exports === --- tools/libclang/libclang.exports +++ tools/libclang/libclang.exports @@ -46,6 +46,7 @@ clang_Cursor_getModule clang_Cursor_getStorageClass clang_File_isEqual +clang_File_tryGetRealPathName clang_Module_getASTFile clang_Module_getParent clang_Module_getName Index: tools/libclang/CIndex.cpp === --- tools/libclang/CIndex.cpp +++ tools/libclang/CIndex.cpp @@ -4249,6 +4249,14 @@ return FEnt1->getUniqueID() == FEnt2->getUniqueID(); } +CXString clang_File_tryGetRealPathName(CXFile SFile) { + if (!SFile) +return cxstring::createNull(); + + FileEntry *FEnt = static_cast(SFile); + return cxstring::createRef(FEnt->tryGetRealPathName()); +} + //===--===// // CXCursor Operations. //===--===// Index: include/clang-c/Index.h === --- include/clang-c/Index.h +++ include/clang-c/Index.h @@ -424,6 +424,13 @@ */ CINDEX_LINKAGE int clang_File_isEqual(CXFile file1, CXFile file2); +/** + * \brief Returns the real path name of \c file. + * + * An empty string may be returned. Use \c clang_getFileName() in that case. + */ +CINDEX_LINKAGE CXString clang_File_tryGetRealPathName(CXFile file); + /** * @} */ ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D42893: [libclang] Add clang_File_tryGetRealPathName
MaskRay created this revision. Herald added a subscriber: cfe-commits. clang_getFileName() may return a path relative to WorkingDir. On Arch Linux, during clang_indexTranslationUnit(), clang_getFileName() on CXIdxIncludedIncludedFileInfo::file may return "/../lib64/gcc/x86_64-pc-linux-gnu/7.3.0/../../../../include/c++/7.3.0/string", for `#include `. I presume WorkingDir is somehow changed to /usr/lib or /usr/include and clang_getFileName() returns a path relative to WorkingDir. clang_File_tryGetRealPathName() returns a better file name more useful for the indexer in this case. Repository: rC Clang https://reviews.llvm.org/D42893 Files: include/clang-c/Index.h tools/libclang/CIndex.cpp tools/libclang/libclang.exports Index: tools/libclang/libclang.exports === --- tools/libclang/libclang.exports +++ tools/libclang/libclang.exports @@ -46,6 +46,7 @@ clang_Cursor_getModule clang_Cursor_getStorageClass clang_File_isEqual +clang_File_tryGetRealPathName clang_Module_getASTFile clang_Module_getParent clang_Module_getName Index: tools/libclang/CIndex.cpp === --- tools/libclang/CIndex.cpp +++ tools/libclang/CIndex.cpp @@ -4249,6 +4249,14 @@ return FEnt1->getUniqueID() == FEnt2->getUniqueID(); } +CXString clang_File_tryGetRealPathName(CXFile SFile) { + if (!SFile) +return cxstring::createNull(); + + FileEntry *FEnt = static_cast(SFile); + return cxstring::createRef(FEnt->tryGetRealPathName()); +} + //===--===// // CXCursor Operations. //===--===// Index: include/clang-c/Index.h === --- include/clang-c/Index.h +++ include/clang-c/Index.h @@ -424,6 +424,13 @@ */ CINDEX_LINKAGE int clang_File_isEqual(CXFile file1, CXFile file2); +/** + * \brief Returns the real path name of \c file. + * + * An empty string may be returned. Use \c clang_getFileName() in that case. + */ +CINDEX_LINKAGE CXString clang_File_tryGetRealPathName(CXFile file); + /** * @} */ Index: tools/libclang/libclang.exports === --- tools/libclang/libclang.exports +++ tools/libclang/libclang.exports @@ -46,6 +46,7 @@ clang_Cursor_getModule clang_Cursor_getStorageClass clang_File_isEqual +clang_File_tryGetRealPathName clang_Module_getASTFile clang_Module_getParent clang_Module_getName Index: tools/libclang/CIndex.cpp === --- tools/libclang/CIndex.cpp +++ tools/libclang/CIndex.cpp @@ -4249,6 +4249,14 @@ return FEnt1->getUniqueID() == FEnt2->getUniqueID(); } +CXString clang_File_tryGetRealPathName(CXFile SFile) { + if (!SFile) +return cxstring::createNull(); + + FileEntry *FEnt = static_cast(SFile); + return cxstring::createRef(FEnt->tryGetRealPathName()); +} + //===--===// // CXCursor Operations. //===--===// Index: include/clang-c/Index.h === --- include/clang-c/Index.h +++ include/clang-c/Index.h @@ -424,6 +424,13 @@ */ CINDEX_LINKAGE int clang_File_isEqual(CXFile file1, CXFile file2); +/** + * \brief Returns the real path name of \c file. + * + * An empty string may be returned. Use \c clang_getFileName() in that case. + */ +CINDEX_LINKAGE CXString clang_File_tryGetRealPathName(CXFile file); + /** * @} */ ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits