[cfe-commits] r82514 - in /cfe/trunk: include/clang/AST/Expr.h lib/AST/Expr.cpp lib/Frontend/PCHReaderStmt.cpp
Daniel Dunbar
daniel at zuster.org
Mon Sep 21 20:27:39 PDT 2009
Author: ddunbar
Date: Mon Sep 21 22:27:33 2009
New Revision: 82514
URL: http://llvm.org/viewvc/llvm-project?rev=82514&view=rev
Log:
Add StringLiteral::getString -> StringRef.
Modified:
cfe/trunk/include/clang/AST/Expr.h
cfe/trunk/lib/AST/Expr.cpp
cfe/trunk/lib/Frontend/PCHReaderStmt.cpp
Modified: cfe/trunk/include/clang/AST/Expr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=82514&r1=82513&r2=82514&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Mon Sep 21 22:27:33 2009
@@ -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 @@
/// \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;
}
Modified: cfe/trunk/lib/AST/Expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=82514&r1=82513&r2=82514&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Expr.cpp (original)
+++ cfe/trunk/lib/AST/Expr.cpp Mon Sep 21 22:27:33 2009
@@ -159,14 +159,14 @@
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
Modified: cfe/trunk/lib/Frontend/PCHReaderStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHReaderStmt.cpp?rev=82514&r1=82513&r2=82514&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PCHReaderStmt.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHReaderStmt.cpp Mon Sep 21 22:27:33 2009
@@ -380,8 +380,8 @@
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
More information about the cfe-commits
mailing list