Convert all uses of StringLiteral::getStrData() to StringLiteral::getString()

and remove getStrData().  Patch by Peter Davies (with some tweaks).

llvm-svn: 111229
This commit is contained in:
Benjamin Kramer 2010-08-17 12:54:38 +00:00
parent 349ded1907
commit 35b077e674
11 changed files with 30 additions and 38 deletions

View File

@ -931,8 +931,7 @@ public:
llvm::StringRef getString() const {
return llvm::StringRef(StrData, ByteLength);
}
// FIXME: These are deprecated, replace with StringRef.
const char *getStrData() const { return StrData; }
unsigned getByteLength() const { return ByteLength; }
/// \brief Sets the string data to the given string data.

View File

@ -215,8 +215,9 @@ int AsmStmt::getNamedOperand(llvm::StringRef SymbolicName) const {
/// true, otherwise return false.
unsigned AsmStmt::AnalyzeAsmString(llvm::SmallVectorImpl<AsmStringPiece>&Pieces,
ASTContext &C, unsigned &DiagOffs) const {
const char *StrStart = getAsmString()->getStrData();
const char *StrEnd = StrStart + getAsmString()->getByteLength();
llvm::StringRef Str = getAsmString()->getString();
const char *StrStart = Str.begin();
const char *StrEnd = Str.end();
const char *CurPtr = StrStart;
// "Simple" inline asms have no constraints or operands, just convert the asm

View File

@ -429,8 +429,7 @@ void StmtDumper::VisitStringLiteral(StringLiteral *Str) {
if (Str->isWide())
OS << "L";
OS << '"';
OS.write_escaped(llvm::StringRef(Str->getStrData(),
Str->getByteLength()));
OS.write_escaped(Str->getString());
OS << '"';
}

View File

@ -621,8 +621,10 @@ void StmtPrinter::VisitStringLiteral(StringLiteral *Str) {
OS << '"';
// FIXME: this doesn't print wstrings right.
for (unsigned i = 0, e = Str->getByteLength(); i != e; ++i) {
unsigned char Char = Str->getStrData()[i];
llvm::StringRef StrData = Str->getString();
for (llvm::StringRef::iterator I = StrData.begin(), E = StrData.end();
I != E; ++I) {
unsigned char Char = *I;
switch (Char) {
default:

View File

@ -1139,7 +1139,7 @@ SVal RegionStoreManager::RetrieveElement(Store store,
// However, such overflows should be caught before reaching this point;
// the only time such an access would be made is if a string literal was
// used to initialize a larger array.
char c = (i >= byteLength) ? '\0' : Str->getStrData()[i];
char c = (i >= byteLength) ? '\0' : Str->getString()[i];
return ValMgr.makeIntVal(c, T);
}
}

View File

@ -449,7 +449,7 @@ llvm::Constant *CGObjCGNU::MakeGlobal(const llvm::ArrayType *Ty,
/// Generate an NSConstantString object.
llvm::Constant *CGObjCGNU::GenerateConstantString(const StringLiteral *SL) {
std::string Str(SL->getStrData(), SL->getByteLength());
std::string Str = SL->getString().str();
// Look for an existing one
llvm::StringMap<llvm::Constant*>::iterator old = ObjCStrings.find(Str);

View File

@ -1480,18 +1480,18 @@ GetConstantCFStringEntry(llvm::StringMap<llvm::Constant*> &Map,
bool TargetIsLSB,
bool &IsUTF16,
unsigned &StringLength) {
unsigned NumBytes = Literal->getByteLength();
llvm::StringRef String = Literal->getString();
unsigned NumBytes = String.size();
// Check for simple case.
if (!Literal->containsNonAsciiOrNull()) {
StringLength = NumBytes;
return Map.GetOrCreateValue(llvm::StringRef(Literal->getStrData(),
StringLength));
return Map.GetOrCreateValue(String);
}
// Otherwise, convert the UTF8 literals into a byte string.
llvm::SmallVector<UTF16, 128> ToBuf(NumBytes);
const UTF8 *FromPtr = (UTF8 *)Literal->getStrData();
const UTF8 *FromPtr = (UTF8 *)String.data();
UTF16 *ToPtr = &ToBuf[0];
ConversionResult Result = ConvertUTF8toUTF16(&FromPtr, FromPtr + NumBytes,
@ -1504,8 +1504,7 @@ GetConstantCFStringEntry(llvm::StringMap<llvm::Constant*> &Map,
// this duplicate code.
assert(Result == sourceIllegal && "UTF-8 to UTF-16 conversion failed");
StringLength = NumBytes;
return Map.GetOrCreateValue(llvm::StringRef(Literal->getStrData(),
StringLength));
return Map.GetOrCreateValue(String);
}
// ConvertUTF8toUTF16 returns the length in ToPtr.
@ -1705,20 +1704,17 @@ CodeGenModule::GetAddrOfConstantNSString(const StringLiteral *Literal) {
/// GetStringForStringLiteral - Return the appropriate bytes for a
/// string literal, properly padded to match the literal type.
std::string CodeGenModule::GetStringForStringLiteral(const StringLiteral *E) {
const char *StrData = E->getStrData();
unsigned Len = E->getByteLength();
const ConstantArrayType *CAT =
getContext().getAsConstantArrayType(E->getType());
assert(CAT && "String isn't pointer or array!");
// Resize the string to the right size.
std::string Str(StrData, StrData+Len);
uint64_t RealLen = CAT->getSize().getZExtValue();
if (E->isWide())
RealLen *= getContext().Target.getWCharWidth()/8;
std::string Str = E->getString().str();
Str.resize(RealLen, '\0');
return Str;

View File

@ -417,8 +417,7 @@ void PCHStmtWriter::VisitStringLiteral(StringLiteral *E) {
// StringLiteral. However, we can't do so now because we have no
// provision for coping with abbreviations when we're jumping around
// the PCH file during deserialization.
Record.insert(Record.end(),
E->getStrData(), E->getStrData() + E->getByteLength());
Record.append(E->getString().begin(), E->getString().end());
for (unsigned I = 0, N = E->getNumConcatenated(); I != N; ++I)
Writer.AddSourceLocation(E->getStrTokenLoc(I), Record);
Code = pch::EXPR_STRING_LITERAL;

View File

@ -32,7 +32,8 @@ namespace {
void addSpecialAttribute(const char* pName, StringLiteral* Str) {
Doc.addAttribute(pName, Doc.escapeString(Str->getStrData(), Str->getByteLength()));
Doc.addAttribute(pName, Doc.escapeString(Str->getString().data(),
Str->getString().size()));
}
void addSpecialAttribute(const char* pName, SizeOfAlignOfExpr* S) {

View File

@ -589,16 +589,11 @@ bool Sema::CheckObjCString(Expr *Arg) {
return true;
}
const char *Data = Literal->getStrData();
unsigned Length = Literal->getByteLength();
for (unsigned i = 0; i < Length; ++i) {
if (!Data[i]) {
Diag(getLocationOfStringLiteralByte(Literal, i),
diag::warn_cfstring_literal_contains_nul_character)
<< Arg->getSourceRange();
break;
}
size_t NulPos = Literal->getString().find('\0');
if (NulPos != llvm::StringRef::npos) {
Diag(getLocationOfStringLiteralByte(Literal, NulPos),
diag::warn_cfstring_literal_contains_nul_character)
<< Arg->getSourceRange();
}
return false;
@ -1755,11 +1750,11 @@ void Sema::CheckFormatString(const StringLiteral *FExpr,
}
// Str - The format string. NOTE: this is NOT null-terminated!
const char *Str = FExpr->getStrData();
llvm::StringRef StrRef = FExpr->getString();
const char *Str = StrRef.data();
unsigned StrLen = StrRef.size();
// CHECK: empty format string?
unsigned StrLen = FExpr->getByteLength();
if (StrLen == 0) {
Diag(FExpr->getLocStart(), diag::warn_empty_format_string)
<< OrigFormatExpr->getSourceRange();

View File

@ -50,8 +50,8 @@ Sema::ExprResult Sema::ParseObjCStringLiteral(SourceLocation *AtLocs,
return true;
}
// Get the string data.
StrBuf.append(S->getStrData(), S->getStrData()+S->getByteLength());
// Append the string.
StrBuf += S->getString();
// Get the locations of the string tokens.
StrLocs.append(S->tokloc_begin(), S->tokloc_end());