[PATCH] D21410: [pdb] Change type visitor pattern to use dynamic polymorphism

Zachary Turner via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 15 14:44:38 PDT 2016


zturner created this revision.
zturner added reviewers: rnk, ruiu.
zturner added a subscriber: llvm-commits.

This gets rid of the CRTP (curiously recurring template pattern) on the `CTypeVisitor`, and instead changes to a method of dynamic polymorphism to call back into the visitor implementation.

This has a number of advantages, including:

1) Ability to implement `CTypeVisitor` in a .cpp file instead of a .h file
2) Removal of a bunch of methods and code duplication since functionality of `CTypeVisitorImpl` can be merged with functionality of `TypeDumper`.
3) It's possible to implement a simple visitor with MUCH less code than before.  Since the base class provides virtual methods with default implementations, if all you want to do is handle a few simple method types, you need only override the few methods you care about.  This can lead to much less code when writing a new visitation handler.  Previously you would have to do the #define magic and implement every method in the class, and if you only wanted 2 or 3 methods to do something, there would be a lot of unnecessary function definitions.
4) More robust error propagation.  Since we don't rely on saving error state in a boolean anymore, we can simply propagate errors all the way out to the top level with actual `llvm::Error`s.  This allows the implementations to propagate more information up the call stack.

http://reviews.llvm.org/D21410

Files:
  include/llvm/DebugInfo/CodeView/CVTypeVisitor.h
  include/llvm/DebugInfo/CodeView/TypeDumper.h
  include/llvm/DebugInfo/CodeView/TypeVisitorCallbacks.h
  lib/DebugInfo/CodeView/CMakeLists.txt
  lib/DebugInfo/CodeView/CVTypeVisitor.cpp
  lib/DebugInfo/CodeView/TypeDumper.cpp
  lib/DebugInfo/CodeView/TypeStreamMerger.cpp
  tools/llvm-pdbdump/LLVMOutputStyle.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D21410.60909.patch
Type: text/x-patch
Size: 52820 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160615/5c5c4c0f/attachment.bin>


More information about the llvm-commits mailing list