diff options
author | Daniel Dunbar <daniel@zuster.org> | 2009-07-24 07:04:27 +0000 |
---|---|---|
committer | Daniel Dunbar <daniel@zuster.org> | 2009-07-24 07:04:27 +0000 |
commit | afcf5b30cbc2f97e11de1978995e3992eff15c30 (patch) | |
tree | b3f41640c3752fac28cdc5ccc7a960690778b498 /llvm/lib/Support/Twine.cpp | |
parent | 963cc31583f7b80b0c8af6c0de16ee196e7de5d9 (diff) | |
download | bcm5719-llvm-afcf5b30cbc2f97e11de1978995e3992eff15c30.tar.gz bcm5719-llvm-afcf5b30cbc2f97e11de1978995e3992eff15c30.zip |
Add Twine ADT.
- Not currently used.
llvm-svn: 76956
Diffstat (limited to 'llvm/lib/Support/Twine.cpp')
-rw-r--r-- | llvm/lib/Support/Twine.cpp | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/llvm/lib/Support/Twine.cpp b/llvm/lib/Support/Twine.cpp new file mode 100644 index 00000000000..4c34d279e8f --- /dev/null +++ b/llvm/lib/Support/Twine.cpp @@ -0,0 +1,91 @@ +//===-- 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" +#include "llvm/Support/raw_ostream.h" +using namespace llvm; + +std::string Twine::str() const { + std::string Res; + raw_string_ostream OS(Res); + print(OS); + return Res; +} + +void Twine::toVector(SmallVectorImpl<char> &Out) const { + raw_svector_ostream OS(Out); + print(OS); +} + +void Twine::printOneChild(raw_ostream &OS, const void *Ptr, + NodeKind Kind) const { + switch (Kind) { + case Twine::NullKind: break; + case Twine::EmptyKind: break; + 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; + case Twine::TwineKind: + static_cast<const Twine*>(Ptr)->print(OS); + 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; + case Twine::CStringKind: + OS << "cstring:\"" + << static_cast<const char*>(Ptr) << "\""; + break; + case Twine::StdStringKind: + OS << "std::string:\"" + << *static_cast<const std::string*>(Ptr) << "\""; + break; + case Twine::StringRefKind: + OS << "stringref:\"" + << *static_cast<const StringRef*>(Ptr) << "\""; + break; + case Twine::TwineKind: + OS << "rope:"; + static_cast<const Twine*>(Ptr)->printRepr(OS); + 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 { + print(llvm::errs()); +} + +void Twine::dumpRepr() const { + printRepr(llvm::errs()); +} |