2010-06-09 00:52:24 +08:00
|
|
|
//===-- FileSpecList.cpp ----------------------------------------*- C++ -*-===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2010-06-09 00:52:24 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2016-03-03 08:51:40 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "lldb/Core/FileSpecList.h"
|
2016-03-03 08:51:40 +08:00
|
|
|
|
2018-11-12 07:16:43 +08:00
|
|
|
#include "lldb/Utility/ConstString.h"
|
2017-02-03 05:39:50 +08:00
|
|
|
#include "lldb/Utility/Stream.h"
|
2017-04-07 05:28:29 +08:00
|
|
|
|
2018-11-12 07:16:43 +08:00
|
|
|
#include <utility>
|
2017-04-07 05:28:29 +08:00
|
|
|
|
2018-11-12 07:16:43 +08:00
|
|
|
#include <stdint.h>
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
using namespace lldb_private;
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
FileSpecList::FileSpecList() : m_files() {}
|
|
|
|
|
2016-03-03 08:51:40 +08:00
|
|
|
FileSpecList::~FileSpecList() = default;
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
// Append the "file_spec" to the end of the file spec list.
|
|
|
|
void FileSpecList::Append(const FileSpec &file_spec) {
|
|
|
|
m_files.push_back(file_spec);
|
|
|
|
}
|
|
|
|
|
2018-05-01 00:49:04 +08:00
|
|
|
// Only append the "file_spec" if this list doesn't already contain it.
|
2010-06-09 00:52:24 +08:00
|
|
|
//
|
2018-05-01 00:49:04 +08:00
|
|
|
// Returns true if "file_spec" was added, false if this list already contained
|
|
|
|
// a copy of "file_spec".
|
2010-06-09 00:52:24 +08:00
|
|
|
bool FileSpecList::AppendIfUnique(const FileSpec &file_spec) {
|
2017-11-03 05:35:26 +08:00
|
|
|
collection::iterator end = m_files.end();
|
2010-06-09 00:52:24 +08:00
|
|
|
if (find(m_files.begin(), end, file_spec) == end) {
|
|
|
|
m_files.push_back(file_spec);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clears the file list.
|
|
|
|
void FileSpecList::Clear() { m_files.clear(); }
|
|
|
|
|
|
|
|
// Dumps the file list to the supplied stream pointer "s".
|
2011-07-07 09:59:51 +08:00
|
|
|
void FileSpecList::Dump(Stream *s, const char *separator_cstr) const {
|
|
|
|
collection::const_iterator pos, end = m_files.end();
|
|
|
|
for (pos = m_files.begin(); pos != end; ++pos) {
|
|
|
|
pos->Dump(s);
|
2012-08-23 01:17:09 +08:00
|
|
|
if (separator_cstr && ((pos + 1) != end))
|
2011-07-07 09:59:51 +08:00
|
|
|
s->PutCString(separator_cstr);
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2018-05-01 00:49:04 +08:00
|
|
|
// Find the index of the file in the file spec list that matches "file_spec"
|
|
|
|
// starting "start_idx" entries into the file spec list.
|
2010-06-09 00:52:24 +08:00
|
|
|
//
|
2018-05-01 00:49:04 +08:00
|
|
|
// Returns the valid index of the file that matches "file_spec" if it is found,
|
|
|
|
// else std::numeric_limits<uint32_t>::max() is returned.
|
2014-11-15 09:54:26 +08:00
|
|
|
size_t FileSpecList::FindFileIndex(size_t start_idx, const FileSpec &file_spec,
|
2018-04-27 23:45:58 +08:00
|
|
|
bool full) const {
|
2013-01-26 02:06:21 +08:00
|
|
|
const size_t num_files = m_files.size();
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2018-05-01 00:49:04 +08:00
|
|
|
// When looking for files, we will compare only the filename if the FILE_SPEC
|
|
|
|
// argument is empty
|
2010-06-09 00:52:24 +08:00
|
|
|
bool compare_filename_only = file_spec.GetDirectory().IsEmpty();
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-01-26 02:06:21 +08:00
|
|
|
for (size_t idx = start_idx; idx < num_files; ++idx) {
|
2010-06-09 00:52:24 +08:00
|
|
|
if (compare_filename_only) {
|
2016-02-25 05:26:47 +08:00
|
|
|
if (ConstString::Equals(
|
|
|
|
m_files[idx].GetFilename(), file_spec.GetFilename(),
|
|
|
|
file_spec.IsCaseSensitive() || m_files[idx].IsCaseSensitive()))
|
2010-06-09 00:52:24 +08:00
|
|
|
return idx;
|
|
|
|
} else {
|
2018-04-27 23:45:58 +08:00
|
|
|
if (FileSpec::Equal(m_files[idx], file_spec, full))
|
2010-06-09 00:52:24 +08:00
|
|
|
return idx;
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
// We didn't find the file, return an invalid index
|
2016-03-12 11:33:36 +08:00
|
|
|
return UINT32_MAX;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2018-05-01 00:49:04 +08:00
|
|
|
// Returns the FileSpec object at index "idx". If "idx" is out of range, then
|
|
|
|
// an empty FileSpec object will be returned.
|
2013-01-26 02:06:21 +08:00
|
|
|
const FileSpec &FileSpecList::GetFileSpecAtIndex(size_t idx) const {
|
2010-06-09 00:52:24 +08:00
|
|
|
if (idx < m_files.size())
|
|
|
|
return m_files[idx];
|
|
|
|
static FileSpec g_empty_file_spec;
|
|
|
|
return g_empty_file_spec;
|
|
|
|
}
|
|
|
|
|
2013-01-26 02:06:21 +08:00
|
|
|
const FileSpec *FileSpecList::GetFileSpecPointerAtIndex(size_t idx) const {
|
2010-06-09 00:52:24 +08:00
|
|
|
if (idx < m_files.size())
|
|
|
|
return &m_files[idx];
|
2016-03-03 08:51:40 +08:00
|
|
|
return nullptr;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2018-05-01 00:49:04 +08:00
|
|
|
// Return the size in bytes that this object takes in memory. This returns the
|
|
|
|
// size in bytes of this object's member variables and any FileSpec objects its
|
|
|
|
// member variables contain, the result doesn't not include the string values
|
|
|
|
// for the directories any filenames as those are in shared string pools.
|
2010-06-09 00:52:24 +08:00
|
|
|
size_t FileSpecList::MemorySize() const {
|
|
|
|
size_t mem_size = sizeof(FileSpecList);
|
|
|
|
collection::const_iterator pos, end = m_files.end();
|
|
|
|
for (pos = m_files.begin(); pos != end; ++pos) {
|
|
|
|
mem_size += pos->MemorySize();
|
|
|
|
}
|
|
|
|
|
|
|
|
return mem_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return the number of files in the file spec list.
|
|
|
|
size_t FileSpecList::GetSize() const { return m_files.size(); }
|
|
|
|
|
|
|
|
size_t FileSpecList::GetFilesMatchingPartialPath(const char *path,
|
|
|
|
bool dir_okay,
|
|
|
|
FileSpecList &matches) {
|
|
|
|
return 0;
|
|
|
|
}
|