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/raw_ostream.h"
15 std::string Twine::str() const {
18 return std::string(Vec.begin(), Vec.end());
21 void Twine::toVector(SmallVectorImpl<char> &Out) const {
22 raw_svector_ostream OS(Out);
26 void Twine::printOneChild(raw_ostream &OS, const void *Ptr,
27 NodeKind Kind) const {
29 case Twine::NullKind: break;
30 case Twine::EmptyKind: break;
31 case Twine::TwineKind:
32 static_cast<const Twine*>(Ptr)->print(OS);
34 case Twine::CStringKind:
35 OS << static_cast<const char*>(Ptr);
37 case Twine::StdStringKind:
38 OS << *static_cast<const std::string*>(Ptr);
40 case Twine::StringRefKind:
41 OS << *static_cast<const StringRef*>(Ptr);
43 case Twine::DecUIKind:
44 OS << *static_cast<const unsigned int*>(Ptr);
47 OS << *static_cast<const int*>(Ptr);
49 case Twine::DecULKind:
50 OS << *static_cast<const unsigned long*>(Ptr);
53 OS << *static_cast<const long*>(Ptr);
55 case Twine::DecULLKind:
56 OS << *static_cast<const unsigned long long*>(Ptr);
58 case Twine::DecLLKind:
59 OS << *static_cast<const long long*>(Ptr);
62 OS.write_hex(*static_cast<const uint64_t*>(Ptr));
67 void Twine::printOneChildRepr(raw_ostream &OS, const void *Ptr,
68 NodeKind Kind) const {
72 case Twine::EmptyKind:
74 case Twine::TwineKind:
76 static_cast<const Twine*>(Ptr)->printRepr(OS);
78 case Twine::CStringKind:
80 << static_cast<const char*>(Ptr) << "\"";
82 case Twine::StdStringKind:
83 OS << "std::string:\""
84 << static_cast<const std::string*>(Ptr) << "\"";
86 case Twine::StringRefKind:
88 << static_cast<const StringRef*>(Ptr) << "\"";
90 case Twine::DecUIKind:
91 OS << "decUI:\"" << *static_cast<const unsigned int*>(Ptr) << "\"";
94 OS << "decI:\"" << *static_cast<const int*>(Ptr) << "\"";
96 case Twine::DecULKind:
97 OS << "decUL:\"" << *static_cast<const unsigned long*>(Ptr) << "\"";
100 OS << "decL:\"" << *static_cast<const long*>(Ptr) << "\"";
102 case Twine::DecULLKind:
103 OS << "decULL:\"" << *static_cast<const unsigned long long*>(Ptr) << "\"";
105 case Twine::DecLLKind:
106 OS << "decLL:\"" << *static_cast<const long long*>(Ptr) << "\"";
108 case Twine::UHexKind:
109 OS << "uhex:\"" << static_cast<const uint64_t*>(Ptr) << "\"";
114 void Twine::print(raw_ostream &OS) const {
115 printOneChild(OS, LHS, getLHSKind());
116 printOneChild(OS, RHS, getRHSKind());
119 void Twine::printRepr(raw_ostream &OS) const {
121 printOneChildRepr(OS, LHS, getLHSKind());
123 printOneChildRepr(OS, RHS, getRHSKind());
127 void Twine::dump() const {
131 void Twine::dumpRepr() const {
132 printRepr(llvm::errs());