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

source code of lldb/source/Core/SourceLocationSpec.cpp