[PATCH] D42893: [libclang] Add clang_File_tryGetRealPathName
Fangrui Song via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sat Apr 7 13:53:55 PDT 2018
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&id=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<FileEntry *>(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);
+
+/**
* @}
*/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D42893.141511.patch
Type: text/x-patch
Size: 2582 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180407/0b2376dc/attachment.bin>
More information about the cfe-commits
mailing list