aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Kramer <benny.kra@googlemail.com>2010-03-16 14:14:31 +0000
committerBenjamin Kramer <benny.kra@googlemail.com>2010-03-16 14:14:31 +0000
commitf6ac97b101c8840efa92bf29166077ce4049e293 (patch)
treeae3c4bd11598f49ee678e6fba5a3e2df38d24427
parentc506357c3778092c2a3251243f12524e8eb89274 (diff)
Let SourceManager::getBufferData return StringRef instead of a pair of two const char*.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@98630 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/Basic/SourceManager.h5
-rw-r--r--lib/AST/ASTContext.cpp4
-rw-r--r--lib/Basic/SourceManager.cpp8
-rw-r--r--lib/Frontend/RewriteObjC.cpp13
-rw-r--r--lib/Frontend/TextDiagnosticPrinter.cpp7
-rw-r--r--lib/Lex/Lexer.cpp9
-rw-r--r--lib/Lex/TokenLexer.cpp2
-rw-r--r--lib/Rewrite/HTMLRewrite.cpp2
-rw-r--r--lib/Rewrite/Rewriter.cpp4
-rw-r--r--lib/Sema/SemaChecking.cpp9
-rw-r--r--tools/CIndex/CIndex.cpp15
11 files changed, 34 insertions, 44 deletions
diff --git a/include/clang/Basic/SourceManager.h b/include/clang/Basic/SourceManager.h
index 9657ee4f1a..3d1fcd3dbb 100644
--- a/include/clang/Basic/SourceManager.h
+++ b/include/clang/Basic/SourceManager.h
@@ -457,9 +457,8 @@ public:
///
/// \param FID The file ID whose contents will be returned.
/// \param Invalid If non-NULL, will be set true if an error occurred.
- std::pair<const char*, const char*> getBufferData(FileID FID,
- bool *Invalid = 0) const;
-
+ llvm::StringRef getBufferData(FileID FID, bool *Invalid = 0) const;
+
//===--------------------------------------------------------------------===//
// SourceLocation manipulation methods.
diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp
index 07243365bf..8230cde3b2 100644
--- a/lib/AST/ASTContext.cpp
+++ b/lib/AST/ASTContext.cpp
@@ -428,7 +428,7 @@ isDoxygenComment(SourceManager &SourceMgr, SourceRange Comment,
bool Invalid = false;
const char *BufferStart
= SourceMgr.getBufferData(SourceMgr.getFileID(Comment.getBegin()),
- &Invalid).first;
+ &Invalid).data();
if (Invalid)
return false;
@@ -495,7 +495,7 @@ const char *ASTContext::getCommentForDecl(const Decl *D) {
= SourceMgr.getDecomposedLoc(DeclStartLoc);
bool Invalid = false;
const char *FileBufferStart
- = SourceMgr.getBufferData(DeclStartDecomp.first, &Invalid).first;
+ = SourceMgr.getBufferData(DeclStartDecomp.first, &Invalid).data();
if (Invalid)
return 0;
diff --git a/lib/Basic/SourceManager.cpp b/lib/Basic/SourceManager.cpp
index 6335504a7d..4007ccf2a6 100644
--- a/lib/Basic/SourceManager.cpp
+++ b/lib/Basic/SourceManager.cpp
@@ -474,8 +474,7 @@ bool SourceManager::overrideFileContents(const FileEntry *SourceFile,
return false;
}
-std::pair<const char*, const char*>
-SourceManager::getBufferData(FileID FID, bool *Invalid) const {
+llvm::StringRef SourceManager::getBufferData(FileID FID, bool *Invalid) const {
if (Invalid)
*Invalid = false;
@@ -483,10 +482,9 @@ SourceManager::getBufferData(FileID FID, bool *Invalid) const {
if (!Buf) {
if (*Invalid)
*Invalid = true;
- const char *FakeText = "";
- return std::make_pair(FakeText, FakeText + strlen(FakeText));
+ return "";
}
- return std::make_pair(Buf->getBufferStart(), Buf->getBufferEnd());
+ return Buf->getBuffer();
}
//===----------------------------------------------------------------------===//
diff --git a/lib/Frontend/RewriteObjC.cpp b/lib/Frontend/RewriteObjC.cpp
index 8889003851..79aecceb70 100644
--- a/lib/Frontend/RewriteObjC.cpp
+++ b/lib/Frontend/RewriteObjC.cpp
@@ -706,9 +706,9 @@ void RewriteObjC::HandleTopLevelSingleDecl(Decl *D) {
void RewriteObjC::RewriteInclude() {
SourceLocation LocStart = SM->getLocForStartOfFile(MainFileID);
- std::pair<const char*, const char*> MainBuf = SM->getBufferData(MainFileID);
- const char *MainBufStart = MainBuf.first;
- const char *MainBufEnd = MainBuf.second;
+ llvm::StringRef MainBuf = SM->getBufferData(MainFileID);
+ const char *MainBufStart = MainBuf.begin();
+ const char *MainBufEnd = MainBuf.end();
size_t ImportLen = strlen("import");
// Loop over the whole file, looking for includes.
@@ -731,9 +731,9 @@ void RewriteObjC::RewriteInclude() {
}
void RewriteObjC::RewriteTabs() {
- std::pair<const char*, const char*> MainBuf = SM->getBufferData(MainFileID);
- const char *MainBufStart = MainBuf.first;
- const char *MainBufEnd = MainBuf.second;
+ llvm::StringRef MainBuf = SM->getBufferData(MainFileID);
+ const char *MainBufStart = MainBuf.begin();
+ const char *MainBufEnd = MainBuf.end();
// Loop over the whole file, looking for tabs.
for (const char *BufPtr = MainBufStart; BufPtr != MainBufEnd; ++BufPtr) {
@@ -973,7 +973,6 @@ void RewriteObjC::RewriteCategoryDecl(ObjCCategoryDecl *CatDecl) {
}
void RewriteObjC::RewriteProtocolDecl(ObjCProtocolDecl *PDecl) {
- std::pair<const char*, const char*> MainBuf = SM->getBufferData(MainFileID);
SourceLocation LocStart = PDecl->getLocStart();
// FIXME: handle protocol headers that are declared across multiple lines.
diff --git a/lib/Frontend/TextDiagnosticPrinter.cpp b/lib/Frontend/TextDiagnosticPrinter.cpp
index 946a6caa15..24d51e2c78 100644
--- a/lib/Frontend/TextDiagnosticPrinter.cpp
+++ b/lib/Frontend/TextDiagnosticPrinter.cpp
@@ -331,13 +331,10 @@ void TextDiagnosticPrinter::EmitCaretDiagnostic(SourceLocation Loc,
// Get information about the buffer it points into.
bool Invalid = false;
- std::pair<const char*, const char*> BufferInfo = SM.getBufferData(FID,
- &Invalid);
+ const char *BufStart = SM.getBufferData(FID, &Invalid).data();
if (Invalid)
return;
-
- const char *BufStart = BufferInfo.first;
-
+
unsigned ColNo = SM.getColumnNumber(FID, FileOffset);
unsigned CaretEndColNo
= ColNo + Lexer::MeasureTokenLength(Loc, SM, *LangOpts);
diff --git a/lib/Lex/Lexer.cpp b/lib/Lex/Lexer.cpp
index d311b7e5dd..6cdb96f37d 100644
--- a/lib/Lex/Lexer.cpp
+++ b/lib/Lex/Lexer.cpp
@@ -230,18 +230,17 @@ unsigned Lexer::MeasureTokenLength(SourceLocation Loc,
Loc = SM.getInstantiationLoc(Loc);
std::pair<FileID, unsigned> LocInfo = SM.getDecomposedLoc(Loc);
bool Invalid = false;
- std::pair<const char *,const char *> Buffer = SM.getBufferData(LocInfo.first,
- &Invalid);
+ llvm::StringRef Buffer = SM.getBufferData(LocInfo.first, &Invalid);
if (Invalid)
return 0;
-
- const char *StrData = Buffer.first+LocInfo.second;
+
+ const char *StrData = Buffer.data()+LocInfo.second;
if (isWhitespace(StrData[0]))
return 0;
// Create a lexer starting at the beginning of this token.
- Lexer TheLexer(Loc, LangOpts, Buffer.first, StrData, Buffer.second);
+ Lexer TheLexer(Loc, LangOpts, Buffer.begin(), StrData, Buffer.end());
TheLexer.SetCommentRetentionState(true);
Token TheTok;
TheLexer.LexFromRawLexer(TheTok);
diff --git a/lib/Lex/TokenLexer.cpp b/lib/Lex/TokenLexer.cpp
index 8f68765543..dbd1b8400d 100644
--- a/lib/Lex/TokenLexer.cpp
+++ b/lib/Lex/TokenLexer.cpp
@@ -441,7 +441,7 @@ bool TokenLexer::PasteTokens(Token &Tok) {
bool Invalid = false;
const char *ScratchBufStart
- = SourceMgr.getBufferData(LocFileID, &Invalid).first;
+ = SourceMgr.getBufferData(LocFileID, &Invalid).data();
if (Invalid)
return false;
diff --git a/lib/Rewrite/HTMLRewrite.cpp b/lib/Rewrite/HTMLRewrite.cpp
index f325121d08..7b78070a27 100644
--- a/lib/Rewrite/HTMLRewrite.cpp
+++ b/lib/Rewrite/HTMLRewrite.cpp
@@ -44,7 +44,7 @@ void html::HighlightRange(Rewriter &R, SourceLocation B, SourceLocation E,
EOffset += Lexer::MeasureTokenLength(E, R.getSourceMgr(), R.getLangOpts());
bool Invalid = false;
- const char *BufferStart = SM.getBufferData(FID, &Invalid).first;
+ const char *BufferStart = SM.getBufferData(FID, &Invalid).data();
if (Invalid)
return;
diff --git a/lib/Rewrite/Rewriter.cpp b/lib/Rewrite/Rewriter.cpp
index 9744496ac4..bf8ba701a8 100644
--- a/lib/Rewrite/Rewriter.cpp
+++ b/lib/Rewrite/Rewriter.cpp
@@ -165,8 +165,8 @@ RewriteBuffer &Rewriter::getEditBuffer(FileID FID) {
return I->second;
I = RewriteBuffers.insert(I, std::make_pair(FID, RewriteBuffer()));
- std::pair<const char*, const char*> MB = SourceMgr->getBufferData(FID);
- I->second.Initialize(MB.first, MB.second);
+ llvm::StringRef MB = SourceMgr->getBufferData(FID);
+ I->second.Initialize(MB.begin(), MB.end());
return I->second;
}
diff --git a/lib/Sema/SemaChecking.cpp b/lib/Sema/SemaChecking.cpp
index 5ec01d0011..3fac79deba 100644
--- a/lib/Sema/SemaChecking.cpp
+++ b/lib/Sema/SemaChecking.cpp
@@ -60,12 +60,11 @@ SourceLocation Sema::getLocationOfStringLiteralByte(const StringLiteral *SL,
std::pair<FileID, unsigned> LocInfo =
SourceMgr.getDecomposedLoc(StrTokSpellingLoc);
bool Invalid = false;
- std::pair<const char *,const char *> Buffer =
- SourceMgr.getBufferData(LocInfo.first, &Invalid);
+ llvm::StringRef Buffer = SourceMgr.getBufferData(LocInfo.first, &Invalid);
if (Invalid)
return StrTokSpellingLoc;
- const char *StrData = Buffer.first+LocInfo.second;
+ const char *StrData = Buffer.data()+LocInfo.second;
// Create a langops struct and enable trigraphs. This is sufficient for
// relexing tokens.
@@ -73,8 +72,8 @@ SourceLocation Sema::getLocationOfStringLiteralByte(const StringLiteral *SL,
LangOpts.Trigraphs = true;
// Create a lexer starting at the beginning of this token.
- Lexer TheLexer(StrTokSpellingLoc, LangOpts, Buffer.first, StrData,
- Buffer.second);
+ Lexer TheLexer(StrTokSpellingLoc, LangOpts, Buffer.begin(), StrData,
+ Buffer.end());
Token TheTok;
TheLexer.LexFromRawLexer(TheTok);
diff --git a/tools/CIndex/CIndex.cpp b/tools/CIndex/CIndex.cpp
index c100caeecb..663b32fa1a 100644
--- a/tools/CIndex/CIndex.cpp
+++ b/tools/CIndex/CIndex.cpp
@@ -2044,13 +2044,12 @@ CXString clang_getTokenSpelling(CXTranslationUnit TU, CXToken CXTok) {
std::pair<FileID, unsigned> LocInfo
= CXXUnit->getSourceManager().getDecomposedLoc(Loc);
bool Invalid = false;
- std::pair<const char *,const char *> Buffer
+ llvm::StringRef Buffer
= CXXUnit->getSourceManager().getBufferData(LocInfo.first, &Invalid);
if (Invalid)
return createCXString("");
- return createCXString(llvm::StringRef(Buffer.first+LocInfo.second,
- CXTok.int_data[2]));
+ return createCXString(Buffer.substr(LocInfo.second, CXTok.int_data[2]));
}
CXSourceLocation clang_getTokenLocation(CXTranslationUnit TU, CXToken CXTok) {
@@ -2100,16 +2099,16 @@ void clang_tokenize(CXTranslationUnit TU, CXSourceRange Range,
// Create a lexer
bool Invalid = false;
- std::pair<const char *,const char *> Buffer
+ llvm::StringRef Buffer
= SourceMgr.getBufferData(BeginLocInfo.first, &Invalid);
Lexer Lex(SourceMgr.getLocForStartOfFile(BeginLocInfo.first),
CXXUnit->getASTContext().getLangOptions(),
- Buffer.first, Buffer.first + BeginLocInfo.second, Buffer.second);
+ Buffer.begin(), Buffer.data() + BeginLocInfo.second, Buffer.end());
Lex.SetCommentRetentionState(true);
// Lex tokens until we hit the end of the range.
- const char *EffectiveBufferEnd = Buffer.first + EndLocInfo.second;
+ const char *EffectiveBufferEnd = Buffer.data() + EndLocInfo.second;
llvm::SmallVector<CXToken, 32> CXTokens;
Token Tok;
do {
@@ -2135,12 +2134,12 @@ void clang_tokenize(CXTranslationUnit TU, CXSourceRange Range,
std::pair<FileID, unsigned> LocInfo
= SourceMgr.getDecomposedLoc(Tok.getLocation());
bool Invalid = false;
- std::pair<const char *, const char *> Buf
+ llvm::StringRef Buf
= CXXUnit->getSourceManager().getBufferData(LocInfo.first, &Invalid);
if (Invalid)
return;
- const char *StartPos= Buf.first + LocInfo.second;
+ const char *StartPos = Buf.data() + LocInfo.second;
IdentifierInfo *II
= CXXUnit->getPreprocessor().LookUpIdentifierInfo(Tok, StartPos);
CXTok.int_data[0] = II->getTokenID() == tok::identifier?