Coverage Report

Created: 2026-06-14 07:58

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/keystone/llvm/lib/Support/Twine.cpp
Line
Count
Source
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/raw_ostream.h"
14
using namespace llvm_ks;
15
16
2.42M
std::string Twine::str() const {
17
  // If we're storing only a std::string, just return it.
18
2.42M
  if (LHSKind == StdStringKind && RHSKind == EmptyKind)
19
785k
    return *LHS.stdString;
20
21
  // Otherwise, flatten and copy the contents first.
22
1.63M
  SmallString<256> Vec;
23
1.63M
  return toStringRef(Vec).str();
24
2.42M
}
25
26
345k
void Twine::toVector(SmallVectorImpl<char> &Out) const {
27
345k
  raw_svector_ostream OS(Out);
28
345k
  print(OS);
29
345k
}
30
31
314k
StringRef Twine::toNullTerminatedStringRef(SmallVectorImpl<char> &Out) const {
32
314k
  if (isUnary()) {
33
314k
    switch (getLHSKind()) {
34
314k
    case CStringKind:
35
      // Already null terminated, yay!
36
314k
      return StringRef(LHS.cString);
37
83
    case StdStringKind: {
38
83
      const std::string *str = LHS.stdString;
39
83
      return StringRef(str->c_str(), str->size());
40
0
    }
41
0
    default:
42
0
      break;
43
314k
    }
44
314k
  }
45
0
  toVector(Out);
46
0
  Out.push_back(0);
47
0
  Out.pop_back();
48
0
  return StringRef(Out.data(), Out.size());
49
314k
}
50
51
void Twine::printOneChild(raw_ostream &OS, Child Ptr,
52
5.71M
                          NodeKind Kind) const {
53
5.71M
  switch (Kind) {
54
0
  case Twine::NullKind: break;
55
2.46M
  case Twine::EmptyKind: break;
56
50.3k
  case Twine::TwineKind:
57
50.3k
    Ptr.twine->print(OS);
58
50.3k
    break;
59
2.70M
  case Twine::CStringKind:
60
2.70M
    OS << Ptr.cString;
61
2.70M
    break;
62
152k
  case Twine::StdStringKind:
63
152k
    OS << *Ptr.stdString;
64
152k
    break;
65
344k
  case Twine::StringRefKind:
66
344k
    OS << *Ptr.stringRef;
67
344k
    break;
68
0
  case Twine::SmallStringKind:
69
0
    OS << *Ptr.smallString;
70
0
    break;
71
0
  case Twine::CharKind:
72
0
    OS << Ptr.character;
73
0
    break;
74
0
  case Twine::DecUIKind:
75
0
    OS << Ptr.decUI;
76
0
    break;
77
378
  case Twine::DecIKind:
78
378
    OS << Ptr.decI;
79
378
    break;
80
0
  case Twine::DecULKind:
81
0
    OS << *Ptr.decUL;
82
0
    break;
83
676
  case Twine::DecLKind:
84
676
    OS << *Ptr.decL;
85
676
    break;
86
0
  case Twine::DecULLKind:
87
0
    OS << *Ptr.decULL;
88
0
    break;
89
0
  case Twine::DecLLKind:
90
0
    OS << *Ptr.decLL;
91
0
    break;
92
0
  case Twine::UHexKind:
93
0
    OS.write_hex(*Ptr.uHex);
94
0
    break;
95
5.71M
  }
96
5.71M
}
97
98
void Twine::printOneChildRepr(raw_ostream &OS, Child Ptr,
99
0
                              NodeKind Kind) const {
100
0
  switch (Kind) {
101
0
  case Twine::NullKind:
102
0
    OS << "null"; break;
103
0
  case Twine::EmptyKind:
104
0
    OS << "empty"; break;
105
0
  case Twine::TwineKind:
106
0
    OS << "rope:";
107
0
    Ptr.twine->printRepr(OS);
108
0
    break;
109
0
  case Twine::CStringKind:
110
0
    OS << "cstring:\""
111
0
       << Ptr.cString << "\"";
112
0
    break;
113
0
  case Twine::StdStringKind:
114
0
    OS << "std::string:\""
115
0
       << Ptr.stdString << "\"";
116
0
    break;
117
0
  case Twine::StringRefKind:
118
0
    OS << "stringref:\""
119
0
       << Ptr.stringRef << "\"";
120
0
    break;
121
0
  case Twine::SmallStringKind:
122
0
    OS << "smallstring:\"" << *Ptr.smallString << "\"";
123
0
    break;
124
0
  case Twine::CharKind:
125
0
    OS << "char:\"" << Ptr.character << "\"";
126
0
    break;
127
0
  case Twine::DecUIKind:
128
0
    OS << "decUI:\"" << Ptr.decUI << "\"";
129
0
    break;
130
0
  case Twine::DecIKind:
131
0
    OS << "decI:\"" << Ptr.decI << "\"";
132
0
    break;
133
0
  case Twine::DecULKind:
134
0
    OS << "decUL:\"" << *Ptr.decUL << "\"";
135
0
    break;
136
0
  case Twine::DecLKind:
137
0
    OS << "decL:\"" << *Ptr.decL << "\"";
138
0
    break;
139
0
  case Twine::DecULLKind:
140
0
    OS << "decULL:\"" << *Ptr.decULL << "\"";
141
0
    break;
142
0
  case Twine::DecLLKind:
143
0
    OS << "decLL:\"" << *Ptr.decLL << "\"";
144
0
    break;
145
0
  case Twine::UHexKind:
146
0
    OS << "uhex:\"" << Ptr.uHex << "\"";
147
0
    break;
148
0
  }
149
0
}
150
151
2.85M
void Twine::print(raw_ostream &OS) const {
152
2.85M
  printOneChild(OS, LHS, getLHSKind());
153
2.85M
  printOneChild(OS, RHS, getRHSKind());
154
2.85M
}
155
156
0
void Twine::printRepr(raw_ostream &OS) const {
157
0
  OS << "(Twine ";
158
0
  printOneChildRepr(OS, LHS, getLHSKind());
159
0
  OS << " ";
160
0
  printOneChildRepr(OS, RHS, getRHSKind());
161
0
  OS << ")";
162
0
}
163
164
0
LLVM_DUMP_METHOD void Twine::dump() const {
165
0
}
166
167
0
void Twine::dumpRepr() const {
168
0
}