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 
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 
22 SourceLocationSpec::operator bool() const { return m_declaration.IsValid(); }
23 
24 bool SourceLocationSpec::operator!() const { return !operator bool(); }
25 
26 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 
32 bool SourceLocationSpec::operator!=(const SourceLocationSpec &rhs) const {
33   return !(*this == rhs);
34 }
35 
36 bool SourceLocationSpec::operator<(const SourceLocationSpec &rhs) const {
37   return SourceLocationSpec::Compare(*this, rhs) < 0;
38 }
39 
40 Stream &lldb_private::operator<<(Stream &s, const SourceLocationSpec &loc) {
41   loc.Dump(s);
42   return s;
43 }
44 
45 int SourceLocationSpec::Compare(const SourceLocationSpec &lhs,
46                                 const SourceLocationSpec &rhs) {
47   return Declaration::Compare(lhs.m_declaration, rhs.m_declaration);
48 }
49 
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 
57 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 
63 std::string SourceLocationSpec::GetString() const {
64   StreamString ss;
65   Dump(ss);
66   return ss.GetString().str();
67 }
68 
69 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 
76 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