aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm-project/lldb/source/Core/SourceLocationSpec.cpp
blob: 610754bb187c8747316e7d51cca18dc14073ce2c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
//===-- SourceLocationSpec.cpp --------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "lldb/Core/SourceLocationSpec.h"
#include "lldb/Utility/StreamString.h"

using namespace lldb;
using namespace lldb_private;

SourceLocationSpec::SourceLocationSpec(FileSpec file_spec, uint32_t line,
                                       llvm::Optional<uint16_t> column,
                                       bool check_inlines, bool exact_match)
    : m_declaration(file_spec, line,
                    column.getValueOr(LLDB_INVALID_COLUMN_NUMBER)),
      m_check_inlines(check_inlines), m_exact_match(exact_match) {}

SourceLocationSpec::operator bool() const { return m_declaration.IsValid(); }

bool SourceLocationSpec::operator!() const { return !operator bool(); }

bool SourceLocationSpec::operator==(const SourceLocationSpec &rhs) const {
  return m_declaration == rhs.m_declaration &&
         m_check_inlines == rhs.GetCheckInlines() &&
         m_exact_match == rhs.GetExactMatch();
}

bool SourceLocationSpec::operator!=(const SourceLocationSpec &rhs) const {
  return !(*this == rhs);
}

bool SourceLocationSpec::operator<(const SourceLocationSpec &rhs) const {
  return SourceLocationSpec::Compare(*this, rhs) < 0;
}

Stream &lldb_private::operator<<(Stream &s, const SourceLocationSpec &loc) {
  loc.Dump(s);
  return s;
}

int SourceLocationSpec::Compare(const SourceLocationSpec &lhs,
                                const SourceLocationSpec &rhs) {
  return Declaration::Compare(lhs.m_declaration, rhs.m_declaration);
}

bool SourceLocationSpec::Equal(const SourceLocationSpec &lhs,
                               const SourceLocationSpec &rhs, bool full) {
  return full ? lhs == rhs
              : (lhs.GetFileSpec() == rhs.GetFileSpec() &&
                 lhs.GetLine() == rhs.GetLine());
}

void SourceLocationSpec::Dump(Stream &s) const {
  s << "check inlines = " << llvm::toStringRef(m_check_inlines);
  s << ", exact match = " << llvm::toStringRef(m_exact_match);
  m_declaration.Dump(&s, true);
}

std::string SourceLocationSpec::GetString() const {
  StreamString ss;
  Dump(ss);
  return ss.GetString().str();
}

llvm::Optional<uint32_t> SourceLocationSpec::GetLine() const {
  uint32_t line = m_declaration.GetLine();
  if (line == 0 || line == LLDB_INVALID_LINE_NUMBER)
    return llvm::None;
  return line;
}

llvm::Optional<uint16_t> SourceLocationSpec::GetColumn() const {
  uint16_t column = m_declaration.GetColumn();
  if (column == LLDB_INVALID_COLUMN_NUMBER)
    return llvm::None;
  return column;
}