Path: blob/main/contrib/llvm-project/lldb/source/Core/SourceLocationSpec.cpp
39587 views
//===-- SourceLocationSpec.cpp --------------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include "lldb/Core/SourceLocationSpec.h"9#include "lldb/Utility/StreamString.h"10#include "llvm/ADT/StringExtras.h"11#include <optional>1213using namespace lldb;14using namespace lldb_private;1516SourceLocationSpec::SourceLocationSpec(FileSpec file_spec, uint32_t line,17std::optional<uint16_t> column,18bool check_inlines, bool exact_match)19: m_declaration(file_spec, line,20column.value_or(LLDB_INVALID_COLUMN_NUMBER)),21m_check_inlines(check_inlines), m_exact_match(exact_match) {}2223SourceLocationSpec::operator bool() const { return m_declaration.IsValid(); }2425bool SourceLocationSpec::operator!() const { return !operator bool(); }2627bool SourceLocationSpec::operator==(const SourceLocationSpec &rhs) const {28return m_declaration == rhs.m_declaration &&29m_check_inlines == rhs.GetCheckInlines() &&30m_exact_match == rhs.GetExactMatch();31}3233bool SourceLocationSpec::operator!=(const SourceLocationSpec &rhs) const {34return !(*this == rhs);35}3637bool SourceLocationSpec::operator<(const SourceLocationSpec &rhs) const {38return SourceLocationSpec::Compare(*this, rhs) < 0;39}4041Stream &lldb_private::operator<<(Stream &s, const SourceLocationSpec &loc) {42loc.Dump(s);43return s;44}4546int SourceLocationSpec::Compare(const SourceLocationSpec &lhs,47const SourceLocationSpec &rhs) {48return Declaration::Compare(lhs.m_declaration, rhs.m_declaration);49}5051bool SourceLocationSpec::Equal(const SourceLocationSpec &lhs,52const SourceLocationSpec &rhs, bool full) {53return full ? lhs == rhs54: (lhs.GetFileSpec() == rhs.GetFileSpec() &&55lhs.GetLine() == rhs.GetLine());56}5758void SourceLocationSpec::Dump(Stream &s) const {59s << "check inlines = " << llvm::toStringRef(m_check_inlines);60s << ", exact match = " << llvm::toStringRef(m_exact_match);61m_declaration.Dump(&s, true);62}6364std::string SourceLocationSpec::GetString() const {65StreamString ss;66Dump(ss);67return ss.GetString().str();68}6970std::optional<uint32_t> SourceLocationSpec::GetLine() const {71uint32_t line = m_declaration.GetLine();72if (line == 0 || line == LLDB_INVALID_LINE_NUMBER)73return std::nullopt;74return line;75}7677std::optional<uint16_t> SourceLocationSpec::GetColumn() const {78uint16_t column = m_declaration.GetColumn();79if (column == LLDB_INVALID_COLUMN_NUMBER)80return std::nullopt;81return column;82}838485