blob: 8f0b067ea0a53a3f9a6a00df82f2978de0bfe255 [file] [log] [blame]
Chris Lattner24943d22010-06-08 16:52:24 +00001//===-- SBFileSpec.cpp ------------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "lldb/API/SBFileSpec.h"
Caroline Tice98f930f2010-09-20 05:20:02 +000011#include "lldb/API/SBStream.h"
Chris Lattner24943d22010-06-08 16:52:24 +000012#include "lldb/Core/FileSpec.h"
Caroline Tice7826c882010-10-26 03:11:13 +000013#include "lldb/Core/Log.h"
Chris Lattner24943d22010-06-08 16:52:24 +000014
15using namespace lldb;
16using namespace lldb_private;
17
18
19
20SBFileSpec::SBFileSpec () :
Greg Clayton63094e02010-06-23 01:19:29 +000021 m_opaque_ap()
Chris Lattner24943d22010-06-08 16:52:24 +000022{
Caroline Tice7826c882010-10-26 03:11:13 +000023 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API | LIBLLDB_LOG_VERBOSE);
24
25 if (log)
26 log->Printf ("SBFileSpec::SBFileSpec () ==> this = %p", this);
Chris Lattner24943d22010-06-08 16:52:24 +000027}
28
29SBFileSpec::SBFileSpec (const SBFileSpec &rhs) :
Greg Clayton63094e02010-06-23 01:19:29 +000030 m_opaque_ap()
Chris Lattner24943d22010-06-08 16:52:24 +000031{
Caroline Tice7826c882010-10-26 03:11:13 +000032 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API | LIBLLDB_LOG_VERBOSE);
33
34 if (log)
35 {
36 SBStream sstr;
37 rhs.GetDescription (sstr);
38 log->Printf ("SBFileSpec::SBFileSpec (const SBFileSpec &rhs) rhs.m_opaque_ap.get() = %p (%s) ==> this = %p",
39 rhs.m_opaque_ap.get(), sstr.GetData(), this);
40 }
41
Greg Clayton63094e02010-06-23 01:19:29 +000042 if (rhs.m_opaque_ap.get())
Johnny Chen4ead2e92010-08-27 22:35:26 +000043 m_opaque_ap.reset (new FileSpec (rhs.get()));
Chris Lattner24943d22010-06-08 16:52:24 +000044}
45
Greg Clayton537a7a82010-10-20 20:54:39 +000046// Deprected!!!
Chris Lattner24943d22010-06-08 16:52:24 +000047SBFileSpec::SBFileSpec (const char *path) :
Greg Clayton537a7a82010-10-20 20:54:39 +000048 m_opaque_ap(new FileSpec (path, true))
49{
50}
51
52SBFileSpec::SBFileSpec (const char *path, bool resolve) :
53 m_opaque_ap(new FileSpec (path, resolve))
Chris Lattner24943d22010-06-08 16:52:24 +000054{
Caroline Tice7826c882010-10-26 03:11:13 +000055 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API | LIBLLDB_LOG_VERBOSE);
56
57 if (log)
58 log->Printf ("SBFileSpec::SBFileSpec (const char *path, bool resolve) path = '%s', resolve = %s ==> "
59 "this = %p (m_opaque_ap.get() = %p)", path, (resolve ? "true" : "false"), this,
60 m_opaque_ap.get());
Chris Lattner24943d22010-06-08 16:52:24 +000061}
62
63SBFileSpec::~SBFileSpec ()
64{
65}
66
67const SBFileSpec &
68SBFileSpec::operator = (const SBFileSpec &rhs)
69{
70 if (this != &rhs)
71 {
72 if (rhs.IsValid())
Greg Clayton63094e02010-06-23 01:19:29 +000073 m_opaque_ap.reset (new lldb_private::FileSpec(*rhs.m_opaque_ap.get()));
Chris Lattner24943d22010-06-08 16:52:24 +000074 }
75 return *this;
76}
77
78bool
79SBFileSpec::IsValid() const
80{
Greg Clayton63094e02010-06-23 01:19:29 +000081 return m_opaque_ap.get() != NULL;
Chris Lattner24943d22010-06-08 16:52:24 +000082}
83
84bool
85SBFileSpec::Exists () const
86{
Caroline Tice7826c882010-10-26 03:11:13 +000087 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
88
89 if (log)
90 log->Printf ("SBFileSpec::Exists ()");
91
92 bool result = false;
Greg Clayton63094e02010-06-23 01:19:29 +000093 if (m_opaque_ap.get())
Caroline Tice7826c882010-10-26 03:11:13 +000094 result = m_opaque_ap->Exists();
95
96 if (log)
97 log->Printf ("SBFileSpec::Exists ==> %s", (result ? "true" : "false"));
98
99 return result;
Chris Lattner24943d22010-06-08 16:52:24 +0000100}
101
Caroline Ticeeddffe92010-09-10 04:48:55 +0000102bool
103SBFileSpec::ResolveExecutableLocation ()
104{
105 if (m_opaque_ap.get())
106 return m_opaque_ap->ResolveExecutableLocation ();
107 return false;
108}
Chris Lattner24943d22010-06-08 16:52:24 +0000109
110int
111SBFileSpec::ResolvePath (const char *src_path, char *dst_path, size_t dst_len)
112{
113 return lldb_private::FileSpec::Resolve (src_path, dst_path, dst_len);
114}
115
116const char *
Johnny Chen4ead2e92010-08-27 22:35:26 +0000117SBFileSpec::GetFilename() const
Chris Lattner24943d22010-06-08 16:52:24 +0000118{
Caroline Tice7826c882010-10-26 03:11:13 +0000119 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
120
121 if (log)
122 log->Printf ("SBFileSpec::GetFilename ()");
123
Greg Clayton63094e02010-06-23 01:19:29 +0000124 if (m_opaque_ap.get())
Caroline Tice7826c882010-10-26 03:11:13 +0000125 {
126 if (log)
127 log->Printf ("SBFileSpec::GetFilename ==> %s", m_opaque_ap->GetFilename().AsCString());
Greg Clayton63094e02010-06-23 01:19:29 +0000128 return m_opaque_ap->GetFilename().AsCString();
Caroline Tice7826c882010-10-26 03:11:13 +0000129 }
130
131 if (log)
132 log->Printf ("SBFileSpec::GetFilename ==> NULL");
133
Chris Lattner24943d22010-06-08 16:52:24 +0000134 return NULL;
135}
136
137const char *
138SBFileSpec::GetDirectory() const
139{
Greg Clayton63094e02010-06-23 01:19:29 +0000140 if (m_opaque_ap.get())
141 return m_opaque_ap->GetDirectory().AsCString();
Chris Lattner24943d22010-06-08 16:52:24 +0000142 return NULL;
143}
144
145uint32_t
146SBFileSpec::GetPath (char *dst_path, size_t dst_len) const
147{
Caroline Tice7826c882010-10-26 03:11:13 +0000148 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
149
150 if (log)
151 log->Printf ("SBFileSpec::GetPath (dst_path, dst_len)");
152
153 uint32_t result;
Greg Clayton63094e02010-06-23 01:19:29 +0000154 if (m_opaque_ap.get())
Caroline Tice7826c882010-10-26 03:11:13 +0000155 {
156 result = m_opaque_ap->GetPath (dst_path, dst_len);
157 if (log)
158 log->Printf ("SBFileSpec::GetPath ==> %s (%d)", dst_path, result);
159 return result;
160 }
161
162 if (log)
163 log->Printf ("SBFileSpec::GetPath ==> NULL (0)");
Chris Lattner24943d22010-06-08 16:52:24 +0000164
165 if (dst_path && dst_len)
166 *dst_path = '\0';
167 return 0;
168}
169
170
171const lldb_private::FileSpec *
172SBFileSpec::operator->() const
173{
Greg Clayton63094e02010-06-23 01:19:29 +0000174 return m_opaque_ap.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000175}
176
177const lldb_private::FileSpec *
178SBFileSpec::get() const
179{
Greg Clayton63094e02010-06-23 01:19:29 +0000180 return m_opaque_ap.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000181}
182
183
184const lldb_private::FileSpec &
185SBFileSpec::operator*() const
186{
Greg Clayton63094e02010-06-23 01:19:29 +0000187 return *m_opaque_ap.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000188}
189
190const lldb_private::FileSpec &
191SBFileSpec::ref() const
192{
Greg Clayton63094e02010-06-23 01:19:29 +0000193 return *m_opaque_ap.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000194}
195
196
197void
198SBFileSpec::SetFileSpec (const lldb_private::FileSpec& fs)
199{
Greg Clayton63094e02010-06-23 01:19:29 +0000200 if (m_opaque_ap.get())
201 *m_opaque_ap = fs;
Chris Lattner24943d22010-06-08 16:52:24 +0000202 else
Greg Clayton63094e02010-06-23 01:19:29 +0000203 m_opaque_ap.reset (new FileSpec (fs));
Chris Lattner24943d22010-06-08 16:52:24 +0000204}
205
Caroline Tice98f930f2010-09-20 05:20:02 +0000206bool
207SBFileSpec::GetDescription (SBStream &description)
208{
209 if (m_opaque_ap.get())
210 {
211 const char *filename = GetFilename();
212 const char *dir_name = GetDirectory();
213 if (!filename && !dir_name)
214 description.Printf ("No value");
215 else if (!dir_name)
216 description.Printf ("%s", filename);
217 else
218 description.Printf ("%s/%s", dir_name, filename);
219 }
220 else
221 description.Printf ("No value");
222
223 return true;
224}
Caroline Tice7826c882010-10-26 03:11:13 +0000225
226bool
227SBFileSpec::GetDescription (SBStream &description) const
228{
229 if (m_opaque_ap.get())
230 {
231 const char *filename = GetFilename();
232 const char *dir_name = GetDirectory();
233 if (!filename && !dir_name)
234 description.Printf ("No value");
235 else if (!dir_name)
236 description.Printf ("%s", filename);
237 else
238 description.Printf ("%s/%s", dir_name, filename);
239 }
240 else
241 description.Printf ("No value");
242
243 return true;
244}