1314564Sdim//===-- SBFileSpecList.cpp --------------------------------------*- C++ -*-===//
2254721Semaste//
3353358Sdim// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4353358Sdim// See https://llvm.org/LICENSE.txt for license information.
5353358Sdim// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6254721Semaste//
7254721Semaste//===----------------------------------------------------------------------===//
8254721Semaste
9353358Sdim#include "lldb/API/SBFileSpecList.h"
10353358Sdim#include "SBReproducerPrivate.h"
11353358Sdim#include "Utils.h"
12254721Semaste#include "lldb/API/SBFileSpec.h"
13254721Semaste#include "lldb/API/SBStream.h"
14254721Semaste#include "lldb/Core/FileSpecList.h"
15321369Sdim#include "lldb/Host/PosixApi.h"
16321369Sdim#include "lldb/Utility/FileSpec.h"
17321369Sdim#include "lldb/Utility/Stream.h"
18254721Semaste
19353358Sdim#include <limits.h>
20353358Sdim
21254721Semasteusing namespace lldb;
22254721Semasteusing namespace lldb_private;
23254721Semaste
24353358SdimSBFileSpecList::SBFileSpecList() : m_opaque_up(new FileSpecList()) {
25353358Sdim  LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBFileSpecList);
26353358Sdim}
27254721Semaste
28353358SdimSBFileSpecList::SBFileSpecList(const SBFileSpecList &rhs) : m_opaque_up() {
29353358Sdim  LLDB_RECORD_CONSTRUCTOR(SBFileSpecList, (const lldb::SBFileSpecList &), rhs);
30254721Semaste
31254721Semaste
32353358Sdim  m_opaque_up = clone(rhs.m_opaque_up);
33254721Semaste}
34254721Semaste
35314564SdimSBFileSpecList::~SBFileSpecList() {}
36254721Semaste
37314564Sdimconst SBFileSpecList &SBFileSpecList::operator=(const SBFileSpecList &rhs) {
38353358Sdim  LLDB_RECORD_METHOD(const lldb::SBFileSpecList &,
39353358Sdim                     SBFileSpecList, operator=,(const lldb::SBFileSpecList &),
40353358Sdim                     rhs);
41353358Sdim
42353358Sdim  if (this != &rhs)
43353358Sdim    m_opaque_up = clone(rhs.m_opaque_up);
44353358Sdim  return LLDB_RECORD_RESULT(*this);
45254721Semaste}
46254721Semaste
47353358Sdimuint32_t SBFileSpecList::GetSize() const {
48353358Sdim  LLDB_RECORD_METHOD_CONST_NO_ARGS(uint32_t, SBFileSpecList, GetSize);
49254721Semaste
50353358Sdim  return m_opaque_up->GetSize();
51353358Sdim}
52353358Sdim
53314564Sdimvoid SBFileSpecList::Append(const SBFileSpec &sb_file) {
54353358Sdim  LLDB_RECORD_METHOD(void, SBFileSpecList, Append, (const lldb::SBFileSpec &),
55353358Sdim                     sb_file);
56353358Sdim
57353358Sdim  m_opaque_up->Append(sb_file.ref());
58254721Semaste}
59254721Semaste
60314564Sdimbool SBFileSpecList::AppendIfUnique(const SBFileSpec &sb_file) {
61353358Sdim  LLDB_RECORD_METHOD(bool, SBFileSpecList, AppendIfUnique,
62353358Sdim                     (const lldb::SBFileSpec &), sb_file);
63353358Sdim
64353358Sdim  return m_opaque_up->AppendIfUnique(sb_file.ref());
65254721Semaste}
66254721Semaste
67353358Sdimvoid SBFileSpecList::Clear() {
68353358Sdim  LLDB_RECORD_METHOD_NO_ARGS(void, SBFileSpecList, Clear);
69254721Semaste
70353358Sdim  m_opaque_up->Clear();
71353358Sdim}
72353358Sdim
73314564Sdimuint32_t SBFileSpecList::FindFileIndex(uint32_t idx, const SBFileSpec &sb_file,
74314564Sdim                                       bool full) {
75353358Sdim  LLDB_RECORD_METHOD(uint32_t, SBFileSpecList, FindFileIndex,
76353358Sdim                     (uint32_t, const lldb::SBFileSpec &, bool), idx, sb_file,
77353358Sdim                     full);
78353358Sdim
79353358Sdim  return m_opaque_up->FindFileIndex(idx, sb_file.ref(), full);
80254721Semaste}
81254721Semaste
82314564Sdimconst SBFileSpec SBFileSpecList::GetFileSpecAtIndex(uint32_t idx) const {
83353358Sdim  LLDB_RECORD_METHOD_CONST(const lldb::SBFileSpec, SBFileSpecList,
84353358Sdim                           GetFileSpecAtIndex, (uint32_t), idx);
85353358Sdim
86314564Sdim  SBFileSpec new_spec;
87353358Sdim  new_spec.SetFileSpec(m_opaque_up->GetFileSpecAtIndex(idx));
88353358Sdim  return LLDB_RECORD_RESULT(new_spec);
89254721Semaste}
90254721Semaste
91314564Sdimconst lldb_private::FileSpecList *SBFileSpecList::operator->() const {
92353358Sdim  return m_opaque_up.get();
93254721Semaste}
94254721Semaste
95314564Sdimconst lldb_private::FileSpecList *SBFileSpecList::get() const {
96353358Sdim  return m_opaque_up.get();
97254721Semaste}
98254721Semaste
99314564Sdimconst lldb_private::FileSpecList &SBFileSpecList::operator*() const {
100353358Sdim  return *m_opaque_up;
101254721Semaste}
102254721Semaste
103314564Sdimconst lldb_private::FileSpecList &SBFileSpecList::ref() const {
104353358Sdim  return *m_opaque_up;
105254721Semaste}
106254721Semaste
107314564Sdimbool SBFileSpecList::GetDescription(SBStream &description) const {
108353358Sdim  LLDB_RECORD_METHOD_CONST(bool, SBFileSpecList, GetDescription,
109353358Sdim                           (lldb::SBStream &), description);
110353358Sdim
111314564Sdim  Stream &strm = description.ref();
112254721Semaste
113353358Sdim  if (m_opaque_up) {
114353358Sdim    uint32_t num_files = m_opaque_up->GetSize();
115314564Sdim    strm.Printf("%d files: ", num_files);
116314564Sdim    for (uint32_t i = 0; i < num_files; i++) {
117314564Sdim      char path[PATH_MAX];
118353358Sdim      if (m_opaque_up->GetFileSpecAtIndex(i).GetPath(path, sizeof(path)))
119314564Sdim        strm.Printf("\n    %s", path);
120254721Semaste    }
121314564Sdim  } else
122314564Sdim    strm.PutCString("No value");
123314564Sdim
124314564Sdim  return true;
125254721Semaste}
126353358Sdim
127353358Sdimnamespace lldb_private {
128353358Sdimnamespace repro {
129353358Sdim
130353358Sdimtemplate <>
131353358Sdimvoid RegisterMethods<SBFileSpecList>(Registry &R) {
132353358Sdim  LLDB_REGISTER_CONSTRUCTOR(SBFileSpecList, ());
133353358Sdim  LLDB_REGISTER_CONSTRUCTOR(SBFileSpecList, (const lldb::SBFileSpecList &));
134353358Sdim  LLDB_REGISTER_METHOD(
135353358Sdim      const lldb::SBFileSpecList &,
136353358Sdim      SBFileSpecList, operator=,(const lldb::SBFileSpecList &));
137353358Sdim  LLDB_REGISTER_METHOD_CONST(uint32_t, SBFileSpecList, GetSize, ());
138353358Sdim  LLDB_REGISTER_METHOD(void, SBFileSpecList, Append,
139353358Sdim                       (const lldb::SBFileSpec &));
140353358Sdim  LLDB_REGISTER_METHOD(bool, SBFileSpecList, AppendIfUnique,
141353358Sdim                       (const lldb::SBFileSpec &));
142353358Sdim  LLDB_REGISTER_METHOD(void, SBFileSpecList, Clear, ());
143353358Sdim  LLDB_REGISTER_METHOD(uint32_t, SBFileSpecList, FindFileIndex,
144353358Sdim                       (uint32_t, const lldb::SBFileSpec &, bool));
145353358Sdim  LLDB_REGISTER_METHOD_CONST(const lldb::SBFileSpec, SBFileSpecList,
146353358Sdim                             GetFileSpecAtIndex, (uint32_t));
147353358Sdim  LLDB_REGISTER_METHOD_CONST(bool, SBFileSpecList, GetDescription,
148353358Sdim                             (lldb::SBStream &));
149353358Sdim}
150353358Sdim
151353358Sdim}
152353358Sdim}
153