Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame^] | 1 | //===-- 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 | |
| 16 | using namespace lldb; |
| 17 | using namespace lldb_private; |
| 18 | |
| 19 | |
| 20 | SBCompileUnit::SBCompileUnit () : |
| 21 | m_lldb_object_ptr (NULL) |
| 22 | { |
| 23 | } |
| 24 | |
| 25 | SBCompileUnit::SBCompileUnit (lldb_private::CompileUnit *lldb_object_ptr) : |
| 26 | m_lldb_object_ptr (lldb_object_ptr) |
| 27 | { |
| 28 | } |
| 29 | |
| 30 | SBCompileUnit::~SBCompileUnit () |
| 31 | { |
| 32 | m_lldb_object_ptr = NULL; |
| 33 | } |
| 34 | |
| 35 | SBFileSpec |
| 36 | SBCompileUnit::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 | |
| 44 | uint32_t |
| 45 | SBCompileUnit::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 | |
| 56 | SBLineEntry |
| 57 | SBCompileUnit::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 | |
| 73 | uint32_t |
| 74 | SBCompileUnit::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 | |
| 92 | bool |
| 93 | SBCompileUnit::IsValid () const |
| 94 | { |
| 95 | return m_lldb_object_ptr != NULL; |
| 96 | } |
| 97 | |
| 98 | bool |
| 99 | SBCompileUnit::operator == (const SBCompileUnit &rhs) const |
| 100 | { |
| 101 | return m_lldb_object_ptr == rhs.m_lldb_object_ptr; |
| 102 | } |
| 103 | |
| 104 | bool |
| 105 | SBCompileUnit::operator != (const SBCompileUnit &rhs) const |
| 106 | { |
| 107 | return m_lldb_object_ptr != rhs.m_lldb_object_ptr; |
| 108 | } |
| 109 | |
| 110 | const lldb_private::CompileUnit * |
| 111 | SBCompileUnit::operator->() const |
| 112 | { |
| 113 | return m_lldb_object_ptr; |
| 114 | } |
| 115 | |
| 116 | const lldb_private::CompileUnit & |
| 117 | SBCompileUnit::operator*() const |
| 118 | { |
| 119 | return *m_lldb_object_ptr; |
| 120 | } |