]> granicus.if.org Git - clang/commitdiff
Add StringLiteral::getString -> StringRef.
authorDaniel Dunbar <daniel@zuster.org>
Tue, 22 Sep 2009 03:27:33 +0000 (03:27 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Tue, 22 Sep 2009 03:27:33 +0000 (03:27 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@82514 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/Expr.h
lib/AST/Expr.cpp
lib/Frontend/PCHReaderStmt.cpp

index 7b60c00d5ba5196bc24f2e11351edb6a08855c89..39a23a1570bcc1a33bad278a4e5b653d6b9dd2ea 100644 (file)
@@ -20,6 +20,7 @@
 #include "llvm/ADT/APSInt.h"
 #include "llvm/ADT/APFloat.h"
 #include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/StringRef.h"
 #include <vector>
 
 namespace clang {
@@ -583,18 +584,23 @@ public:
   /// \brief Construct an empty string literal.
   static StringLiteral *CreateEmpty(ASTContext &C, unsigned NumStrs);
 
+  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.
-  void setStrData(ASTContext &C, const char *Str, unsigned Len);
+  void setString(ASTContext &C, llvm::StringRef Str);
 
   bool isWide() const { return IsWide; }
   void setWide(bool W) { IsWide = W; }
 
   bool containsNonAsciiOrNull() const {
-    for (unsigned i = 0; i < getByteLength(); ++i)
-      if (!isascii(getStrData()[i]) || !getStrData()[i])
+    llvm::StringRef Str = getString();
+    for (unsigned i = 0, e = Str.size(); i != e; ++i)
+      if (!isascii(Str[i]) || !Str[i])
         return true;
     return false;
   }
index 6e46c4f701a479a9edb6c9a7c08cab5626827d21..9d2d46fa0c17e178c4592229a8f46acd090a024b 100644 (file)
@@ -159,14 +159,14 @@ void StringLiteral::DoDestroy(ASTContext &C) {
   Expr::DoDestroy(C);
 }
 
-void StringLiteral::setStrData(ASTContext &C, const char *Str, unsigned Len) {
+void StringLiteral::setString(ASTContext &C, llvm::StringRef Str) {
   if (StrData)
     C.Deallocate(const_cast<char*>(StrData));
 
-  char *AStrData = new (C, 1) char[Len];
-  memcpy(AStrData, Str, Len);
+  char *AStrData = new (C, 1) char[Str.size()];
+  memcpy(AStrData, Str.data(), Str.size());
   StrData = AStrData;
-  ByteLength = Len;
+  ByteLength = Str.size();
 }
 
 /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it
index 67b7c1f4408c1441fb8a3d032eb59d5ce7534313..4b9496e00f8bbea55c256b4815364b933cc57467 100644 (file)
@@ -380,8 +380,8 @@ unsigned PCHStmtReader::VisitStringLiteral(StringLiteral *E) {
   E->setWide(Record[Idx++]);
 
   // Read string data
-  llvm::SmallVector<char, 16> Str(&Record[Idx], &Record[Idx] + Len);
-  E->setStrData(*Reader.getContext(), Str.data(), Len);
+  llvm::SmallString<16> Str(&Record[Idx], &Record[Idx] + Len);
+  E->setString(*Reader.getContext(), Str.str());
   Idx += Len;
 
   // Read source locations