1344a3780SDimitry Andric //===-- SourceLocationSpec.cpp --------------------------------------------===//
2344a3780SDimitry Andric //
3344a3780SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4344a3780SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
5344a3780SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6344a3780SDimitry Andric //
7344a3780SDimitry Andric //===----------------------------------------------------------------------===//
8344a3780SDimitry Andric
9344a3780SDimitry Andric #include "lldb/Core/SourceLocationSpec.h"
10344a3780SDimitry Andric #include "lldb/Utility/StreamString.h"
117fa27ce4SDimitry Andric #include "llvm/ADT/StringExtras.h"
12e3b55780SDimitry Andric #include <optional>
13344a3780SDimitry Andric
14344a3780SDimitry Andric using namespace lldb;
15344a3780SDimitry Andric using namespace lldb_private;
16344a3780SDimitry Andric
SourceLocationSpec(FileSpec file_spec,uint32_t line,std::optional<uint16_t> column,bool check_inlines,bool exact_match)17344a3780SDimitry Andric SourceLocationSpec::SourceLocationSpec(FileSpec file_spec, uint32_t line,
18e3b55780SDimitry Andric std::optional<uint16_t> column,
19344a3780SDimitry Andric bool check_inlines, bool exact_match)
20344a3780SDimitry Andric : m_declaration(file_spec, line,
21145449b1SDimitry Andric column.value_or(LLDB_INVALID_COLUMN_NUMBER)),
22344a3780SDimitry Andric m_check_inlines(check_inlines), m_exact_match(exact_match) {}
23344a3780SDimitry Andric
operator bool() const24344a3780SDimitry Andric SourceLocationSpec::operator bool() const { return m_declaration.IsValid(); }
25344a3780SDimitry Andric
operator !() const26344a3780SDimitry Andric bool SourceLocationSpec::operator!() const { return !operator bool(); }
27344a3780SDimitry Andric
operator ==(const SourceLocationSpec & rhs) const28344a3780SDimitry Andric bool SourceLocationSpec::operator==(const SourceLocationSpec &rhs) const {
29344a3780SDimitry Andric return m_declaration == rhs.m_declaration &&
30344a3780SDimitry Andric m_check_inlines == rhs.GetCheckInlines() &&
31344a3780SDimitry Andric m_exact_match == rhs.GetExactMatch();
32344a3780SDimitry Andric }
33344a3780SDimitry Andric
operator !=(const SourceLocationSpec & rhs) const34344a3780SDimitry Andric bool SourceLocationSpec::operator!=(const SourceLocationSpec &rhs) const {
35344a3780SDimitry Andric return !(*this == rhs);
36344a3780SDimitry Andric }
37344a3780SDimitry Andric
operator <(const SourceLocationSpec & rhs) const38344a3780SDimitry Andric bool SourceLocationSpec::operator<(const SourceLocationSpec &rhs) const {
39344a3780SDimitry Andric return SourceLocationSpec::Compare(*this, rhs) < 0;
40344a3780SDimitry Andric }
41344a3780SDimitry Andric
operator <<(Stream & s,const SourceLocationSpec & loc)42344a3780SDimitry Andric Stream &lldb_private::operator<<(Stream &s, const SourceLocationSpec &loc) {
43344a3780SDimitry Andric loc.Dump(s);
44344a3780SDimitry Andric return s;
45344a3780SDimitry Andric }
46344a3780SDimitry Andric
Compare(const SourceLocationSpec & lhs,const SourceLocationSpec & rhs)47344a3780SDimitry Andric int SourceLocationSpec::Compare(const SourceLocationSpec &lhs,
48344a3780SDimitry Andric const SourceLocationSpec &rhs) {
49344a3780SDimitry Andric return Declaration::Compare(lhs.m_declaration, rhs.m_declaration);
50344a3780SDimitry Andric }
51344a3780SDimitry Andric
Equal(const SourceLocationSpec & lhs,const SourceLocationSpec & rhs,bool full)52344a3780SDimitry Andric bool SourceLocationSpec::Equal(const SourceLocationSpec &lhs,
53344a3780SDimitry Andric const SourceLocationSpec &rhs, bool full) {
54344a3780SDimitry Andric return full ? lhs == rhs
55344a3780SDimitry Andric : (lhs.GetFileSpec() == rhs.GetFileSpec() &&
56344a3780SDimitry Andric lhs.GetLine() == rhs.GetLine());
57344a3780SDimitry Andric }
58344a3780SDimitry Andric
Dump(Stream & s) const59344a3780SDimitry Andric void SourceLocationSpec::Dump(Stream &s) const {
60344a3780SDimitry Andric s << "check inlines = " << llvm::toStringRef(m_check_inlines);
61344a3780SDimitry Andric s << ", exact match = " << llvm::toStringRef(m_exact_match);
62344a3780SDimitry Andric m_declaration.Dump(&s, true);
63344a3780SDimitry Andric }
64344a3780SDimitry Andric
GetString() const65344a3780SDimitry Andric std::string SourceLocationSpec::GetString() const {
66344a3780SDimitry Andric StreamString ss;
67344a3780SDimitry Andric Dump(ss);
68344a3780SDimitry Andric return ss.GetString().str();
69344a3780SDimitry Andric }
70344a3780SDimitry Andric
GetLine() const71e3b55780SDimitry Andric std::optional<uint32_t> SourceLocationSpec::GetLine() const {
72344a3780SDimitry Andric uint32_t line = m_declaration.GetLine();
73344a3780SDimitry Andric if (line == 0 || line == LLDB_INVALID_LINE_NUMBER)
74e3b55780SDimitry Andric return std::nullopt;
75344a3780SDimitry Andric return line;
76344a3780SDimitry Andric }
77344a3780SDimitry Andric
GetColumn() const78e3b55780SDimitry Andric std::optional<uint16_t> SourceLocationSpec::GetColumn() const {
79344a3780SDimitry Andric uint16_t column = m_declaration.GetColumn();
80344a3780SDimitry Andric if (column == LLDB_INVALID_COLUMN_NUMBER)
81e3b55780SDimitry Andric return std::nullopt;
82344a3780SDimitry Andric return column;
83344a3780SDimitry Andric }
84