LCOV - code coverage report
Current view: top level - include/llvm/Support - FormatAdapters.h (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 26 26 100.0 %
Date: 2017-09-14 15:23:50 Functions: 17 54 31.5 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===- FormatAdapters.h - Formatters for common LLVM types -----*- 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             : 
      10             : #ifndef LLVM_SUPPORT_FORMATADAPTERS_H
      11             : #define LLVM_SUPPORT_FORMATADAPTERS_H
      12             : 
      13             : #include "llvm/ADT/SmallString.h"
      14             : #include "llvm/ADT/StringRef.h"
      15             : #include "llvm/Support/FormatCommon.h"
      16             : #include "llvm/Support/FormatVariadicDetails.h"
      17             : #include "llvm/Support/raw_ostream.h"
      18             : 
      19             : namespace llvm {
      20       16230 : template <typename T> class FormatAdapter : public detail::format_adapter {
      21             : protected:
      22        2041 :   explicit FormatAdapter(T &&Item) : Item(Item) {}
      23             : 
      24             :   T Item;
      25             : };
      26             : 
      27             : namespace detail {
      28       19418 : template <typename T> class AlignAdapter final : public FormatAdapter<T> {
      29             :   AlignStyle Where;
      30             :   size_t Amount;
      31             :   char Fill;
      32             : 
      33             : public:
      34             :   AlignAdapter(T &&Item, AlignStyle Where, size_t Amount, char Fill)
      35             :       : FormatAdapter<T>(std::forward<T>(Item)), Where(Where), Amount(Amount),
      36        2774 :         Fill(Fill) {}
      37             : 
      38        1387 :   void format(llvm::raw_ostream &Stream, StringRef Style) {
      39        4119 :     auto Adapter = detail::build_format_adapter(std::forward<T>(this->Item));
      40        2774 :     FmtAlign(Adapter, Where, Amount, Fill).format(Stream, Style);
      41        1387 :   }
      42             : };
      43             : 
      44          50 : template <typename T> class PadAdapter final : public FormatAdapter<T> {
      45             :   size_t Left;
      46             :   size_t Right;
      47             : 
      48             : public:
      49             :   PadAdapter(T &&Item, size_t Left, size_t Right)
      50           6 :       : FormatAdapter<T>(std::forward<T>(Item)), Left(Left), Right(Right) {}
      51             : 
      52           7 :   void format(llvm::raw_ostream &Stream, StringRef Style) {
      53          21 :     auto Adapter = detail::build_format_adapter(std::forward<T>(this->Item));
      54           7 :     Stream.indent(Left);
      55           7 :     Adapter.format(Stream, Style);
      56           7 :     Stream.indent(Right);
      57           7 :   }
      58             : };
      59             : 
      60        6112 : template <typename T> class RepeatAdapter final : public FormatAdapter<T> {
      61             :   size_t Count;
      62             : 
      63             : public:
      64             :   RepeatAdapter(T &&Item, size_t Count)
      65         872 :       : FormatAdapter<T>(std::forward<T>(Item)), Count(Count) {}
      66             : 
      67         435 :   void format(llvm::raw_ostream &Stream, StringRef Style) {
      68        1308 :     auto Adapter = detail::build_format_adapter(std::forward<T>(this->Item));
      69       13038 :     for (size_t I = 0; I < Count; ++I) {
      70       12602 :       Adapter.format(Stream, Style);
      71             :     }
      72         435 :   }
      73             : };
      74             : }
      75             : 
      76             : template <typename T>
      77             : detail::AlignAdapter<T> fmt_align(T &&Item, AlignStyle Where, size_t Amount,
      78             :                                   char Fill = ' ') {
      79        2774 :   return detail::AlignAdapter<T>(std::forward<T>(Item), Where, Amount, Fill);
      80             : }
      81             : 
      82             : template <typename T>
      83             : detail::PadAdapter<T> fmt_pad(T &&Item, size_t Left, size_t Right) {
      84           6 :   return detail::PadAdapter<T>(std::forward<T>(Item), Left, Right);
      85             : }
      86             : 
      87             : template <typename T>
      88             : detail::RepeatAdapter<T> fmt_repeat(T &&Item, size_t Count) {
      89         872 :   return detail::RepeatAdapter<T>(std::forward<T>(Item), Count);
      90             : }
      91             : }
      92             : 
      93             : #endif

Generated by: LCOV version 1.13