1696bd635SAlexander Shaposhnikov //===-- SBFileSpecList.cpp --------------------------------------*- C++ -*-===// 2969795f1SJim Ingham // 32946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 42946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information. 52946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6969795f1SJim Ingham // 7969795f1SJim Ingham //===----------------------------------------------------------------------===// 8969795f1SJim Ingham 9969795f1SJim Ingham #include <limits.h> 10969795f1SJim Ingham 11*bd4bf82aSJonas Devlieghere #include "Utils.h" 12969795f1SJim Ingham #include "lldb/API/SBFileSpec.h" 13969795f1SJim Ingham #include "lldb/API/SBFileSpecList.h" 14969795f1SJim Ingham #include "lldb/API/SBStream.h" 15969795f1SJim Ingham #include "lldb/Core/FileSpecList.h" 168d48cd60SZachary Turner #include "lldb/Host/PosixApi.h" 175713a05bSZachary Turner #include "lldb/Utility/FileSpec.h" 186f9e6901SZachary Turner #include "lldb/Utility/Log.h" 19bf9a7730SZachary Turner #include "lldb/Utility/Stream.h" 20969795f1SJim Ingham 21969795f1SJim Ingham using namespace lldb; 22969795f1SJim Ingham using namespace lldb_private; 23969795f1SJim Ingham 24d5b44036SJonas Devlieghere SBFileSpecList::SBFileSpecList() : m_opaque_up(new FileSpecList()) {} 25969795f1SJim Ingham 26d5b44036SJonas Devlieghere SBFileSpecList::SBFileSpecList(const SBFileSpecList &rhs) : m_opaque_up() { 275160ce5cSGreg Clayton Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); 28969795f1SJim Ingham 29*bd4bf82aSJonas Devlieghere m_opaque_up = clone(rhs.m_opaque_up); 30969795f1SJim Ingham 31b9c1b51eSKate Stone if (log) { 32b9c1b51eSKate Stone log->Printf("SBFileSpecList::SBFileSpecList (const SBFileSpecList " 33b9c1b51eSKate Stone "rhs.ap=%p) => SBFileSpecList(%p)", 34d5b44036SJonas Devlieghere static_cast<void *>(rhs.m_opaque_up.get()), 35d5b44036SJonas Devlieghere static_cast<void *>(m_opaque_up.get())); 36969795f1SJim Ingham } 37969795f1SJim Ingham } 38969795f1SJim Ingham 39b9c1b51eSKate Stone SBFileSpecList::~SBFileSpecList() {} 40969795f1SJim Ingham 41b9c1b51eSKate Stone const SBFileSpecList &SBFileSpecList::operator=(const SBFileSpecList &rhs) { 42*bd4bf82aSJonas Devlieghere if (this != &rhs) 43*bd4bf82aSJonas Devlieghere m_opaque_up = clone(rhs.m_opaque_up); 44969795f1SJim Ingham return *this; 45969795f1SJim Ingham } 46969795f1SJim Ingham 47d5b44036SJonas Devlieghere uint32_t SBFileSpecList::GetSize() const { return m_opaque_up->GetSize(); } 48969795f1SJim Ingham 49b9c1b51eSKate Stone void SBFileSpecList::Append(const SBFileSpec &sb_file) { 50d5b44036SJonas Devlieghere m_opaque_up->Append(sb_file.ref()); 51969795f1SJim Ingham } 52969795f1SJim Ingham 53b9c1b51eSKate Stone bool SBFileSpecList::AppendIfUnique(const SBFileSpec &sb_file) { 54d5b44036SJonas Devlieghere return m_opaque_up->AppendIfUnique(sb_file.ref()); 55969795f1SJim Ingham } 56969795f1SJim Ingham 57d5b44036SJonas Devlieghere void SBFileSpecList::Clear() { m_opaque_up->Clear(); } 58969795f1SJim Ingham 59b9c1b51eSKate Stone uint32_t SBFileSpecList::FindFileIndex(uint32_t idx, const SBFileSpec &sb_file, 60b9c1b51eSKate Stone bool full) { 61d5b44036SJonas Devlieghere return m_opaque_up->FindFileIndex(idx, sb_file.ref(), full); 62969795f1SJim Ingham } 63969795f1SJim Ingham 64b9c1b51eSKate Stone const SBFileSpec SBFileSpecList::GetFileSpecAtIndex(uint32_t idx) const { 65969795f1SJim Ingham SBFileSpec new_spec; 66d5b44036SJonas Devlieghere new_spec.SetFileSpec(m_opaque_up->GetFileSpecAtIndex(idx)); 67969795f1SJim Ingham return new_spec; 68969795f1SJim Ingham } 69969795f1SJim Ingham 70b9c1b51eSKate Stone const lldb_private::FileSpecList *SBFileSpecList::operator->() const { 71d5b44036SJonas Devlieghere return m_opaque_up.get(); 72969795f1SJim Ingham } 73969795f1SJim Ingham 74b9c1b51eSKate Stone const lldb_private::FileSpecList *SBFileSpecList::get() const { 75d5b44036SJonas Devlieghere return m_opaque_up.get(); 76969795f1SJim Ingham } 77969795f1SJim Ingham 78b9c1b51eSKate Stone const lldb_private::FileSpecList &SBFileSpecList::operator*() const { 79d5b44036SJonas Devlieghere return *m_opaque_up; 80969795f1SJim Ingham } 81969795f1SJim Ingham 82b9c1b51eSKate Stone const lldb_private::FileSpecList &SBFileSpecList::ref() const { 83d5b44036SJonas Devlieghere return *m_opaque_up; 84969795f1SJim Ingham } 85969795f1SJim Ingham 86b9c1b51eSKate Stone bool SBFileSpecList::GetDescription(SBStream &description) const { 87da7bc7d0SGreg Clayton Stream &strm = description.ref(); 88da7bc7d0SGreg Clayton 89d5b44036SJonas Devlieghere if (m_opaque_up) { 90d5b44036SJonas Devlieghere uint32_t num_files = m_opaque_up->GetSize(); 91da7bc7d0SGreg Clayton strm.Printf("%d files: ", num_files); 92b9c1b51eSKate Stone for (uint32_t i = 0; i < num_files; i++) { 93969795f1SJim Ingham char path[PATH_MAX]; 94d5b44036SJonas Devlieghere if (m_opaque_up->GetFileSpecAtIndex(i).GetPath(path, sizeof(path))) 95da7bc7d0SGreg Clayton strm.Printf("\n %s", path); 96969795f1SJim Ingham } 97b9c1b51eSKate Stone } else 98da7bc7d0SGreg Clayton strm.PutCString("No value"); 99969795f1SJim Ingham 100969795f1SJim Ingham return true; 101969795f1SJim Ingham } 102