diff options
-rw-r--r-- | include/clang/AST/Expr.h | 12 | ||||
-rw-r--r-- | lib/AST/Expr.cpp | 8 | ||||
-rw-r--r-- | lib/Frontend/PCHReaderStmt.cpp | 4 |
3 files changed, 15 insertions, 9 deletions
diff --git a/include/clang/AST/Expr.h b/include/clang/AST/Expr.h index 7b60c00d5b..39a23a1570 100644 --- a/include/clang/AST/Expr.h +++ b/include/clang/AST/Expr.h @@ -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; } diff --git a/lib/AST/Expr.cpp b/lib/AST/Expr.cpp index 6e46c4f701..9d2d46fa0c 100644 --- a/lib/AST/Expr.cpp +++ b/lib/AST/Expr.cpp @@ -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 diff --git a/lib/Frontend/PCHReaderStmt.cpp b/lib/Frontend/PCHReaderStmt.cpp index 67b7c1f440..4b9496e00f 100644 --- a/lib/Frontend/PCHReaderStmt.cpp +++ b/lib/Frontend/PCHReaderStmt.cpp @@ -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 |