diff options
author | Chaoren Lin <chaorenl@google.com> | 2015-05-28 17:02:45 +0000 |
---|---|---|
committer | Chaoren Lin <chaorenl@google.com> | 2015-05-28 17:02:45 +0000 |
commit | 1c614fedf95a04f3d75c7562e96d21b5d732d6b1 (patch) | |
tree | 5bd9c9e4939b6a22e51ccbaf0cc9df0df8e86a23 /lldb/source/Host/common/FileSpec.cpp | |
parent | 3adf9b8d80172e3c9a63b1578fc5dc9eea95c1ef (diff) | |
download | bcm5719-llvm-1c614fedf95a04f3d75c7562e96d21b5d732d6b1.tar.gz bcm5719-llvm-1c614fedf95a04f3d75c7562e96d21b5d732d6b1.zip |
Make FileSpec::Dump use FileSpec::GetPath(), not the other way around.
Summary:
Fix FileSpec::Dump() to output denormalized path.
See D9942 for previous discussions.
Reviewers: zturner
Reviewed By: zturner
Subscribers: lldb-commits
Differential Revision: http://reviews.llvm.org/D10077
llvm-svn: 238440
Diffstat (limited to 'lldb/source/Host/common/FileSpec.cpp')
-rw-r--r-- | lldb/source/Host/common/FileSpec.cpp | 106 |
1 files changed, 62 insertions, 44 deletions
diff --git a/lldb/source/Host/common/FileSpec.cpp b/lldb/source/Host/common/FileSpec.cpp index 7f0407578e1..c0efa71aad1 100644 --- a/lldb/source/Host/common/FileSpec.cpp +++ b/lldb/source/Host/common/FileSpec.cpp @@ -47,7 +47,45 @@ using namespace lldb; using namespace lldb_private; -static bool +namespace { + +bool +PathSyntaxIsPosix(FileSpec::PathSyntax syntax) +{ + return (syntax == FileSpec::ePathSyntaxPosix || + (syntax == FileSpec::ePathSyntaxHostNative && + FileSystem::GetNativePathSyntax() == FileSpec::ePathSyntaxPosix)); +} + +char +GetPathSeparator(FileSpec::PathSyntax syntax) +{ + return PathSyntaxIsPosix(syntax) ? '/' : '\\'; +} + +void +Normalize(llvm::SmallVectorImpl<char> &path, FileSpec::PathSyntax syntax) +{ + if (PathSyntaxIsPosix(syntax)) return; + + std::replace(path.begin(), path.end(), '\\', '/'); + // Windows path can have \\ slashes which can be changed by replace + // call above to //. Here we remove the duplicate. + auto iter = std::unique ( path.begin(), path.end(), + []( char &c1, char &c2 ){ + return (c1 == '/' && c2 == '/');}); + path.erase(iter, path.end()); +} + +void +Denormalize(llvm::SmallVectorImpl<char> &path, FileSpec::PathSyntax syntax) +{ + if (PathSyntaxIsPosix(syntax)) return; + + std::replace(path.begin(), path.end(), '/', '\\'); +} + +bool GetFileStats (const FileSpec *file_spec, struct stat *stats_ptr) { char resolved_path[PATH_MAX]; @@ -56,6 +94,8 @@ GetFileStats (const FileSpec *file_spec, struct stat *stats_ptr) return false; } +} + // Resolves the username part of a path of the form ~user/other/directories, and // writes the result into dst_path. This will also resolve "~" to the current user. // If you want to complete "~" to the list of users, pass it to ResolvePartialUsername. @@ -252,30 +292,6 @@ FileSpec::operator= (const FileSpec& rhs) return *this; } -void FileSpec::Normalize(llvm::SmallVectorImpl<char> &path, PathSyntax syntax) -{ - if (syntax == ePathSyntaxPosix || - (syntax == ePathSyntaxHostNative && FileSystem::GetNativePathSyntax() == ePathSyntaxPosix)) - return; - - std::replace(path.begin(), path.end(), '\\', '/'); - // Windows path can have \\ slashes which can be changed by replace - // call above to //. Here we remove the duplicate. - auto iter = std::unique ( path.begin(), path.end(), - []( char &c1, char &c2 ){ - return (c1 == '/' && c2 == '/');}); - path.erase(iter, path.end()); -} - -void FileSpec::DeNormalize(llvm::SmallVectorImpl<char> &path, PathSyntax syntax) -{ - if (syntax == ePathSyntaxPosix || - (syntax == ePathSyntaxHostNative && FileSystem::GetNativePathSyntax() == ePathSyntaxPosix)) - return; - - std::replace(path.begin(), path.end(), '/', '\\'); -} - //------------------------------------------------------------------ // Update the contents of this object with a new path. The path will // be split up into a directory and filename and stored as uniqued @@ -609,15 +625,15 @@ FileSpec::RemoveBackupDots (const ConstString &input_const_str, ConstString &res // directory delimiter, and the filename. //------------------------------------------------------------------ void -FileSpec::Dump(Stream *s, bool trailing_slash) const +FileSpec::Dump(Stream *s) const { if (s) { - m_directory.Dump(s); - if ((m_filename || trailing_slash) && m_directory && - !m_directory.GetStringRef().endswith("/")) - s->PutChar('/'); - m_filename.Dump(s); + std::string path{GetPath(true)}; + s->PutCString(path.c_str()); + char path_separator = GetPathSeparator(m_syntax); + if (!m_filename && !path.empty() && path.back() != path_separator) + s->PutChar(path_separator); } } @@ -816,12 +832,14 @@ FileSpec::GetPath(bool denormalize) const void FileSpec::GetPath(llvm::SmallVectorImpl<char> &path, bool denormalize) const { - StreamString stream; - Dump(&stream, false); - path.append(stream.GetString().begin(), stream.GetString().end()); + path.append(m_directory.GetStringRef().begin(), m_directory.GetStringRef().end()); + if (m_directory) + path.insert(path.end(), '/'); + path.append(m_filename.GetStringRef().begin(), m_filename.GetStringRef().end()); Normalize(path, m_syntax); + if (path.size() > 1 && path.back() == '/') path.pop_back(); if (denormalize && !path.empty()) - DeNormalize(path, m_syntax); + Denormalize(path, m_syntax); } ConstString @@ -1383,15 +1401,7 @@ FileSpec::IsRelativeToCurrentWorkingDirectory () const if (directory.size() > 0) { - if (m_syntax == ePathSyntaxWindows) - { - if (directory.size() >= 2 && directory[1] == ':') - return false; - if (directory[0] == '/') - return false; - return true; - } - else + if (PathSyntaxIsPosix(m_syntax)) { // If the path doesn't start with '/' or '~', return true switch (directory[0]) @@ -1403,6 +1413,14 @@ FileSpec::IsRelativeToCurrentWorkingDirectory () const return true; } } + else + { + if (directory.size() >= 2 && directory[1] == ':') + return false; + if (directory[0] == '/') + return false; + return true; + } } else if (m_filename) { |