[PATCH] D34281: [Format] Simplify some of the formatter template glue

Zachary Turner via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 16 09:07:18 PDT 2017


zturner created this revision.

The original idea here was that we would take the parameter pack and store it as both a tuple and a vector.  To put things in a vector the items had to share a common base, so I made this `format_adapter_base`.  Then there were 2 implementations.  One implementation that would be used for types where the format method would invoke a member function on the type itself, and another where a global formatter would be used.

But we can make this simpler though.  The only thing we need to store is just the value itself, and we can defer the knowledge of what kind of formatter it uses until we actually go to format it, and we can have the final selection just delegate to a global template function that is properly specialized.  This has the advantage of making the template glue much simpler, but also allowing us a convenient syntax to define new formatters via a macro.  A few existing formatters are converted to this new syntax as an example.  The rest can be done in a followup, for now I just want to see if the approach is ok.

Eventually I'd like to get the point where the adapters are composable, so you can say like `align(pad(Value, 7), Left, 3)` but part of that means simplifying the underlying glue so that there's fewer moving parts.


https://reviews.llvm.org/D34281

Files:
  llvm/include/llvm/Support/FormatAdapters.h
  llvm/include/llvm/Support/FormatProviders.h
  llvm/include/llvm/Support/FormatVariadic.h
  llvm/include/llvm/Support/FormatVariadicDetails.h
  llvm/unittests/Support/FormatVariadicTest.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D34281.102834.patch
Type: text/x-patch
Size: 15408 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170616/a8053f57/attachment-0001.bin>


More information about the llvm-commits mailing list