LinePrinter.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. //===- LinePrinter.h ------------------------------------------ *- 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. #ifndef LLVM_TOOLS_LLVMPDBDUMP_LINEPRINTER_H
  10. #define LLVM_TOOLS_LLVMPDBDUMP_LINEPRINTER_H
  11. #include "llvm/ADT/StringRef.h"
  12. #include "llvm/ADT/Twine.h"
  13. #include "llvm/Support/raw_ostream.h"
  14. #include "llvm/Support/Regex.h"
  15. #include <list>
  16. namespace llvm {
  17. class LinePrinter {
  18. friend class WithColor;
  19. public:
  20. LinePrinter(int Indent, raw_ostream &Stream);
  21. void Indent();
  22. void Unindent();
  23. void NewLine();
  24. raw_ostream &getStream() { return OS; }
  25. int getIndentLevel() const { return CurrentIndent; }
  26. bool IsTypeExcluded(llvm::StringRef TypeName);
  27. bool IsSymbolExcluded(llvm::StringRef SymbolName);
  28. bool IsCompilandExcluded(llvm::StringRef CompilandName);
  29. private:
  30. template <typename Iter>
  31. void SetFilters(std::list<Regex> &List, Iter Begin, Iter End) {
  32. List.clear();
  33. for (; Begin != End; ++Begin)
  34. List.emplace_back(StringRef(*Begin));
  35. }
  36. raw_ostream &OS;
  37. int IndentSpaces;
  38. int CurrentIndent;
  39. std::list<Regex> CompilandFilters;
  40. std::list<Regex> TypeFilters;
  41. std::list<Regex> SymbolFilters;
  42. };
  43. template <class T>
  44. inline raw_ostream &operator<<(LinePrinter &Printer, const T &Item) {
  45. Printer.getStream() << Item;
  46. return Printer.getStream();
  47. }
  48. enum class PDB_ColorItem {
  49. None,
  50. Address,
  51. Type,
  52. Keyword,
  53. Offset,
  54. Identifier,
  55. Path,
  56. SectionHeader,
  57. LiteralValue,
  58. Register,
  59. };
  60. class WithColor {
  61. public:
  62. WithColor(LinePrinter &P, PDB_ColorItem C);
  63. ~WithColor();
  64. raw_ostream &get() { return OS; }
  65. private:
  66. void translateColor(PDB_ColorItem C, raw_ostream::Colors &Color,
  67. bool &Bold) const;
  68. raw_ostream &OS;
  69. };
  70. }
  71. #endif