[llvm-pdbdump] Minor prepatory refactor of Class Def Dumper.

In a followup patch I intend to introduce an additional dumping
mode which dumps a graphical representation of a class's layout.
In preparation for this, the text-based layout printer needs to
be split out from the graphical layout printer, and both need
to be able to use the same code for printing the intro and outro
of a class's definition (e.g. base class list, etc).

This patch does so, and in the process introduces a skeleton
definition for the graphical printer, while currently making
the graphical printer just print nothing.

NFC

llvm-svn: 300134
diff --git a/llvm/tools/llvm-pdbdump/PrettyClassDefinitionDumper.cpp b/llvm/tools/llvm-pdbdump/PrettyClassDefinitionDumper.cpp
index 2e1e54e..ba829e7 100644
--- a/llvm/tools/llvm-pdbdump/PrettyClassDefinitionDumper.cpp
+++ b/llvm/tools/llvm-pdbdump/PrettyClassDefinitionDumper.cpp
@@ -10,24 +10,14 @@
 #include "PrettyClassDefinitionDumper.h"
 
 #include "LinePrinter.h"
-#include "PrettyEnumDumper.h"
-#include "PrettyFunctionDumper.h"
-#include "PrettyTypedefDumper.h"
-#include "PrettyVariableDumper.h"
+#include "PrettyClassLayoutGraphicalDumper.h"
+#include "PrettyClassLayoutTextDumper.h"
 #include "llvm-pdbdump.h"
 
 #include "llvm/ADT/APFloat.h"
 #include "llvm/ADT/SmallString.h"
-#include "llvm/DebugInfo/PDB/IPDBSession.h"
-#include "llvm/DebugInfo/PDB/PDBExtras.h"
-#include "llvm/DebugInfo/PDB/PDBSymbolData.h"
-#include "llvm/DebugInfo/PDB/PDBSymbolFunc.h"
 #include "llvm/DebugInfo/PDB/PDBSymbolTypeBaseClass.h"
-#include "llvm/DebugInfo/PDB/PDBSymbolTypeEnum.h"
-#include "llvm/DebugInfo/PDB/PDBSymbolTypePointer.h"
-#include "llvm/DebugInfo/PDB/PDBSymbolTypeTypedef.h"
 #include "llvm/DebugInfo/PDB/PDBSymbolTypeUDT.h"
-#include "llvm/DebugInfo/PDB/PDBSymbolTypeVTable.h"
 #include "llvm/DebugInfo/PDB/UDTLayout.h"
 
 #include "llvm/Support/Format.h"
@@ -42,33 +32,57 @@
   assert(opts::pretty::ClassFormat !=
          opts::pretty::ClassDefinitionFormat::None);
 
-  uint32_t Size = Class.getLength();
-
-  ClassLayout Layout(Class.clone());
+  ClassLayout Layout(Class);
 
   if (opts::pretty::OnlyPaddingClasses && (Layout.shallowPaddingSize() == 0))
     return;
 
+  prettyPrintClassIntro(Layout);
+
+  switch (opts::pretty::ClassFormat) {
+  case opts::pretty::ClassDefinitionFormat::Graphical: {
+    PrettyClassLayoutGraphicalDumper Dumper(Printer);
+    DumpedAnything = Dumper.start(Layout);
+    break;
+  }
+  case opts::pretty::ClassDefinitionFormat::Standard:
+  case opts::pretty::ClassDefinitionFormat::Layout: {
+    PrettyClassLayoutTextDumper Dumper(Printer);
+    DumpedAnything |= Dumper.start(Layout);
+    break;
+  }
+  default:
+    llvm_unreachable("Unreachable!");
+  }
+
+  prettyPrintClassOutro(Layout);
+}
+
+void ClassDefinitionDumper::prettyPrintClassIntro(const ClassLayout &Layout) {
+  DumpedAnything = false;
   Printer.NewLine();
 
+  uint32_t Size = Layout.getClassSize();
+  const PDBSymbolTypeUDT &Class = Layout.getClass();
+
   WithColor(Printer, PDB_ColorItem::Keyword).get() << Class.getUdtKind() << " ";
   WithColor(Printer, PDB_ColorItem::Type).get() << Class.getName();
   WithColor(Printer, PDB_ColorItem::Comment).get() << " [sizeof = " << Size
                                                    << "]";
-
-  auto Bases = Class.findAllChildren<PDBSymbolTypeBaseClass>();
-  if (Bases->getChildCount() > 0) {
+  uint32_t BaseCount = Layout.base_classes().size();
+  if (BaseCount > 0) {
     Printer.Indent();
     Printer.NewLine();
     Printer << ":";
     uint32_t BaseIndex = 0;
-    while (auto Base = Bases->getNext()) {
+    for (auto BC : Layout.base_classes()) {
+      const auto &Base = BC->getBase();
       Printer << " ";
-      WithColor(Printer, PDB_ColorItem::Keyword).get() << Base->getAccess();
-      if (Base->isVirtualBaseClass())
+      WithColor(Printer, PDB_ColorItem::Keyword).get() << Base.getAccess();
+      if (Base.isVirtualBaseClass())
         WithColor(Printer, PDB_ColorItem::Keyword).get() << " virtual";
-      WithColor(Printer, PDB_ColorItem::Type).get() << " " << Base->getName();
-      if (++BaseIndex < Bases->getChildCount()) {
+      WithColor(Printer, PDB_ColorItem::Type).get() << " " << Base.getName();
+      if (++BaseIndex < BaseCount) {
         Printer.NewLine();
         Printer << ",";
       }
@@ -78,49 +92,17 @@
 
   Printer << " {";
   Printer.Indent();
+}
 
-  // Dump non-layout items first, but only if we're not in layout-only mode.
-  if (opts::pretty::ClassFormat !=
-      opts::pretty::ClassDefinitionFormat::Layout) {
-    for (auto &Other : Layout.other_items())
-      Other->dump(*this);
-  }
-
-  const BitVector &UseMap = Layout.usedBytes();
-  int NextUnusedByte = Layout.usedBytes().find_first_unset();
-  // Next dump items which affect class layout.
-  for (auto &LayoutItem : Layout.layout_items()) {
-    if (NextUnusedByte >= 0) {
-      // If there are padding bytes remaining, see if this field is the first to
-      // cross a padding boundary, and print a padding field indicator if so.
-      int Off = LayoutItem->getOffsetInParent();
-      if (Off > NextUnusedByte) {
-        uint32_t Amount = Off - NextUnusedByte;
-        Printer.NewLine();
-        WithColor(Printer, PDB_ColorItem::Padding).get() << "<padding> ("
-                                                         << Amount << " bytes)";
-        assert(UseMap.find_next(NextUnusedByte) == Off);
-        NextUnusedByte = UseMap.find_next_unset(Off);
-      }
-    }
-    LayoutItem->getSymbol().dump(*this);
-  }
-
-  if (NextUnusedByte >= 0 && Layout.getClassSize() > 1) {
-    uint32_t Amount = Layout.getClassSize() - NextUnusedByte;
-    Printer.NewLine();
-    WithColor(Printer, PDB_ColorItem::Padding).get() << "<padding> (" << Amount
-                                                     << " bytes)";
-    DumpedAnything = true;
-  }
-
+void ClassDefinitionDumper::prettyPrintClassOutro(const ClassLayout &Layout) {
   Printer.Unindent();
   if (DumpedAnything)
     Printer.NewLine();
   Printer << "}";
   Printer.NewLine();
   if (Layout.deepPaddingSize() > 0) {
-    APFloat Pct(100.0 * (double)Layout.deepPaddingSize() / (double)Size);
+    APFloat Pct(100.0 * (double)Layout.deepPaddingSize() /
+                (double)Layout.getClassSize());
     SmallString<8> PctStr;
     Pct.toString(PctStr, 4);
     WithColor(Printer, PDB_ColorItem::Padding).get()
@@ -129,54 +111,3 @@
     Printer.NewLine();
   }
 }
-
-void ClassDefinitionDumper::dump(const PDBSymbolTypeBaseClass &Symbol) {}
-
-void ClassDefinitionDumper::dump(const PDBSymbolData &Symbol) {
-  VariableDumper Dumper(Printer);
-  Dumper.start(Symbol);
-  DumpedAnything = true;
-}
-
-void ClassDefinitionDumper::dump(const PDBSymbolFunc &Symbol) {
-  if (Printer.IsSymbolExcluded(Symbol.getName()))
-    return;
-  if (Symbol.isCompilerGenerated() && opts::pretty::ExcludeCompilerGenerated)
-    return;
-  if (Symbol.getLength() == 0 && !Symbol.isPureVirtual() &&
-      !Symbol.isIntroVirtualFunction())
-    return;
-
-  DumpedAnything = true;
-  Printer.NewLine();
-  FunctionDumper Dumper(Printer);
-  Dumper.start(Symbol, FunctionDumper::PointerType::None);
-}
-
-void ClassDefinitionDumper::dump(const PDBSymbolTypeVTable &Symbol) {
-  VariableDumper Dumper(Printer);
-  Dumper.start(Symbol);
-  DumpedAnything = true;
-}
-
-void ClassDefinitionDumper::dump(const PDBSymbolTypeEnum &Symbol) {
-  if (Printer.IsTypeExcluded(Symbol.getName()))
-    return;
-
-  DumpedAnything = true;
-  Printer.NewLine();
-  EnumDumper Dumper(Printer);
-  Dumper.start(Symbol);
-}
-
-void ClassDefinitionDumper::dump(const PDBSymbolTypeTypedef &Symbol) {
-  if (Printer.IsTypeExcluded(Symbol.getName()))
-    return;
-
-  DumpedAnything = true;
-  Printer.NewLine();
-  TypedefDumper Dumper(Printer);
-  Dumper.start(Symbol);
-}
-
-void ClassDefinitionDumper::dump(const PDBSymbolTypeUDT &Symbol) {}