[CodeView] Simplify the use of visiting type records & streams.
authorZachary Turner <zturner@google.com>
Wed, 17 May 2017 16:39:06 +0000 (16:39 +0000)
committerZachary Turner <zturner@google.com>
Wed, 17 May 2017 16:39:06 +0000 (16:39 +0000)
commit1d795c451e132f3a1232821aeb941ce303ef3b96
tree68422d20f8ec68992757dbf1cbe7dbf0a641be13
parente67c5f6b52d328bfe08d2830467badaca21611fa
[CodeView] Simplify the use of visiting type records & streams.

There is often a lot of boilerplate code required to visit a type
record or type stream.  The #1 use case is that you have a sequence
of bytes that represent one or more records, and you want to
deserialize each one, switch on it, and call a callback with the
deserialized record that the user can examine.  Currently this
requires at least 6 lines of code:

  codeview::TypeVisitorCallbackPipeline Pipeline;
  Pipeline.addCallbackToPipeline(Deserializer);
  Pipeline.addCallbackToPipeline(MyCallbacks);

  codeview::CVTypeVisitor Visitor(Pipeline);
  consumeError(Visitor.visitTypeRecord(Record));

With this patch, it becomes one line of code:

  consumeError(codeview::visitTypeRecord(Record, MyCallbacks));

This is done by having the deserialization happen internally inside
of the visitTypeRecord function.  Since this is occasionally not
desirable, the function provides a 3rd parameter that can be used
to change this behavior.

Hopefully this can significantly reduce the barrier to entry
to using the visitation infrastructure.

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

llvm-svn: 303271
16 files changed:
llvm/include/llvm/DebugInfo/CodeView/CVTypeVisitor.h
llvm/include/llvm/DebugInfo/CodeView/RandomAccessTypeVisitor.h
llvm/include/llvm/DebugInfo/PDB/Native/TpiStream.h
llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
llvm/lib/DebugInfo/CodeView/CVTypeDumper.cpp
llvm/lib/DebugInfo/CodeView/CVTypeVisitor.cpp
llvm/lib/DebugInfo/CodeView/RandomAccessTypeVisitor.cpp
llvm/lib/DebugInfo/CodeView/TypeDumpVisitor.cpp
llvm/lib/DebugInfo/CodeView/TypeStreamMerger.cpp
llvm/lib/DebugInfo/PDB/Native/PDBTypeServerHandler.cpp
llvm/tools/llvm-pdbdump/Analyze.cpp
llvm/tools/llvm-pdbdump/LLVMOutputStyle.cpp
llvm/tools/llvm-pdbdump/PdbYaml.cpp
llvm/tools/llvm-pdbdump/YamlTypeDumper.cpp
llvm/unittests/DebugInfo/CodeView/RandomAccessVisitorTest.cpp
llvm/unittests/DebugInfo/PDB/TypeServerHandlerTest.cpp