blob: a12934a0587b0d29af8c3217fafdf6b91a79409b [file] [log] [blame]
Chris Lattner24943d22010-06-08 16:52:24 +00001//===-- SBCompileUnit.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/SBCompileUnit.h"
11#include "lldb/API/SBLineEntry.h"
12#include "lldb/Symbol/CompileUnit.h"
13#include "lldb/Symbol/LineEntry.h"
14#include "lldb/Symbol/LineTable.h"
15
16using namespace lldb;
17using namespace lldb_private;
18
19
20SBCompileUnit::SBCompileUnit () :
21 m_lldb_object_ptr (NULL)
22{
23}
24
25SBCompileUnit::SBCompileUnit (lldb_private::CompileUnit *lldb_object_ptr) :
26 m_lldb_object_ptr (lldb_object_ptr)
27{
28}
29
30SBCompileUnit::~SBCompileUnit ()
31{
32 m_lldb_object_ptr = NULL;
33}
34
35SBFileSpec
36SBCompileUnit::GetFileSpec () const
37{
38 SBFileSpec file_spec;
39 if (m_lldb_object_ptr)
40 file_spec.SetFileSpec(*m_lldb_object_ptr);
41 return file_spec;
42}
43
44uint32_t
45SBCompileUnit::GetNumLineEntries () const
46{
47 if (m_lldb_object_ptr)
48 {
49 LineTable *line_table = m_lldb_object_ptr->GetLineTable ();
50 if (line_table)
51 return line_table->GetSize();
52 }
53 return 0;
54}
55
56SBLineEntry
57SBCompileUnit::GetLineEntryAtIndex (uint32_t idx) const
58{
59 SBLineEntry sb_line_entry;
60 if (m_lldb_object_ptr)
61 {
62 LineTable *line_table = m_lldb_object_ptr->GetLineTable ();
63 if (line_table)
64 {
65 LineEntry line_entry;
66 if (line_table->GetLineEntryAtIndex(idx, line_entry))
67 sb_line_entry.SetLineEntry(line_entry);
68 }
69 }
70 return sb_line_entry;
71}
72
73uint32_t
74SBCompileUnit::FindLineEntryIndex (uint32_t start_idx, uint32_t line, SBFileSpec *inline_file_spec) const
75{
76 if (m_lldb_object_ptr)
77 {
78 FileSpec file_spec;
79 if (inline_file_spec && inline_file_spec->IsValid())
80 file_spec = inline_file_spec->ref();
81 else
82 file_spec = *m_lldb_object_ptr;
83
84 return m_lldb_object_ptr->FindLineEntry (start_idx,
85 line,
86 inline_file_spec ? inline_file_spec->get() : NULL,
87 NULL);
88 }
89 return UINT32_MAX;
90}
91
92bool
93SBCompileUnit::IsValid () const
94{
95 return m_lldb_object_ptr != NULL;
96}
97
98bool
99SBCompileUnit::operator == (const SBCompileUnit &rhs) const
100{
101 return m_lldb_object_ptr == rhs.m_lldb_object_ptr;
102}
103
104bool
105SBCompileUnit::operator != (const SBCompileUnit &rhs) const
106{
107 return m_lldb_object_ptr != rhs.m_lldb_object_ptr;
108}
109
110const lldb_private::CompileUnit *
111SBCompileUnit::operator->() const
112{
113 return m_lldb_object_ptr;
114}
115
116const lldb_private::CompileUnit &
117SBCompileUnit::operator*() const
118{
119 return *m_lldb_object_ptr;
120}