[cfe-commits] r133515 - in /cfe/trunk: include/clang/AST/Expr.h include/clang/Basic/IdentifierTable.h include/clang/Basic/SourceManager.h include/clang/Basic/SourceManagerInternals.h include/clang/Lex/LiteralSupport.h lib/AST/Expr.cpp lib/Basic/SourceManager.cpp lib/Frontend/CacheTokens.cpp lib/Lex/PPDirectives.cpp lib/Lex/Pragma.cpp lib/Rewrite/RewriteObjC.cpp lib/Sema/SemaExpr.cpp lib/Sema/SemaExprObjC.cpp lib/Serialization/ASTReader.cpp
Jay Foad
jay.foad at gmail.com
Tue Jun 21 08:13:30 PDT 2011
Author: foad
Date: Tue Jun 21 10:13:30 2011
New Revision: 133515
URL: http://llvm.org/viewvc/llvm-project?rev=133515&view=rev
Log:
Make more use of llvm::StringRef in various APIs. In particular, don't
use the deprecated forms of llvm::StringMap::GetOrCreateValue().
Modified:
cfe/trunk/include/clang/AST/Expr.h
cfe/trunk/include/clang/Basic/IdentifierTable.h
cfe/trunk/include/clang/Basic/SourceManager.h
cfe/trunk/include/clang/Basic/SourceManagerInternals.h
cfe/trunk/include/clang/Lex/LiteralSupport.h
cfe/trunk/lib/AST/Expr.cpp
cfe/trunk/lib/Basic/SourceManager.cpp
cfe/trunk/lib/Frontend/CacheTokens.cpp
cfe/trunk/lib/Lex/PPDirectives.cpp
cfe/trunk/lib/Lex/Pragma.cpp
cfe/trunk/lib/Rewrite/RewriteObjC.cpp
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/lib/Sema/SemaExprObjC.cpp
cfe/trunk/lib/Serialization/ASTReader.cpp
Modified: cfe/trunk/include/clang/AST/Expr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=133515&r1=133514&r2=133515&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Tue Jun 21 10:13:30 2011
@@ -1205,16 +1205,14 @@
public:
/// This is the "fully general" constructor that allows representation of
/// strings formed from multiple concatenated tokens.
- static StringLiteral *Create(ASTContext &C, const char *StrData,
- unsigned ByteLength, bool Wide, bool Pascal,
- QualType Ty,
+ static StringLiteral *Create(ASTContext &C, llvm::StringRef Str, bool Wide,
+ bool Pascal, QualType Ty,
const SourceLocation *Loc, unsigned NumStrs);
/// Simple constructor for string literals made from one token.
- static StringLiteral *Create(ASTContext &C, const char *StrData,
- unsigned ByteLength, bool Wide,
+ static StringLiteral *Create(ASTContext &C, llvm::StringRef Str, bool Wide,
bool Pascal, QualType Ty, SourceLocation Loc) {
- return Create(C, StrData, ByteLength, Wide, Pascal, Ty, &Loc, 1);
+ return Create(C, Str, Wide, Pascal, Ty, &Loc, 1);
}
/// \brief Construct an empty string literal.
Modified: cfe/trunk/include/clang/Basic/IdentifierTable.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/IdentifierTable.h?rev=133515&r1=133514&r2=133515&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/IdentifierTable.h (original)
+++ cfe/trunk/include/clang/Basic/IdentifierTable.h Tue Jun 21 10:13:30 2011
@@ -411,23 +411,15 @@
return II;
}
- IdentifierInfo &get(const char *NameStart, const char *NameEnd) {
- return get(llvm::StringRef(NameStart, NameEnd-NameStart));
- }
-
- IdentifierInfo &get(const char *Name, size_t NameLen) {
- return get(llvm::StringRef(Name, NameLen));
- }
-
/// \brief Gets an IdentifierInfo for the given name without consulting
/// external sources.
///
/// This is a version of get() meant for external sources that want to
/// introduce or modify an identifier. If they called get(), they would
/// likely end up in a recursion.
- IdentifierInfo &getOwn(const char *NameStart, const char *NameEnd) {
+ IdentifierInfo &getOwn(llvm::StringRef Name) {
llvm::StringMapEntry<IdentifierInfo*> &Entry =
- HashTable.GetOrCreateValue(NameStart, NameEnd);
+ HashTable.GetOrCreateValue(Name);
IdentifierInfo *II = Entry.getValue();
if (!II) {
@@ -444,9 +436,6 @@
return *II;
}
- IdentifierInfo &getOwn(llvm::StringRef Name) {
- return getOwn(Name.begin(), Name.end());
- }
typedef HashTableTy::const_iterator iterator;
typedef HashTableTy::const_iterator const_iterator;
Modified: cfe/trunk/include/clang/Basic/SourceManager.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/SourceManager.h?rev=133515&r1=133514&r2=133515&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/SourceManager.h (original)
+++ cfe/trunk/include/clang/Basic/SourceManager.h Tue Jun 21 10:13:30 2011
@@ -845,7 +845,7 @@
/// getLineTableFilenameID - Return the uniqued ID for the specified filename.
///
- unsigned getLineTableFilenameID(const char *Ptr, unsigned Len);
+ unsigned getLineTableFilenameID(llvm::StringRef Str);
/// AddLineNote - Add a line note to the line table for the FileID and offset
/// specified by Loc. If FilenameID is -1, it is considered to be
Modified: cfe/trunk/include/clang/Basic/SourceManagerInternals.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/SourceManagerInternals.h?rev=133515&r1=133514&r2=133515&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/SourceManagerInternals.h (original)
+++ cfe/trunk/include/clang/Basic/SourceManagerInternals.h Tue Jun 21 10:13:30 2011
@@ -97,7 +97,7 @@
~LineTableInfo() {}
- unsigned getLineTableFilenameID(const char *Ptr, unsigned Len);
+ unsigned getLineTableFilenameID(llvm::StringRef Str);
const char *getFilename(unsigned ID) const {
assert(ID < FilenamesByID.size() && "Invalid FilenameID");
return FilenamesByID[ID]->getKeyData();
Modified: cfe/trunk/include/clang/Lex/LiteralSupport.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/LiteralSupport.h?rev=133515&r1=133514&r2=133515&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/LiteralSupport.h (original)
+++ cfe/trunk/include/clang/Lex/LiteralSupport.h Tue Jun 21 10:13:30 2011
@@ -167,7 +167,9 @@
bool AnyWide;
bool Pascal;
- const char *GetString() { return ResultBuf.data(); }
+ llvm::StringRef GetString() const {
+ return llvm::StringRef(ResultBuf.data(), GetStringLength());
+ }
unsigned GetStringLength() const { return ResultPtr-ResultBuf.data(); }
unsigned GetNumStringChars() const {
Modified: cfe/trunk/lib/AST/Expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=133515&r1=133514&r2=133515&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Expr.cpp (original)
+++ cfe/trunk/lib/AST/Expr.cpp Tue Jun 21 10:13:30 2011
@@ -498,8 +498,8 @@
return V.convertToDouble();
}
-StringLiteral *StringLiteral::Create(ASTContext &C, const char *StrData,
- unsigned ByteLength, bool Wide,
+StringLiteral *StringLiteral::Create(ASTContext &C, llvm::StringRef Str,
+ bool Wide,
bool Pascal, QualType Ty,
const SourceLocation *Loc,
unsigned NumStrs) {
@@ -511,10 +511,10 @@
StringLiteral *SL = new (Mem) StringLiteral(Ty);
// OPTIMIZE: could allocate this appended to the StringLiteral.
- char *AStrData = new (C, 1) char[ByteLength];
- memcpy(AStrData, StrData, ByteLength);
+ char *AStrData = new (C, 1) char[Str.size()];
+ memcpy(AStrData, Str.data(), Str.size());
SL->StrData = AStrData;
- SL->ByteLength = ByteLength;
+ SL->ByteLength = Str.size();
SL->IsWide = Wide;
SL->IsPascal = Pascal;
SL->TokLocs[0] = Loc[0];
Modified: cfe/trunk/lib/Basic/SourceManager.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/SourceManager.cpp?rev=133515&r1=133514&r2=133515&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/SourceManager.cpp (original)
+++ cfe/trunk/lib/Basic/SourceManager.cpp Tue Jun 21 10:13:30 2011
@@ -169,11 +169,11 @@
return Buffer.getPointer();
}
-unsigned LineTableInfo::getLineTableFilenameID(const char *Ptr, unsigned Len) {
+unsigned LineTableInfo::getLineTableFilenameID(llvm::StringRef Name) {
// Look up the filename in the string table, returning the pre-existing value
// if it exists.
llvm::StringMapEntry<unsigned> &Entry =
- FilenameIDs.GetOrCreateValue(Ptr, Ptr+Len, ~0U);
+ FilenameIDs.GetOrCreateValue(Name, ~0U);
if (Entry.getValue() != ~0U)
return Entry.getValue();
@@ -277,10 +277,10 @@
/// getLineTableFilenameID - Return the uniqued ID for the specified filename.
///
-unsigned SourceManager::getLineTableFilenameID(const char *Ptr, unsigned Len) {
+unsigned SourceManager::getLineTableFilenameID(llvm::StringRef Name) {
if (LineTable == 0)
LineTable = new LineTableInfo();
- return LineTable->getLineTableFilenameID(Ptr, Len);
+ return LineTable->getLineTableFilenameID(Name);
}
Modified: cfe/trunk/lib/Frontend/CacheTokens.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CacheTokens.cpp?rev=133515&r1=133514&r2=133515&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/CacheTokens.cpp (original)
+++ cfe/trunk/lib/Frontend/CacheTokens.cpp Tue Jun 21 10:13:30 2011
@@ -247,17 +247,16 @@
} else {
// We cache *un-cleaned* spellings. This gives us 100% fidelity with the
// source code.
- const char* s = T.getLiteralData();
- unsigned len = T.getLength();
+ llvm::StringRef s(T.getLiteralData(), T.getLength());
// Get the string entry.
- llvm::StringMapEntry<OffsetOpt> *E = &CachedStrs.GetOrCreateValue(s, s+len);
+ llvm::StringMapEntry<OffsetOpt> *E = &CachedStrs.GetOrCreateValue(s);
// If this is a new string entry, bump the PTH offset.
if (!E->getValue().hasOffset()) {
E->getValue().setOffset(CurStrOffset);
StrEntries.push_back(E);
- CurStrOffset += len + 1;
+ CurStrOffset += s.size() + 1;
}
// Emit the relative offset into the PTH file for the spelling string.
Modified: cfe/trunk/lib/Lex/PPDirectives.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPDirectives.cpp?rev=133515&r1=133514&r2=133515&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PPDirectives.cpp (original)
+++ cfe/trunk/lib/Lex/PPDirectives.cpp Tue Jun 21 10:13:30 2011
@@ -784,8 +784,7 @@
Diag(StrTok, diag::err_pp_linemarker_invalid_filename);
return DiscardUntilEndOfDirective();
}
- FilenameID = SourceMgr.getLineTableFilenameID(Literal.GetString(),
- Literal.GetStringLength());
+ FilenameID = SourceMgr.getLineTableFilenameID(Literal.GetString());
// Verify that there is nothing after the string, other than EOD. Because
// of C99 6.10.4p5, macros that expand to empty tokens are ok.
@@ -918,8 +917,7 @@
Diag(StrTok, diag::err_pp_linemarker_invalid_filename);
return DiscardUntilEndOfDirective();
}
- FilenameID = SourceMgr.getLineTableFilenameID(Literal.GetString(),
- Literal.GetStringLength());
+ FilenameID = SourceMgr.getLineTableFilenameID(Literal.GetString());
// If a filename was present, read any flags that are present.
if (ReadLineMarkerFlags(IsFileEntry, IsFileExit,
Modified: cfe/trunk/lib/Lex/Pragma.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Pragma.cpp?rev=133515&r1=133514&r2=133515&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/Pragma.cpp (original)
+++ cfe/trunk/lib/Lex/Pragma.cpp Tue Jun 21 10:13:30 2011
@@ -326,9 +326,7 @@
if (PLoc.isInvalid())
return;
- unsigned FilenameLen = strlen(PLoc.getFilename());
- unsigned FilenameID = SourceMgr.getLineTableFilenameID(PLoc.getFilename(),
- FilenameLen);
+ unsigned FilenameID = SourceMgr.getLineTableFilenameID(PLoc.getFilename());
// Notify the client, if desired, that we are in a new source file.
if (Callbacks)
@@ -454,8 +452,7 @@
return;
}
- ArgumentString = std::string(Literal.GetString(),
- Literal.GetString()+Literal.GetStringLength());
+ ArgumentString = Literal.GetString();
}
// FIXME: If the kind is "compiler" warn if the string is present (it is
@@ -531,7 +528,7 @@
return;
}
- llvm::StringRef MessageString(Literal.GetString(), Literal.GetStringLength());
+ llvm::StringRef MessageString(Literal.GetString());
if (ExpectClosingParen) {
if (Tok.isNot(tok::r_paren)) {
@@ -906,7 +903,7 @@
return;
}
- llvm::StringRef WarningName(Literal.GetString(), Literal.GetStringLength());
+ llvm::StringRef WarningName(Literal.GetString());
if (WarningName.size() < 3 || WarningName[0] != '-' ||
WarningName[1] != 'W') {
Modified: cfe/trunk/lib/Rewrite/RewriteObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Rewrite/RewriteObjC.cpp?rev=133515&r1=133514&r2=133515&view=diff
==============================================================================
--- cfe/trunk/lib/Rewrite/RewriteObjC.cpp (original)
+++ cfe/trunk/lib/Rewrite/RewriteObjC.cpp Tue Jun 21 10:13:30 2011
@@ -2110,8 +2110,7 @@
QualType StrType = Context->getPointerType(Context->CharTy);
std::string StrEncoding;
Context->getObjCEncodingForType(Exp->getEncodedType(), StrEncoding);
- Expr *Replacement = StringLiteral::Create(*Context,StrEncoding.c_str(),
- StrEncoding.length(),
+ Expr *Replacement = StringLiteral::Create(*Context, StrEncoding,
false, false, StrType,
SourceLocation());
ReplaceStmt(Exp, Replacement);
@@ -2129,9 +2128,8 @@
llvm::SmallVector<Expr*, 8> SelExprs;
QualType argType = Context->getPointerType(Context->CharTy);
SelExprs.push_back(StringLiteral::Create(*Context,
- Exp->getSelector().getAsString().c_str(),
- Exp->getSelector().getAsString().size(),
- false, false, argType,
+ Exp->getSelector().getAsString(),
+ false, false, argType,
SourceLocation()));
CallExpr *SelExp = SynthesizeCallToFunctionDecl(SelGetUidFunctionDecl,
&SelExprs[0], SelExprs.size());
@@ -2798,8 +2796,7 @@
llvm::SmallVector<Expr*, 8> ClsExprs;
QualType argType = Context->getPointerType(Context->CharTy);
ClsExprs.push_back(StringLiteral::Create(*Context,
- ClassDecl->getIdentifier()->getNameStart(),
- ClassDecl->getIdentifier()->getLength(),
+ ClassDecl->getIdentifier()->getName(),
false, false, argType, SourceLocation()));
CallExpr *Cls = SynthesizeCallToFunctionDecl(GetMetaClassFunctionDecl,
&ClsExprs[0],
@@ -2877,8 +2874,7 @@
= Exp->getClassReceiver()->getAs<ObjCObjectType>()->getInterface();
IdentifierInfo *clsName = Class->getIdentifier();
ClsExprs.push_back(StringLiteral::Create(*Context,
- clsName->getNameStart(),
- clsName->getLength(),
+ clsName->getName(),
false, false,
argType, SourceLocation()));
CallExpr *Cls = SynthesizeCallToFunctionDecl(GetClassFunctionDecl,
@@ -2909,8 +2905,7 @@
llvm::SmallVector<Expr*, 8> ClsExprs;
QualType argType = Context->getPointerType(Context->CharTy);
ClsExprs.push_back(StringLiteral::Create(*Context,
- ClassDecl->getIdentifier()->getNameStart(),
- ClassDecl->getIdentifier()->getLength(),
+ ClassDecl->getIdentifier()->getName(),
false, false, argType, SourceLocation()));
CallExpr *Cls = SynthesizeCallToFunctionDecl(GetClassFunctionDecl,
&ClsExprs[0],
@@ -2991,8 +2986,7 @@
llvm::SmallVector<Expr*, 8> SelExprs;
QualType argType = Context->getPointerType(Context->CharTy);
SelExprs.push_back(StringLiteral::Create(*Context,
- Exp->getSelector().getAsString().c_str(),
- Exp->getSelector().getAsString().size(),
+ Exp->getSelector().getAsString(),
false, false, argType, SourceLocation()));
CallExpr *SelExp = SynthesizeCallToFunctionDecl(SelGetUidFunctionDecl,
&SelExprs[0], SelExprs.size(),
Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=133515&r1=133514&r2=133515&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Tue Jun 21 10:13:30 2011
@@ -1016,7 +1016,6 @@
// Pass &StringTokLocs[0], StringTokLocs.size() to factory!
return Owned(StringLiteral::Create(Context, Literal.GetString(),
- Literal.GetStringLength(),
Literal.AnyWide, Literal.Pascal, StrTy,
&StringTokLocs[0],
StringTokLocs.size()));
Modified: cfe/trunk/lib/Sema/SemaExprObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprObjC.cpp?rev=133515&r1=133514&r2=133515&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprObjC.cpp Tue Jun 21 10:13:30 2011
@@ -63,7 +63,7 @@
// Create the aggregate string with the appropriate content and location
// information.
- S = StringLiteral::Create(Context, &StrBuf[0], StrBuf.size(),
+ S = StringLiteral::Create(Context, StrBuf,
/*Wide=*/false, /*Pascal=*/false,
Context.getPointerType(Context.CharTy),
&StrLocs[0], StrLocs.size());
Modified: cfe/trunk/lib/Serialization/ASTReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=133515&r1=133514&r2=133515&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReader.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReader.cpp Tue Jun 21 10:13:30 2011
@@ -657,7 +657,8 @@
// and associate it with the persistent ID.
IdentifierInfo *II = KnownII;
if (!II)
- II = &Reader.getIdentifierTable().getOwn(k.first, k.first + k.second);
+ II = &Reader.getIdentifierTable().getOwn(llvm::StringRef(k.first,
+ k.second));
Reader.SetIdentifierInfo(ID, II);
II->setIsFromAST();
return II;
@@ -684,7 +685,8 @@
// the new IdentifierInfo.
IdentifierInfo *II = KnownII;
if (!II)
- II = &Reader.getIdentifierTable().getOwn(k.first, k.first + k.second);
+ II = &Reader.getIdentifierTable().getOwn(llvm::StringRef(k.first,
+ k.second));
Reader.SetIdentifierInfo(ID, II);
// Set or check the various bits in the IdentifierInfo structure.
@@ -1001,8 +1003,7 @@
std::string Filename(&Record[Idx], &Record[Idx] + FilenameLen);
Idx += FilenameLen;
MaybeAddSystemRootToFilename(Filename);
- FileIDs[I] = LineTable.getLineTableFilenameID(Filename.c_str(),
- Filename.size());
+ FileIDs[I] = LineTable.getLineTableFilenameID(Filename);
}
// Parse the line entries
@@ -4545,7 +4546,7 @@
unsigned StrLen = (((unsigned) StrLenPtr[0])
| (((unsigned) StrLenPtr[1]) << 8)) - 1;
IdentifiersLoaded[ID]
- = &PP->getIdentifierTable().get(Str, StrLen);
+ = &PP->getIdentifierTable().get(llvm::StringRef(Str, StrLen));
if (DeserializationListener)
DeserializationListener->IdentifierRead(ID + 1, IdentifiersLoaded[ID]);
}
More information about the cfe-commits
mailing list