Skip to content

Commit 1435f6b

Browse files
committed
[lldb] Move and clean-up the Declaration class (NFC)
This patch moves the Declaration class from the Symbol library to the Core library. This will allow to use it in a more generic fashion and aims to lower the dependency cycles when it comes to the linking. The patch also does some cleaning up by making column information permanent and removing the LLDB_ENABLE_DECLARATION_COLUMNS directives. Differential revision: https://reviews.llvm.org/D101556 Signed-off-by: Med Ismail Bennani <[email protected]>
1 parent 0c3f762 commit 1435f6b

File tree

17 files changed

+69
-94
lines changed

17 files changed

+69
-94
lines changed

lldb/include/lldb/Symbol/Declaration.h renamed to lldb/include/lldb/Core/Declaration.h

Lines changed: 48 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
namespace lldb_private {
1616

17-
/// \class Declaration Declaration.h "lldb/Symbol/Declaration.h"
17+
/// \class Declaration Declaration.h "lldb/Core/Declaration.h"
1818
/// A class that describes the declaration location of a
1919
/// lldb object.
2020
///
@@ -24,14 +24,7 @@ namespace lldb_private {
2424
class Declaration {
2525
public:
2626
/// Default constructor.
27-
Declaration()
28-
: m_file(), m_line(0)
29-
#ifdef LLDB_ENABLE_DECLARATION_COLUMNS
30-
,
31-
m_column(0)
32-
#endif
33-
{
34-
}
27+
Declaration() : m_file(), m_line(0), m_column(LLDB_INVALID_COLUMN_NUMBER) {}
3528

3629
/// Construct with file specification, and optional line and column.
3730
///
@@ -46,23 +39,13 @@ class Declaration {
4639
/// \param[in] column
4740
/// The column number that describes where this was declared.
4841
/// Set to zero if there is no column number information.
49-
Declaration(const FileSpec &file_spec, uint32_t line = 0, uint32_t column = 0)
50-
: m_file(file_spec), m_line(line)
51-
#ifdef LLDB_ENABLE_DECLARATION_COLUMNS
52-
,
53-
m_column(column)
54-
#endif
55-
{
56-
}
42+
Declaration(const FileSpec &file_spec, uint32_t line = 0,
43+
uint16_t column = LLDB_INVALID_COLUMN_NUMBER)
44+
: m_file(file_spec), m_line(line), m_column(column) {}
5745

5846
/// Construct with a pointer to another Declaration object.
5947
Declaration(const Declaration *decl_ptr)
60-
: m_file(), m_line(0)
61-
#ifdef LLDB_ENABLE_DECLARATION_COLUMNS
62-
,
63-
m_column(0)
64-
#endif
65-
{
48+
: m_file(), m_line(0), m_column(LLDB_INVALID_COLUMN_NUMBER) {
6649
if (decl_ptr)
6750
*this = *decl_ptr;
6851
}
@@ -74,9 +57,7 @@ class Declaration {
7457
void Clear() {
7558
m_file.Clear();
7659
m_line = 0;
77-
#ifdef LLDB_ENABLE_DECLARATION_COLUMNS
7860
m_column = 0;
79-
#endif
8061
}
8162

8263
/// Compare two declaration objects.
@@ -118,18 +99,6 @@ class Declaration {
11899
void Dump(Stream *s, bool show_fullpaths) const;
119100

120101
bool DumpStopContext(Stream *s, bool show_fullpaths) const;
121-
/// Get accessor for the declaration column number.
122-
///
123-
/// \return
124-
/// Non-zero indicates a valid column number, zero indicates no
125-
/// column information is available.
126-
uint32_t GetColumn() const {
127-
#ifdef LLDB_ENABLE_DECLARATION_COLUMNS
128-
return m_column;
129-
#else
130-
return 0;
131-
#endif
132-
}
133102

134103
/// Get accessor for file specification.
135104
///
@@ -150,7 +119,32 @@ class Declaration {
150119
/// line information is available.
151120
uint32_t GetLine() const { return m_line; }
152121

153-
bool IsValid() const { return m_file && m_line != 0; }
122+
/// Get accessor for the declaration column number.
123+
///
124+
/// \return
125+
/// Non-zero indicates a valid column number, zero indicates no
126+
/// column information is available.
127+
uint16_t GetColumn() const { return m_column; }
128+
129+
/// Convert to boolean operator.
130+
///
131+
/// This allows code to check a Declaration object to see if it
132+
/// contains anything valid using code such as:
133+
///
134+
/// \code
135+
/// Declaration decl(...);
136+
/// if (decl)
137+
/// { ...
138+
/// \endcode
139+
///
140+
/// \return
141+
/// A \b true if both the file_spec and the line are valid,
142+
/// \b false otherwise.
143+
explicit operator bool() const { return IsValid(); }
144+
145+
bool IsValid() const {
146+
return m_file && m_line != 0 && m_line != LLDB_INVALID_LINE_NUMBER;
147+
}
154148

155149
/// Get the memory cost of this object.
156150
///
@@ -162,17 +156,6 @@ class Declaration {
162156
/// \see ConstString::StaticMemorySize ()
163157
size_t MemorySize() const;
164158

165-
/// Set accessor for the declaration column number.
166-
///
167-
/// \param[in] column
168-
/// Non-zero indicates a valid column number, zero indicates no
169-
/// column information is available.
170-
void SetColumn(uint32_t column) {
171-
#ifdef LLDB_ENABLE_DECLARATION_COLUMNS
172-
m_column = col;
173-
#endif
174-
}
175-
176159
/// Set accessor for the declaration file specification.
177160
///
178161
/// \param[in] file_spec
@@ -186,16 +169,23 @@ class Declaration {
186169
/// line information is available.
187170
void SetLine(uint32_t line) { m_line = line; }
188171

172+
/// Set accessor for the declaration column number.
173+
///
174+
/// \param[in] column
175+
/// Non-zero indicates a valid column number, zero indicates no
176+
/// column information is available.
177+
void SetColumn(uint16_t column) { m_column = column; }
178+
189179
protected:
190-
/// Member variables.
191-
FileSpec m_file; ///< The file specification that points to the
192-
///< source file where the declaration occurred.
193-
uint32_t m_line; ///< Non-zero values indicates a valid line number,
194-
///< zero indicates no line number information is available.
195-
#ifdef LLDB_ENABLE_DECLARATION_COLUMNS
196-
uint32_t m_column; ///< Non-zero values indicates a valid column number,
197-
///< zero indicates no column information is available.
198-
#endif
180+
/// The file specification that points to the source file where the
181+
/// declaration occurred.
182+
FileSpec m_file;
183+
/// Non-zero values indicates a valid line number, zero indicates no line
184+
/// number information is available.
185+
uint32_t m_line;
186+
/// Non-zero values indicates a valid column number, zero indicates no column
187+
/// information is available.
188+
uint16_t m_column;
199189
};
200190

201191
bool operator==(const Declaration &lhs, const Declaration &rhs);

lldb/include/lldb/Symbol/Function.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
#define LLDB_SYMBOL_FUNCTION_H
1111

1212
#include "lldb/Core/AddressRange.h"
13+
#include "lldb/Core/Declaration.h"
1314
#include "lldb/Core/Mangled.h"
1415
#include "lldb/Expression/DWARFExpression.h"
1516
#include "lldb/Symbol/Block.h"
16-
#include "lldb/Symbol/Declaration.h"
1717
#include "lldb/Utility/UserID.h"
1818
#include "llvm/ADT/ArrayRef.h"
1919

lldb/include/lldb/Symbol/Type.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
#ifndef LLDB_SYMBOL_TYPE_H
1010
#define LLDB_SYMBOL_TYPE_H
1111

12+
#include "lldb/Core/Declaration.h"
1213
#include "lldb/Symbol/CompilerDecl.h"
1314
#include "lldb/Symbol/CompilerType.h"
14-
#include "lldb/Symbol/Declaration.h"
1515
#include "lldb/Utility/ConstString.h"
1616
#include "lldb/Utility/UserID.h"
1717
#include "lldb/lldb-private.h"

lldb/include/lldb/Symbol/Variable.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
#ifndef LLDB_SYMBOL_VARIABLE_H
1010
#define LLDB_SYMBOL_VARIABLE_H
1111

12+
#include "lldb/Core/Declaration.h"
1213
#include "lldb/Core/Mangled.h"
1314
#include "lldb/Expression/DWARFExpression.h"
14-
#include "lldb/Symbol/Declaration.h"
1515
#include "lldb/Utility/CompletionRequest.h"
1616
#include "lldb/Utility/RangeMap.h"
1717
#include "lldb/Utility/UserID.h"

lldb/source/API/SBDeclaration.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
#include "SBReproducerPrivate.h"
1111
#include "Utils.h"
1212
#include "lldb/API/SBStream.h"
13+
#include "lldb/Core/Declaration.h"
1314
#include "lldb/Host/PosixApi.h"
14-
#include "lldb/Symbol/Declaration.h"
1515
#include "lldb/Utility/Stream.h"
1616

1717
#include <limits.h>

lldb/source/API/SBValue.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "lldb/API/SBTypeSynthetic.h"
1818

1919
#include "lldb/Breakpoint/Watchpoint.h"
20+
#include "lldb/Core/Declaration.h"
2021
#include "lldb/Core/Module.h"
2122
#include "lldb/Core/Section.h"
2223
#include "lldb/Core/StreamFile.h"
@@ -25,7 +26,6 @@
2526
#include "lldb/Core/ValueObjectConstResult.h"
2627
#include "lldb/DataFormatters/DataVisualization.h"
2728
#include "lldb/Symbol/Block.h"
28-
#include "lldb/Symbol/Declaration.h"
2929
#include "lldb/Symbol/ObjectFile.h"
3030
#include "lldb/Symbol/Type.h"
3131
#include "lldb/Symbol/Variable.h"

lldb/source/Core/Address.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "lldb/Core/Address.h"
10+
#include "lldb/Core/Declaration.h"
1011
#include "lldb/Core/DumpDataExtractor.h"
1112
#include "lldb/Core/Module.h"
1213
#include "lldb/Core/ModuleList.h"
1314
#include "lldb/Core/Section.h"
1415
#include "lldb/Symbol/Block.h"
15-
#include "lldb/Symbol/Declaration.h"
1616
#include "lldb/Symbol/LineEntry.h"
1717
#include "lldb/Symbol/ObjectFile.h"
1818
#include "lldb/Symbol/Symbol.h"

lldb/source/Core/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ add_lldb_library(lldbCore
2626
AddressResolverFileLine.cpp
2727
Communication.cpp
2828
Debugger.cpp
29+
Declaration.cpp
2930
Disassembler.cpp
3031
DumpDataExtractor.cpp
3132
DumpRegisterValue.cpp

lldb/source/Symbol/Declaration.cpp renamed to lldb/source/Core/Declaration.cpp

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#include "lldb/Symbol/Declaration.h"
9+
#include "lldb/Core/Declaration.h"
1010
#include "lldb/Utility/Stream.h"
1111

1212
using namespace lldb_private;
@@ -20,22 +20,15 @@ void Declaration::Dump(Stream *s, bool show_fullpaths) const {
2020
*s << m_file.GetFilename();
2121
if (m_line > 0)
2222
s->Printf(":%u", m_line);
23-
#ifdef LLDB_ENABLE_DECLARATION_COLUMNS
24-
if (m_column > 0)
23+
if (m_column != LLDB_INVALID_COLUMN_NUMBER)
2524
s->Printf(":%u", m_column);
26-
#endif
2725
} else {
2826
if (m_line > 0) {
2927
s->Printf(", line = %u", m_line);
30-
#ifdef LLDB_ENABLE_DECLARATION_COLUMNS
31-
if (m_column > 0)
28+
if (m_column != LLDB_INVALID_COLUMN_NUMBER)
3229
s->Printf(":%u", m_column);
33-
#endif
34-
}
35-
#ifdef LLDB_ENABLE_DECLARATION_COLUMNS
36-
else if (m_column > 0)
30+
} else if (m_column != LLDB_INVALID_COLUMN_NUMBER)
3731
s->Printf(", column = %u", m_column);
38-
#endif
3932
}
4033
}
4134

@@ -48,17 +41,13 @@ bool Declaration::DumpStopContext(Stream *s, bool show_fullpaths) const {
4841

4942
if (m_line > 0)
5043
s->Printf(":%u", m_line);
51-
#ifdef LLDB_ENABLE_DECLARATION_COLUMNS
52-
if (m_column > 0)
44+
if (m_column != LLDB_INVALID_COLUMN_NUMBER)
5345
s->Printf(":%u", m_column);
54-
#endif
5546
return true;
5647
} else if (m_line > 0) {
5748
s->Printf(" line %u", m_line);
58-
#ifdef LLDB_ENABLE_DECLARATION_COLUMNS
59-
if (m_column > 0)
49+
if (m_column != LLDB_INVALID_COLUMN_NUMBER)
6050
s->Printf(":%u", m_column);
61-
#endif
6251
return true;
6352
}
6453
return false;
@@ -74,12 +63,10 @@ int Declaration::Compare(const Declaration &a, const Declaration &b) {
7463
return -1;
7564
else if (a.m_line > b.m_line)
7665
return 1;
77-
#ifdef LLDB_ENABLE_DECLARATION_COLUMNS
7866
if (a.m_column < b.m_column)
7967
return -1;
8068
else if (a.m_column > b.m_column)
8169
return 1;
82-
#endif
8370
return 0;
8471
}
8572

@@ -89,10 +76,8 @@ bool Declaration::FileAndLineEqual(const Declaration &declaration) const {
8976
}
9077

9178
bool lldb_private::operator==(const Declaration &lhs, const Declaration &rhs) {
92-
#ifdef LLDB_ENABLE_DECLARATION_COLUMNS
9379
if (lhs.GetColumn() != rhs.GetColumn())
9480
return false;
95-
#else
81+
9682
return lhs.GetLine() == rhs.GetLine() && lhs.GetFile() == rhs.GetFile();
97-
#endif
9883
}

lldb/source/Core/ValueObject.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "lldb/Core/ValueObject.h"
1010

1111
#include "lldb/Core/Address.h"
12+
#include "lldb/Core/Declaration.h"
1213
#include "lldb/Core/Module.h"
1314
#include "lldb/Core/ValueObjectCast.h"
1415
#include "lldb/Core/ValueObjectChild.h"
@@ -27,7 +28,6 @@
2728
#include "lldb/Host/Config.h"
2829
#include "lldb/Symbol/CompileUnit.h"
2930
#include "lldb/Symbol/CompilerType.h"
30-
#include "lldb/Symbol/Declaration.h"
3131
#include "lldb/Symbol/SymbolContext.h"
3232
#include "lldb/Symbol/Type.h"
3333
#include "lldb/Symbol/Variable.h"

lldb/source/Core/ValueObjectVariable.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010

1111
#include "lldb/Core/Address.h"
1212
#include "lldb/Core/AddressRange.h"
13+
#include "lldb/Core/Declaration.h"
1314
#include "lldb/Core/Module.h"
1415
#include "lldb/Core/Value.h"
1516
#include "lldb/Expression/DWARFExpression.h"
16-
#include "lldb/Symbol/Declaration.h"
1717
#include "lldb/Symbol/Function.h"
1818
#include "lldb/Symbol/ObjectFile.h"
1919
#include "lldb/Symbol/SymbolContext.h"

lldb/source/Plugins/SymbolFile/DWARF/UniqueDWARFASTType.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
#include "UniqueDWARFASTType.h"
1010

11-
#include "lldb/Symbol/Declaration.h"
11+
#include "lldb/Core/Declaration.h"
1212

1313
bool UniqueDWARFASTTypeList::Find(const DWARFDIE &die,
1414
const lldb_private::Declaration &decl,

lldb/source/Plugins/SymbolFile/DWARF/UniqueDWARFASTType.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#include "llvm/ADT/DenseMap.h"
1515

1616
#include "DWARFDIE.h"
17-
#include "lldb/Symbol/Declaration.h"
17+
#include "lldb/Core/Declaration.h"
1818

1919
class UniqueDWARFASTType {
2020
public:

lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
#include "Plugins/ExpressionParser/Clang/ClangASTMetadata.h"
1818
#include "Plugins/ExpressionParser/Clang/ClangUtil.h"
1919
#include "Plugins/TypeSystem/Clang/TypeSystemClang.h"
20+
#include "lldb/Core/Declaration.h"
2021
#include "lldb/Core/Module.h"
21-
#include "lldb/Symbol/Declaration.h"
2222
#include "lldb/Symbol/SymbolFile.h"
2323
#include "lldb/Symbol/TypeMap.h"
2424
#include "lldb/Symbol/TypeSystem.h"

lldb/source/Symbol/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ add_lldb_library(lldbSymbol
1414
CompilerType.cpp
1515
DWARFCallFrameInfo.cpp
1616
DebugMacros.cpp
17-
Declaration.cpp
1817
DeclVendor.cpp
1918
FuncUnwinders.cpp
2019
Function.cpp

0 commit comments

Comments
 (0)