blob: a4fda531cdb261acef4f94103c65b6bf6c51c1cc [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{
23}
24
25SBFileSpec::SBFileSpec (const SBFileSpec &rhs) :
Greg Clayton63094e02010-06-23 01:19:29 +000026 m_opaque_ap()
Chris Lattner24943d22010-06-08 16:52:24 +000027{
Caroline Tice61ba7ec2010-10-26 23:49:36 +000028 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
29
30 if (rhs.m_opaque_ap.get())
31 m_opaque_ap.reset (new FileSpec (rhs.get()));
Caroline Tice7826c882010-10-26 03:11:13 +000032
33 if (log)
34 {
35 SBStream sstr;
Caroline Tice61ba7ec2010-10-26 23:49:36 +000036 GetDescription (sstr);
37 log->Printf ("SBFileSpec::SBFileSpec (const SBFileSpec rhs.ap=%p) => this.ap = %p ('%s')",
38 rhs.m_opaque_ap.get(), m_opaque_ap.get(), sstr.GetData());
Caroline Tice7826c882010-10-26 03:11:13 +000039 }
Chris Lattner24943d22010-06-08 16:52:24 +000040}
41
Greg Clayton537a7a82010-10-20 20:54:39 +000042// Deprected!!!
Chris Lattner24943d22010-06-08 16:52:24 +000043SBFileSpec::SBFileSpec (const char *path) :
Greg Clayton537a7a82010-10-20 20:54:39 +000044 m_opaque_ap(new FileSpec (path, true))
45{
46}
47
48SBFileSpec::SBFileSpec (const char *path, bool resolve) :
49 m_opaque_ap(new FileSpec (path, resolve))
Chris Lattner24943d22010-06-08 16:52:24 +000050{
Caroline Tice61ba7ec2010-10-26 23:49:36 +000051 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
Caroline Tice7826c882010-10-26 03:11:13 +000052
53 if (log)
Caroline Tice61ba7ec2010-10-26 23:49:36 +000054 log->Printf ("SBFileSpec::SBFileSpec (path='%s', resolve='%s') => this.ap = %p", path,
55 (resolve ? "true" : "false"), m_opaque_ap.get());
Chris Lattner24943d22010-06-08 16:52:24 +000056}
57
58SBFileSpec::~SBFileSpec ()
59{
60}
61
62const SBFileSpec &
63SBFileSpec::operator = (const SBFileSpec &rhs)
64{
65 if (this != &rhs)
66 {
67 if (rhs.IsValid())
Greg Clayton63094e02010-06-23 01:19:29 +000068 m_opaque_ap.reset (new lldb_private::FileSpec(*rhs.m_opaque_ap.get()));
Chris Lattner24943d22010-06-08 16:52:24 +000069 }
70 return *this;
71}
72
73bool
74SBFileSpec::IsValid() const
75{
Greg Clayton63094e02010-06-23 01:19:29 +000076 return m_opaque_ap.get() != NULL;
Chris Lattner24943d22010-06-08 16:52:24 +000077}
78
79bool
80SBFileSpec::Exists () const
81{
Caroline Tice7826c882010-10-26 03:11:13 +000082 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
83
Caroline Tice61ba7ec2010-10-26 23:49:36 +000084 //if (log)
85 // log->Printf ("SBFileSpec::Exists (this.ap=%p)", m_opaque_ap.get());
Caroline Tice7826c882010-10-26 03:11:13 +000086
87 bool result = false;
Greg Clayton63094e02010-06-23 01:19:29 +000088 if (m_opaque_ap.get())
Caroline Tice7826c882010-10-26 03:11:13 +000089 result = m_opaque_ap->Exists();
90
91 if (log)
Caroline Tice61ba7ec2010-10-26 23:49:36 +000092 log->Printf ("SBFileSpec::Exists (this.ap=%p) => %s", m_opaque_ap.get(), (result ? "true" : "false"));
Caroline Tice7826c882010-10-26 03:11:13 +000093
94 return result;
Chris Lattner24943d22010-06-08 16:52:24 +000095}
96
Caroline Ticeeddffe92010-09-10 04:48:55 +000097bool
98SBFileSpec::ResolveExecutableLocation ()
99{
100 if (m_opaque_ap.get())
101 return m_opaque_ap->ResolveExecutableLocation ();
102 return false;
103}
Chris Lattner24943d22010-06-08 16:52:24 +0000104
105int
106SBFileSpec::ResolvePath (const char *src_path, char *dst_path, size_t dst_len)
107{
108 return lldb_private::FileSpec::Resolve (src_path, dst_path, dst_len);
109}
110
111const char *
Johnny Chen4ead2e92010-08-27 22:35:26 +0000112SBFileSpec::GetFilename() const
Chris Lattner24943d22010-06-08 16:52:24 +0000113{
Caroline Tice7826c882010-10-26 03:11:13 +0000114 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
115
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000116 //if (log)
117 // log->Printf ("SBFileSpec::GetFilename (this.ap=%p)", m_opaque_ap.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000118
Greg Clayton63094e02010-06-23 01:19:29 +0000119 if (m_opaque_ap.get())
Caroline Tice7826c882010-10-26 03:11:13 +0000120 {
121 if (log)
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000122 log->Printf ("SBFileSpec::GetFilename (this.ap=%p) => %s", m_opaque_ap.get(),
123 m_opaque_ap->GetFilename().AsCString());
124
Greg Clayton63094e02010-06-23 01:19:29 +0000125 return m_opaque_ap->GetFilename().AsCString();
Caroline Tice7826c882010-10-26 03:11:13 +0000126 }
127
128 if (log)
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000129 log->Printf ("SBFileSpec::GetFilename (this.ap=%p) => NULL", m_opaque_ap.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000130
Chris Lattner24943d22010-06-08 16:52:24 +0000131 return NULL;
132}
133
134const char *
135SBFileSpec::GetDirectory() const
136{
Greg Clayton63094e02010-06-23 01:19:29 +0000137 if (m_opaque_ap.get())
138 return m_opaque_ap->GetDirectory().AsCString();
Chris Lattner24943d22010-06-08 16:52:24 +0000139 return NULL;
140}
141
142uint32_t
143SBFileSpec::GetPath (char *dst_path, size_t dst_len) const
144{
Caroline Tice7826c882010-10-26 03:11:13 +0000145 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
146
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000147 //if (log)
148 // log->Printf ("SBFileSpec::GetPath (dst_path, dst_len)");
Caroline Tice7826c882010-10-26 03:11:13 +0000149
150 uint32_t result;
Greg Clayton63094e02010-06-23 01:19:29 +0000151 if (m_opaque_ap.get())
Caroline Tice7826c882010-10-26 03:11:13 +0000152 {
153 result = m_opaque_ap->GetPath (dst_path, dst_len);
154 if (log)
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000155 log->Printf ("SBFileSpec::GetPath (this.ap=%p, dst_path, dst_len) => dst_path='%s', dst_len='%d', "
156 "result='%d'", m_opaque_ap.get(), dst_path, (uint32_t) dst_len, result);
Caroline Tice7826c882010-10-26 03:11:13 +0000157 return result;
158 }
159
160 if (log)
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000161 log->Printf ("SBFileSpec::GetPath (this.ap=%p, dst_path, dst_len) => NULL (0)", m_opaque_ap.get());
Chris Lattner24943d22010-06-08 16:52:24 +0000162
163 if (dst_path && dst_len)
164 *dst_path = '\0';
165 return 0;
166}
167
168
169const lldb_private::FileSpec *
170SBFileSpec::operator->() const
171{
Greg Clayton63094e02010-06-23 01:19:29 +0000172 return m_opaque_ap.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000173}
174
175const lldb_private::FileSpec *
176SBFileSpec::get() const
177{
Greg Clayton63094e02010-06-23 01:19:29 +0000178 return m_opaque_ap.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000179}
180
181
182const lldb_private::FileSpec &
183SBFileSpec::operator*() const
184{
Greg Clayton63094e02010-06-23 01:19:29 +0000185 return *m_opaque_ap.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000186}
187
188const lldb_private::FileSpec &
189SBFileSpec::ref() const
190{
Greg Clayton63094e02010-06-23 01:19:29 +0000191 return *m_opaque_ap.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000192}
193
194
195void
196SBFileSpec::SetFileSpec (const lldb_private::FileSpec& fs)
197{
Greg Clayton63094e02010-06-23 01:19:29 +0000198 if (m_opaque_ap.get())
199 *m_opaque_ap = fs;
Chris Lattner24943d22010-06-08 16:52:24 +0000200 else
Greg Clayton63094e02010-06-23 01:19:29 +0000201 m_opaque_ap.reset (new FileSpec (fs));
Chris Lattner24943d22010-06-08 16:52:24 +0000202}
203
Caroline Tice98f930f2010-09-20 05:20:02 +0000204bool
205SBFileSpec::GetDescription (SBStream &description)
206{
207 if (m_opaque_ap.get())
208 {
209 const char *filename = GetFilename();
210 const char *dir_name = GetDirectory();
211 if (!filename && !dir_name)
212 description.Printf ("No value");
213 else if (!dir_name)
214 description.Printf ("%s", filename);
215 else
216 description.Printf ("%s/%s", dir_name, filename);
217 }
218 else
219 description.Printf ("No value");
220
221 return true;
222}
Caroline Tice7826c882010-10-26 03:11:13 +0000223
224bool
225SBFileSpec::GetDescription (SBStream &description) const
226{
227 if (m_opaque_ap.get())
228 {
229 const char *filename = GetFilename();
230 const char *dir_name = GetDirectory();
231 if (!filename && !dir_name)
232 description.Printf ("No value");
233 else if (!dir_name)
234 description.Printf ("%s", filename);
235 else
236 description.Printf ("%s/%s", dir_name, filename);
237 }
238 else
239 description.Printf ("No value");
240
241 return true;
242}