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 | #include "llvm/ADT/StringExtras.h" |
12 | #include <optional> |
13 | |
14 | using namespace lldb; |
15 | using namespace lldb_private; |
16 | |
17 | SourceLocationSpec::SourceLocationSpec(FileSpec file_spec, uint32_t line, |
18 | std::optional<uint16_t> column, |
19 | bool check_inlines, bool exact_match) |
20 | : m_declaration(file_spec, line, |
21 | column.value_or(LLDB_INVALID_COLUMN_NUMBER)), |
22 | m_check_inlines(check_inlines), m_exact_match(exact_match) {} |
23 | |
24 | SourceLocationSpec::operator bool() const { return m_declaration.IsValid(); } |
25 | |
26 | bool SourceLocationSpec::operator!() const { return !operator bool(); } |
27 | |
28 | bool SourceLocationSpec::operator==(const SourceLocationSpec &rhs) const { |
29 | return m_declaration == rhs.m_declaration && |
30 | m_check_inlines == rhs.GetCheckInlines() && |
31 | m_exact_match == rhs.GetExactMatch(); |
32 | } |
33 | |
34 | bool SourceLocationSpec::operator!=(const SourceLocationSpec &rhs) const { |
35 | return !(*this == rhs); |
36 | } |
37 | |
38 | bool SourceLocationSpec::operator<(const SourceLocationSpec &rhs) const { |
39 | return SourceLocationSpec::Compare(lhs: *this, rhs) < 0; |
40 | } |
41 | |
42 | Stream &lldb_private::operator<<(Stream &s, const SourceLocationSpec &loc) { |
43 | loc.Dump(s); |
44 | return s; |
45 | } |
46 | |
47 | int SourceLocationSpec::Compare(const SourceLocationSpec &lhs, |
48 | const SourceLocationSpec &rhs) { |
49 | return Declaration::Compare(lhs: lhs.m_declaration, rhs: rhs.m_declaration); |
50 | } |
51 | |
52 | bool SourceLocationSpec::Equal(const SourceLocationSpec &lhs, |
53 | const SourceLocationSpec &rhs, bool full) { |
54 | return full ? lhs == rhs |
55 | : (lhs.GetFileSpec() == rhs.GetFileSpec() && |
56 | lhs.GetLine() == rhs.GetLine()); |
57 | } |
58 | |
59 | void SourceLocationSpec::Dump(Stream &s) const { |
60 | s << "check inlines = " << llvm::toStringRef(B: m_check_inlines); |
61 | s << ", exact match = " << llvm::toStringRef(B: m_exact_match); |
62 | m_declaration.Dump(s: &s, show_fullpaths: true); |
63 | } |
64 | |
65 | std::string SourceLocationSpec::GetString() const { |
66 | StreamString ss; |
67 | Dump(s&: ss); |
68 | return ss.GetString().str(); |
69 | } |
70 | |
71 | std::optional<uint32_t> SourceLocationSpec::GetLine() const { |
72 | uint32_t line = m_declaration.GetLine(); |
73 | if (line == 0 || line == LLDB_INVALID_LINE_NUMBER) |
74 | return std::nullopt; |
75 | return line; |
76 | } |
77 | |
78 | std::optional<uint16_t> SourceLocationSpec::GetColumn() const { |
79 | uint16_t column = m_declaration.GetColumn(); |
80 | if (column == LLDB_INVALID_COLUMN_NUMBER) |
81 | return std::nullopt; |
82 | return column; |
83 | } |
84 | |