projects
/
oota-llvm.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Pass a std::uinque_ptr to ParseAssembly to make the ownership explicit. NFC.
[oota-llvm.git]
/
lib
/
Support
/
Twine.cpp
diff --git
a/lib/Support/Twine.cpp
b/lib/Support/Twine.cpp
index 75cea2961a9dc68d8faccbbd4a6e99681c69283f..56ed964a50eb5afe14b4108d3826ca7b73590671 100644
(file)
--- a/
lib/Support/Twine.cpp
+++ b/
lib/Support/Twine.cpp
@@
-14,6
+14,11
@@
using namespace llvm;
std::string Twine::str() const {
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();
}
SmallString<256> Vec;
return toStringRef(Vec).str();
}
@@
-35,11
+40,11
@@
StringRef Twine::toNullTerminatedStringRef(SmallVectorImpl<char> &Out) const {
switch (getLHSKind()) {
case CStringKind:
// Already null terminated, yay!
switch (getLHSKind()) {
case CStringKind:
// Already null terminated, yay!
- return StringRef(
static_cast<const char*>(LHS)
);
+ return StringRef(
LHS.cString
);
case StdStringKind: {
case StdStringKind: {
-
const std::string *str = static_cast<const std::string*>(LHS)
;
-
return StringRef(str->c_str(), str->size());
-
}
+
const std::string *str = LHS.stdString
;
+ return StringRef(str->c_str(), str->size());
+ }
default:
break;
}
default:
break;
}
@@
-50,48
+55,51
@@
StringRef Twine::toNullTerminatedStringRef(SmallVectorImpl<char> &Out) const {
return StringRef(Out.data(), Out.size());
}
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:
NodeKind Kind) const {
switch (Kind) {
case Twine::NullKind: break;
case Twine::EmptyKind: break;
case Twine::TwineKind:
-
static_cast<const Twine*>(Ptr)
->print(OS);
+
Ptr.twine
->print(OS);
break;
case Twine::CStringKind:
break;
case Twine::CStringKind:
- OS <<
static_cast<const char*>(Ptr)
;
+ OS <<
Ptr.cString
;
break;
case Twine::StdStringKind:
break;
case Twine::StdStringKind:
- OS << *
static_cast<const std::string*>(Ptr)
;
+ OS << *
Ptr.stdString
;
break;
case Twine::StringRefKind:
break;
case Twine::StringRefKind:
- OS << *static_cast<const StringRef*>(Ptr);
+ OS << *Ptr.stringRef;
+ break;
+ case Twine::CharKind:
+ OS << Ptr.character;
break;
case Twine::DecUIKind:
break;
case Twine::DecUIKind:
- OS <<
(unsigned)(uintptr_t)Ptr
;
+ OS <<
Ptr.decUI
;
break;
case Twine::DecIKind:
break;
case Twine::DecIKind:
- OS <<
(int)(intptr_t)Ptr
;
+ OS <<
Ptr.decI
;
break;
case Twine::DecULKind:
break;
case Twine::DecULKind:
- OS << *
static_cast<const unsigned long*>(Ptr)
;
+ OS << *
Ptr.decUL
;
break;
case Twine::DecLKind:
break;
case Twine::DecLKind:
- OS << *
static_cast<const long*>(Ptr)
;
+ OS << *
Ptr.decL
;
break;
case Twine::DecULLKind:
break;
case Twine::DecULLKind:
- OS << *
static_cast<const unsigned long long*>(Ptr)
;
+ OS << *
Ptr.decULL
;
break;
case Twine::DecLLKind:
break;
case Twine::DecLLKind:
- OS << *
static_cast<const long long*>(Ptr)
;
+ OS << *
Ptr.decLL
;
break;
case Twine::UHexKind:
break;
case Twine::UHexKind:
- OS.write_hex(*
static_cast<const uint64_t*>(Ptr)
);
+ OS.write_hex(*
Ptr.uHex
);
break;
}
}
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:
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:";
OS << "empty"; break;
case Twine::TwineKind:
OS << "rope:";
-
static_cast<const Twine*>(Ptr)
->printRepr(OS);
+
Ptr.twine
->printRepr(OS);
break;
case Twine::CStringKind:
OS << "cstring:\""
break;
case Twine::CStringKind:
OS << "cstring:\""
- <<
static_cast<const char*>(Ptr)
<< "\"";
+ <<
Ptr.cString
<< "\"";
break;
case Twine::StdStringKind:
OS << "std::string:\""
break;
case Twine::StdStringKind:
OS << "std::string:\""
- <<
static_cast<const std::string*>(Ptr)
<< "\"";
+ <<
Ptr.stdString
<< "\"";
break;
case Twine::StringRefKind:
OS << "stringref:\""
break;
case Twine::StringRefKind:
OS << "stringref:\""
- << static_cast<const StringRef*>(Ptr) << "\"";
+ << Ptr.stringRef << "\"";
+ break;
+ case Twine::CharKind:
+ OS << "char:\"" << Ptr.character << "\"";
break;
case Twine::DecUIKind:
break;
case Twine::DecUIKind:
- OS << "decUI:\"" <<
(unsigned)(uintptr_t)Ptr
<< "\"";
+ OS << "decUI:\"" <<
Ptr.decUI
<< "\"";
break;
case Twine::DecIKind:
break;
case Twine::DecIKind:
- OS << "decI:\"" <<
(int)(intptr_t)Ptr
<< "\"";
+ OS << "decI:\"" <<
Ptr.decI
<< "\"";
break;
case Twine::DecULKind:
break;
case Twine::DecULKind:
- OS << "decUL:\"" << *
static_cast<const unsigned long*>(Ptr)
<< "\"";
+ OS << "decUL:\"" << *
Ptr.decUL
<< "\"";
break;
case Twine::DecLKind:
break;
case Twine::DecLKind:
- OS << "decL:\"" << *
static_cast<const long*>(Ptr)
<< "\"";
+ OS << "decL:\"" << *
Ptr.decL
<< "\"";
break;
case Twine::DecULLKind:
break;
case Twine::DecULLKind:
- OS << "decULL:\"" << *
static_cast<const unsigned long long*>(Ptr)
<< "\"";
+ OS << "decULL:\"" << *
Ptr.decULL
<< "\"";
break;
case Twine::DecLLKind:
break;
case Twine::DecLLKind:
- OS << "decLL:\"" << *
static_cast<const long long*>(Ptr)
<< "\"";
+ OS << "decLL:\"" << *
Ptr.decLL
<< "\"";
break;
case Twine::UHexKind:
break;
case Twine::UHexKind:
- OS << "uhex:\"" <<
static_cast<const uint64_t*>(Ptr)
<< "\"";
+ OS << "uhex:\"" <<
Ptr.uHex
<< "\"";
break;
}
}
break;
}
}
@@
-152,9
+163,9
@@
void Twine::printRepr(raw_ostream &OS) const {
}
void Twine::dump() const {
}
void Twine::dump() const {
- print(
llvm::
dbgs());
+ print(dbgs());
}
void Twine::dumpRepr() const {
}
void Twine::dumpRepr() const {
- printRepr(
llvm::
dbgs());
+ printRepr(dbgs());
}
}