TypedefDumper.cpp 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. //===- TypedefDumper.cpp - PDBSymDumper impl for typedefs -------- * C++ *-===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. #include "TypedefDumper.h"
  10. #include "BuiltinDumper.h"
  11. #include "FunctionDumper.h"
  12. #include "LinePrinter.h"
  13. #include "llvm-pdbdump.h"
  14. #include "llvm/DebugInfo/PDB/IPDBSession.h"
  15. #include "llvm/DebugInfo/PDB/PDBExtras.h"
  16. #include "llvm/DebugInfo/PDB/PDBSymbolTypeEnum.h"
  17. #include "llvm/DebugInfo/PDB/PDBSymbolTypeFunctionSig.h"
  18. #include "llvm/DebugInfo/PDB/PDBSymbolTypePointer.h"
  19. #include "llvm/DebugInfo/PDB/PDBSymbolTypeTypedef.h"
  20. #include "llvm/DebugInfo/PDB/PDBSymbolTypeUDT.h"
  21. using namespace llvm;
  22. TypedefDumper::TypedefDumper(LinePrinter &P) : PDBSymDumper(true), Printer(P) {}
  23. void TypedefDumper::start(const PDBSymbolTypeTypedef &Symbol) {
  24. WithColor(Printer, PDB_ColorItem::Keyword).get() << "typedef ";
  25. uint32_t TargetId = Symbol.getTypeId();
  26. if (auto TypeSymbol = Symbol.getSession().getSymbolById(TargetId))
  27. TypeSymbol->dump(*this);
  28. WithColor(Printer, PDB_ColorItem::Identifier).get() << " "
  29. << Symbol.getName();
  30. }
  31. void TypedefDumper::dump(const PDBSymbolTypeArray &Symbol) {}
  32. void TypedefDumper::dump(const PDBSymbolTypeBuiltin &Symbol) {
  33. BuiltinDumper Dumper(Printer);
  34. Dumper.start(Symbol);
  35. }
  36. void TypedefDumper::dump(const PDBSymbolTypeEnum &Symbol) {
  37. WithColor(Printer, PDB_ColorItem::Keyword).get() << "enum ";
  38. WithColor(Printer, PDB_ColorItem::Type).get() << " " << Symbol.getName();
  39. }
  40. void TypedefDumper::dump(const PDBSymbolTypePointer &Symbol) {
  41. if (Symbol.isConstType())
  42. WithColor(Printer, PDB_ColorItem::Keyword).get() << "const ";
  43. if (Symbol.isVolatileType())
  44. WithColor(Printer, PDB_ColorItem::Keyword).get() << "volatile ";
  45. uint32_t PointeeId = Symbol.getTypeId();
  46. auto PointeeType = Symbol.getSession().getSymbolById(PointeeId);
  47. if (!PointeeType)
  48. return;
  49. if (auto FuncSig = dyn_cast<PDBSymbolTypeFunctionSig>(PointeeType.get())) {
  50. FunctionDumper::PointerType Pointer = FunctionDumper::PointerType::Pointer;
  51. if (Symbol.isReference())
  52. Pointer = FunctionDumper::PointerType::Reference;
  53. FunctionDumper NestedDumper(Printer);
  54. NestedDumper.start(*FuncSig, nullptr, Pointer);
  55. } else {
  56. PointeeType->dump(*this);
  57. Printer << ((Symbol.isReference()) ? "&" : "*");
  58. }
  59. }
  60. void TypedefDumper::dump(const PDBSymbolTypeFunctionSig &Symbol) {
  61. FunctionDumper Dumper(Printer);
  62. Dumper.start(Symbol, nullptr, FunctionDumper::PointerType::None);
  63. }
  64. void TypedefDumper::dump(const PDBSymbolTypeUDT &Symbol) {
  65. WithColor(Printer, PDB_ColorItem::Keyword).get() << "class ";
  66. WithColor(Printer, PDB_ColorItem::Type).get() << Symbol.getName();
  67. }