diff options
author | Benjamin Kramer <benny.kra@googlemail.com> | 2010-08-17 12:54:38 +0000 |
---|---|---|
committer | Benjamin Kramer <benny.kra@googlemail.com> | 2010-08-17 12:54:38 +0000 |
commit | 2f4eaef37476ae6891ede8ba215d0f6fd093629b (patch) | |
tree | 0b7d6c8f65b72c84bddeb847b25137ace553928b | |
parent | 572fc62b52b5b113cbaf528bd3ec00fcde19a46e (diff) |
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
-rw-r--r-- | include/clang/AST/Expr.h | 3 | ||||
-rw-r--r-- | lib/AST/Stmt.cpp | 5 | ||||
-rw-r--r-- | lib/AST/StmtDumper.cpp | 3 | ||||
-rw-r--r-- | lib/AST/StmtPrinter.cpp | 6 | ||||
-rw-r--r-- | lib/Checker/RegionStore.cpp | 2 | ||||
-rw-r--r-- | lib/CodeGen/CGObjCGNU.cpp | 2 | ||||
-rw-r--r-- | lib/CodeGen/CodeGenModule.cpp | 16 | ||||
-rw-r--r-- | lib/Frontend/PCHWriterStmt.cpp | 3 | ||||
-rw-r--r-- | lib/Frontend/StmtXML.cpp | 3 | ||||
-rw-r--r-- | lib/Sema/SemaChecking.cpp | 21 | ||||
-rw-r--r-- | lib/Sema/SemaExprObjC.cpp | 4 |
11 files changed, 30 insertions, 38 deletions
diff --git a/include/clang/AST/Expr.h b/include/clang/AST/Expr.h index 9db92111e6..5fbd45e227 100644 --- a/include/clang/AST/Expr.h +++ b/include/clang/AST/Expr.h @@ -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. diff --git a/lib/AST/Stmt.cpp b/lib/AST/Stmt.cpp index 7c69a79364..dba6b08d78 100644 --- a/lib/AST/Stmt.cpp +++ b/lib/AST/Stmt.cpp @@ -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 diff --git a/lib/AST/StmtDumper.cpp b/lib/AST/StmtDumper.cpp index 4b7c8f0b40..3707b61848 100644 --- a/lib/AST/StmtDumper.cpp +++ b/lib/AST/StmtDumper.cpp @@ -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 << '"'; } diff --git a/lib/AST/StmtPrinter.cpp b/lib/AST/StmtPrinter.cpp index 7f497a3d60..62336ec7d5 100644 --- a/lib/AST/StmtPrinter.cpp +++ b/lib/AST/StmtPrinter.cpp @@ -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: diff --git a/lib/Checker/RegionStore.cpp b/lib/Checker/RegionStore.cpp index 7dd503c0f5..9b8579cdeb 100644 --- a/lib/Checker/RegionStore.cpp +++ b/lib/Checker/RegionStore.cpp @@ -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); } } diff --git a/lib/CodeGen/CGObjCGNU.cpp b/lib/CodeGen/CGObjCGNU.cpp index fdee1dee13..d7960beb1d 100644 --- a/lib/CodeGen/CGObjCGNU.cpp +++ b/lib/CodeGen/CGObjCGNU.cpp @@ -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); diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index 1715042691..ffe8f22791 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -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; diff --git a/lib/Frontend/PCHWriterStmt.cpp b/lib/Frontend/PCHWriterStmt.cpp index e464a4477a..0c149f2c20 100644 --- a/lib/Frontend/PCHWriterStmt.cpp +++ b/lib/Frontend/PCHWriterStmt.cpp @@ -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; diff --git a/lib/Frontend/StmtXML.cpp b/lib/Frontend/StmtXML.cpp index c810bca6c6..b6607349d7 100644 --- a/lib/Frontend/StmtXML.cpp +++ b/lib/Frontend/StmtXML.cpp @@ -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) { diff --git a/lib/Sema/SemaChecking.cpp b/lib/Sema/SemaChecking.cpp index 3245d0c987..9a484932b2 100644 --- a/lib/Sema/SemaChecking.cpp +++ b/lib/Sema/SemaChecking.cpp @@ -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(); diff --git a/lib/Sema/SemaExprObjC.cpp b/lib/Sema/SemaExprObjC.cpp index 9dcc3cd16f..336fbf2c77 100644 --- a/lib/Sema/SemaExprObjC.cpp +++ b/lib/Sema/SemaExprObjC.cpp @@ -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()); |