Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/lib/Support/Twine.cpp
Line
Count
Source (jump to first uncovered line)
1
//===-- Twine.cpp - Fast Temporary String Concatenation -------------------===//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
9
#include "llvm/ADT/Twine.h"
10
#include "llvm/ADT/SmallString.h"
11
#include "llvm/Config/llvm-config.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
15.3M
std::string Twine::str() const {
18
15.3M
  // If we're storing only a std::string, just return it.
19
15.3M
  if (LHSKind == StdStringKind && 
RHSKind == EmptyKind1.53M
)
20
1.48M
    return *LHS.stdString;
21
13.9M
22
13.9M
  // If we're storing a formatv_object, we can avoid an extra copy by formatting
23
13.9M
  // it immediately and returning the result.
24
13.9M
  if (LHSKind == FormatvObjectKind && 
RHSKind == EmptyKind2
)
25
2
    return LHS.formatvObject->str();
26
13.9M
27
13.9M
  // Otherwise, flatten and copy the contents first.
28
13.9M
  SmallString<256> Vec;
29
13.9M
  return toStringRef(Vec).str();
30
13.9M
}
31
32
18.8M
void Twine::toVector(SmallVectorImpl<char> &Out) const {
33
18.8M
  raw_svector_ostream OS(Out);
34
18.8M
  print(OS);
35
18.8M
}
36
37
3.01M
StringRef Twine::toNullTerminatedStringRef(SmallVectorImpl<char> &Out) const {
38
3.01M
  if (isUnary()) {
39
3.00M
    switch (getLHSKind()) {
40
3.00M
    case CStringKind:
41
562k
      // Already null terminated, yay!
42
562k
      return StringRef(LHS.cString);
43
3.00M
    case StdStringKind: {
44
113k
      const std::string *str = LHS.stdString;
45
113k
      return StringRef(str->c_str(), str->size());
46
3.00M
    }
47
3.00M
    default:
48
2.32M
      break;
49
2.33M
    }
50
2.33M
  }
51
2.33M
  toVector(Out);
52
2.33M
  Out.push_back(0);
53
2.33M
  Out.pop_back();
54
2.33M
  return StringRef(Out.data(), Out.size());
55
2.33M
}
56
57
void Twine::printOneChild(raw_ostream &OS, Child Ptr,
58
195M
                          NodeKind Kind) const {
59
195M
  switch (Kind) {
60
195M
  
case Twine::NullKind: break0
;
61
195M
  
case Twine::EmptyKind: break26.7M
;
62
195M
  case Twine::TwineKind:
63
40.3M
    Ptr.twine->print(OS);
64
40.3M
    break;
65
195M
  case Twine::CStringKind:
66
70.5M
    OS << Ptr.cString;
67
70.5M
    break;
68
195M
  case Twine::StdStringKind:
69
3.62M
    OS << *Ptr.stdString;
70
3.62M
    break;
71
195M
  case Twine::StringRefKind:
72
24.9M
    OS << *Ptr.stringRef;
73
24.9M
    break;
74
195M
  case Twine::SmallStringKind:
75
1.15M
    OS << *Ptr.smallString;
76
1.15M
    break;
77
195M
  case Twine::FormatvObjectKind:
78
25.3k
    OS << *Ptr.formatvObject;
79
25.3k
    break;
80
195M
  case Twine::CharKind:
81
9.68M
    OS << Ptr.character;
82
9.68M
    break;
83
195M
  case Twine::DecUIKind:
84
8.12M
    OS << Ptr.decUI;
85
8.12M
    break;
86
195M
  case Twine::DecIKind:
87
5.87M
    OS << Ptr.decI;
88
5.87M
    break;
89
195M
  case Twine::DecULKind:
90
5.17k
    OS << *Ptr.decUL;
91
5.17k
    break;
92
195M
  case Twine::DecLKind:
93
2.97k
    OS << *Ptr.decL;
94
2.97k
    break;
95
195M
  case Twine::DecULLKind:
96
4.11M
    OS << *Ptr.decULL;
97
4.11M
    break;
98
195M
  case Twine::DecLLKind:
99
6.98k
    OS << *Ptr.decLL;
100
6.98k
    break;
101
195M
  case Twine::UHexKind:
102
106k
    OS.write_hex(*Ptr.uHex);
103
106k
    break;
104
195M
  }
105
195M
}
106
107
void Twine::printOneChildRepr(raw_ostream &OS, Child Ptr,
108
30
                              NodeKind Kind) const {
109
30
  switch (Kind) {
110
30
  case Twine::NullKind:
111
2
    OS << "null"; break;
112
30
  case Twine::EmptyKind:
113
7
    OS << "empty"; break;
114
30
  case Twine::TwineKind:
115
3
    OS << "rope:";
116
3
    Ptr.twine->printRepr(OS);
117
3
    break;
118
30
  case Twine::CStringKind:
119
13
    OS << "cstring:\""
120
13
       << Ptr.cString << "\"";
121
13
    break;
122
30
  case Twine::StdStringKind:
123
0
    OS << "std::string:\""
124
0
       << Ptr.stdString << "\"";
125
0
    break;
126
30
  case Twine::StringRefKind:
127
0
    OS << "stringref:\""
128
0
       << Ptr.stringRef << "\"";
129
0
    break;
130
30
  case Twine::SmallStringKind:
131
3
    OS << "smallstring:\"" << *Ptr.smallString << "\"";
132
3
    break;
133
30
  case Twine::FormatvObjectKind:
134
2
    OS << "formatv:\"" << *Ptr.formatvObject << "\"";
135
2
    break;
136
30
  case Twine::CharKind:
137
0
    OS << "char:\"" << Ptr.character << "\"";
138
0
    break;
139
30
  case Twine::DecUIKind:
140
0
    OS << "decUI:\"" << Ptr.decUI << "\"";
141
0
    break;
142
30
  case Twine::DecIKind:
143
0
    OS << "decI:\"" << Ptr.decI << "\"";
144
0
    break;
145
30
  case Twine::DecULKind:
146
0
    OS << "decUL:\"" << *Ptr.decUL << "\"";
147
0
    break;
148
30
  case Twine::DecLKind:
149
0
    OS << "decL:\"" << *Ptr.decL << "\"";
150
0
    break;
151
30
  case Twine::DecULLKind:
152
0
    OS << "decULL:\"" << *Ptr.decULL << "\"";
153
0
    break;
154
30
  case Twine::DecLLKind:
155
0
    OS << "decLL:\"" << *Ptr.decLL << "\"";
156
0
    break;
157
30
  case Twine::UHexKind:
158
0
    OS << "uhex:\"" << Ptr.uHex << "\"";
159
0
    break;
160
30
  }
161
30
}
162
163
97.6M
void Twine::print(raw_ostream &OS) const {
164
97.6M
  printOneChild(OS, LHS, getLHSKind());
165
97.6M
  printOneChild(OS, RHS, getRHSKind());
166
97.6M
}
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