Add StringLiteral::getString -> StringRef.

llvm-svn: 82514
This commit is contained in:
Daniel Dunbar 2009-09-22 03:27:33 +00:00
parent 8143069417
commit 362178883c
3 changed files with 15 additions and 9 deletions

View 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;
}

View 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

View 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