2009-07-24 09:04:27 +02:00
|
|
|
//===-- Twine.cpp - Fast Temporary String Concatenation -------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "llvm/ADT/Twine.h"
|
2009-08-19 20:09:47 +02:00
|
|
|
#include "llvm/ADT/SmallString.h"
|
2010-01-05 02:28:40 +01:00
|
|
|
#include "llvm/Support/Debug.h"
|
2009-07-24 09:04:27 +02:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
std::string Twine::str() const {
|
2009-08-19 20:09:47 +02:00
|
|
|
SmallString<256> Vec;
|
2010-01-13 13:45:23 +01:00
|
|
|
return toStringRef(Vec).str();
|
2009-07-24 09:04:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Twine::toVector(SmallVectorImpl<char> &Out) const {
|
|
|
|
raw_svector_ostream OS(Out);
|
|
|
|
print(OS);
|
|
|
|
}
|
|
|
|
|
2010-01-13 13:45:23 +01:00
|
|
|
StringRef Twine::toStringRef(SmallVectorImpl<char> &Out) const {
|
|
|
|
if (isSingleStringRef())
|
|
|
|
return getSingleStringRef();
|
|
|
|
toVector(Out);
|
|
|
|
return StringRef(Out.data(), Out.size());
|
|
|
|
}
|
|
|
|
|
2009-07-24 09:04:27 +02:00
|
|
|
void Twine::printOneChild(raw_ostream &OS, const void *Ptr,
|
|
|
|
NodeKind Kind) const {
|
|
|
|
switch (Kind) {
|
|
|
|
case Twine::NullKind: break;
|
|
|
|
case Twine::EmptyKind: break;
|
2009-07-29 09:08:44 +02:00
|
|
|
case Twine::TwineKind:
|
|
|
|
static_cast<const Twine*>(Ptr)->print(OS);
|
|
|
|
break;
|
2009-07-24 09:04:27 +02:00
|
|
|
case Twine::CStringKind:
|
|
|
|
OS << static_cast<const char*>(Ptr);
|
|
|
|
break;
|
|
|
|
case Twine::StdStringKind:
|
|
|
|
OS << *static_cast<const std::string*>(Ptr);
|
|
|
|
break;
|
|
|
|
case Twine::StringRefKind:
|
|
|
|
OS << *static_cast<const StringRef*>(Ptr);
|
|
|
|
break;
|
2009-07-30 23:15:14 +02:00
|
|
|
case Twine::DecUIKind:
|
|
|
|
OS << *static_cast<const unsigned int*>(Ptr);
|
2009-07-30 05:47:15 +02:00
|
|
|
break;
|
2009-07-30 23:15:14 +02:00
|
|
|
case Twine::DecIKind:
|
|
|
|
OS << *static_cast<const int*>(Ptr);
|
2009-07-30 05:47:15 +02:00
|
|
|
break;
|
2009-07-30 23:15:14 +02:00
|
|
|
case Twine::DecULKind:
|
|
|
|
OS << *static_cast<const unsigned long*>(Ptr);
|
2009-07-29 09:08:44 +02:00
|
|
|
break;
|
2009-07-30 23:15:14 +02:00
|
|
|
case Twine::DecLKind:
|
|
|
|
OS << *static_cast<const long*>(Ptr);
|
|
|
|
break;
|
|
|
|
case Twine::DecULLKind:
|
|
|
|
OS << *static_cast<const unsigned long long*>(Ptr);
|
|
|
|
break;
|
|
|
|
case Twine::DecLLKind:
|
|
|
|
OS << *static_cast<const long long*>(Ptr);
|
2009-07-29 09:08:44 +02:00
|
|
|
break;
|
|
|
|
case Twine::UHexKind:
|
2009-07-30 20:30:19 +02:00
|
|
|
OS.write_hex(*static_cast<const uint64_t*>(Ptr));
|
2009-07-24 09:04:27 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Twine::printOneChildRepr(raw_ostream &OS, const void *Ptr,
|
|
|
|
NodeKind Kind) const {
|
|
|
|
switch (Kind) {
|
|
|
|
case Twine::NullKind:
|
|
|
|
OS << "null"; break;
|
|
|
|
case Twine::EmptyKind:
|
|
|
|
OS << "empty"; break;
|
2009-07-29 09:08:44 +02:00
|
|
|
case Twine::TwineKind:
|
|
|
|
OS << "rope:";
|
|
|
|
static_cast<const Twine*>(Ptr)->printRepr(OS);
|
|
|
|
break;
|
2009-07-24 09:04:27 +02:00
|
|
|
case Twine::CStringKind:
|
2009-07-29 09:08:44 +02:00
|
|
|
OS << "cstring:\""
|
|
|
|
<< static_cast<const char*>(Ptr) << "\"";
|
2009-07-24 09:04:27 +02:00
|
|
|
break;
|
|
|
|
case Twine::StdStringKind:
|
2009-07-29 09:08:44 +02:00
|
|
|
OS << "std::string:\""
|
|
|
|
<< static_cast<const std::string*>(Ptr) << "\"";
|
2009-07-24 09:04:27 +02:00
|
|
|
break;
|
|
|
|
case Twine::StringRefKind:
|
2009-07-29 09:08:44 +02:00
|
|
|
OS << "stringref:\""
|
|
|
|
<< static_cast<const StringRef*>(Ptr) << "\"";
|
2009-07-24 09:04:27 +02:00
|
|
|
break;
|
2009-07-30 23:15:14 +02:00
|
|
|
case Twine::DecUIKind:
|
|
|
|
OS << "decUI:\"" << *static_cast<const unsigned int*>(Ptr) << "\"";
|
|
|
|
break;
|
|
|
|
case Twine::DecIKind:
|
|
|
|
OS << "decI:\"" << *static_cast<const int*>(Ptr) << "\"";
|
|
|
|
break;
|
|
|
|
case Twine::DecULKind:
|
|
|
|
OS << "decUL:\"" << *static_cast<const unsigned long*>(Ptr) << "\"";
|
2009-07-30 05:47:15 +02:00
|
|
|
break;
|
2009-07-30 23:15:14 +02:00
|
|
|
case Twine::DecLKind:
|
|
|
|
OS << "decL:\"" << *static_cast<const long*>(Ptr) << "\"";
|
2009-07-30 05:47:15 +02:00
|
|
|
break;
|
2009-07-30 23:15:14 +02:00
|
|
|
case Twine::DecULLKind:
|
|
|
|
OS << "decULL:\"" << *static_cast<const unsigned long long*>(Ptr) << "\"";
|
2009-07-29 09:08:44 +02:00
|
|
|
break;
|
2009-07-30 23:15:14 +02:00
|
|
|
case Twine::DecLLKind:
|
|
|
|
OS << "decLL:\"" << *static_cast<const long long*>(Ptr) << "\"";
|
2009-07-29 09:08:44 +02:00
|
|
|
break;
|
|
|
|
case Twine::UHexKind:
|
2009-07-30 23:15:14 +02:00
|
|
|
OS << "uhex:\"" << static_cast<const uint64_t*>(Ptr) << "\"";
|
2009-07-24 09:04:27 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Twine::print(raw_ostream &OS) const {
|
|
|
|
printOneChild(OS, LHS, getLHSKind());
|
|
|
|
printOneChild(OS, RHS, getRHSKind());
|
|
|
|
}
|
|
|
|
|
|
|
|
void Twine::printRepr(raw_ostream &OS) const {
|
|
|
|
OS << "(Twine ";
|
|
|
|
printOneChildRepr(OS, LHS, getLHSKind());
|
|
|
|
OS << " ";
|
|
|
|
printOneChildRepr(OS, RHS, getRHSKind());
|
|
|
|
OS << ")";
|
|
|
|
}
|
|
|
|
|
|
|
|
void Twine::dump() const {
|
2010-01-05 02:28:40 +01:00
|
|
|
print(llvm::dbgs());
|
2009-07-24 09:04:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Twine::dumpRepr() const {
|
2010-01-05 02:28:40 +01:00
|
|
|
printRepr(llvm::dbgs());
|
2009-07-24 09:04:27 +02:00
|
|
|
}
|