[Lldb-commits] [lldb] 564ff8f - [lldb][NFCI] Remove use of Stream * from TypeSystem

Alex Langford via lldb-commits lldb-commits at lists.llvm.org
Fri Jul 7 10:11:46 PDT 2023


Author: Alex Langford
Date: 2023-07-07T10:09:43-07:00
New Revision: 564ff8ffe75d9353ac02be5a4d3aa424cb79429c

URL: https://github.com/llvm/llvm-project/commit/564ff8ffe75d9353ac02be5a4d3aa424cb79429c
DIFF: https://github.com/llvm/llvm-project/commit/564ff8ffe75d9353ac02be5a4d3aa424cb79429c.diff

LOG: [lldb][NFCI] Remove use of Stream * from TypeSystem

We always assume these streams are valid, might as well take references
instead of raw pointers.

Differential Revision: https://reviews.llvm.org/D154549

Added: 
    

Modified: 
    lldb/include/lldb/Symbol/TypeSystem.h
    lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
    lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h
    lldb/source/Symbol/CompilerType.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/include/lldb/Symbol/TypeSystem.h b/lldb/include/lldb/Symbol/TypeSystem.h
index 7b5be3aabaf582..eb6e453e1aec0d 100644
--- a/lldb/include/lldb/Symbol/TypeSystem.h
+++ b/lldb/include/lldb/Symbol/TypeSystem.h
@@ -385,14 +385,14 @@ class TypeSystem : public PluginInterface,
 #endif
 
   virtual void DumpValue(lldb::opaque_compiler_type_t type,
-                         ExecutionContext *exe_ctx, Stream *s,
+                         ExecutionContext *exe_ctx, Stream &s,
                          lldb::Format format, const DataExtractor &data,
                          lldb::offset_t data_offset, size_t data_byte_size,
                          uint32_t bitfield_bit_size,
                          uint32_t bitfield_bit_offset, bool show_types,
                          bool show_summary, bool verbose, uint32_t depth) = 0;
 
-  virtual bool DumpTypeValue(lldb::opaque_compiler_type_t type, Stream *s,
+  virtual bool DumpTypeValue(lldb::opaque_compiler_type_t type, Stream &s,
                              lldb::Format format, const DataExtractor &data,
                              lldb::offset_t data_offset, size_t data_byte_size,
                              uint32_t bitfield_bit_size,
@@ -409,7 +409,7 @@ class TypeSystem : public PluginInterface,
   /// source-like representation of the type, whereas eDescriptionLevelVerbose
   /// does a dump of the underlying AST if applicable.
   virtual void DumpTypeDescription(
-      lldb::opaque_compiler_type_t type, Stream *s,
+      lldb::opaque_compiler_type_t type, Stream &s,
       lldb::DescriptionLevel level = lldb::eDescriptionLevelFull) = 0;
 
   /// Dump a textual representation of the internal TypeSystem state to the
@@ -423,7 +423,7 @@ class TypeSystem : public PluginInterface,
   virtual bool IsRuntimeGeneratedType(lldb::opaque_compiler_type_t type) = 0;
 
   virtual void DumpSummary(lldb::opaque_compiler_type_t type,
-                           ExecutionContext *exe_ctx, Stream *s,
+                           ExecutionContext *exe_ctx, Stream &s,
                            const DataExtractor &data,
                            lldb::offset_t data_offset,
                            size_t data_byte_size) = 0;

diff  --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
index 8933e6c60e1984..8d6b9f54315b78 100644
--- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
+++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
@@ -4750,7 +4750,7 @@ TypeSystemClang::GetBitSize(lldb::opaque_compiler_type_t type,
         static bool g_printed = false;
         if (!g_printed) {
           StreamString s;
-          DumpTypeDescription(type, &s);
+          DumpTypeDescription(type, s);
 
           llvm::outs() << "warning: trying to determine the size of type ";
           llvm::outs() << s.GetString() << "\n";
@@ -8523,7 +8523,7 @@ void TypeSystemClang::DumpFromSymbolFile(Stream &s,
 }
 
 void TypeSystemClang::DumpValue(
-    lldb::opaque_compiler_type_t type, ExecutionContext *exe_ctx, Stream *s,
+    lldb::opaque_compiler_type_t type, ExecutionContext *exe_ctx, Stream &s,
     lldb::Format format, const lldb_private::DataExtractor &data,
     lldb::offset_t data_byte_offset, size_t data_byte_size,
     uint32_t bitfield_bit_size, uint32_t bitfield_bit_offset, bool show_types,
@@ -8574,15 +8574,15 @@ void TypeSystemClang::DumpValue(
           field_byte_offset = field_bit_offset / 8;
           assert(field_bit_offset % 8 == 0);
           if (child_idx == 0)
-            s->PutChar('{');
+            s.PutChar('{');
           else
-            s->PutChar(',');
+            s.PutChar(',');
 
           clang::QualType base_class_qual_type = base_class->getType();
           std::string base_class_type_name(base_class_qual_type.getAsString());
 
           // Indent and print the base class type name
-          s->Format("\n{0}{1}", llvm::fmt_repeat(" ", depth + DEPTH_INCREMENT),
+          s.Format("\n{0}{1}", llvm::fmt_repeat(" ", depth + DEPTH_INCREMENT),
                     base_class_type_name);
 
           clang::TypeInfo base_class_type_info =
@@ -8592,7 +8592,7 @@ void TypeSystemClang::DumpValue(
           CompilerType base_clang_type = GetType(base_class_qual_type);
           base_clang_type.DumpValue(
               exe_ctx,
-              s, // Stream to dump to
+              &s, // Stream to dump to
               base_clang_type
                   .GetFormat(), // The format with which to display the member
               data, // Data buffer containing all bytes for this type
@@ -8620,12 +8620,12 @@ void TypeSystemClang::DumpValue(
         // Print the starting squiggly bracket (if this is the first member) or
         // comma (for member 2 and beyond) for the struct/union/class member.
         if (child_idx == 0)
-          s->PutChar('{');
+          s.PutChar('{');
         else
-          s->PutChar(',');
+          s.PutChar(',');
 
         // Indent
-        s->Printf("\n%*s", depth + DEPTH_INCREMENT, "");
+        s.Printf("\n%*s", depth + DEPTH_INCREMENT, "");
 
         clang::QualType field_type = field->getType();
         // Print the member type if requested
@@ -8646,19 +8646,19 @@ void TypeSystemClang::DumpValue(
         if (show_types) {
           std::string field_type_name(field_type.getAsString());
           if (field_bitfield_bit_size > 0)
-            s->Printf("(%s:%u) ", field_type_name.c_str(),
-                      field_bitfield_bit_size);
+            s.Printf("(%s:%u) ", field_type_name.c_str(),
+                     field_bitfield_bit_size);
           else
-            s->Printf("(%s) ", field_type_name.c_str());
+            s.Printf("(%s) ", field_type_name.c_str());
         }
         // Print the member name and equal sign
-        s->Printf("%s = ", field->getNameAsString().c_str());
+        s.Printf("%s = ", field->getNameAsString().c_str());
 
         // Dump the value of the member
         CompilerType field_clang_type = GetType(field_type);
         field_clang_type.DumpValue(
             exe_ctx,
-            s, // Stream to dump to
+            &s, // Stream to dump to
             field_clang_type
                 .GetFormat(), // The format with which to display the member
             data,             // Data buffer containing all bytes for this type
@@ -8678,7 +8678,7 @@ void TypeSystemClang::DumpValue(
 
       // Indent the trailing squiggly bracket
       if (child_idx > 0)
-        s->Printf("\n%*s}", depth, "");
+        s.Printf("\n%*s}", depth, "");
     }
     return;
 
@@ -8696,13 +8696,13 @@ void TypeSystemClang::DumpValue(
           enum_end_pos = enum_decl->enumerator_end();
            enum_pos != enum_end_pos; ++enum_pos) {
         if (enum_pos->getInitVal() == enum_value) {
-          s->Printf("%s", enum_pos->getNameAsString().c_str());
+          s.Printf("%s", enum_pos->getNameAsString().c_str());
           return;
         }
       }
       // If we have gotten here we didn't get find the enumerator in the enum
       // decl, so just print the integer.
-      s->Printf("%" PRIi64, enum_value);
+      s.Printf("%" PRIi64, enum_value);
     }
     return;
 
@@ -8728,11 +8728,11 @@ void TypeSystemClang::DumpValue(
     uint32_t element_stride = element_byte_size;
 
     if (is_array_of_characters) {
-      s->PutChar('"');
-      DumpDataExtractor(data, s, data_byte_offset, lldb::eFormatChar,
+      s.PutChar('"');
+      DumpDataExtractor(data, &s, data_byte_offset, lldb::eFormatChar,
                         element_byte_size, element_count, UINT32_MAX,
                         LLDB_INVALID_ADDRESS, 0, 0);
-      s->PutChar('"');
+      s.PutChar('"');
       return;
     } else {
       CompilerType element_clang_type = GetType(element_qual_type);
@@ -8742,12 +8742,12 @@ void TypeSystemClang::DumpValue(
         // Print the starting squiggly bracket (if this is the first member) or
         // comman (for member 2 and beyong) for the struct/union/class member.
         if (element_idx == 0)
-          s->PutChar('{');
+          s.PutChar('{');
         else
-          s->PutChar(',');
+          s.PutChar(',');
 
         // Indent and print the index
-        s->Printf("\n%*s[%u] ", depth + DEPTH_INCREMENT, "", element_idx);
+        s.Printf("\n%*s[%u] ", depth + DEPTH_INCREMENT, "", element_idx);
 
         // Figure out the field offset within the current struct/union/class
         // type
@@ -8756,7 +8756,7 @@ void TypeSystemClang::DumpValue(
         // Dump the value of the member
         element_clang_type.DumpValue(
             exe_ctx,
-            s,              // Stream to dump to
+            &s,             // Stream to dump to
             element_format, // The format with which to display the element
             data,           // Data buffer containing all bytes for this type
             data_byte_offset +
@@ -8775,7 +8775,7 @@ void TypeSystemClang::DumpValue(
 
       // Indent the trailing squiggly bracket
       if (element_idx > 0)
-        s->Printf("\n%*s}", depth, "");
+        s.Printf("\n%*s}", depth, "");
     }
   }
     return;
@@ -8794,7 +8794,7 @@ void TypeSystemClang::DumpValue(
 
     return typedef_clang_type.DumpValue(
         exe_ctx,
-        s,                   // Stream to dump to
+        &s,                  // Stream to dump to
         typedef_format,      // The format with which to display the element
         data,                // Data buffer containing all bytes for this type
         data_byte_offset,    // Offset into "data" where to grab value from
@@ -8819,7 +8819,7 @@ void TypeSystemClang::DumpValue(
 
     return elaborated_clang_type.DumpValue(
         exe_ctx,
-        s,                    // Stream to dump to
+        &s,                   // Stream to dump to
         elaborated_format,    // The format with which to display the element
         data,                 // Data buffer containing all bytes for this type
         data_byte_offset,     // Offset into "data" where to grab value from
@@ -8844,7 +8844,7 @@ void TypeSystemClang::DumpValue(
 
     return elaborated_clang_type.DumpValue(
         exe_ctx,
-        s,                    // Stream to dump to
+        &s,                   // Stream to dump to
         elaborated_format,    // The format with which to display the element
         data,                 // Data buffer containing all bytes for this type
         data_byte_offset,     // Offset into "data" where to grab value from
@@ -8870,7 +8870,7 @@ void TypeSystemClang::DumpValue(
 
     return desugar_clang_type.DumpValue(
         exe_ctx,
-        s,                   // Stream to dump to
+        &s,                  // Stream to dump to
         desugar_format,      // The format with which to display the element
         data,                // Data buffer containing all bytes for this type
         data_byte_offset,    // Offset into "data" where to grab value from
@@ -8886,7 +8886,7 @@ void TypeSystemClang::DumpValue(
 
   default:
     // We are down to a scalar type that we just need to display.
-    DumpDataExtractor(data, s, data_byte_offset, format, data_byte_size, 1,
+    DumpDataExtractor(data, &s, data_byte_offset, format, data_byte_size, 1,
                       UINT32_MAX, LLDB_INVALID_ADDRESS, bitfield_bit_size,
                       bitfield_bit_offset);
 
@@ -8896,7 +8896,7 @@ void TypeSystemClang::DumpValue(
   }
 }
 
-static bool DumpEnumValue(const clang::QualType &qual_type, Stream *s,
+static bool DumpEnumValue(const clang::QualType &qual_type, Stream &s,
                           const DataExtractor &data, lldb::offset_t byte_offset,
                           size_t byte_size, uint32_t bitfield_bit_offset,
                           uint32_t bitfield_bit_size) {
@@ -8926,7 +8926,7 @@ static bool DumpEnumValue(const clang::QualType &qual_type, Stream *s,
     ++num_enumerators;
     if (val == enum_svalue) {
       // Found an exact match, that's all we need to do.
-      s->PutCString(enumerator->getNameAsString());
+      s.PutCString(enumerator->getNameAsString());
       return true;
     }
   }
@@ -8940,9 +8940,9 @@ static bool DumpEnumValue(const clang::QualType &qual_type, Stream *s,
   // decimal.
   if (!can_be_bitfield) {
     if (qual_type->isSignedIntegerOrEnumerationType())
-      s->Printf("%" PRIi64, enum_svalue);
+      s.Printf("%" PRIi64, enum_svalue);
     else
-      s->Printf("%" PRIu64, enum_uvalue);
+      s.Printf("%" PRIu64, enum_uvalue);
     return true;
   }
 
@@ -8965,20 +8965,20 @@ static bool DumpEnumValue(const clang::QualType &qual_type, Stream *s,
     if ((remaining_value & val.first) != val.first)
       continue;
     remaining_value &= ~val.first;
-    s->PutCString(val.second);
+    s.PutCString(val.second);
     if (remaining_value)
-      s->PutCString(" | ");
+      s.PutCString(" | ");
   }
 
   // If there is a remainder that is not covered by the value, print it as hex.
   if (remaining_value)
-    s->Printf("0x%" PRIx64, remaining_value);
+    s.Printf("0x%" PRIx64, remaining_value);
 
   return true;
 }
 
 bool TypeSystemClang::DumpTypeValue(
-    lldb::opaque_compiler_type_t type, Stream *s, lldb::Format format,
+    lldb::opaque_compiler_type_t type, Stream &s, lldb::Format format,
     const lldb_private::DataExtractor &data, lldb::offset_t byte_offset,
     size_t byte_size, uint32_t bitfield_bit_size, uint32_t bitfield_bit_offset,
     ExecutionContextScope *exe_scope) {
@@ -9011,7 +9011,7 @@ bool TypeSystemClang::DumpTypeValue(
       uint64_t typedef_byte_size = typedef_type_info.Width / 8;
 
       return typedef_clang_type.DumpTypeValue(
-          s,
+          &s,
           format,            // The format with which to display the element
           data,              // Data buffer containing all bytes for this type
           byte_offset,       // Offset into "data" where to grab value from
@@ -9090,7 +9090,7 @@ bool TypeSystemClang::DumpTypeValue(
           byte_size = 4;
           break;
         }
-        return DumpDataExtractor(data, s, byte_offset, format, byte_size,
+        return DumpDataExtractor(data, &s, byte_offset, format, byte_size,
                                  item_count, UINT32_MAX, LLDB_INVALID_ADDRESS,
                                  bitfield_bit_size, bitfield_bit_offset,
                                  exe_scope);
@@ -9102,7 +9102,7 @@ bool TypeSystemClang::DumpTypeValue(
 }
 
 void TypeSystemClang::DumpSummary(lldb::opaque_compiler_type_t type,
-                                  ExecutionContext *exe_ctx, Stream *s,
+                                  ExecutionContext *exe_ctx, Stream &s,
                                   const lldb_private::DataExtractor &data,
                                   lldb::offset_t data_byte_offset,
                                   size_t data_byte_size) {
@@ -9131,8 +9131,8 @@ void TypeSystemClang::DumpSummary(lldb::opaque_compiler_type_t type,
           if (len == 0)
             break;
           if (total_cstr_len == 0)
-            s->PutCString(" \"");
-          DumpDataExtractor(cstr_data, s, 0, lldb::eFormatChar, 1, len,
+            s.PutCString(" \"");
+          DumpDataExtractor(cstr_data, &s, 0, lldb::eFormatChar, 1, len,
                             UINT32_MAX, LLDB_INVALID_ADDRESS, 0, 0);
           total_cstr_len += len;
           if (len < buf.size())
@@ -9140,7 +9140,7 @@ void TypeSystemClang::DumpSummary(lldb::opaque_compiler_type_t type,
           pointer_address += total_cstr_len;
         }
         if (total_cstr_len > 0)
-          s->PutChar('"');
+          s.PutChar('"');
       }
     }
   }
@@ -9149,7 +9149,7 @@ void TypeSystemClang::DumpSummary(lldb::opaque_compiler_type_t type,
 void TypeSystemClang::DumpTypeDescription(lldb::opaque_compiler_type_t type,
                                           lldb::DescriptionLevel level) {
   StreamFile s(stdout, false);
-  DumpTypeDescription(type, &s, level);
+  DumpTypeDescription(type, s, level);
 
   CompilerType ct(weak_from_this(), type);
   const clang::Type *clang_type = ClangUtil::GetQualType(ct).getTypePtr();
@@ -9160,7 +9160,7 @@ void TypeSystemClang::DumpTypeDescription(lldb::opaque_compiler_type_t type,
 }
 
 void TypeSystemClang::DumpTypeDescription(lldb::opaque_compiler_type_t type,
-                                          Stream *s,
+                                          Stream &s,
                                           lldb::DescriptionLevel level) {
   if (type) {
     clang::QualType qual_type =
@@ -9189,7 +9189,7 @@ void TypeSystemClang::DumpTypeDescription(lldb::opaque_compiler_type_t type,
       else
         class_interface_decl->print(llvm_ostrm,
                                     getASTContext().getPrintingPolicy(),
-                                    s->GetIndentLevel());
+                                    s.GetIndentLevel());
     } break;
 
     case clang::Type::Typedef: {
@@ -9202,8 +9202,8 @@ void TypeSystemClang::DumpTypeDescription(lldb::opaque_compiler_type_t type,
       else {
         std::string clang_typedef_name(GetTypeNameForDecl(typedef_decl));
         if (!clang_typedef_name.empty()) {
-          s->PutCString("typedef ");
-          s->PutCString(clang_typedef_name);
+          s.PutCString("typedef ");
+          s.PutCString(clang_typedef_name);
         }
       }
     } break;
@@ -9217,7 +9217,7 @@ void TypeSystemClang::DumpTypeDescription(lldb::opaque_compiler_type_t type,
         record_decl->dump(llvm_ostrm);
       else {
         record_decl->print(llvm_ostrm, getASTContext().getPrintingPolicy(),
-                           s->GetIndentLevel());
+                           s.GetIndentLevel());
       }
     } break;
 
@@ -9236,14 +9236,14 @@ void TypeSystemClang::DumpTypeDescription(lldb::opaque_compiler_type_t type,
         else {
           std::string clang_type_name(qual_type.getAsString());
           if (!clang_type_name.empty())
-            s->PutCString(clang_type_name);
+            s.PutCString(clang_type_name);
         }
       }
     }
     }
 
     if (buf.size() > 0) {
-      s->Write(buf.data(), buf.size());
+      s.Write(buf.data(), buf.size());
     }
 }
 }

diff  --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h
index acd1c6e3e8d81c..0544de3cd33bef 100644
--- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h
+++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h
@@ -1030,20 +1030,20 @@ class TypeSystemClang : public TypeSystem {
   void DumpFromSymbolFile(Stream &s, llvm::StringRef symbol_name);
 
   void DumpValue(lldb::opaque_compiler_type_t type, ExecutionContext *exe_ctx,
-                 Stream *s, lldb::Format format, const DataExtractor &data,
+                 Stream &s, lldb::Format format, const DataExtractor &data,
                  lldb::offset_t data_offset, size_t data_byte_size,
                  uint32_t bitfield_bit_size, uint32_t bitfield_bit_offset,
                  bool show_types, bool show_summary, bool verbose,
                  uint32_t depth) override;
 
-  bool DumpTypeValue(lldb::opaque_compiler_type_t type, Stream *s,
+  bool DumpTypeValue(lldb::opaque_compiler_type_t type, Stream &s,
                      lldb::Format format, const DataExtractor &data,
                      lldb::offset_t data_offset, size_t data_byte_size,
                      uint32_t bitfield_bit_size, uint32_t bitfield_bit_offset,
                      ExecutionContextScope *exe_scope) override;
 
   void DumpSummary(lldb::opaque_compiler_type_t type, ExecutionContext *exe_ctx,
-                   Stream *s, const DataExtractor &data,
+                   Stream &s, const DataExtractor &data,
                    lldb::offset_t data_offset, size_t data_byte_size) override;
 
   void DumpTypeDescription(
@@ -1051,7 +1051,7 @@ class TypeSystemClang : public TypeSystem {
       lldb::DescriptionLevel level = lldb::eDescriptionLevelFull) override;
 
   void DumpTypeDescription(
-      lldb::opaque_compiler_type_t type, Stream *s,
+      lldb::opaque_compiler_type_t type, Stream &s,
       lldb::DescriptionLevel level = lldb::eDescriptionLevelFull) override;
 
   static void DumpTypeName(const CompilerType &type);

diff  --git a/lldb/source/Symbol/CompilerType.cpp b/lldb/source/Symbol/CompilerType.cpp
index 4bce2c5071bf3c..90d17b921a9689 100644
--- a/lldb/source/Symbol/CompilerType.cpp
+++ b/lldb/source/Symbol/CompilerType.cpp
@@ -830,7 +830,7 @@ void CompilerType::DumpValue(ExecutionContext *exe_ctx, Stream *s,
                              bool show_summary, bool verbose, uint32_t depth) {
   if (!IsValid())
     if (auto type_system_sp = GetTypeSystem())
-      type_system_sp->DumpValue(m_type, exe_ctx, s, format, data,
+      type_system_sp->DumpValue(m_type, exe_ctx, *s, format, data,
                                 data_byte_offset, data_byte_size,
                                 bitfield_bit_size, bitfield_bit_offset,
                                 show_types, show_summary, verbose, depth);
@@ -844,9 +844,9 @@ bool CompilerType::DumpTypeValue(Stream *s, lldb::Format format,
                                  ExecutionContextScope *exe_scope) {
   if (IsValid())
     if (auto type_system_sp = GetTypeSystem())
-      return type_system_sp->DumpTypeValue(m_type, s, format, data, byte_offset,
-                                           byte_size, bitfield_bit_size,
-                                           bitfield_bit_offset, exe_scope);
+      return type_system_sp->DumpTypeValue(
+          m_type, *s, format, data, byte_offset, byte_size, bitfield_bit_size,
+          bitfield_bit_offset, exe_scope);
   return false;
 }
 
@@ -856,7 +856,7 @@ void CompilerType::DumpSummary(ExecutionContext *exe_ctx, Stream *s,
                                size_t data_byte_size) {
   if (IsValid())
     if (auto type_system_sp = GetTypeSystem())
-      type_system_sp->DumpSummary(m_type, exe_ctx, s, data, data_byte_offset,
+      type_system_sp->DumpSummary(m_type, exe_ctx, *s, data, data_byte_offset,
                                   data_byte_size);
 }
 
@@ -870,7 +870,7 @@ void CompilerType::DumpTypeDescription(Stream *s,
                                        lldb::DescriptionLevel level) const {
   if (IsValid())
     if (auto type_system_sp = GetTypeSystem())
-      type_system_sp->DumpTypeDescription(m_type, s, level);
+      type_system_sp->DumpTypeDescription(m_type, *s, level);
 }
 
 #ifndef NDEBUG


        


More information about the lldb-commits mailing list