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 
9baf5664fSJonas Devlieghere #include "lldb/API/SBFileSpecList.h"
10baf5664fSJonas Devlieghere #include "SBReproducerPrivate.h"
11bd4bf82aSJonas Devlieghere #include "Utils.h"
12969795f1SJim Ingham #include "lldb/API/SBFileSpec.h"
13969795f1SJim Ingham #include "lldb/API/SBStream.h"
14969795f1SJim Ingham #include "lldb/Core/FileSpecList.h"
158d48cd60SZachary Turner #include "lldb/Host/PosixApi.h"
165713a05bSZachary Turner #include "lldb/Utility/FileSpec.h"
17bf9a7730SZachary Turner #include "lldb/Utility/Stream.h"
18969795f1SJim Ingham 
19baf5664fSJonas Devlieghere #include <limits.h>
20baf5664fSJonas Devlieghere 
21969795f1SJim Ingham using namespace lldb;
22969795f1SJim Ingham using namespace lldb_private;
23969795f1SJim Ingham 
24baf5664fSJonas Devlieghere SBFileSpecList::SBFileSpecList() : m_opaque_up(new FileSpecList()) {
25baf5664fSJonas Devlieghere   LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBFileSpecList);
26baf5664fSJonas Devlieghere }
27969795f1SJim Ingham 
28d5b44036SJonas Devlieghere SBFileSpecList::SBFileSpecList(const SBFileSpecList &rhs) : m_opaque_up() {
29baf5664fSJonas Devlieghere   LLDB_RECORD_CONSTRUCTOR(SBFileSpecList, (const lldb::SBFileSpecList &), rhs);
30baf5664fSJonas Devlieghere 
31969795f1SJim Ingham 
32bd4bf82aSJonas Devlieghere   m_opaque_up = clone(rhs.m_opaque_up);
33969795f1SJim Ingham }
34969795f1SJim Ingham 
35b9c1b51eSKate Stone SBFileSpecList::~SBFileSpecList() {}
36969795f1SJim Ingham 
37b9c1b51eSKate Stone const SBFileSpecList &SBFileSpecList::operator=(const SBFileSpecList &rhs) {
38baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD(const lldb::SBFileSpecList &,
39baf5664fSJonas Devlieghere                      SBFileSpecList, operator=,(const lldb::SBFileSpecList &),
40baf5664fSJonas Devlieghere                      rhs);
41baf5664fSJonas Devlieghere 
42bd4bf82aSJonas Devlieghere   if (this != &rhs)
43bd4bf82aSJonas Devlieghere     m_opaque_up = clone(rhs.m_opaque_up);
44*306809f2SJonas Devlieghere   return LLDB_RECORD_RESULT(*this);
45969795f1SJim Ingham }
46969795f1SJim Ingham 
47baf5664fSJonas Devlieghere uint32_t SBFileSpecList::GetSize() const {
48baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD_CONST_NO_ARGS(uint32_t, SBFileSpecList, GetSize);
49baf5664fSJonas Devlieghere 
50baf5664fSJonas Devlieghere   return m_opaque_up->GetSize();
51baf5664fSJonas Devlieghere }
52969795f1SJim Ingham 
53b9c1b51eSKate Stone void SBFileSpecList::Append(const SBFileSpec &sb_file) {
54baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD(void, SBFileSpecList, Append, (const lldb::SBFileSpec &),
55baf5664fSJonas Devlieghere                      sb_file);
56baf5664fSJonas Devlieghere 
57d5b44036SJonas Devlieghere   m_opaque_up->Append(sb_file.ref());
58969795f1SJim Ingham }
59969795f1SJim Ingham 
60b9c1b51eSKate Stone bool SBFileSpecList::AppendIfUnique(const SBFileSpec &sb_file) {
61baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD(bool, SBFileSpecList, AppendIfUnique,
62baf5664fSJonas Devlieghere                      (const lldb::SBFileSpec &), sb_file);
63baf5664fSJonas Devlieghere 
64d5b44036SJonas Devlieghere   return m_opaque_up->AppendIfUnique(sb_file.ref());
65969795f1SJim Ingham }
66969795f1SJim Ingham 
67baf5664fSJonas Devlieghere void SBFileSpecList::Clear() {
68baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD_NO_ARGS(void, SBFileSpecList, Clear);
69baf5664fSJonas Devlieghere 
70baf5664fSJonas Devlieghere   m_opaque_up->Clear();
71baf5664fSJonas Devlieghere }
72969795f1SJim Ingham 
73b9c1b51eSKate Stone uint32_t SBFileSpecList::FindFileIndex(uint32_t idx, const SBFileSpec &sb_file,
74b9c1b51eSKate Stone                                        bool full) {
75baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD(uint32_t, SBFileSpecList, FindFileIndex,
76baf5664fSJonas Devlieghere                      (uint32_t, const lldb::SBFileSpec &, bool), idx, sb_file,
77baf5664fSJonas Devlieghere                      full);
78baf5664fSJonas Devlieghere 
79d5b44036SJonas Devlieghere   return m_opaque_up->FindFileIndex(idx, sb_file.ref(), full);
80969795f1SJim Ingham }
81969795f1SJim Ingham 
82b9c1b51eSKate Stone const SBFileSpec SBFileSpecList::GetFileSpecAtIndex(uint32_t idx) const {
83baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD_CONST(const lldb::SBFileSpec, SBFileSpecList,
84baf5664fSJonas Devlieghere                            GetFileSpecAtIndex, (uint32_t), idx);
85baf5664fSJonas Devlieghere 
86969795f1SJim Ingham   SBFileSpec new_spec;
87d5b44036SJonas Devlieghere   new_spec.SetFileSpec(m_opaque_up->GetFileSpecAtIndex(idx));
88baf5664fSJonas Devlieghere   return LLDB_RECORD_RESULT(new_spec);
89969795f1SJim Ingham }
90969795f1SJim Ingham 
91b9c1b51eSKate Stone const lldb_private::FileSpecList *SBFileSpecList::operator->() const {
92d5b44036SJonas Devlieghere   return m_opaque_up.get();
93969795f1SJim Ingham }
94969795f1SJim Ingham 
95b9c1b51eSKate Stone const lldb_private::FileSpecList *SBFileSpecList::get() const {
96d5b44036SJonas Devlieghere   return m_opaque_up.get();
97969795f1SJim Ingham }
98969795f1SJim Ingham 
99b9c1b51eSKate Stone const lldb_private::FileSpecList &SBFileSpecList::operator*() const {
100d5b44036SJonas Devlieghere   return *m_opaque_up;
101969795f1SJim Ingham }
102969795f1SJim Ingham 
103b9c1b51eSKate Stone const lldb_private::FileSpecList &SBFileSpecList::ref() const {
104d5b44036SJonas Devlieghere   return *m_opaque_up;
105969795f1SJim Ingham }
106969795f1SJim Ingham 
107b9c1b51eSKate Stone bool SBFileSpecList::GetDescription(SBStream &description) const {
108baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD_CONST(bool, SBFileSpecList, GetDescription,
109baf5664fSJonas Devlieghere                            (lldb::SBStream &), description);
110baf5664fSJonas Devlieghere 
111da7bc7d0SGreg Clayton   Stream &strm = description.ref();
112da7bc7d0SGreg Clayton 
113d5b44036SJonas Devlieghere   if (m_opaque_up) {
114d5b44036SJonas Devlieghere     uint32_t num_files = m_opaque_up->GetSize();
115da7bc7d0SGreg Clayton     strm.Printf("%d files: ", num_files);
116b9c1b51eSKate Stone     for (uint32_t i = 0; i < num_files; i++) {
117969795f1SJim Ingham       char path[PATH_MAX];
118d5b44036SJonas Devlieghere       if (m_opaque_up->GetFileSpecAtIndex(i).GetPath(path, sizeof(path)))
119da7bc7d0SGreg Clayton         strm.Printf("\n    %s", path);
120969795f1SJim Ingham     }
121b9c1b51eSKate Stone   } else
122da7bc7d0SGreg Clayton     strm.PutCString("No value");
123969795f1SJim Ingham 
124969795f1SJim Ingham   return true;
125969795f1SJim Ingham }
126ae211eceSMichal Gorny 
127ae211eceSMichal Gorny namespace lldb_private {
128ae211eceSMichal Gorny namespace repro {
129ae211eceSMichal Gorny 
130ae211eceSMichal Gorny template <>
131ae211eceSMichal Gorny void RegisterMethods<SBFileSpecList>(Registry &R) {
132ae211eceSMichal Gorny   LLDB_REGISTER_CONSTRUCTOR(SBFileSpecList, ());
133ae211eceSMichal Gorny   LLDB_REGISTER_CONSTRUCTOR(SBFileSpecList, (const lldb::SBFileSpecList &));
134ae211eceSMichal Gorny   LLDB_REGISTER_METHOD(
135ae211eceSMichal Gorny       const lldb::SBFileSpecList &,
136ae211eceSMichal Gorny       SBFileSpecList, operator=,(const lldb::SBFileSpecList &));
137ae211eceSMichal Gorny   LLDB_REGISTER_METHOD_CONST(uint32_t, SBFileSpecList, GetSize, ());
138ae211eceSMichal Gorny   LLDB_REGISTER_METHOD(void, SBFileSpecList, Append,
139ae211eceSMichal Gorny                        (const lldb::SBFileSpec &));
140ae211eceSMichal Gorny   LLDB_REGISTER_METHOD(bool, SBFileSpecList, AppendIfUnique,
141ae211eceSMichal Gorny                        (const lldb::SBFileSpec &));
142ae211eceSMichal Gorny   LLDB_REGISTER_METHOD(void, SBFileSpecList, Clear, ());
143ae211eceSMichal Gorny   LLDB_REGISTER_METHOD(uint32_t, SBFileSpecList, FindFileIndex,
144ae211eceSMichal Gorny                        (uint32_t, const lldb::SBFileSpec &, bool));
145ae211eceSMichal Gorny   LLDB_REGISTER_METHOD_CONST(const lldb::SBFileSpec, SBFileSpecList,
146ae211eceSMichal Gorny                              GetFileSpecAtIndex, (uint32_t));
147ae211eceSMichal Gorny   LLDB_REGISTER_METHOD_CONST(bool, SBFileSpecList, GetDescription,
148ae211eceSMichal Gorny                              (lldb::SBStream &));
149ae211eceSMichal Gorny }
150ae211eceSMichal Gorny 
151ae211eceSMichal Gorny }
152ae211eceSMichal Gorny }
153