1fe6060f1SDimitry Andric //===-- SourceLocationSpec.cpp --------------------------------------------===//
2fe6060f1SDimitry Andric //
3fe6060f1SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4fe6060f1SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
5fe6060f1SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6fe6060f1SDimitry Andric //
7fe6060f1SDimitry Andric //===----------------------------------------------------------------------===//
8fe6060f1SDimitry Andric
9fe6060f1SDimitry Andric #include "lldb/Core/SourceLocationSpec.h"
10fe6060f1SDimitry Andric #include "lldb/Utility/StreamString.h"
11*06c3fb27SDimitry Andric #include "llvm/ADT/StringExtras.h"
12bdd1243dSDimitry Andric #include <optional>
13fe6060f1SDimitry Andric
14fe6060f1SDimitry Andric using namespace lldb;
15fe6060f1SDimitry Andric using namespace lldb_private;
16fe6060f1SDimitry Andric
SourceLocationSpec(FileSpec file_spec,uint32_t line,std::optional<uint16_t> column,bool check_inlines,bool exact_match)17fe6060f1SDimitry Andric SourceLocationSpec::SourceLocationSpec(FileSpec file_spec, uint32_t line,
18bdd1243dSDimitry Andric std::optional<uint16_t> column,
19fe6060f1SDimitry Andric bool check_inlines, bool exact_match)
20fe6060f1SDimitry Andric : m_declaration(file_spec, line,
2181ad6265SDimitry Andric column.value_or(LLDB_INVALID_COLUMN_NUMBER)),
22fe6060f1SDimitry Andric m_check_inlines(check_inlines), m_exact_match(exact_match) {}
23fe6060f1SDimitry Andric
operator bool() const24fe6060f1SDimitry Andric SourceLocationSpec::operator bool() const { return m_declaration.IsValid(); }
25fe6060f1SDimitry Andric
operator !() const26fe6060f1SDimitry Andric bool SourceLocationSpec::operator!() const { return !operator bool(); }
27fe6060f1SDimitry Andric
operator ==(const SourceLocationSpec & rhs) const28fe6060f1SDimitry Andric bool SourceLocationSpec::operator==(const SourceLocationSpec &rhs) const {
29fe6060f1SDimitry Andric return m_declaration == rhs.m_declaration &&
30fe6060f1SDimitry Andric m_check_inlines == rhs.GetCheckInlines() &&
31fe6060f1SDimitry Andric m_exact_match == rhs.GetExactMatch();
32fe6060f1SDimitry Andric }
33fe6060f1SDimitry Andric
operator !=(const SourceLocationSpec & rhs) const34fe6060f1SDimitry Andric bool SourceLocationSpec::operator!=(const SourceLocationSpec &rhs) const {
35fe6060f1SDimitry Andric return !(*this == rhs);
36fe6060f1SDimitry Andric }
37fe6060f1SDimitry Andric
operator <(const SourceLocationSpec & rhs) const38fe6060f1SDimitry Andric bool SourceLocationSpec::operator<(const SourceLocationSpec &rhs) const {
39fe6060f1SDimitry Andric return SourceLocationSpec::Compare(*this, rhs) < 0;
40fe6060f1SDimitry Andric }
41fe6060f1SDimitry Andric
operator <<(Stream & s,const SourceLocationSpec & loc)42fe6060f1SDimitry Andric Stream &lldb_private::operator<<(Stream &s, const SourceLocationSpec &loc) {
43fe6060f1SDimitry Andric loc.Dump(s);
44fe6060f1SDimitry Andric return s;
45fe6060f1SDimitry Andric }
46fe6060f1SDimitry Andric
Compare(const SourceLocationSpec & lhs,const SourceLocationSpec & rhs)47fe6060f1SDimitry Andric int SourceLocationSpec::Compare(const SourceLocationSpec &lhs,
48fe6060f1SDimitry Andric const SourceLocationSpec &rhs) {
49fe6060f1SDimitry Andric return Declaration::Compare(lhs.m_declaration, rhs.m_declaration);
50fe6060f1SDimitry Andric }
51fe6060f1SDimitry Andric
Equal(const SourceLocationSpec & lhs,const SourceLocationSpec & rhs,bool full)52fe6060f1SDimitry Andric bool SourceLocationSpec::Equal(const SourceLocationSpec &lhs,
53fe6060f1SDimitry Andric const SourceLocationSpec &rhs, bool full) {
54fe6060f1SDimitry Andric return full ? lhs == rhs
55fe6060f1SDimitry Andric : (lhs.GetFileSpec() == rhs.GetFileSpec() &&
56fe6060f1SDimitry Andric lhs.GetLine() == rhs.GetLine());
57fe6060f1SDimitry Andric }
58fe6060f1SDimitry Andric
Dump(Stream & s) const59fe6060f1SDimitry Andric void SourceLocationSpec::Dump(Stream &s) const {
60fe6060f1SDimitry Andric s << "check inlines = " << llvm::toStringRef(m_check_inlines);
61fe6060f1SDimitry Andric s << ", exact match = " << llvm::toStringRef(m_exact_match);
62fe6060f1SDimitry Andric m_declaration.Dump(&s, true);
63fe6060f1SDimitry Andric }
64fe6060f1SDimitry Andric
GetString() const65fe6060f1SDimitry Andric std::string SourceLocationSpec::GetString() const {
66fe6060f1SDimitry Andric StreamString ss;
67fe6060f1SDimitry Andric Dump(ss);
68fe6060f1SDimitry Andric return ss.GetString().str();
69fe6060f1SDimitry Andric }
70fe6060f1SDimitry Andric
GetLine() const71bdd1243dSDimitry Andric std::optional<uint32_t> SourceLocationSpec::GetLine() const {
72fe6060f1SDimitry Andric uint32_t line = m_declaration.GetLine();
73fe6060f1SDimitry Andric if (line == 0 || line == LLDB_INVALID_LINE_NUMBER)
74bdd1243dSDimitry Andric return std::nullopt;
75fe6060f1SDimitry Andric return line;
76fe6060f1SDimitry Andric }
77fe6060f1SDimitry Andric
GetColumn() const78bdd1243dSDimitry Andric std::optional<uint16_t> SourceLocationSpec::GetColumn() const {
79fe6060f1SDimitry Andric uint16_t column = m_declaration.GetColumn();
80fe6060f1SDimitry Andric if (column == LLDB_INVALID_COLUMN_NUMBER)
81bdd1243dSDimitry Andric return std::nullopt;
82fe6060f1SDimitry Andric return column;
83fe6060f1SDimitry Andric }
84