LCOV - code coverage report
Current view: top level - lib/Support - Twine.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 89 127 70.1 %
Date: 2017-09-14 15:23:50 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/Support/Debug.h"
      13             : #include "llvm/Support/FormatVariadic.h"
      14             : #include "llvm/Support/raw_ostream.h"
      15             : using namespace llvm;
      16             : 
      17     4830998 : std::string Twine::str() const {
      18             :   // If we're storing only a std::string, just return it.
      19     4830998 :   if (LHSKind == StdStringKind && RHSKind == EmptyKind)
      20      491158 :     return *LHS.stdString;
      21             : 
      22             :   // If we're storing a formatv_object, we can avoid an extra copy by formatting
      23             :   // it immediately and returning the result.
      24     4339840 :   if (LHSKind == FormatvObjectKind && RHSKind == EmptyKind)
      25           2 :     return LHS.formatvObject->str();
      26             : 
      27             :   // Otherwise, flatten and copy the contents first.
      28     4339838 :   SmallString<256> Vec;
      29     8679676 :   return toStringRef(Vec).str();
      30             : }
      31             : 
      32     5487749 : void Twine::toVector(SmallVectorImpl<char> &Out) const {
      33    10975496 :   raw_svector_ostream OS(Out);
      34     5487747 :   print(OS);
      35     5487749 : }
      36             : 
      37     1373441 : StringRef Twine::toNullTerminatedStringRef(SmallVectorImpl<char> &Out) const {
      38     1247451 :   if (isUnary()) {
      39     1247451 :     switch (getLHSKind()) {
      40      208341 :     case CStringKind:
      41             :       // Already null terminated, yay!
      42      416682 :       return StringRef(LHS.cString);
      43      600681 :     case StdStringKind: {
      44      600681 :       const std::string *str = LHS.stdString;
      45     1201362 :       return StringRef(str->c_str(), str->size());
      46             :     }
      47             :     default:
      48             :       break;
      49             :     }
      50             :   }
      51      564419 :   toVector(Out);
      52      564417 :   Out.push_back(0);
      53     1128834 :   Out.pop_back();
      54     1693251 :   return StringRef(Out.data(), Out.size());
      55             : }
      56             : 
      57    75386230 : void Twine::printOneChild(raw_ostream &OS, Child Ptr,
      58             :                           NodeKind Kind) const {
      59    75386230 :   switch (Kind) {
      60             :   case Twine::NullKind: break;
      61             :   case Twine::EmptyKind: break;
      62    13648663 :   case Twine::TwineKind:
      63    13648663 :     Ptr.twine->print(OS);
      64    13648664 :     break;
      65    26783109 :   case Twine::CStringKind:
      66    26783109 :     OS << Ptr.cString;
      67    26783109 :     break;
      68     3092094 :   case Twine::StdStringKind:
      69     3092094 :     OS << *Ptr.stdString;
      70             :     break;
      71    11000919 :   case Twine::StringRefKind:
      72    11000919 :     OS << *Ptr.stringRef;
      73    11000918 :     break;
      74      102318 :   case Twine::SmallStringKind:
      75      102318 :     OS << *Ptr.smallString;
      76             :     break;
      77        4483 :   case Twine::FormatvObjectKind:
      78        4483 :     OS << *Ptr.formatvObject;
      79        4483 :     break;
      80     4853934 :   case Twine::CharKind:
      81     4853934 :     OS << Ptr.character;
      82             :     break;
      83     2914494 :   case Twine::DecUIKind:
      84     2914494 :     OS << Ptr.decUI;
      85             :     break;
      86     2008513 :   case Twine::DecIKind:
      87     2008513 :     OS << Ptr.decI;
      88             :     break;
      89      370760 :   case Twine::DecULKind:
      90      370760 :     OS << *Ptr.decUL;
      91      370760 :     break;
      92        3393 :   case Twine::DecLKind:
      93        3393 :     OS << *Ptr.decL;
      94        3393 :     break;
      95           0 :   case Twine::DecULLKind:
      96           0 :     OS << *Ptr.decULL;
      97           0 :     break;
      98           0 :   case Twine::DecLLKind:
      99           0 :     OS << *Ptr.decLL;
     100           0 :     break;
     101        4274 :   case Twine::UHexKind:
     102        4274 :     OS.write_hex(*Ptr.uHex);
     103        4274 :     break;
     104             :   }
     105    75386230 : }
     106             : 
     107          30 : void Twine::printOneChildRepr(raw_ostream &OS, Child Ptr,
     108             :                               NodeKind Kind) const {
     109          30 :   switch (Kind) {
     110           2 :   case Twine::NullKind:
     111           2 :     OS << "null"; break;
     112           7 :   case Twine::EmptyKind:
     113           7 :     OS << "empty"; break;
     114           3 :   case Twine::TwineKind:
     115           3 :     OS << "rope:";
     116           3 :     Ptr.twine->printRepr(OS);
     117           3 :     break;
     118          13 :   case Twine::CStringKind:
     119          13 :     OS << "cstring:\""
     120          13 :        << Ptr.cString << "\"";
     121          13 :     break;
     122           0 :   case Twine::StdStringKind:
     123           0 :     OS << "std::string:\""
     124           0 :        << Ptr.stdString << "\"";
     125           0 :     break;
     126           0 :   case Twine::StringRefKind:
     127           0 :     OS << "stringref:\""
     128           0 :        << Ptr.stringRef << "\"";
     129           0 :     break;
     130           3 :   case Twine::SmallStringKind:
     131           6 :     OS << "smallstring:\"" << *Ptr.smallString << "\"";
     132           3 :     break;
     133           2 :   case Twine::FormatvObjectKind:
     134           2 :     OS << "formatv:\"" << *Ptr.formatvObject << "\"";
     135           2 :     break;
     136           0 :   case Twine::CharKind:
     137           0 :     OS << "char:\"" << Ptr.character << "\"";
     138           0 :     break;
     139           0 :   case Twine::DecUIKind:
     140           0 :     OS << "decUI:\"" << Ptr.decUI << "\"";
     141           0 :     break;
     142           0 :   case Twine::DecIKind:
     143           0 :     OS << "decI:\"" << Ptr.decI << "\"";
     144           0 :     break;
     145           0 :   case Twine::DecULKind:
     146           0 :     OS << "decUL:\"" << *Ptr.decUL << "\"";
     147           0 :     break;
     148           0 :   case Twine::DecLKind:
     149           0 :     OS << "decL:\"" << *Ptr.decL << "\"";
     150           0 :     break;
     151           0 :   case Twine::DecULLKind:
     152           0 :     OS << "decULL:\"" << *Ptr.decULL << "\"";
     153           0 :     break;
     154           0 :   case Twine::DecLLKind:
     155           0 :     OS << "decLL:\"" << *Ptr.decLL << "\"";
     156           0 :     break;
     157           0 :   case Twine::UHexKind:
     158           0 :     OS << "uhex:\"" << Ptr.uHex << "\"";
     159           0 :     break;
     160             :   }
     161          30 : }
     162             : 
     163    37693113 : void Twine::print(raw_ostream &OS) const {
     164    37693113 :   printOneChild(OS, LHS, getLHSKind());
     165    37693116 :   printOneChild(OS, RHS, getRHSKind());
     166    37693116 : }
     167             : 
     168          15 : void Twine::printRepr(raw_ostream &OS) const {
     169          15 :   OS << "(Twine ";
     170          15 :   printOneChildRepr(OS, LHS, getLHSKind());
     171          15 :   OS << " ";
     172          15 :   printOneChildRepr(OS, RHS, getRHSKind());
     173          15 :   OS << ")";
     174          15 : }
     175             : 
     176             : #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
     177             : LLVM_DUMP_METHOD void Twine::dump() const {
     178             :   print(dbgs());
     179             : }
     180             : 
     181             : LLVM_DUMP_METHOD void Twine::dumpRepr() const {
     182             :   printRepr(dbgs());
     183             : }
     184             : #endif

Generated by: LCOV version 1.13