LCOV - code coverage report
Current view: top level - lib/Support - Twine.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 88 123 71.5 %
Date: 2018-06-17 00:07:59 Functions: 7 7 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===-- Twine.cpp - Fast Temporary String Concatenation -------------------===//
       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             : #include "llvm/ADT/Twine.h"
      11             : #include "llvm/ADT/SmallString.h"
      12             : #include "llvm/Config/llvm-config.h"
      13             : #include "llvm/Support/Debug.h"
      14             : #include "llvm/Support/FormatVariadic.h"
      15             : #include "llvm/Support/raw_ostream.h"
      16             : using namespace llvm;
      17             : 
      18     7726416 : std::string Twine::str() const {
      19             :   // If we're storing only a std::string, just return it.
      20     7726416 :   if (LHSKind == StdStringKind && RHSKind == EmptyKind)
      21     1199147 :     return *LHS.stdString;
      22             : 
      23             :   // If we're storing a formatv_object, we can avoid an extra copy by formatting
      24             :   // it immediately and returning the result.
      25     6527269 :   if (LHSKind == FormatvObjectKind && RHSKind == EmptyKind)
      26         184 :     return LHS.formatvObject->str();
      27             : 
      28             :   // Otherwise, flatten and copy the contents first.
      29             :   SmallString<256> Vec;
      30    13054141 :   return toStringRef(Vec).str();
      31             : }
      32             : 
      33    10997363 : void Twine::toVector(SmallVectorImpl<char> &Out) const {
      34             :   raw_svector_ostream OS(Out);
      35    10997488 :   print(OS);
      36    10997464 : }
      37             : 
      38     4233186 : StringRef Twine::toNullTerminatedStringRef(SmallVectorImpl<char> &Out) const {
      39             :   if (isUnary()) {
      40     3858859 :     switch (getLHSKind()) {
      41      482329 :     case CStringKind:
      42             :       // Already null terminated, yay!
      43      964658 :       return StringRef(LHS.cString);
      44     1726314 :     case StdStringKind: {
      45     1726314 :       const std::string *str = LHS.stdString;
      46     3452628 :       return StringRef(str->c_str(), str->size());
      47             :     }
      48             :     default:
      49             :       break;
      50             :     }
      51             :   }
      52     2024543 :   toVector(Out);
      53     2024546 :   Out.push_back(0);
      54             :   Out.pop_back();
      55     2024546 :   return StringRef(Out.data(), Out.size());
      56             : }
      57             : 
      58   122458161 : void Twine::printOneChild(raw_ostream &OS, Child Ptr,
      59             :                           NodeKind Kind) const {
      60   122458161 :   switch (Kind) {
      61             :   case Twine::NullKind: break;
      62             :   case Twine::EmptyKind: break;
      63    21173653 :   case Twine::TwineKind:
      64    21173653 :     Ptr.twine->print(OS);
      65    21173602 :     break;
      66    40516712 :   case Twine::CStringKind:
      67    40516712 :     OS << Ptr.cString;
      68    40516781 :     break;
      69     6141590 :   case Twine::StdStringKind:
      70     6141590 :     OS << *Ptr.stdString;
      71             :     break;
      72    20491971 :   case Twine::StringRefKind:
      73    20491971 :     OS << *Ptr.stringRef;
      74    20492000 :     break;
      75      179081 :   case Twine::SmallStringKind:
      76      179081 :     OS << *Ptr.smallString;
      77             :     break;
      78       36550 :   case Twine::FormatvObjectKind:
      79       36550 :     OS << *Ptr.formatvObject;
      80       36550 :     break;
      81     8040061 :   case Twine::CharKind:
      82     8040061 :     OS << Ptr.character;
      83             :     break;
      84     4251382 :   case Twine::DecUIKind:
      85     4251382 :     OS << Ptr.decUI;
      86             :     break;
      87     3033039 :   case Twine::DecIKind:
      88     3033039 :     OS << Ptr.decI;
      89             :     break;
      90      428130 :   case Twine::DecULKind:
      91      428130 :     OS << *Ptr.decUL;
      92      428130 :     break;
      93        7839 :   case Twine::DecLKind:
      94        7839 :     OS << *Ptr.decL;
      95        7839 :     break;
      96           5 :   case Twine::DecULLKind:
      97           5 :     OS << *Ptr.decULL;
      98           5 :     break;
      99           0 :   case Twine::DecLLKind:
     100           0 :     OS << *Ptr.decLL;
     101           0 :     break;
     102       62983 :   case Twine::UHexKind:
     103       62983 :     OS.write_hex(*Ptr.uHex);
     104       62983 :     break;
     105             :   }
     106   122458287 : }
     107             : 
     108          30 : void Twine::printOneChildRepr(raw_ostream &OS, Child Ptr,
     109             :                               NodeKind Kind) const {
     110          30 :   switch (Kind) {
     111           2 :   case Twine::NullKind:
     112           2 :     OS << "null"; break;
     113           7 :   case Twine::EmptyKind:
     114           7 :     OS << "empty"; break;
     115           3 :   case Twine::TwineKind:
     116           3 :     OS << "rope:";
     117           3 :     Ptr.twine->printRepr(OS);
     118           3 :     break;
     119          13 :   case Twine::CStringKind:
     120          13 :     OS << "cstring:\""
     121          13 :        << Ptr.cString << "\"";
     122          13 :     break;
     123           0 :   case Twine::StdStringKind:
     124           0 :     OS << "std::string:\""
     125           0 :        << Ptr.stdString << "\"";
     126           0 :     break;
     127           0 :   case Twine::StringRefKind:
     128           0 :     OS << "stringref:\""
     129           0 :        << Ptr.stringRef << "\"";
     130           0 :     break;
     131           3 :   case Twine::SmallStringKind:
     132           6 :     OS << "smallstring:\"" << *Ptr.smallString << "\"";
     133           3 :     break;
     134           2 :   case Twine::FormatvObjectKind:
     135           2 :     OS << "formatv:\"" << *Ptr.formatvObject << "\"";
     136           2 :     break;
     137           0 :   case Twine::CharKind:
     138           0 :     OS << "char:\"" << Ptr.character << "\"";
     139           0 :     break;
     140           0 :   case Twine::DecUIKind:
     141           0 :     OS << "decUI:\"" << Ptr.decUI << "\"";
     142           0 :     break;
     143           0 :   case Twine::DecIKind:
     144           0 :     OS << "decI:\"" << Ptr.decI << "\"";
     145           0 :     break;
     146           0 :   case Twine::DecULKind:
     147           0 :     OS << "decUL:\"" << *Ptr.decUL << "\"";
     148           0 :     break;
     149           0 :   case Twine::DecLKind:
     150           0 :     OS << "decL:\"" << *Ptr.decL << "\"";
     151           0 :     break;
     152           0 :   case Twine::DecULLKind:
     153           0 :     OS << "decULL:\"" << *Ptr.decULL << "\"";
     154           0 :     break;
     155           0 :   case Twine::DecLLKind:
     156           0 :     OS << "decLL:\"" << *Ptr.decLL << "\"";
     157           0 :     break;
     158           0 :   case Twine::UHexKind:
     159           0 :     OS << "uhex:\"" << Ptr.uHex << "\"";
     160           0 :     break;
     161             :   }
     162          30 : }
     163             : 
     164    61230671 : void Twine::print(raw_ostream &OS) const {
     165    61230671 :   printOneChild(OS, LHS, getLHSKind());
     166    61230751 :   printOneChild(OS, RHS, getRHSKind());
     167    61230585 : }
     168             : 
     169          15 : void Twine::printRepr(raw_ostream &OS) const {
     170          15 :   OS << "(Twine ";
     171          15 :   printOneChildRepr(OS, LHS, getLHSKind());
     172          15 :   OS << " ";
     173          15 :   printOneChildRepr(OS, RHS, getRHSKind());
     174          15 :   OS << ")";
     175          15 : }
     176             : 
     177             : #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
     178             : LLVM_DUMP_METHOD void Twine::dump() const {
     179             :   print(dbgs());
     180             : }
     181             : 
     182             : LLVM_DUMP_METHOD void Twine::dumpRepr() const {
     183             :   printRepr(dbgs());
     184             : }
     185             : #endif

Generated by: LCOV version 1.13