aboutsummaryrefslogtreecommitdiff
path: root/lldb/source/Utility/FileSpec.cpp
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2023-07-26 19:03:47 +0000
committerDimitry Andric <dim@FreeBSD.org>2023-07-26 19:04:23 +0000
commit7fa27ce4a07f19b07799a767fc29416f3b625afb (patch)
tree27825c83636c4de341eb09a74f49f5d38a15d165 /lldb/source/Utility/FileSpec.cpp
parente3b557809604d036af6e00c60f012c2025b59a5e (diff)
Diffstat (limited to 'lldb/source/Utility/FileSpec.cpp')
-rw-r--r--lldb/source/Utility/FileSpec.cpp40
1 files changed, 27 insertions, 13 deletions
diff --git a/lldb/source/Utility/FileSpec.cpp b/lldb/source/Utility/FileSpec.cpp
index 7ff57307dec5..eb34ef97cea0 100644
--- a/lldb/source/Utility/FileSpec.cpp
+++ b/lldb/source/Utility/FileSpec.cpp
@@ -12,13 +12,14 @@
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringRef.h"
-#include "llvm/ADT/Triple.h"
#include "llvm/ADT/Twine.h"
#include "llvm/Support/ErrorOr.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Program.h"
#include "llvm/Support/raw_ostream.h"
+#include "llvm/TargetParser/Triple.h"
#include <algorithm>
#include <optional>
@@ -399,9 +400,8 @@ void FileSpec::GetPath(llvm::SmallVectorImpl<char> &path,
Denormalize(path, m_style);
}
-ConstString FileSpec::GetFileNameExtension() const {
- return ConstString(
- llvm::sys::path::extension(m_filename.GetStringRef(), m_style));
+llvm::StringRef FileSpec::GetFileNameExtension() const {
+ return llvm::sys::path::extension(m_filename.GetStringRef(), m_style);
}
ConstString FileSpec::GetFileNameStrippingExtension() const {
@@ -430,12 +430,6 @@ FileSpec FileSpec::CopyByRemovingLastPathComponent() const {
return *this;
}
-ConstString FileSpec::GetLastPathComponent() const {
- llvm::SmallString<64> current_path;
- GetPath(current_path, false);
- return ConstString(llvm::sys::path::filename(current_path, m_style));
-}
-
void FileSpec::PrependPathComponent(llvm::StringRef component) {
llvm::SmallString<64> new_path(component);
llvm::SmallString<64> current_path;
@@ -470,6 +464,26 @@ bool FileSpec::RemoveLastPathComponent() {
}
return false;
}
+
+std::vector<llvm::StringRef> FileSpec::GetComponents() const {
+ std::vector<llvm::StringRef> components;
+
+ auto dir_begin = llvm::sys::path::begin(m_directory.GetStringRef(), m_style);
+ auto dir_end = llvm::sys::path::end(m_directory.GetStringRef());
+
+ for (auto iter = dir_begin; iter != dir_end; ++iter) {
+ if (*iter == "/" || *iter == ".")
+ continue;
+
+ components.push_back(*iter);
+ }
+
+ if (!m_filename.IsEmpty() && m_filename != "/" && m_filename != ".")
+ components.push_back(m_filename.GetStringRef());
+
+ return components;
+}
+
/// Returns true if the filespec represents an implementation source
/// file (files with a ".c", ".cpp", ".m", ".mm" (many more)
/// extension).
@@ -478,8 +492,8 @@ bool FileSpec::RemoveLastPathComponent() {
/// \b true if the filespec represents an implementation source
/// file, \b false otherwise.
bool FileSpec::IsSourceImplementationFile() const {
- ConstString extension(GetFileNameExtension());
- if (!extension)
+ llvm::StringRef extension = GetFileNameExtension();
+ if (extension.empty())
return false;
static RegularExpression g_source_file_regex(llvm::StringRef(
@@ -487,7 +501,7 @@ bool FileSpec::IsSourceImplementationFile() const {
"cC][pP]|[sS]|[aA][sS][mM]|[fF]|[fF]77|[fF]90|[fF]95|[fF]03|[fF][oO]["
"rR]|[fF][tT][nN]|[fF][pP][pP]|[aA][dD][aA]|[aA][dD][bB]|[aA][dD][sS])"
"$"));
- return g_source_file_regex.Execute(extension.GetStringRef());
+ return g_source_file_regex.Execute(extension);
}
bool FileSpec::IsRelative() const {