1 //===-- Twine.cpp - Fast Temporary String Concatenation -------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
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"
16 std::string Twine::str() const {
19 return std::string(Vec.begin(), Vec.end());
22 void Twine::toVector(SmallVectorImpl<char> &Out) const {
23 raw_svector_ostream OS(Out);
27 void Twine::printOneChild(raw_ostream &OS, const void *Ptr,
28 NodeKind Kind) const {
30 case Twine::NullKind: break;
31 case Twine::EmptyKind: break;
32 case Twine::TwineKind:
33 static_cast<const Twine*>(Ptr)->print(OS);
35 case Twine::CStringKind:
36 OS << static_cast<const char*>(Ptr);
38 case Twine::StdStringKind:
39 OS << *static_cast<const std::string*>(Ptr);
41 case Twine::StringRefKind:
42 OS << *static_cast<const StringRef*>(Ptr);
44 case Twine::DecUIKind:
45 OS << *static_cast<const unsigned int*>(Ptr);
48 OS << *static_cast<const int*>(Ptr);
50 case Twine::DecULKind:
51 OS << *static_cast<const unsigned long*>(Ptr);
54 OS << *static_cast<const long*>(Ptr);
56 case Twine::DecULLKind:
57 OS << *static_cast<const unsigned long long*>(Ptr);
59 case Twine::DecLLKind:
60 OS << *static_cast<const long long*>(Ptr);
63 OS.write_hex(*static_cast<const uint64_t*>(Ptr));
68 void Twine::printOneChildRepr(raw_ostream &OS, const void *Ptr,
69 NodeKind Kind) const {
73 case Twine::EmptyKind:
75 case Twine::TwineKind:
77 static_cast<const Twine*>(Ptr)->printRepr(OS);
79 case Twine::CStringKind:
81 << static_cast<const char*>(Ptr) << "\"";
83 case Twine::StdStringKind:
84 OS << "std::string:\""
85 << static_cast<const std::string*>(Ptr) << "\"";
87 case Twine::StringRefKind:
89 << static_cast<const StringRef*>(Ptr) << "\"";
91 case Twine::DecUIKind:
92 OS << "decUI:\"" << *static_cast<const unsigned int*>(Ptr) << "\"";
95 OS << "decI:\"" << *static_cast<const int*>(Ptr) << "\"";
97 case Twine::DecULKind:
98 OS << "decUL:\"" << *static_cast<const unsigned long*>(Ptr) << "\"";
100 case Twine::DecLKind:
101 OS << "decL:\"" << *static_cast<const long*>(Ptr) << "\"";
103 case Twine::DecULLKind:
104 OS << "decULL:\"" << *static_cast<const unsigned long long*>(Ptr) << "\"";
106 case Twine::DecLLKind:
107 OS << "decLL:\"" << *static_cast<const long long*>(Ptr) << "\"";
109 case Twine::UHexKind:
110 OS << "uhex:\"" << static_cast<const uint64_t*>(Ptr) << "\"";
115 void Twine::print(raw_ostream &OS) const {
116 printOneChild(OS, LHS, getLHSKind());
117 printOneChild(OS, RHS, getRHSKind());
120 void Twine::printRepr(raw_ostream &OS) const {
122 printOneChildRepr(OS, LHS, getLHSKind());
124 printOneChildRepr(OS, RHS, getRHSKind());
128 void Twine::dump() const {
132 void Twine::dumpRepr() const {
133 printRepr(llvm::dbgs());