[Lldb-commits] [lldb] 1435f6b - [lldb] Move and clean-up the Declaration class (NFC)

Med Ismail Bennani via lldb-commits lldb-commits at lists.llvm.org
Tue May 4 09:34:59 PDT 2021


Author: Med Ismail Bennani
Date: 2021-05-04T16:34:44Z
New Revision: 1435f6b00be79f1042818da8714ad4de2aef7848

URL: https://github.com/llvm/llvm-project/commit/1435f6b00be79f1042818da8714ad4de2aef7848
DIFF: https://github.com/llvm/llvm-project/commit/1435f6b00be79f1042818da8714ad4de2aef7848.diff

LOG: [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 <medismail.bennani at gmail.com>

Added: 
    lldb/include/lldb/Core/Declaration.h
    lldb/source/Core/Declaration.cpp

Modified: 
    lldb/include/lldb/Symbol/Function.h
    lldb/include/lldb/Symbol/Type.h
    lldb/include/lldb/Symbol/Variable.h
    lldb/source/API/SBDeclaration.cpp
    lldb/source/API/SBValue.cpp
    lldb/source/Core/Address.cpp
    lldb/source/Core/CMakeLists.txt
    lldb/source/Core/ValueObject.cpp
    lldb/source/Core/ValueObjectVariable.cpp
    lldb/source/Plugins/SymbolFile/DWARF/UniqueDWARFASTType.cpp
    lldb/source/Plugins/SymbolFile/DWARF/UniqueDWARFASTType.h
    lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp
    lldb/source/Symbol/CMakeLists.txt
    lldb/unittests/Symbol/TestClangASTImporter.cpp
    lldb/unittests/Symbol/TestTypeSystemClang.cpp

Removed: 
    lldb/include/lldb/Symbol/Declaration.h
    lldb/source/Symbol/Declaration.cpp


################################################################################
diff  --git a/lldb/include/lldb/Symbol/Declaration.h b/lldb/include/lldb/Core/Declaration.h
similarity index 77%
rename from lldb/include/lldb/Symbol/Declaration.h
rename to lldb/include/lldb/Core/Declaration.h
index 7f19f45411a02..5df8034ae3c4b 100644
--- a/lldb/include/lldb/Symbol/Declaration.h
+++ b/lldb/include/lldb/Core/Declaration.h
@@ -14,7 +14,7 @@
 
 namespace lldb_private {
 
-/// \class Declaration Declaration.h "lldb/Symbol/Declaration.h"
+/// \class Declaration Declaration.h "lldb/Core/Declaration.h"
 /// A class that describes the declaration location of a
 ///        lldb object.
 ///
@@ -24,14 +24,7 @@ namespace lldb_private {
 class Declaration {
 public:
   /// Default constructor.
-  Declaration()
-      : m_file(), m_line(0)
-#ifdef LLDB_ENABLE_DECLARATION_COLUMNS
-        ,
-        m_column(0)
-#endif
-  {
-  }
+  Declaration() : m_file(), m_line(0), m_column(LLDB_INVALID_COLUMN_NUMBER) {}
 
   /// Construct with file specification, and optional line and column.
   ///
@@ -46,23 +39,13 @@ class Declaration {
   /// \param[in] column
   ///     The column number that describes where this was declared.
   ///     Set to zero if there is no column number information.
-  Declaration(const FileSpec &file_spec, uint32_t line = 0, uint32_t column = 0)
-      : m_file(file_spec), m_line(line)
-#ifdef LLDB_ENABLE_DECLARATION_COLUMNS
-        ,
-        m_column(column)
-#endif
-  {
-  }
+  Declaration(const FileSpec &file_spec, uint32_t line = 0,
+              uint16_t column = LLDB_INVALID_COLUMN_NUMBER)
+      : m_file(file_spec), m_line(line), m_column(column) {}
 
   /// Construct with a pointer to another Declaration object.
   Declaration(const Declaration *decl_ptr)
-      : m_file(), m_line(0)
-#ifdef LLDB_ENABLE_DECLARATION_COLUMNS
-        ,
-        m_column(0)
-#endif
-  {
+      : m_file(), m_line(0), m_column(LLDB_INVALID_COLUMN_NUMBER) {
     if (decl_ptr)
       *this = *decl_ptr;
   }
@@ -74,9 +57,7 @@ class Declaration {
   void Clear() {
     m_file.Clear();
     m_line = 0;
-#ifdef LLDB_ENABLE_DECLARATION_COLUMNS
     m_column = 0;
-#endif
   }
 
   /// Compare two declaration objects.
@@ -118,18 +99,6 @@ class Declaration {
   void Dump(Stream *s, bool show_fullpaths) const;
 
   bool DumpStopContext(Stream *s, bool show_fullpaths) const;
-  /// Get accessor for the declaration column number.
-  ///
-  /// \return
-  ///     Non-zero indicates a valid column number, zero indicates no
-  ///     column information is available.
-  uint32_t GetColumn() const {
-#ifdef LLDB_ENABLE_DECLARATION_COLUMNS
-    return m_column;
-#else
-    return 0;
-#endif
-  }
 
   /// Get accessor for file specification.
   ///
@@ -150,7 +119,32 @@ class Declaration {
   ///     line information is available.
   uint32_t GetLine() const { return m_line; }
 
-  bool IsValid() const { return m_file && m_line != 0; }
+  /// Get accessor for the declaration column number.
+  ///
+  /// \return
+  ///     Non-zero indicates a valid column number, zero indicates no
+  ///     column information is available.
+  uint16_t GetColumn() const { return m_column; }
+
+  /// Convert to boolean operator.
+  ///
+  /// This allows code to check a Declaration object to see if it
+  /// contains anything valid using code such as:
+  ///
+  /// \code
+  /// Declaration decl(...);
+  /// if (decl)
+  /// { ...
+  /// \endcode
+  ///
+  /// \return
+  ///     A \b true if both the file_spec and the line are valid,
+  ///     \b false otherwise.
+  explicit operator bool() const { return IsValid(); }
+
+  bool IsValid() const {
+    return m_file && m_line != 0 && m_line != LLDB_INVALID_LINE_NUMBER;
+  }
 
   /// Get the memory cost of this object.
   ///
@@ -162,17 +156,6 @@ class Declaration {
   /// \see ConstString::StaticMemorySize ()
   size_t MemorySize() const;
 
-  /// Set accessor for the declaration column number.
-  ///
-  /// \param[in] column
-  ///     Non-zero indicates a valid column number, zero indicates no
-  ///     column information is available.
-  void SetColumn(uint32_t column) {
-#ifdef LLDB_ENABLE_DECLARATION_COLUMNS
-    m_column = col;
-#endif
-  }
-
   /// Set accessor for the declaration file specification.
   ///
   /// \param[in] file_spec
@@ -186,16 +169,23 @@ class Declaration {
   ///     line information is available.
   void SetLine(uint32_t line) { m_line = line; }
 
+  /// Set accessor for the declaration column number.
+  ///
+  /// \param[in] column
+  ///     Non-zero indicates a valid column number, zero indicates no
+  ///     column information is available.
+  void SetColumn(uint16_t column) { m_column = column; }
+
 protected:
-  /// Member variables.
-  FileSpec m_file; ///< The file specification that points to the
-                   ///< source file where the declaration occurred.
-  uint32_t m_line; ///< Non-zero values indicates a valid line number,
-                   ///< zero indicates no line number information is available.
-#ifdef LLDB_ENABLE_DECLARATION_COLUMNS
-  uint32_t m_column; ///< Non-zero values indicates a valid column number,
-                     ///< zero indicates no column information is available.
-#endif
+  /// The file specification that points to the source file where the
+  /// declaration occurred.
+  FileSpec m_file;
+  /// Non-zero values indicates a valid line number, zero indicates no line
+  /// number information is available.
+  uint32_t m_line;
+  /// Non-zero values indicates a valid column number, zero indicates no column
+  /// information is available.
+  uint16_t m_column;
 };
 
 bool operator==(const Declaration &lhs, const Declaration &rhs);

diff  --git a/lldb/include/lldb/Symbol/Function.h b/lldb/include/lldb/Symbol/Function.h
index aae5b4a496c2c..6e5077ed45557 100644
--- a/lldb/include/lldb/Symbol/Function.h
+++ b/lldb/include/lldb/Symbol/Function.h
@@ -10,10 +10,10 @@
 #define LLDB_SYMBOL_FUNCTION_H
 
 #include "lldb/Core/AddressRange.h"
+#include "lldb/Core/Declaration.h"
 #include "lldb/Core/Mangled.h"
 #include "lldb/Expression/DWARFExpression.h"
 #include "lldb/Symbol/Block.h"
-#include "lldb/Symbol/Declaration.h"
 #include "lldb/Utility/UserID.h"
 #include "llvm/ADT/ArrayRef.h"
 

diff  --git a/lldb/include/lldb/Symbol/Type.h b/lldb/include/lldb/Symbol/Type.h
index dd917cfb7ca8e..6614950c2437a 100644
--- a/lldb/include/lldb/Symbol/Type.h
+++ b/lldb/include/lldb/Symbol/Type.h
@@ -9,9 +9,9 @@
 #ifndef LLDB_SYMBOL_TYPE_H
 #define LLDB_SYMBOL_TYPE_H
 
+#include "lldb/Core/Declaration.h"
 #include "lldb/Symbol/CompilerDecl.h"
 #include "lldb/Symbol/CompilerType.h"
-#include "lldb/Symbol/Declaration.h"
 #include "lldb/Utility/ConstString.h"
 #include "lldb/Utility/UserID.h"
 #include "lldb/lldb-private.h"

diff  --git a/lldb/include/lldb/Symbol/Variable.h b/lldb/include/lldb/Symbol/Variable.h
index 0dcbbd8e4c8ee..ccd5072c3d234 100644
--- a/lldb/include/lldb/Symbol/Variable.h
+++ b/lldb/include/lldb/Symbol/Variable.h
@@ -9,9 +9,9 @@
 #ifndef LLDB_SYMBOL_VARIABLE_H
 #define LLDB_SYMBOL_VARIABLE_H
 
+#include "lldb/Core/Declaration.h"
 #include "lldb/Core/Mangled.h"
 #include "lldb/Expression/DWARFExpression.h"
-#include "lldb/Symbol/Declaration.h"
 #include "lldb/Utility/CompletionRequest.h"
 #include "lldb/Utility/RangeMap.h"
 #include "lldb/Utility/UserID.h"

diff  --git a/lldb/source/API/SBDeclaration.cpp b/lldb/source/API/SBDeclaration.cpp
index f1066d63c06ab..2748190f2e810 100644
--- a/lldb/source/API/SBDeclaration.cpp
+++ b/lldb/source/API/SBDeclaration.cpp
@@ -10,8 +10,8 @@
 #include "SBReproducerPrivate.h"
 #include "Utils.h"
 #include "lldb/API/SBStream.h"
+#include "lldb/Core/Declaration.h"
 #include "lldb/Host/PosixApi.h"
-#include "lldb/Symbol/Declaration.h"
 #include "lldb/Utility/Stream.h"
 
 #include <limits.h>

diff  --git a/lldb/source/API/SBValue.cpp b/lldb/source/API/SBValue.cpp
index 0a95cf41263dd..9faee102c5e3d 100644
--- a/lldb/source/API/SBValue.cpp
+++ b/lldb/source/API/SBValue.cpp
@@ -17,6 +17,7 @@
 #include "lldb/API/SBTypeSynthetic.h"
 
 #include "lldb/Breakpoint/Watchpoint.h"
+#include "lldb/Core/Declaration.h"
 #include "lldb/Core/Module.h"
 #include "lldb/Core/Section.h"
 #include "lldb/Core/StreamFile.h"
@@ -25,7 +26,6 @@
 #include "lldb/Core/ValueObjectConstResult.h"
 #include "lldb/DataFormatters/DataVisualization.h"
 #include "lldb/Symbol/Block.h"
-#include "lldb/Symbol/Declaration.h"
 #include "lldb/Symbol/ObjectFile.h"
 #include "lldb/Symbol/Type.h"
 #include "lldb/Symbol/Variable.h"

diff  --git a/lldb/source/Core/Address.cpp b/lldb/source/Core/Address.cpp
index 24bb8417b69b4..6079d0e7a3367 100644
--- a/lldb/source/Core/Address.cpp
+++ b/lldb/source/Core/Address.cpp
@@ -7,12 +7,12 @@
 //===----------------------------------------------------------------------===//
 
 #include "lldb/Core/Address.h"
+#include "lldb/Core/Declaration.h"
 #include "lldb/Core/DumpDataExtractor.h"
 #include "lldb/Core/Module.h"
 #include "lldb/Core/ModuleList.h"
 #include "lldb/Core/Section.h"
 #include "lldb/Symbol/Block.h"
-#include "lldb/Symbol/Declaration.h"
 #include "lldb/Symbol/LineEntry.h"
 #include "lldb/Symbol/ObjectFile.h"
 #include "lldb/Symbol/Symbol.h"

diff  --git a/lldb/source/Core/CMakeLists.txt b/lldb/source/Core/CMakeLists.txt
index ae07de6789c57..338fd4aaa921f 100644
--- a/lldb/source/Core/CMakeLists.txt
+++ b/lldb/source/Core/CMakeLists.txt
@@ -26,6 +26,7 @@ add_lldb_library(lldbCore
   AddressResolverFileLine.cpp
   Communication.cpp
   Debugger.cpp
+  Declaration.cpp
   Disassembler.cpp
   DumpDataExtractor.cpp
   DumpRegisterValue.cpp

diff  --git a/lldb/source/Symbol/Declaration.cpp b/lldb/source/Core/Declaration.cpp
similarity index 81%
rename from lldb/source/Symbol/Declaration.cpp
rename to lldb/source/Core/Declaration.cpp
index 48d8013811d9e..579a3999d14ea 100644
--- a/lldb/source/Symbol/Declaration.cpp
+++ b/lldb/source/Core/Declaration.cpp
@@ -6,7 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "lldb/Symbol/Declaration.h"
+#include "lldb/Core/Declaration.h"
 #include "lldb/Utility/Stream.h"
 
 using namespace lldb_private;
@@ -20,22 +20,15 @@ void Declaration::Dump(Stream *s, bool show_fullpaths) const {
       *s << m_file.GetFilename();
     if (m_line > 0)
       s->Printf(":%u", m_line);
-#ifdef LLDB_ENABLE_DECLARATION_COLUMNS
-    if (m_column > 0)
+    if (m_column != LLDB_INVALID_COLUMN_NUMBER)
       s->Printf(":%u", m_column);
-#endif
   } else {
     if (m_line > 0) {
       s->Printf(", line = %u", m_line);
-#ifdef LLDB_ENABLE_DECLARATION_COLUMNS
-      if (m_column > 0)
+      if (m_column != LLDB_INVALID_COLUMN_NUMBER)
         s->Printf(":%u", m_column);
-#endif
-    }
-#ifdef LLDB_ENABLE_DECLARATION_COLUMNS
-    else if (m_column > 0)
+    } else if (m_column != LLDB_INVALID_COLUMN_NUMBER)
       s->Printf(", column = %u", m_column);
-#endif
   }
 }
 
@@ -48,17 +41,13 @@ bool Declaration::DumpStopContext(Stream *s, bool show_fullpaths) const {
 
     if (m_line > 0)
       s->Printf(":%u", m_line);
-#ifdef LLDB_ENABLE_DECLARATION_COLUMNS
-    if (m_column > 0)
+    if (m_column != LLDB_INVALID_COLUMN_NUMBER)
       s->Printf(":%u", m_column);
-#endif
     return true;
   } else if (m_line > 0) {
     s->Printf(" line %u", m_line);
-#ifdef LLDB_ENABLE_DECLARATION_COLUMNS
-    if (m_column > 0)
+    if (m_column != LLDB_INVALID_COLUMN_NUMBER)
       s->Printf(":%u", m_column);
-#endif
     return true;
   }
   return false;
@@ -74,12 +63,10 @@ int Declaration::Compare(const Declaration &a, const Declaration &b) {
     return -1;
   else if (a.m_line > b.m_line)
     return 1;
-#ifdef LLDB_ENABLE_DECLARATION_COLUMNS
   if (a.m_column < b.m_column)
     return -1;
   else if (a.m_column > b.m_column)
     return 1;
-#endif
   return 0;
 }
 
@@ -89,10 +76,8 @@ bool Declaration::FileAndLineEqual(const Declaration &declaration) const {
 }
 
 bool lldb_private::operator==(const Declaration &lhs, const Declaration &rhs) {
-#ifdef LLDB_ENABLE_DECLARATION_COLUMNS
   if (lhs.GetColumn() != rhs.GetColumn())
     return false;
-#else
+
   return lhs.GetLine() == rhs.GetLine() && lhs.GetFile() == rhs.GetFile();
-#endif
 }

diff  --git a/lldb/source/Core/ValueObject.cpp b/lldb/source/Core/ValueObject.cpp
index 55fc5ff641729..83c2098bede1f 100644
--- a/lldb/source/Core/ValueObject.cpp
+++ b/lldb/source/Core/ValueObject.cpp
@@ -9,6 +9,7 @@
 #include "lldb/Core/ValueObject.h"
 
 #include "lldb/Core/Address.h"
+#include "lldb/Core/Declaration.h"
 #include "lldb/Core/Module.h"
 #include "lldb/Core/ValueObjectCast.h"
 #include "lldb/Core/ValueObjectChild.h"
@@ -27,7 +28,6 @@
 #include "lldb/Host/Config.h"
 #include "lldb/Symbol/CompileUnit.h"
 #include "lldb/Symbol/CompilerType.h"
-#include "lldb/Symbol/Declaration.h"
 #include "lldb/Symbol/SymbolContext.h"
 #include "lldb/Symbol/Type.h"
 #include "lldb/Symbol/Variable.h"

diff  --git a/lldb/source/Core/ValueObjectVariable.cpp b/lldb/source/Core/ValueObjectVariable.cpp
index ffb584597f77d..751b502d6b996 100644
--- a/lldb/source/Core/ValueObjectVariable.cpp
+++ b/lldb/source/Core/ValueObjectVariable.cpp
@@ -10,10 +10,10 @@
 
 #include "lldb/Core/Address.h"
 #include "lldb/Core/AddressRange.h"
+#include "lldb/Core/Declaration.h"
 #include "lldb/Core/Module.h"
 #include "lldb/Core/Value.h"
 #include "lldb/Expression/DWARFExpression.h"
-#include "lldb/Symbol/Declaration.h"
 #include "lldb/Symbol/Function.h"
 #include "lldb/Symbol/ObjectFile.h"
 #include "lldb/Symbol/SymbolContext.h"

diff  --git a/lldb/source/Plugins/SymbolFile/DWARF/UniqueDWARFASTType.cpp b/lldb/source/Plugins/SymbolFile/DWARF/UniqueDWARFASTType.cpp
index 2181989cd37a4..34ff23667465c 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/UniqueDWARFASTType.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/UniqueDWARFASTType.cpp
@@ -8,7 +8,7 @@
 
 #include "UniqueDWARFASTType.h"
 
-#include "lldb/Symbol/Declaration.h"
+#include "lldb/Core/Declaration.h"
 
 bool UniqueDWARFASTTypeList::Find(const DWARFDIE &die,
                                   const lldb_private::Declaration &decl,

diff  --git a/lldb/source/Plugins/SymbolFile/DWARF/UniqueDWARFASTType.h b/lldb/source/Plugins/SymbolFile/DWARF/UniqueDWARFASTType.h
index a1b1a30097874..40240a1f2a12e 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/UniqueDWARFASTType.h
+++ b/lldb/source/Plugins/SymbolFile/DWARF/UniqueDWARFASTType.h
@@ -14,7 +14,7 @@
 #include "llvm/ADT/DenseMap.h"
 
 #include "DWARFDIE.h"
-#include "lldb/Symbol/Declaration.h"
+#include "lldb/Core/Declaration.h"
 
 class UniqueDWARFASTType {
 public:

diff  --git a/lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp b/lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp
index ef80d764eb495..bf8753e88a6cc 100644
--- a/lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp
+++ b/lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp
@@ -17,8 +17,8 @@
 #include "Plugins/ExpressionParser/Clang/ClangASTMetadata.h"
 #include "Plugins/ExpressionParser/Clang/ClangUtil.h"
 #include "Plugins/TypeSystem/Clang/TypeSystemClang.h"
+#include "lldb/Core/Declaration.h"
 #include "lldb/Core/Module.h"
-#include "lldb/Symbol/Declaration.h"
 #include "lldb/Symbol/SymbolFile.h"
 #include "lldb/Symbol/TypeMap.h"
 #include "lldb/Symbol/TypeSystem.h"

diff  --git a/lldb/source/Symbol/CMakeLists.txt b/lldb/source/Symbol/CMakeLists.txt
index 95bf156ff538b..8ff874e982994 100644
--- a/lldb/source/Symbol/CMakeLists.txt
+++ b/lldb/source/Symbol/CMakeLists.txt
@@ -14,7 +14,6 @@ add_lldb_library(lldbSymbol
   CompilerType.cpp
   DWARFCallFrameInfo.cpp
   DebugMacros.cpp
-  Declaration.cpp
   DeclVendor.cpp
   FuncUnwinders.cpp
   Function.cpp

diff  --git a/lldb/unittests/Symbol/TestClangASTImporter.cpp b/lldb/unittests/Symbol/TestClangASTImporter.cpp
index 02151a20a20b8..f1bb4512d83fa 100644
--- a/lldb/unittests/Symbol/TestClangASTImporter.cpp
+++ b/lldb/unittests/Symbol/TestClangASTImporter.cpp
@@ -14,9 +14,9 @@
 #include "Plugins/TypeSystem/Clang/TypeSystemClang.h"
 #include "TestingSupport/SubsystemRAII.h"
 #include "TestingSupport/Symbol/ClangTestUtils.h"
+#include "lldb/Core/Declaration.h"
 #include "lldb/Host/FileSystem.h"
 #include "lldb/Host/HostInfo.h"
-#include "lldb/Symbol/Declaration.h"
 #include "clang/AST/DeclCXX.h"
 
 using namespace clang;

diff  --git a/lldb/unittests/Symbol/TestTypeSystemClang.cpp b/lldb/unittests/Symbol/TestTypeSystemClang.cpp
index e6a453bf912e9..ef7fc4e45b0b2 100644
--- a/lldb/unittests/Symbol/TestTypeSystemClang.cpp
+++ b/lldb/unittests/Symbol/TestTypeSystemClang.cpp
@@ -10,9 +10,9 @@
 #include "Plugins/TypeSystem/Clang/TypeSystemClang.h"
 #include "TestingSupport/SubsystemRAII.h"
 #include "TestingSupport/Symbol/ClangTestUtils.h"
+#include "lldb/Core/Declaration.h"
 #include "lldb/Host/FileSystem.h"
 #include "lldb/Host/HostInfo.h"
-#include "lldb/Symbol/Declaration.h"
 #include "clang/AST/DeclCXX.h"
 #include "clang/AST/DeclObjC.h"
 #include "clang/AST/ExprCXX.h"


        


More information about the lldb-commits mailing list