diff options
author | Michael Kruse <llvm-project@meinersbur.de> | 2020-10-23 09:50:30 -0500 |
---|---|---|
committer | Michael Kruse <llvm-project@meinersbur.de> | 2020-10-23 22:22:37 -0500 |
commit | b57937861f68305068d8a35154811b4303ce52e5 (patch) | |
tree | 647db9cabb44c4d320293b68a026ce852df71b81 /flang/lib/Parser/source.cpp | |
parent | e92eeaf3c21923151cf86c706e396b613145f142 (diff) | |
download | llvm-b57937861f68305068d8a35154811b4303ce52e5.zip llvm-b57937861f68305068d8a35154811b4303ce52e5.tar.gz llvm-b57937861f68305068d8a35154811b4303ce52e5.tar.bz2 |
[flang][windows] Support platform-specific path separator.
Remove the assumption that the path separator is `/`. Use functions from `llvm::sys::path` instead.
Reviewed By: isuruf, klausler
Differential Revision: https://reviews.llvm.org/D89369
Diffstat (limited to 'flang/lib/Parser/source.cpp')
-rw-r--r-- | flang/lib/Parser/source.cpp | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/flang/lib/Parser/source.cpp b/flang/lib/Parser/source.cpp index 693138c..11cd591 100644 --- a/flang/lib/Parser/source.cpp +++ b/flang/lib/Parser/source.cpp @@ -11,6 +11,7 @@ #include "flang/Parser/char-buffer.h" #include "llvm/Support/Errno.h" #include "llvm/Support/FileSystem.h" +#include "llvm/Support/Path.h" #include "llvm/Support/raw_ostream.h" #include <algorithm> #include <memory> @@ -50,21 +51,23 @@ void SourceFile::IdentifyPayload() { } std::string DirectoryName(std::string path) { - auto lastSlash{path.rfind("/")}; - return lastSlash == std::string::npos ? path : path.substr(0, lastSlash); + llvm::SmallString<128> pathBuf{path}; + llvm::sys::path::remove_filename(pathBuf); + return pathBuf.str().str(); } std::string LocateSourceFile( std::string name, const std::vector<std::string> &searchPath) { - if (name.empty() || name == "-" || name[0] == '/') { + if (name.empty() || name == "-" || llvm::sys::path::is_absolute(name)) { return name; } for (const std::string &dir : searchPath) { - std::string path{dir + '/' + name}; + llvm::SmallString<128> path{dir}; + llvm::sys::path::append(path, name); bool isDir{false}; auto er = llvm::sys::fs::is_directory(path, isDir); if (!er && !isDir) { - return path; + return path.str().str(); } } return name; |