1254721Semaste//===-- SBCompileUnit.cpp ---------------------------------------*- C++ -*-===//
2254721Semaste//
3254721Semaste//                     The LLVM Compiler Infrastructure
4254721Semaste//
5254721Semaste// This file is distributed under the University of Illinois Open Source
6254721Semaste// License. See LICENSE.TXT for details.
7254721Semaste//
8254721Semaste//===----------------------------------------------------------------------===//
9254721Semaste
10254721Semaste#include "lldb/API/SBCompileUnit.h"
11254721Semaste#include "lldb/API/SBLineEntry.h"
12254721Semaste#include "lldb/API/SBStream.h"
13254721Semaste#include "lldb/Core/Log.h"
14254721Semaste#include "lldb/Core/Module.h"
15254721Semaste#include "lldb/Symbol/CompileUnit.h"
16254721Semaste#include "lldb/Symbol/LineEntry.h"
17254721Semaste#include "lldb/Symbol/LineTable.h"
18254721Semaste#include "lldb/Symbol/SymbolVendor.h"
19254721Semaste#include "lldb/Symbol/Type.h"
20254721Semaste
21254721Semasteusing namespace lldb;
22254721Semasteusing namespace lldb_private;
23254721Semaste
24254721Semaste
25254721SemasteSBCompileUnit::SBCompileUnit () :
26254721Semaste    m_opaque_ptr (NULL)
27254721Semaste{
28254721Semaste}
29254721Semaste
30254721SemasteSBCompileUnit::SBCompileUnit (lldb_private::CompileUnit *lldb_object_ptr) :
31254721Semaste    m_opaque_ptr (lldb_object_ptr)
32254721Semaste{
33254721Semaste}
34254721Semaste
35254721SemasteSBCompileUnit::SBCompileUnit(const SBCompileUnit &rhs) :
36254721Semaste    m_opaque_ptr (rhs.m_opaque_ptr)
37254721Semaste{
38254721Semaste}
39254721Semaste
40254721Semasteconst SBCompileUnit &
41254721SemasteSBCompileUnit::operator = (const SBCompileUnit &rhs)
42254721Semaste{
43254721Semaste    m_opaque_ptr = rhs.m_opaque_ptr;
44254721Semaste    return *this;
45254721Semaste}
46254721Semaste
47254721Semaste
48254721SemasteSBCompileUnit::~SBCompileUnit ()
49254721Semaste{
50254721Semaste    m_opaque_ptr = NULL;
51254721Semaste}
52254721Semaste
53254721SemasteSBFileSpec
54254721SemasteSBCompileUnit::GetFileSpec () const
55254721Semaste{
56254721Semaste    SBFileSpec file_spec;
57254721Semaste    if (m_opaque_ptr)
58254721Semaste        file_spec.SetFileSpec(*m_opaque_ptr);
59254721Semaste    return file_spec;
60254721Semaste}
61254721Semaste
62254721Semasteuint32_t
63254721SemasteSBCompileUnit::GetNumLineEntries () const
64254721Semaste{
65254721Semaste    if (m_opaque_ptr)
66254721Semaste    {
67254721Semaste        LineTable *line_table = m_opaque_ptr->GetLineTable ();
68254721Semaste        if (line_table)
69254721Semaste            return line_table->GetSize();
70254721Semaste    }
71254721Semaste    return 0;
72254721Semaste}
73254721Semaste
74254721SemasteSBLineEntry
75254721SemasteSBCompileUnit::GetLineEntryAtIndex (uint32_t idx) const
76254721Semaste{
77254721Semaste    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
78254721Semaste
79254721Semaste    SBLineEntry sb_line_entry;
80254721Semaste    if (m_opaque_ptr)
81254721Semaste    {
82254721Semaste        LineTable *line_table = m_opaque_ptr->GetLineTable ();
83254721Semaste        if (line_table)
84254721Semaste        {
85254721Semaste            LineEntry line_entry;
86254721Semaste            if (line_table->GetLineEntryAtIndex(idx, line_entry))
87254721Semaste                sb_line_entry.SetLineEntry(line_entry);
88254721Semaste        }
89254721Semaste    }
90254721Semaste
91254721Semaste    if (log)
92254721Semaste    {
93254721Semaste        SBStream sstr;
94254721Semaste        sb_line_entry.GetDescription (sstr);
95254721Semaste        log->Printf ("SBCompileUnit(%p)::GetLineEntryAtIndex (idx=%u) => SBLineEntry(%p): '%s'",
96254721Semaste                     m_opaque_ptr, idx, sb_line_entry.get(), sstr.GetData());
97254721Semaste    }
98254721Semaste
99254721Semaste    return sb_line_entry;
100254721Semaste}
101254721Semaste
102254721Semasteuint32_t
103254721SemasteSBCompileUnit::FindLineEntryIndex (uint32_t start_idx, uint32_t line, SBFileSpec *inline_file_spec) const
104254721Semaste{
105254721Semaste    const bool exact = true;
106254721Semaste    return FindLineEntryIndex (start_idx, line, inline_file_spec, exact);
107254721Semaste}
108254721Semaste
109254721Semasteuint32_t
110254721SemasteSBCompileUnit::FindLineEntryIndex (uint32_t start_idx, uint32_t line, SBFileSpec *inline_file_spec, bool exact) const
111254721Semaste{
112254721Semaste    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
113254721Semaste
114254721Semaste    uint32_t index = UINT32_MAX;
115254721Semaste    if (m_opaque_ptr)
116254721Semaste    {
117254721Semaste        FileSpec file_spec;
118254721Semaste        if (inline_file_spec && inline_file_spec->IsValid())
119254721Semaste            file_spec = inline_file_spec->ref();
120254721Semaste        else
121254721Semaste            file_spec = *m_opaque_ptr;
122254721Semaste
123254721Semaste
124254721Semaste        index = m_opaque_ptr->FindLineEntry (start_idx,
125254721Semaste                                             line,
126254721Semaste                                             inline_file_spec ? inline_file_spec->get() : NULL,
127254721Semaste                                             exact,
128254721Semaste                                             NULL);
129254721Semaste    }
130254721Semaste
131254721Semaste    if (log)
132254721Semaste    {
133254721Semaste        SBStream sstr;
134254721Semaste        if (index == UINT32_MAX)
135254721Semaste        {
136254721Semaste            log->Printf ("SBCompileUnit(%p)::FindLineEntryIndex (start_idx=%u, line=%u, SBFileSpec(%p)) => NOT FOUND",
137254721Semaste                         m_opaque_ptr, start_idx, line, inline_file_spec ? inline_file_spec->get() : NULL);
138254721Semaste        }
139254721Semaste        else
140254721Semaste        {
141254721Semaste            log->Printf ("SBCompileUnit(%p)::FindLineEntryIndex (start_idx=%u, line=%u, SBFileSpec(%p)) => %u",
142254721Semaste                         m_opaque_ptr, start_idx, line, inline_file_spec ? inline_file_spec->get() : NULL, index);
143254721Semaste        }
144254721Semaste    }
145254721Semaste
146254721Semaste    return index;
147254721Semaste}
148254721Semaste
149254721Semasteuint32_t
150254721SemasteSBCompileUnit::GetNumSupportFiles () const
151254721Semaste{
152254721Semaste    if (m_opaque_ptr)
153254721Semaste    {
154254721Semaste        FileSpecList& support_files = m_opaque_ptr->GetSupportFiles ();
155254721Semaste        return support_files.GetSize();
156254721Semaste    }
157254721Semaste    return 0;
158254721Semaste}
159254721Semaste
160254721Semaste
161254721Semaste
162254721Semastelldb::SBTypeList
163254721SemasteSBCompileUnit::GetTypes (uint32_t type_mask)
164254721Semaste{
165254721Semaste    SBTypeList sb_type_list;
166254721Semaste
167254721Semaste    if (m_opaque_ptr)
168254721Semaste    {
169254721Semaste        ModuleSP module_sp (m_opaque_ptr->GetModule());
170254721Semaste        if (module_sp)
171254721Semaste        {
172254721Semaste            SymbolVendor* vendor = module_sp->GetSymbolVendor();
173254721Semaste            if (vendor)
174254721Semaste            {
175254721Semaste                TypeList type_list;
176254721Semaste                vendor->GetTypes (m_opaque_ptr, type_mask, type_list);
177254721Semaste                sb_type_list.m_opaque_ap->Append(type_list);
178254721Semaste            }
179254721Semaste        }
180254721Semaste    }
181254721Semaste    return sb_type_list;
182254721Semaste}
183254721Semaste
184254721Semaste
185254721Semaste
186254721Semaste
187254721SemasteSBFileSpec
188254721SemasteSBCompileUnit::GetSupportFileAtIndex (uint32_t idx) const
189254721Semaste{
190254721Semaste    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
191254721Semaste
192254721Semaste    SBFileSpec sb_file_spec;
193254721Semaste    if (m_opaque_ptr)
194254721Semaste    {
195254721Semaste        FileSpecList &support_files = m_opaque_ptr->GetSupportFiles ();
196254721Semaste        FileSpec file_spec = support_files.GetFileSpecAtIndex(idx);
197254721Semaste        sb_file_spec.SetFileSpec(file_spec);
198254721Semaste    }
199254721Semaste
200254721Semaste    if (log)
201254721Semaste    {
202254721Semaste        SBStream sstr;
203254721Semaste        sb_file_spec.GetDescription (sstr);
204254721Semaste        log->Printf ("SBCompileUnit(%p)::GetGetFileSpecAtIndex (idx=%u) => SBFileSpec(%p): '%s'",
205254721Semaste                     m_opaque_ptr, idx, sb_file_spec.get(), sstr.GetData());
206254721Semaste    }
207254721Semaste
208254721Semaste    return sb_file_spec;
209254721Semaste}
210254721Semaste
211254721Semasteuint32_t
212254721SemasteSBCompileUnit::FindSupportFileIndex (uint32_t start_idx, const SBFileSpec &sb_file, bool full)
213254721Semaste{
214254721Semaste    if (m_opaque_ptr)
215254721Semaste    {
216254721Semaste	FileSpecList &support_files = m_opaque_ptr->GetSupportFiles ();
217254721Semaste	return support_files.FindFileIndex(start_idx, sb_file.ref(), full);
218254721Semaste    }
219254721Semaste    return 0;
220254721Semaste}
221254721Semaste
222254721Semastebool
223254721SemasteSBCompileUnit::IsValid () const
224254721Semaste{
225254721Semaste    return m_opaque_ptr != NULL;
226254721Semaste}
227254721Semaste
228254721Semastebool
229254721SemasteSBCompileUnit::operator == (const SBCompileUnit &rhs) const
230254721Semaste{
231254721Semaste    return m_opaque_ptr == rhs.m_opaque_ptr;
232254721Semaste}
233254721Semaste
234254721Semastebool
235254721SemasteSBCompileUnit::operator != (const SBCompileUnit &rhs) const
236254721Semaste{
237254721Semaste    return m_opaque_ptr != rhs.m_opaque_ptr;
238254721Semaste}
239254721Semaste
240254721Semasteconst lldb_private::CompileUnit *
241254721SemasteSBCompileUnit::operator->() const
242254721Semaste{
243254721Semaste    return m_opaque_ptr;
244254721Semaste}
245254721Semaste
246254721Semasteconst lldb_private::CompileUnit &
247254721SemasteSBCompileUnit::operator*() const
248254721Semaste{
249254721Semaste    return *m_opaque_ptr;
250254721Semaste}
251254721Semaste
252254721Semastelldb_private::CompileUnit *
253254721SemasteSBCompileUnit::get ()
254254721Semaste{
255254721Semaste    return m_opaque_ptr;
256254721Semaste}
257254721Semaste
258254721Semastevoid
259254721SemasteSBCompileUnit::reset (lldb_private::CompileUnit *lldb_object_ptr)
260254721Semaste{
261254721Semaste    m_opaque_ptr = lldb_object_ptr;
262254721Semaste}
263254721Semaste
264254721Semaste
265254721Semastebool
266254721SemasteSBCompileUnit::GetDescription (SBStream &description)
267254721Semaste{
268254721Semaste    Stream &strm = description.ref();
269254721Semaste
270254721Semaste    if (m_opaque_ptr)
271254721Semaste    {
272254721Semaste        m_opaque_ptr->Dump (&strm, false);
273254721Semaste    }
274254721Semaste    else
275254721Semaste        strm.PutCString ("No value");
276254721Semaste
277254721Semaste    return true;
278254721Semaste}
279