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-07-13 00:08:38 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     7637773 : std::string Twine::str() const {
      19             :   // If we're storing only a std::string, just return it.
      20     7637773 :   if (LHSKind == StdStringKind && RHSKind == EmptyKind)
      21     1145299 :     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     6492474 :   if (LHSKind == FormatvObjectKind && RHSKind == EmptyKind)
      26         200 :     return LHS.formatvObject->str();
      27             : 
      28             :   // Otherwise, flatten and copy the contents first.
      29             :   SmallString<256> Vec;
      30    12984500 :   return toStringRef(Vec).str();
      31             : }
      32             : 
      33    10431742 : void Twine::toVector(SmallVectorImpl<char> &Out) const {
      34             :   raw_svector_ostream OS(Out);
      35    10431847 :   print(OS);
      36    10431990 : }
      37             : 
      38     3606422 : StringRef Twine::toNullTerminatedStringRef(SmallVectorImpl<char> &Out) const {
      39             :   if (isUnary()) {
      40     3277485 :     switch (getLHSKind()) {
      41      449411 :     case CStringKind:
      42             :       // Already null terminated, yay!
      43      898822 :       return StringRef(LHS.cString);
      44     1490405 :     case StdStringKind: {
      45     1490405 :       const std::string *str = LHS.stdString;
      46     2980810 :       return StringRef(str->c_str(), str->size());
      47             :     }
      48             :     default:
      49             :       break;
      50             :     }
      51             :   }
      52     1666606 :   toVector(Out);
      53     1666614 :   Out.push_back(0);
      54             :   Out.pop_back();
      55     1666614 :   return StringRef(Out.data(), Out.size());
      56             : }
      57             : 
      58   118534274 : void Twine::printOneChild(raw_ostream &OS, Child Ptr,
      59             :                           NodeKind Kind) const {
      60   118534274 :   switch (Kind) {
      61             :   case Twine::NullKind: break;
      62             :   case Twine::EmptyKind: break;
      63    20598507 :   case Twine::TwineKind:
      64    20598507 :     Ptr.twine->print(OS);
      65    20598482 :     break;
      66    39719943 :   case Twine::CStringKind:
      67    39719943 :     OS << Ptr.cString;
      68    39719966 :     break;
      69     5882935 :   case Twine::StdStringKind:
      70     5882935 :     OS << *Ptr.stdString;
      71             :     break;
      72    19410273 :   case Twine::StringRefKind:
      73    19410273 :     OS << *Ptr.stringRef;
      74    19410392 :     break;
      75      180700 :   case Twine::SmallStringKind:
      76      180700 :     OS << *Ptr.smallString;
      77             :     break;
      78       36676 :   case Twine::FormatvObjectKind:
      79       36676 :     OS << *Ptr.formatvObject;
      80       36676 :     break;
      81     7774498 :   case Twine::CharKind:
      82     7774498 :     OS << Ptr.character;
      83             :     break;
      84     4174138 :   case Twine::DecUIKind:
      85     4174138 :     OS << Ptr.decUI;
      86             :     break;
      87     2946025 :   case Twine::DecIKind:
      88     2946025 :     OS << Ptr.decI;
      89             :     break;
      90      427259 :   case Twine::DecULKind:
      91      427259 :     OS << *Ptr.decUL;
      92      427259 :     break;
      93        8104 :   case Twine::DecLKind:
      94        8104 :     OS << *Ptr.decL;
      95        8104 :     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       63185 :   case Twine::UHexKind:
     103       63185 :     OS.write_hex(*Ptr.uHex);
     104       63185 :     break;
     105             :   }
     106   118534508 : }
     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    59268839 : void Twine::print(raw_ostream &OS) const {
     165    59268839 :   printOneChild(OS, LHS, getLHSKind());
     166    59268950 :   printOneChild(OS, RHS, getRHSKind());
     167    59268964 : }
     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