1 //===-- SourceLocationSpec.cpp --------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8
9 #include "lldb/Core/SourceLocationSpec.h"
10 #include "lldb/Utility/StreamString.h"
11
12 using namespace lldb;
13 using namespace lldb_private;
14
SourceLocationSpec(FileSpec file_spec,uint32_t line,llvm::Optional<uint16_t> column,bool check_inlines,bool exact_match)15 SourceLocationSpec::SourceLocationSpec(FileSpec file_spec, uint32_t line,
16 llvm::Optional<uint16_t> column,
17 bool check_inlines, bool exact_match)
18 : m_declaration(file_spec, line,
19 column.getValueOr(LLDB_INVALID_COLUMN_NUMBER)),
20 m_check_inlines(check_inlines), m_exact_match(exact_match) {}
21
operator bool() const22 SourceLocationSpec::operator bool() const { return m_declaration.IsValid(); }
23
operator !() const24 bool SourceLocationSpec::operator!() const { return !operator bool(); }
25
operator ==(const SourceLocationSpec & rhs) const26 bool SourceLocationSpec::operator==(const SourceLocationSpec &rhs) const {
27 return m_declaration == rhs.m_declaration &&
28 m_check_inlines == rhs.GetCheckInlines() &&
29 m_exact_match == rhs.GetExactMatch();
30 }
31
operator !=(const SourceLocationSpec & rhs) const32 bool SourceLocationSpec::operator!=(const SourceLocationSpec &rhs) const {
33 return !(*this == rhs);
34 }
35
operator <(const SourceLocationSpec & rhs) const36 bool SourceLocationSpec::operator<(const SourceLocationSpec &rhs) const {
37 return SourceLocationSpec::Compare(*this, rhs) < 0;
38 }
39
operator <<(Stream & s,const SourceLocationSpec & loc)40 Stream &lldb_private::operator<<(Stream &s, const SourceLocationSpec &loc) {
41 loc.Dump(s);
42 return s;
43 }
44
Compare(const SourceLocationSpec & lhs,const SourceLocationSpec & rhs)45 int SourceLocationSpec::Compare(const SourceLocationSpec &lhs,
46 const SourceLocationSpec &rhs) {
47 return Declaration::Compare(lhs.m_declaration, rhs.m_declaration);
48 }
49
Equal(const SourceLocationSpec & lhs,const SourceLocationSpec & rhs,bool full)50 bool SourceLocationSpec::Equal(const SourceLocationSpec &lhs,
51 const SourceLocationSpec &rhs, bool full) {
52 return full ? lhs == rhs
53 : (lhs.GetFileSpec() == rhs.GetFileSpec() &&
54 lhs.GetLine() == rhs.GetLine());
55 }
56
Dump(Stream & s) const57 void SourceLocationSpec::Dump(Stream &s) const {
58 s << "check inlines = " << llvm::toStringRef(m_check_inlines);
59 s << ", exact match = " << llvm::toStringRef(m_exact_match);
60 m_declaration.Dump(&s, true);
61 }
62
GetString() const63 std::string SourceLocationSpec::GetString() const {
64 StreamString ss;
65 Dump(ss);
66 return ss.GetString().str();
67 }
68
GetLine() const69 llvm::Optional<uint32_t> SourceLocationSpec::GetLine() const {
70 uint32_t line = m_declaration.GetLine();
71 if (line == 0 || line == LLDB_INVALID_LINE_NUMBER)
72 return llvm::None;
73 return line;
74 }
75
GetColumn() const76 llvm::Optional<uint16_t> SourceLocationSpec::GetColumn() const {
77 uint16_t column = m_declaration.GetColumn();
78 if (column == LLDB_INVALID_COLUMN_NUMBER)
79 return llvm::None;
80 return column;
81 }
82