xref: /openbsd-src/gnu/llvm/lldb/source/Core/SourceLocationSpec.cpp (revision f6aab3d83b51b91c24247ad2c2573574de475a82)
1be691f3bSpatrick //===-- SourceLocationSpec.cpp --------------------------------------------===//
2be691f3bSpatrick //
3be691f3bSpatrick // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4be691f3bSpatrick // See https://llvm.org/LICENSE.txt for license information.
5be691f3bSpatrick // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6be691f3bSpatrick //
7be691f3bSpatrick //===----------------------------------------------------------------------===//
8be691f3bSpatrick 
9be691f3bSpatrick #include "lldb/Core/SourceLocationSpec.h"
10be691f3bSpatrick #include "lldb/Utility/StreamString.h"
11*f6aab3d8Srobert #include <optional>
12be691f3bSpatrick 
13be691f3bSpatrick using namespace lldb;
14be691f3bSpatrick using namespace lldb_private;
15be691f3bSpatrick 
SourceLocationSpec(FileSpec file_spec,uint32_t line,std::optional<uint16_t> column,bool check_inlines,bool exact_match)16be691f3bSpatrick SourceLocationSpec::SourceLocationSpec(FileSpec file_spec, uint32_t line,
17*f6aab3d8Srobert                                        std::optional<uint16_t> column,
18be691f3bSpatrick                                        bool check_inlines, bool exact_match)
19be691f3bSpatrick     : m_declaration(file_spec, line,
20*f6aab3d8Srobert                     column.value_or(LLDB_INVALID_COLUMN_NUMBER)),
21be691f3bSpatrick       m_check_inlines(check_inlines), m_exact_match(exact_match) {}
22be691f3bSpatrick 
operator bool() const23be691f3bSpatrick SourceLocationSpec::operator bool() const { return m_declaration.IsValid(); }
24be691f3bSpatrick 
operator !() const25be691f3bSpatrick bool SourceLocationSpec::operator!() const { return !operator bool(); }
26be691f3bSpatrick 
operator ==(const SourceLocationSpec & rhs) const27be691f3bSpatrick bool SourceLocationSpec::operator==(const SourceLocationSpec &rhs) const {
28be691f3bSpatrick   return m_declaration == rhs.m_declaration &&
29be691f3bSpatrick          m_check_inlines == rhs.GetCheckInlines() &&
30be691f3bSpatrick          m_exact_match == rhs.GetExactMatch();
31be691f3bSpatrick }
32be691f3bSpatrick 
operator !=(const SourceLocationSpec & rhs) const33be691f3bSpatrick bool SourceLocationSpec::operator!=(const SourceLocationSpec &rhs) const {
34be691f3bSpatrick   return !(*this == rhs);
35be691f3bSpatrick }
36be691f3bSpatrick 
operator <(const SourceLocationSpec & rhs) const37be691f3bSpatrick bool SourceLocationSpec::operator<(const SourceLocationSpec &rhs) const {
38be691f3bSpatrick   return SourceLocationSpec::Compare(*this, rhs) < 0;
39be691f3bSpatrick }
40be691f3bSpatrick 
operator <<(Stream & s,const SourceLocationSpec & loc)41be691f3bSpatrick Stream &lldb_private::operator<<(Stream &s, const SourceLocationSpec &loc) {
42be691f3bSpatrick   loc.Dump(s);
43be691f3bSpatrick   return s;
44be691f3bSpatrick }
45be691f3bSpatrick 
Compare(const SourceLocationSpec & lhs,const SourceLocationSpec & rhs)46be691f3bSpatrick int SourceLocationSpec::Compare(const SourceLocationSpec &lhs,
47be691f3bSpatrick                                 const SourceLocationSpec &rhs) {
48be691f3bSpatrick   return Declaration::Compare(lhs.m_declaration, rhs.m_declaration);
49be691f3bSpatrick }
50be691f3bSpatrick 
Equal(const SourceLocationSpec & lhs,const SourceLocationSpec & rhs,bool full)51be691f3bSpatrick bool SourceLocationSpec::Equal(const SourceLocationSpec &lhs,
52be691f3bSpatrick                                const SourceLocationSpec &rhs, bool full) {
53be691f3bSpatrick   return full ? lhs == rhs
54be691f3bSpatrick               : (lhs.GetFileSpec() == rhs.GetFileSpec() &&
55be691f3bSpatrick                  lhs.GetLine() == rhs.GetLine());
56be691f3bSpatrick }
57be691f3bSpatrick 
Dump(Stream & s) const58be691f3bSpatrick void SourceLocationSpec::Dump(Stream &s) const {
59be691f3bSpatrick   s << "check inlines = " << llvm::toStringRef(m_check_inlines);
60be691f3bSpatrick   s << ", exact match = " << llvm::toStringRef(m_exact_match);
61be691f3bSpatrick   m_declaration.Dump(&s, true);
62be691f3bSpatrick }
63be691f3bSpatrick 
GetString() const64be691f3bSpatrick std::string SourceLocationSpec::GetString() const {
65be691f3bSpatrick   StreamString ss;
66be691f3bSpatrick   Dump(ss);
67be691f3bSpatrick   return ss.GetString().str();
68be691f3bSpatrick }
69be691f3bSpatrick 
GetLine() const70*f6aab3d8Srobert std::optional<uint32_t> SourceLocationSpec::GetLine() const {
71be691f3bSpatrick   uint32_t line = m_declaration.GetLine();
72be691f3bSpatrick   if (line == 0 || line == LLDB_INVALID_LINE_NUMBER)
73*f6aab3d8Srobert     return std::nullopt;
74be691f3bSpatrick   return line;
75be691f3bSpatrick }
76be691f3bSpatrick 
GetColumn() const77*f6aab3d8Srobert std::optional<uint16_t> SourceLocationSpec::GetColumn() const {
78be691f3bSpatrick   uint16_t column = m_declaration.GetColumn();
79be691f3bSpatrick   if (column == LLDB_INVALID_COLUMN_NUMBER)
80*f6aab3d8Srobert     return std::nullopt;
81be691f3bSpatrick   return column;
82be691f3bSpatrick }
83