Convert all uses of StringLiteral::getStrData() to StringLiteral::getString()
and remove getStrData(). Patch by Peter Davies (with some tweaks).
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@111229 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/AST/Stmt.cpp b/lib/AST/Stmt.cpp
index 7c69a79..dba6b08 100644
--- a/lib/AST/Stmt.cpp
+++ b/lib/AST/Stmt.cpp
@@ -215,8 +215,9 @@
/// 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
diff --git a/lib/AST/StmtDumper.cpp b/lib/AST/StmtDumper.cpp
index 4b7c8f0..3707b61 100644
--- a/lib/AST/StmtDumper.cpp
+++ b/lib/AST/StmtDumper.cpp
@@ -429,8 +429,7 @@
if (Str->isWide())
OS << "L";
OS << '"';
- OS.write_escaped(llvm::StringRef(Str->getStrData(),
- Str->getByteLength()));
+ OS.write_escaped(Str->getString());
OS << '"';
}
diff --git a/lib/AST/StmtPrinter.cpp b/lib/AST/StmtPrinter.cpp
index 7f497a3..62336ec 100644
--- a/lib/AST/StmtPrinter.cpp
+++ b/lib/AST/StmtPrinter.cpp
@@ -621,8 +621,10 @@
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:
diff --git a/lib/Checker/RegionStore.cpp b/lib/Checker/RegionStore.cpp
index 7dd503c..9b8579c 100644
--- a/lib/Checker/RegionStore.cpp
+++ b/lib/Checker/RegionStore.cpp
@@ -1139,7 +1139,7 @@
// 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);
}
}
diff --git a/lib/CodeGen/CGObjCGNU.cpp b/lib/CodeGen/CGObjCGNU.cpp
index fdee1de..d7960be 100644
--- a/lib/CodeGen/CGObjCGNU.cpp
+++ b/lib/CodeGen/CGObjCGNU.cpp
@@ -449,7 +449,7 @@
/// 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);
diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp
index 1715042..ffe8f22 100644
--- a/lib/CodeGen/CodeGenModule.cpp
+++ b/lib/CodeGen/CodeGenModule.cpp
@@ -1480,18 +1480,18 @@
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 @@
// 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 @@
/// 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;
diff --git a/lib/Frontend/PCHWriterStmt.cpp b/lib/Frontend/PCHWriterStmt.cpp
index e464a44..0c149f2 100644
--- a/lib/Frontend/PCHWriterStmt.cpp
+++ b/lib/Frontend/PCHWriterStmt.cpp
@@ -417,8 +417,7 @@
// 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;
diff --git a/lib/Frontend/StmtXML.cpp b/lib/Frontend/StmtXML.cpp
index c810bca..b660734 100644
--- a/lib/Frontend/StmtXML.cpp
+++ b/lib/Frontend/StmtXML.cpp
@@ -32,7 +32,8 @@
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) {
diff --git a/lib/Sema/SemaChecking.cpp b/lib/Sema/SemaChecking.cpp
index 3245d0c..9a48493 100644
--- a/lib/Sema/SemaChecking.cpp
+++ b/lib/Sema/SemaChecking.cpp
@@ -589,16 +589,11 @@
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 @@
}
// 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();
diff --git a/lib/Sema/SemaExprObjC.cpp b/lib/Sema/SemaExprObjC.cpp
index 9dcc3cd..336fbf2 100644
--- a/lib/Sema/SemaExprObjC.cpp
+++ b/lib/Sema/SemaExprObjC.cpp
@@ -50,8 +50,8 @@
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());