aboutsummaryrefslogtreecommitdiff
path: root/lldb/source/Host/common/FileSpec.cpp
diff options
context:
space:
mode:
authorZachary Turner <zturner@google.com>2016-12-16 04:27:00 +0000
committerZachary Turner <zturner@google.com>2016-12-16 04:27:00 +0000
commit827d5d74a5b6a1214cbaec74aeb4a8f73d21dca0 (patch)
treec55d603b456e014c599ccbb0f2873105231a2f7c /lldb/source/Host/common/FileSpec.cpp
parentdb4c86f953f139eaa75acdd58d5213be2f6fe65b (diff)
downloadllvm-827d5d74a5b6a1214cbaec74aeb4a8f73d21dca0.zip
llvm-827d5d74a5b6a1214cbaec74aeb4a8f73d21dca0.tar.gz
llvm-827d5d74a5b6a1214cbaec74aeb4a8f73d21dca0.tar.bz2
Add methods to enable using formatv syntax in LLDB.
This adds formatv-backed formatting functions in various places in LLDB such as StreamString, logging, constructing error messages, etc. A couple of callsites are changed from Printf style syntax to formatv style syntax to illustrate its usage. Additionally, a FileSpec formatter is introduced so that FileSpecs can be formatted natively. Differential Revision: https://reviews.llvm.org/D27632 llvm-svn: 289922
Diffstat (limited to 'lldb/source/Host/common/FileSpec.cpp')
-rw-r--r--lldb/source/Host/common/FileSpec.cpp51
1 files changed, 47 insertions, 4 deletions
diff --git a/lldb/source/Host/common/FileSpec.cpp b/lldb/source/Host/common/FileSpec.cpp
index 9287336..7f46d30 100644
--- a/lldb/source/Host/common/FileSpec.cpp
+++ b/lldb/source/Host/common/FileSpec.cpp
@@ -354,10 +354,10 @@ void FileSpec::SetFile(llvm::StringRef pathname, bool resolve,
m_is_resolved = true;
}
- Normalize(resolved, syntax);
+ Normalize(resolved, m_syntax);
llvm::StringRef resolve_path_ref(resolved.c_str());
- size_t dir_end = ParentPathEnd(resolve_path_ref, syntax);
+ size_t dir_end = ParentPathEnd(resolve_path_ref, m_syntax);
if (dir_end == 0) {
m_filename.SetString(resolve_path_ref);
return;
@@ -366,11 +366,11 @@ void FileSpec::SetFile(llvm::StringRef pathname, bool resolve,
m_directory.SetString(resolve_path_ref.substr(0, dir_end));
size_t filename_begin = dir_end;
- size_t root_dir_start = RootDirStart(resolve_path_ref, syntax);
+ size_t root_dir_start = RootDirStart(resolve_path_ref, m_syntax);
while (filename_begin != llvm::StringRef::npos &&
filename_begin < resolve_path_ref.size() &&
filename_begin != root_dir_start &&
- IsPathSeparator(resolve_path_ref[filename_begin], syntax))
+ IsPathSeparator(resolve_path_ref[filename_begin], m_syntax))
++filename_begin;
m_filename.SetString((filename_begin == llvm::StringRef::npos ||
filename_begin >= resolve_path_ref.size())
@@ -1386,3 +1386,46 @@ bool FileSpec::IsRelative() const {
}
bool FileSpec::IsAbsolute() const { return !FileSpec::IsRelative(); }
+
+void llvm::format_provider<FileSpec>::format(const FileSpec &F,
+ raw_ostream &Stream,
+ StringRef Style) {
+ assert(
+ (Style.empty() || Style.equals_lower("F") || Style.equals_lower("D")) &&
+ "Invalid FileSpec style!");
+
+ StringRef dir = F.GetDirectory().GetStringRef();
+ StringRef file = F.GetFilename().GetStringRef();
+
+ if (dir.empty() && file.empty()) {
+ Stream << "(empty)";
+ return;
+ }
+
+ if (Style.equals_lower("F")) {
+ Stream << (file.empty() ? "(empty)" : file);
+ return;
+ }
+
+ // Style is either D or empty, either way we need to print the directory.
+ if (!dir.empty()) {
+ // Directory is stored in normalized form, which might be different
+ // than preferred form. In order to handle this, we need to cut off
+ // the filename, then denormalize, then write the entire denorm'ed
+ // directory.
+ llvm::SmallString<64> denormalized_dir = dir;
+ Denormalize(denormalized_dir, F.GetPathSyntax());
+ Stream << denormalized_dir;
+ Stream << GetPreferredPathSeparator(F.GetPathSyntax());
+ }
+
+ if (Style.equals_lower("D")) {
+ // We only want to print the directory, so now just exit.
+ if (dir.empty())
+ Stream << "(empty)";
+ return;
+ }
+
+ if (!file.empty())
+ Stream << file;
+}