diff options
author | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2021-10-21 18:33:24 -0700 |
---|---|---|
committer | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2021-10-29 12:09:41 -0700 |
commit | 99023627010bbfefb71e25a2b4d056de1cbd354e (patch) | |
tree | a7ad434f3071922aac052bf9eb23c29c577cb885 /llvm/lib/Support/Path.cpp | |
parent | 51ce567b38ec92163ec05c9bef0bd0e2bd53c667 (diff) | |
download | llvm-99023627010bbfefb71e25a2b4d056de1cbd354e.zip llvm-99023627010bbfefb71e25a2b4d056de1cbd354e.tar.gz llvm-99023627010bbfefb71e25a2b4d056de1cbd354e.tar.bz2 |
Support: Use sys::path::is_style_{posix,windows}() in a few places
Use the new sys::path::is_style_posix() and is_style_windows() in a few
places that need to detect the system's native path style.
In llvm/lib/Support/Path.cpp, this patch removes most uses of the
private `real_style()`, where is_style_posix() and is_style_windows()
are just a little tidier.
Elsewhere, this removes `_WIN32` macro checks. Added a FIXME to a
FileManagerTest that seemed fishy, but maintained the existing
behaviour.
Differential Revision: https://reviews.llvm.org/D112289
Diffstat (limited to 'llvm/lib/Support/Path.cpp')
-rw-r--r-- | llvm/lib/Support/Path.cpp | 32 |
1 files changed, 15 insertions, 17 deletions
diff --git a/llvm/lib/Support/Path.cpp b/llvm/lib/Support/Path.cpp index 89fe923..a5045f6 100644 --- a/llvm/lib/Support/Path.cpp +++ b/llvm/lib/Support/Path.cpp @@ -64,7 +64,7 @@ namespace { if (path.empty()) return path; - if (real_style(style) == Style::windows) { + if (is_style_windows(style)) { // C: if (path.size() >= 2 && std::isalpha(static_cast<unsigned char>(path[0])) && path[1] == ':') @@ -96,7 +96,7 @@ namespace { size_t pos = str.find_last_of(separators(style), str.size() - 1); - if (real_style(style) == Style::windows) { + if (is_style_windows(style)) { if (pos == StringRef::npos) pos = str.find_last_of(':', str.size() - 2); } @@ -111,7 +111,7 @@ namespace { // directory in str, it returns StringRef::npos. size_t root_dir_start(StringRef str, Style style) { // case "c:/" - if (real_style(style) == Style::windows) { + if (is_style_windows(style)) { if (str.size() > 2 && str[1] == ':' && is_separator(str[2], style)) return 2; } @@ -257,7 +257,7 @@ const_iterator &const_iterator::operator++() { // Root dir. if (was_net || // c:/ - (real_style(S) == Style::windows && Component.endswith(":"))) { + (is_style_windows(S) && Component.endswith(":"))) { Component = Path.substr(Position, 1); return *this; } @@ -346,7 +346,7 @@ StringRef root_path(StringRef path, Style style) { if (b != e) { bool has_net = b->size() > 2 && is_separator((*b)[0], style) && (*b)[1] == (*b)[0]; - bool has_drive = (real_style(style) == Style::windows) && b->endswith(":"); + bool has_drive = is_style_windows(style) && b->endswith(":"); if (has_net || has_drive) { if ((++pos != e) && is_separator((*pos)[0], style)) { @@ -371,7 +371,7 @@ StringRef root_name(StringRef path, Style style) { if (b != e) { bool has_net = b->size() > 2 && is_separator((*b)[0], style) && (*b)[1] == (*b)[0]; - bool has_drive = (real_style(style) == Style::windows) && b->endswith(":"); + bool has_drive = is_style_windows(style) && b->endswith(":"); if (has_net || has_drive) { // just {C:,//net}, return the first component. @@ -388,7 +388,7 @@ StringRef root_directory(StringRef path, Style style) { if (b != e) { bool has_net = b->size() > 2 && is_separator((*b)[0], style) && (*b)[1] == (*b)[0]; - bool has_drive = (real_style(style) == Style::windows) && b->endswith(":"); + bool has_drive = is_style_windows(style) && b->endswith(":"); if ((has_net || has_drive) && // {C:,//net}, skip to the next component. @@ -495,7 +495,7 @@ void replace_extension(SmallVectorImpl<char> &path, const Twine &extension, static bool starts_with(StringRef Path, StringRef Prefix, Style style = Style::native) { // Windows prefix matching : case and separator insensitive - if (real_style(style) == Style::windows) { + if (is_style_windows(style)) { if (Path.size() < Prefix.size()) return false; for (size_t I = 0, E = Prefix.size(); I != E; ++I) { @@ -546,7 +546,7 @@ void native(const Twine &path, SmallVectorImpl<char> &result, Style style) { void native(SmallVectorImpl<char> &Path, Style style) { if (Path.empty()) return; - if (real_style(style) == Style::windows) { + if (is_style_windows(style)) { std::replace(Path.begin(), Path.end(), '/', '\\'); if (Path[0] == '~' && (Path.size() == 1 || is_separator(Path[1], style))) { SmallString<128> PathHome; @@ -560,7 +560,7 @@ void native(SmallVectorImpl<char> &Path, Style style) { } std::string convert_to_slash(StringRef path, Style style) { - if (real_style(style) != Style::windows) + if (is_style_posix(style)) return std::string(path); std::string s = path.str(); @@ -595,13 +595,13 @@ StringRef extension(StringRef path, Style style) { bool is_separator(char value, Style style) { if (value == '/') return true; - if (real_style(style) == Style::windows) + if (is_style_windows(style)) return value == '\\'; return false; } StringRef get_separator(Style style) { - if (real_style(style) == Style::windows) + if (is_style_windows(style)) return "\\"; return "/"; } @@ -667,8 +667,7 @@ bool is_absolute(const Twine &path, Style style) { StringRef p = path.toStringRef(path_storage); bool rootDir = has_root_directory(p, style); - bool rootName = - (real_style(style) != Style::windows) || has_root_name(p, style); + bool rootName = is_style_posix(style) || has_root_name(p, style); return rootDir && rootName; } @@ -682,7 +681,7 @@ bool is_absolute_gnu(const Twine &path, Style style) { if (!p.empty() && is_separator(p.front(), style)) return true; - if (real_style(style) == Style::windows) { + if (is_style_windows(style)) { // Handle drive letter pattern (a character followed by ':') on Windows. if (p.size() >= 2 && (p[0] && p[1] == ':')) return true; @@ -902,8 +901,7 @@ void make_absolute(const Twine ¤t_directory, bool rootName = path::has_root_name(p); // Already absolute. - if ((rootName || real_style(Style::native) != Style::windows) && - rootDirectory) + if ((rootName || is_style_posix(Style::native)) && rootDirectory) return; // All of the following conditions will need the current directory. |