X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FSupport%2FTwine.cpp;h=56ed964a50eb5afe14b4108d3826ca7b73590671;hb=e80ca34c933d9b2b15450809ddc80dbb6a3862ba;hp=75cea2961a9dc68d8faccbbd4a6e99681c69283f;hpb=0dda5437f8044269a90acddad822866056a0c8b3;p=oota-llvm.git diff --git a/lib/Support/Twine.cpp b/lib/Support/Twine.cpp index 75cea2961a9..56ed964a50e 100644 --- a/lib/Support/Twine.cpp +++ b/lib/Support/Twine.cpp @@ -14,6 +14,11 @@ using namespace llvm; std::string Twine::str() const { + // If we're storing only a std::string, just return it. + if (LHSKind == StdStringKind && RHSKind == EmptyKind) + return *LHS.stdString; + + // Otherwise, flatten and copy the contents first. SmallString<256> Vec; return toStringRef(Vec).str(); } @@ -35,11 +40,11 @@ StringRef Twine::toNullTerminatedStringRef(SmallVectorImpl &Out) const { switch (getLHSKind()) { case CStringKind: // Already null terminated, yay! - return StringRef(static_cast(LHS)); + return StringRef(LHS.cString); case StdStringKind: { - const std::string *str = static_cast(LHS); - return StringRef(str->c_str(), str->size()); - } + const std::string *str = LHS.stdString; + return StringRef(str->c_str(), str->size()); + } default: break; } @@ -50,48 +55,51 @@ StringRef Twine::toNullTerminatedStringRef(SmallVectorImpl &Out) const { return StringRef(Out.data(), Out.size()); } -void Twine::printOneChild(raw_ostream &OS, const void *Ptr, +void Twine::printOneChild(raw_ostream &OS, Child Ptr, NodeKind Kind) const { switch (Kind) { case Twine::NullKind: break; case Twine::EmptyKind: break; case Twine::TwineKind: - static_cast(Ptr)->print(OS); + Ptr.twine->print(OS); break; case Twine::CStringKind: - OS << static_cast(Ptr); + OS << Ptr.cString; break; case Twine::StdStringKind: - OS << *static_cast(Ptr); + OS << *Ptr.stdString; break; case Twine::StringRefKind: - OS << *static_cast(Ptr); + OS << *Ptr.stringRef; + break; + case Twine::CharKind: + OS << Ptr.character; break; case Twine::DecUIKind: - OS << (unsigned)(uintptr_t)Ptr; + OS << Ptr.decUI; break; case Twine::DecIKind: - OS << (int)(intptr_t)Ptr; + OS << Ptr.decI; break; case Twine::DecULKind: - OS << *static_cast(Ptr); + OS << *Ptr.decUL; break; case Twine::DecLKind: - OS << *static_cast(Ptr); + OS << *Ptr.decL; break; case Twine::DecULLKind: - OS << *static_cast(Ptr); + OS << *Ptr.decULL; break; case Twine::DecLLKind: - OS << *static_cast(Ptr); + OS << *Ptr.decLL; break; case Twine::UHexKind: - OS.write_hex(*static_cast(Ptr)); + OS.write_hex(*Ptr.uHex); break; } } -void Twine::printOneChildRepr(raw_ostream &OS, const void *Ptr, +void Twine::printOneChildRepr(raw_ostream &OS, Child Ptr, NodeKind Kind) const { switch (Kind) { case Twine::NullKind: @@ -100,40 +108,43 @@ void Twine::printOneChildRepr(raw_ostream &OS, const void *Ptr, OS << "empty"; break; case Twine::TwineKind: OS << "rope:"; - static_cast(Ptr)->printRepr(OS); + Ptr.twine->printRepr(OS); break; case Twine::CStringKind: OS << "cstring:\"" - << static_cast(Ptr) << "\""; + << Ptr.cString << "\""; break; case Twine::StdStringKind: OS << "std::string:\"" - << static_cast(Ptr) << "\""; + << Ptr.stdString << "\""; break; case Twine::StringRefKind: OS << "stringref:\"" - << static_cast(Ptr) << "\""; + << Ptr.stringRef << "\""; + break; + case Twine::CharKind: + OS << "char:\"" << Ptr.character << "\""; break; case Twine::DecUIKind: - OS << "decUI:\"" << (unsigned)(uintptr_t)Ptr << "\""; + OS << "decUI:\"" << Ptr.decUI << "\""; break; case Twine::DecIKind: - OS << "decI:\"" << (int)(intptr_t)Ptr << "\""; + OS << "decI:\"" << Ptr.decI << "\""; break; case Twine::DecULKind: - OS << "decUL:\"" << *static_cast(Ptr) << "\""; + OS << "decUL:\"" << *Ptr.decUL << "\""; break; case Twine::DecLKind: - OS << "decL:\"" << *static_cast(Ptr) << "\""; + OS << "decL:\"" << *Ptr.decL << "\""; break; case Twine::DecULLKind: - OS << "decULL:\"" << *static_cast(Ptr) << "\""; + OS << "decULL:\"" << *Ptr.decULL << "\""; break; case Twine::DecLLKind: - OS << "decLL:\"" << *static_cast(Ptr) << "\""; + OS << "decLL:\"" << *Ptr.decLL << "\""; break; case Twine::UHexKind: - OS << "uhex:\"" << static_cast(Ptr) << "\""; + OS << "uhex:\"" << Ptr.uHex << "\""; break; } } @@ -152,9 +163,9 @@ void Twine::printRepr(raw_ostream &OS) const { } void Twine::dump() const { - print(llvm::dbgs()); + print(dbgs()); } void Twine::dumpRepr() const { - printRepr(llvm::dbgs()); + printRepr(dbgs()); }