[cfe-commits] Convert all uses of StringLiteral::getStrData() to StringLiteral::getString() and remove getStrData()

Peter Davies ultratwo at gmail.com
Tue Aug 17 05:06:17 PDT 2010


I have kept getByteLength() because it is used in places where the
contents of the string is unimportant.

Peter
-------------- next part --------------
Index: include/clang/AST/Expr.h
===================================================================
--- include/clang/AST/Expr.h	(revision 111227)
+++ include/clang/AST/Expr.h	(working copy)
@@ -931,8 +931,7 @@
   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.
Index: lib/Frontend/StmtXML.cpp
===================================================================
--- lib/Frontend/StmtXML.cpp	(revision 111227)
+++ lib/Frontend/StmtXML.cpp	(working copy)
@@ -32,7 +32,7 @@
 
 
   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) {
Index: lib/Frontend/PCHWriterStmt.cpp
===================================================================
--- lib/Frontend/PCHWriterStmt.cpp	(revision 111227)
+++ lib/Frontend/PCHWriterStmt.cpp	(working copy)
@@ -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;
Index: lib/Sema/SemaChecking.cpp
===================================================================
--- lib/Sema/SemaChecking.cpp	(revision 111227)
+++ lib/Sema/SemaChecking.cpp	(working copy)
@@ -589,8 +589,8 @@
     return true;
   }
 
-  const char *Data = Literal->getStrData();
-  unsigned Length = Literal->getByteLength();
+  llvm::StringRef Data = Literal->getString();
+  unsigned Length = Data.size();
 
   for (unsigned i = 0; i < Length; ++i) {
     if (!Data[i]) {
@@ -1755,11 +1755,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();
Index: lib/Sema/SemaExprObjC.cpp
===================================================================
--- lib/Sema/SemaExprObjC.cpp	(revision 111227)
+++ lib/Sema/SemaExprObjC.cpp	(working copy)
@@ -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());
Index: lib/AST/StmtDumper.cpp
===================================================================
--- lib/AST/StmtDumper.cpp	(revision 111227)
+++ lib/AST/StmtDumper.cpp	(working copy)
@@ -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 << '"';
 }
 
Index: lib/AST/Stmt.cpp
===================================================================
--- lib/AST/Stmt.cpp	(revision 111227)
+++ lib/AST/Stmt.cpp	(working copy)
@@ -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
Index: lib/AST/StmtPrinter.cpp
===================================================================
--- lib/AST/StmtPrinter.cpp	(revision 111227)
+++ lib/AST/StmtPrinter.cpp	(working copy)
@@ -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:
Index: lib/CodeGen/CGObjCGNU.cpp
===================================================================
--- lib/CodeGen/CGObjCGNU.cpp	(revision 111227)
+++ lib/CodeGen/CGObjCGNU.cpp	(working copy)
@@ -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);
Index: lib/CodeGen/CodeGenModule.cpp
===================================================================
--- lib/CodeGen/CodeGenModule.cpp	(revision 111227)
+++ lib/CodeGen/CodeGenModule.cpp	(working copy)
@@ -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,15 +1704,13 @@
 /// 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();
+  std::string Str = E->getString().str();
 
   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())
Index: lib/Checker/RegionStore.cpp
===================================================================
--- lib/Checker/RegionStore.cpp	(revision 111227)
+++ lib/Checker/RegionStore.cpp	(working copy)
@@ -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);
     }
   }


More information about the cfe-commits mailing list