mib updated this revision to Diff 341727.
mib added a comment.

Addressed @JDevlieghere comments.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D101556/new/

https://reviews.llvm.org/D101556

Files:
  lldb/include/lldb/Core/Declaration.h
  lldb/include/lldb/Symbol/Declaration.h
  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/Declaration.cpp
  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/source/Symbol/Declaration.cpp
  lldb/unittests/Symbol/TestClangASTImporter.cpp
  lldb/unittests/Symbol/TestTypeSystemClang.cpp

Index: lldb/unittests/Symbol/TestTypeSystemClang.cpp
===================================================================
--- lldb/unittests/Symbol/TestTypeSystemClang.cpp
+++ 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"
Index: lldb/unittests/Symbol/TestClangASTImporter.cpp
===================================================================
--- lldb/unittests/Symbol/TestClangASTImporter.cpp
+++ 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;
Index: lldb/source/Symbol/CMakeLists.txt
===================================================================
--- lldb/source/Symbol/CMakeLists.txt
+++ lldb/source/Symbol/CMakeLists.txt
@@ -14,7 +14,6 @@
   CompilerType.cpp
   DWARFCallFrameInfo.cpp
   DebugMacros.cpp
-  Declaration.cpp
   DeclVendor.cpp
   FuncUnwinders.cpp
   Function.cpp
Index: lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp
===================================================================
--- lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp
+++ 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"
Index: lldb/source/Plugins/SymbolFile/DWARF/UniqueDWARFASTType.h
===================================================================
--- lldb/source/Plugins/SymbolFile/DWARF/UniqueDWARFASTType.h
+++ 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:
Index: lldb/source/Plugins/SymbolFile/DWARF/UniqueDWARFASTType.cpp
===================================================================
--- lldb/source/Plugins/SymbolFile/DWARF/UniqueDWARFASTType.cpp
+++ 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,
Index: lldb/source/Core/ValueObjectVariable.cpp
===================================================================
--- lldb/source/Core/ValueObjectVariable.cpp
+++ 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"
Index: lldb/source/Core/ValueObject.cpp
===================================================================
--- lldb/source/Core/ValueObject.cpp
+++ 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"
Index: lldb/source/Core/Declaration.cpp
===================================================================
--- lldb/source/Core/Declaration.cpp
+++ 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 @@
       *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 @@
 
     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 @@
     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 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
 }
Index: lldb/source/Core/CMakeLists.txt
===================================================================
--- lldb/source/Core/CMakeLists.txt
+++ lldb/source/Core/CMakeLists.txt
@@ -26,6 +26,7 @@
   AddressResolverFileLine.cpp
   Communication.cpp
   Debugger.cpp
+  Declaration.cpp
   Disassembler.cpp
   DumpDataExtractor.cpp
   DumpRegisterValue.cpp
Index: lldb/source/Core/Address.cpp
===================================================================
--- lldb/source/Core/Address.cpp
+++ 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"
Index: lldb/source/API/SBValue.cpp
===================================================================
--- lldb/source/API/SBValue.cpp
+++ 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"
Index: lldb/source/API/SBDeclaration.cpp
===================================================================
--- lldb/source/API/SBDeclaration.cpp
+++ 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>
Index: lldb/include/lldb/Symbol/Variable.h
===================================================================
--- lldb/include/lldb/Symbol/Variable.h
+++ 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"
Index: lldb/include/lldb/Symbol/Type.h
===================================================================
--- lldb/include/lldb/Symbol/Type.h
+++ 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"
Index: lldb/include/lldb/Symbol/Function.h
===================================================================
--- lldb/include/lldb/Symbol/Function.h
+++ 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"
 
Index: lldb/include/lldb/Core/Declaration.h
===================================================================
--- lldb/include/lldb/Core/Declaration.h
+++ 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 @@
 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 @@
   /// \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 @@
   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 @@
   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,50 @@
   ///     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();
+  }
+
+  /// Logical NOT operator.
+  ///
+  /// This allows code to check a Declaration object to see if it is
+  /// invalid using code such as:
+  ///
+  /// \code
+  /// Declaration decl(...);
+  /// if (!decl)
+  /// { ...
+  /// \endcode
+  ///
+  /// \return
+  ///     Returns \b true if the object has an invalid file_spec or line number,
+  ///     \b false otherwise.
+  bool operator!() const { return !operator bool(); }
+
+  bool IsValid() const {
+    return m_file && m_line != 0 && m_line != LLDB_INVALID_LINE_NUMBER;
+  }
 
   /// Get the memory cost of this object.
   ///
@@ -162,17 +174,6 @@
   /// \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 +187,21 @@
   ///     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
+  // Member variables.
+  /// 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);
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to