2020-01-24 08:23:27 +01:00
|
|
|
//===-- Declaration.cpp ---------------------------------------------------===//
|
2010-06-08 16:52:24 +00:00
|
|
|
//
|
2019-01-19 08:50:56 +00:00
|
|
|
// 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
|
2010-06-08 16:52:24 +00:00
|
|
|
//
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
|
|
#include "lldb/Symbol/Declaration.h"
|
2017-02-02 21:39:50 +00:00
|
|
|
#include "lldb/Utility/Stream.h"
|
2010-06-08 16:52:24 +00:00
|
|
|
|
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
|
2010-09-15 05:51:24 +00:00
|
|
|
void Declaration::Dump(Stream *s, bool show_fullpaths) const {
|
2010-06-08 16:52:24 +00:00
|
|
|
if (m_file) {
|
2010-09-15 05:51:24 +00:00
|
|
|
*s << ", decl = ";
|
|
|
|
|
if (show_fullpaths)
|
|
|
|
|
*s << m_file;
|
2010-06-08 16:52:24 +00:00
|
|
|
else
|
2010-09-15 05:51:24 +00:00
|
|
|
*s << m_file.GetFilename();
|
2010-06-08 16:52:24 +00:00
|
|
|
if (m_line > 0)
|
|
|
|
|
s->Printf(":%u", m_line);
|
2011-02-02 02:24:04 +00:00
|
|
|
#ifdef LLDB_ENABLE_DECLARATION_COLUMNS
|
2010-06-08 16:52:24 +00:00
|
|
|
if (m_column > 0)
|
|
|
|
|
s->Printf(":%u", m_column);
|
2011-02-02 02:24:04 +00:00
|
|
|
#endif
|
2010-06-08 16:52:24 +00:00
|
|
|
} else {
|
|
|
|
|
if (m_line > 0) {
|
|
|
|
|
s->Printf(", line = %u", m_line);
|
2011-02-02 02:24:04 +00:00
|
|
|
#ifdef LLDB_ENABLE_DECLARATION_COLUMNS
|
2010-06-08 16:52:24 +00:00
|
|
|
if (m_column > 0)
|
|
|
|
|
s->Printf(":%u", m_column);
|
2011-02-02 02:24:04 +00:00
|
|
|
#endif
|
2010-06-08 16:52:24 +00:00
|
|
|
}
|
2011-02-02 02:24:04 +00:00
|
|
|
#ifdef LLDB_ENABLE_DECLARATION_COLUMNS
|
2010-06-08 16:52:24 +00:00
|
|
|
else if (m_column > 0)
|
|
|
|
|
s->Printf(", column = %u", m_column);
|
2011-02-02 02:24:04 +00:00
|
|
|
#endif
|
2010-06-08 16:52:24 +00:00
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
|
2010-09-02 21:44:10 +00:00
|
|
|
bool Declaration::DumpStopContext(Stream *s, bool show_fullpaths) const {
|
2010-06-08 16:52:24 +00:00
|
|
|
if (m_file) {
|
2017-01-13 10:41:59 +00:00
|
|
|
if (show_fullpaths)
|
2010-06-08 16:52:24 +00:00
|
|
|
*s << m_file;
|
2011-07-10 19:21:23 +00:00
|
|
|
else
|
2010-06-08 16:52:24 +00:00
|
|
|
m_file.GetFilename().Dump(s);
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2011-07-10 19:21:23 +00:00
|
|
|
if (m_line > 0)
|
2010-06-08 16:52:24 +00:00
|
|
|
s->Printf(":%u", m_line);
|
2011-02-02 02:24:04 +00:00
|
|
|
#ifdef LLDB_ENABLE_DECLARATION_COLUMNS
|
2010-06-08 16:52:24 +00:00
|
|
|
if (m_column > 0)
|
|
|
|
|
s->Printf(":%u", m_column);
|
2011-02-02 02:24:04 +00:00
|
|
|
#endif
|
2011-07-10 19:21:23 +00:00
|
|
|
return true;
|
2010-06-08 16:52:24 +00:00
|
|
|
} else if (m_line > 0) {
|
|
|
|
|
s->Printf(" line %u", m_line);
|
2011-02-02 02:24:04 +00:00
|
|
|
#ifdef LLDB_ENABLE_DECLARATION_COLUMNS
|
2010-06-08 16:52:24 +00:00
|
|
|
if (m_column > 0)
|
|
|
|
|
s->Printf(":%u", m_column);
|
2011-02-02 02:24:04 +00:00
|
|
|
#endif
|
2010-06-08 16:52:24 +00:00
|
|
|
return true;
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2011-07-10 19:21:23 +00:00
|
|
|
return false;
|
2010-06-08 16:52:24 +00:00
|
|
|
}
|
2011-02-02 02:24:04 +00:00
|
|
|
|
|
|
|
|
size_t Declaration::MemorySize() const { return sizeof(Declaration); }
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2011-02-02 02:24:04 +00:00
|
|
|
int Declaration::Compare(const Declaration &a, const Declaration &b) {
|
|
|
|
|
int result = FileSpec::Compare(a.m_file, b.m_file, true);
|
|
|
|
|
if (result)
|
2010-06-08 16:52:24 +00:00
|
|
|
return result;
|
|
|
|
|
if (a.m_line < b.m_line)
|
|
|
|
|
return -1;
|
|
|
|
|
else if (a.m_line > b.m_line)
|
|
|
|
|
return 1;
|
2011-02-02 02:24:04 +00:00
|
|
|
#ifdef LLDB_ENABLE_DECLARATION_COLUMNS
|
|
|
|
|
if (a.m_column < b.m_column)
|
2010-06-08 16:52:24 +00:00
|
|
|
return -1;
|
2011-02-02 02:24:04 +00:00
|
|
|
else if (a.m_column > b.m_column)
|
2010-06-08 16:52:24 +00:00
|
|
|
return 1;
|
2016-09-06 20:57:50 +00:00
|
|
|
#endif
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-06 20:01:21 +00:00
|
|
|
bool Declaration::FileAndLineEqual(const Declaration &declaration) const {
|
|
|
|
|
int file_compare = FileSpec::Compare(this->m_file, declaration.m_file, true);
|
|
|
|
|
return file_compare == 0 && this->m_line == declaration.m_line;
|
|
|
|
|
}
|
|
|
|
|
|
2010-06-08 16:52:24 +00:00
|
|
|
bool lldb_private::operator==(const Declaration &lhs, const Declaration &rhs) {
|
2011-02-02 02:24:04 +00:00
|
|
|
#ifdef LLDB_ENABLE_DECLARATION_COLUMNS
|
2019-11-29 11:31:00 +01:00
|
|
|
if (lhs.GetColumn() != rhs.GetColumn())
|
|
|
|
|
return false;
|
2011-02-02 02:24:04 +00:00
|
|
|
#else
|
2019-11-29 11:31:00 +01:00
|
|
|
return lhs.GetLine() == rhs.GetLine() && lhs.GetFile() == rhs.GetFile();
|
2011-02-02 02:24:04 +00:00
|
|
|
#endif
|
|
|
|
|
}
|