Let SourceManager::getBufferData return StringRef instead of a pair of two const char*.
llvm-svn: 98630
This commit is contained in:
@@ -457,9 +457,8 @@ public:
|
|||||||
///
|
///
|
||||||
/// \param FID The file ID whose contents will be returned.
|
/// \param FID The file ID whose contents will be returned.
|
||||||
/// \param Invalid If non-NULL, will be set true if an error occurred.
|
/// \param Invalid If non-NULL, will be set true if an error occurred.
|
||||||
std::pair<const char*, const char*> getBufferData(FileID FID,
|
llvm::StringRef getBufferData(FileID FID, bool *Invalid = 0) const;
|
||||||
bool *Invalid = 0) const;
|
|
||||||
|
|
||||||
|
|
||||||
//===--------------------------------------------------------------------===//
|
//===--------------------------------------------------------------------===//
|
||||||
// SourceLocation manipulation methods.
|
// SourceLocation manipulation methods.
|
||||||
|
|||||||
@@ -428,7 +428,7 @@ isDoxygenComment(SourceManager &SourceMgr, SourceRange Comment,
|
|||||||
bool Invalid = false;
|
bool Invalid = false;
|
||||||
const char *BufferStart
|
const char *BufferStart
|
||||||
= SourceMgr.getBufferData(SourceMgr.getFileID(Comment.getBegin()),
|
= SourceMgr.getBufferData(SourceMgr.getFileID(Comment.getBegin()),
|
||||||
&Invalid).first;
|
&Invalid).data();
|
||||||
if (Invalid)
|
if (Invalid)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@@ -495,7 +495,7 @@ const char *ASTContext::getCommentForDecl(const Decl *D) {
|
|||||||
= SourceMgr.getDecomposedLoc(DeclStartLoc);
|
= SourceMgr.getDecomposedLoc(DeclStartLoc);
|
||||||
bool Invalid = false;
|
bool Invalid = false;
|
||||||
const char *FileBufferStart
|
const char *FileBufferStart
|
||||||
= SourceMgr.getBufferData(DeclStartDecomp.first, &Invalid).first;
|
= SourceMgr.getBufferData(DeclStartDecomp.first, &Invalid).data();
|
||||||
if (Invalid)
|
if (Invalid)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
|||||||
@@ -474,8 +474,7 @@ bool SourceManager::overrideFileContents(const FileEntry *SourceFile,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::pair<const char*, const char*>
|
llvm::StringRef SourceManager::getBufferData(FileID FID, bool *Invalid) const {
|
||||||
SourceManager::getBufferData(FileID FID, bool *Invalid) const {
|
|
||||||
if (Invalid)
|
if (Invalid)
|
||||||
*Invalid = false;
|
*Invalid = false;
|
||||||
|
|
||||||
@@ -483,10 +482,9 @@ SourceManager::getBufferData(FileID FID, bool *Invalid) const {
|
|||||||
if (!Buf) {
|
if (!Buf) {
|
||||||
if (*Invalid)
|
if (*Invalid)
|
||||||
*Invalid = true;
|
*Invalid = true;
|
||||||
const char *FakeText = "";
|
return "";
|
||||||
return std::make_pair(FakeText, FakeText + strlen(FakeText));
|
|
||||||
}
|
}
|
||||||
return std::make_pair(Buf->getBufferStart(), Buf->getBufferEnd());
|
return Buf->getBuffer();
|
||||||
}
|
}
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|||||||
@@ -706,9 +706,9 @@ void RewriteObjC::HandleTopLevelSingleDecl(Decl *D) {
|
|||||||
|
|
||||||
void RewriteObjC::RewriteInclude() {
|
void RewriteObjC::RewriteInclude() {
|
||||||
SourceLocation LocStart = SM->getLocForStartOfFile(MainFileID);
|
SourceLocation LocStart = SM->getLocForStartOfFile(MainFileID);
|
||||||
std::pair<const char*, const char*> MainBuf = SM->getBufferData(MainFileID);
|
llvm::StringRef MainBuf = SM->getBufferData(MainFileID);
|
||||||
const char *MainBufStart = MainBuf.first;
|
const char *MainBufStart = MainBuf.begin();
|
||||||
const char *MainBufEnd = MainBuf.second;
|
const char *MainBufEnd = MainBuf.end();
|
||||||
size_t ImportLen = strlen("import");
|
size_t ImportLen = strlen("import");
|
||||||
|
|
||||||
// Loop over the whole file, looking for includes.
|
// Loop over the whole file, looking for includes.
|
||||||
@@ -731,9 +731,9 @@ void RewriteObjC::RewriteInclude() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void RewriteObjC::RewriteTabs() {
|
void RewriteObjC::RewriteTabs() {
|
||||||
std::pair<const char*, const char*> MainBuf = SM->getBufferData(MainFileID);
|
llvm::StringRef MainBuf = SM->getBufferData(MainFileID);
|
||||||
const char *MainBufStart = MainBuf.first;
|
const char *MainBufStart = MainBuf.begin();
|
||||||
const char *MainBufEnd = MainBuf.second;
|
const char *MainBufEnd = MainBuf.end();
|
||||||
|
|
||||||
// Loop over the whole file, looking for tabs.
|
// Loop over the whole file, looking for tabs.
|
||||||
for (const char *BufPtr = MainBufStart; BufPtr != MainBufEnd; ++BufPtr) {
|
for (const char *BufPtr = MainBufStart; BufPtr != MainBufEnd; ++BufPtr) {
|
||||||
@@ -973,7 +973,6 @@ void RewriteObjC::RewriteCategoryDecl(ObjCCategoryDecl *CatDecl) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void RewriteObjC::RewriteProtocolDecl(ObjCProtocolDecl *PDecl) {
|
void RewriteObjC::RewriteProtocolDecl(ObjCProtocolDecl *PDecl) {
|
||||||
std::pair<const char*, const char*> MainBuf = SM->getBufferData(MainFileID);
|
|
||||||
SourceLocation LocStart = PDecl->getLocStart();
|
SourceLocation LocStart = PDecl->getLocStart();
|
||||||
|
|
||||||
// FIXME: handle protocol headers that are declared across multiple lines.
|
// FIXME: handle protocol headers that are declared across multiple lines.
|
||||||
|
|||||||
@@ -331,13 +331,10 @@ void TextDiagnosticPrinter::EmitCaretDiagnostic(SourceLocation Loc,
|
|||||||
|
|
||||||
// Get information about the buffer it points into.
|
// Get information about the buffer it points into.
|
||||||
bool Invalid = false;
|
bool Invalid = false;
|
||||||
std::pair<const char*, const char*> BufferInfo = SM.getBufferData(FID,
|
const char *BufStart = SM.getBufferData(FID, &Invalid).data();
|
||||||
&Invalid);
|
|
||||||
if (Invalid)
|
if (Invalid)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const char *BufStart = BufferInfo.first;
|
|
||||||
|
|
||||||
unsigned ColNo = SM.getColumnNumber(FID, FileOffset);
|
unsigned ColNo = SM.getColumnNumber(FID, FileOffset);
|
||||||
unsigned CaretEndColNo
|
unsigned CaretEndColNo
|
||||||
= ColNo + Lexer::MeasureTokenLength(Loc, SM, *LangOpts);
|
= ColNo + Lexer::MeasureTokenLength(Loc, SM, *LangOpts);
|
||||||
|
|||||||
@@ -230,18 +230,17 @@ unsigned Lexer::MeasureTokenLength(SourceLocation Loc,
|
|||||||
Loc = SM.getInstantiationLoc(Loc);
|
Loc = SM.getInstantiationLoc(Loc);
|
||||||
std::pair<FileID, unsigned> LocInfo = SM.getDecomposedLoc(Loc);
|
std::pair<FileID, unsigned> LocInfo = SM.getDecomposedLoc(Loc);
|
||||||
bool Invalid = false;
|
bool Invalid = false;
|
||||||
std::pair<const char *,const char *> Buffer = SM.getBufferData(LocInfo.first,
|
llvm::StringRef Buffer = SM.getBufferData(LocInfo.first, &Invalid);
|
||||||
&Invalid);
|
|
||||||
if (Invalid)
|
if (Invalid)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
const char *StrData = Buffer.first+LocInfo.second;
|
const char *StrData = Buffer.data()+LocInfo.second;
|
||||||
|
|
||||||
if (isWhitespace(StrData[0]))
|
if (isWhitespace(StrData[0]))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
// Create a lexer starting at the beginning of this token.
|
// 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);
|
TheLexer.SetCommentRetentionState(true);
|
||||||
Token TheTok;
|
Token TheTok;
|
||||||
TheLexer.LexFromRawLexer(TheTok);
|
TheLexer.LexFromRawLexer(TheTok);
|
||||||
|
|||||||
@@ -441,7 +441,7 @@ bool TokenLexer::PasteTokens(Token &Tok) {
|
|||||||
|
|
||||||
bool Invalid = false;
|
bool Invalid = false;
|
||||||
const char *ScratchBufStart
|
const char *ScratchBufStart
|
||||||
= SourceMgr.getBufferData(LocFileID, &Invalid).first;
|
= SourceMgr.getBufferData(LocFileID, &Invalid).data();
|
||||||
if (Invalid)
|
if (Invalid)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ void html::HighlightRange(Rewriter &R, SourceLocation B, SourceLocation E,
|
|||||||
EOffset += Lexer::MeasureTokenLength(E, R.getSourceMgr(), R.getLangOpts());
|
EOffset += Lexer::MeasureTokenLength(E, R.getSourceMgr(), R.getLangOpts());
|
||||||
|
|
||||||
bool Invalid = false;
|
bool Invalid = false;
|
||||||
const char *BufferStart = SM.getBufferData(FID, &Invalid).first;
|
const char *BufferStart = SM.getBufferData(FID, &Invalid).data();
|
||||||
if (Invalid)
|
if (Invalid)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|||||||
@@ -165,8 +165,8 @@ RewriteBuffer &Rewriter::getEditBuffer(FileID FID) {
|
|||||||
return I->second;
|
return I->second;
|
||||||
I = RewriteBuffers.insert(I, std::make_pair(FID, RewriteBuffer()));
|
I = RewriteBuffers.insert(I, std::make_pair(FID, RewriteBuffer()));
|
||||||
|
|
||||||
std::pair<const char*, const char*> MB = SourceMgr->getBufferData(FID);
|
llvm::StringRef MB = SourceMgr->getBufferData(FID);
|
||||||
I->second.Initialize(MB.first, MB.second);
|
I->second.Initialize(MB.begin(), MB.end());
|
||||||
|
|
||||||
return I->second;
|
return I->second;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,12 +60,11 @@ SourceLocation Sema::getLocationOfStringLiteralByte(const StringLiteral *SL,
|
|||||||
std::pair<FileID, unsigned> LocInfo =
|
std::pair<FileID, unsigned> LocInfo =
|
||||||
SourceMgr.getDecomposedLoc(StrTokSpellingLoc);
|
SourceMgr.getDecomposedLoc(StrTokSpellingLoc);
|
||||||
bool Invalid = false;
|
bool Invalid = false;
|
||||||
std::pair<const char *,const char *> Buffer =
|
llvm::StringRef Buffer = SourceMgr.getBufferData(LocInfo.first, &Invalid);
|
||||||
SourceMgr.getBufferData(LocInfo.first, &Invalid);
|
|
||||||
if (Invalid)
|
if (Invalid)
|
||||||
return StrTokSpellingLoc;
|
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
|
// Create a langops struct and enable trigraphs. This is sufficient for
|
||||||
// relexing tokens.
|
// relexing tokens.
|
||||||
@@ -73,8 +72,8 @@ SourceLocation Sema::getLocationOfStringLiteralByte(const StringLiteral *SL,
|
|||||||
LangOpts.Trigraphs = true;
|
LangOpts.Trigraphs = true;
|
||||||
|
|
||||||
// Create a lexer starting at the beginning of this token.
|
// Create a lexer starting at the beginning of this token.
|
||||||
Lexer TheLexer(StrTokSpellingLoc, LangOpts, Buffer.first, StrData,
|
Lexer TheLexer(StrTokSpellingLoc, LangOpts, Buffer.begin(), StrData,
|
||||||
Buffer.second);
|
Buffer.end());
|
||||||
Token TheTok;
|
Token TheTok;
|
||||||
TheLexer.LexFromRawLexer(TheTok);
|
TheLexer.LexFromRawLexer(TheTok);
|
||||||
|
|
||||||
|
|||||||
@@ -2044,13 +2044,12 @@ CXString clang_getTokenSpelling(CXTranslationUnit TU, CXToken CXTok) {
|
|||||||
std::pair<FileID, unsigned> LocInfo
|
std::pair<FileID, unsigned> LocInfo
|
||||||
= CXXUnit->getSourceManager().getDecomposedLoc(Loc);
|
= CXXUnit->getSourceManager().getDecomposedLoc(Loc);
|
||||||
bool Invalid = false;
|
bool Invalid = false;
|
||||||
std::pair<const char *,const char *> Buffer
|
llvm::StringRef Buffer
|
||||||
= CXXUnit->getSourceManager().getBufferData(LocInfo.first, &Invalid);
|
= CXXUnit->getSourceManager().getBufferData(LocInfo.first, &Invalid);
|
||||||
if (Invalid)
|
if (Invalid)
|
||||||
return createCXString("");
|
return createCXString("");
|
||||||
|
|
||||||
return createCXString(llvm::StringRef(Buffer.first+LocInfo.second,
|
return createCXString(Buffer.substr(LocInfo.second, CXTok.int_data[2]));
|
||||||
CXTok.int_data[2]));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CXSourceLocation clang_getTokenLocation(CXTranslationUnit TU, CXToken CXTok) {
|
CXSourceLocation clang_getTokenLocation(CXTranslationUnit TU, CXToken CXTok) {
|
||||||
@@ -2100,16 +2099,16 @@ void clang_tokenize(CXTranslationUnit TU, CXSourceRange Range,
|
|||||||
|
|
||||||
// Create a lexer
|
// Create a lexer
|
||||||
bool Invalid = false;
|
bool Invalid = false;
|
||||||
std::pair<const char *,const char *> Buffer
|
llvm::StringRef Buffer
|
||||||
= SourceMgr.getBufferData(BeginLocInfo.first, &Invalid);
|
= SourceMgr.getBufferData(BeginLocInfo.first, &Invalid);
|
||||||
|
|
||||||
Lexer Lex(SourceMgr.getLocForStartOfFile(BeginLocInfo.first),
|
Lexer Lex(SourceMgr.getLocForStartOfFile(BeginLocInfo.first),
|
||||||
CXXUnit->getASTContext().getLangOptions(),
|
CXXUnit->getASTContext().getLangOptions(),
|
||||||
Buffer.first, Buffer.first + BeginLocInfo.second, Buffer.second);
|
Buffer.begin(), Buffer.data() + BeginLocInfo.second, Buffer.end());
|
||||||
Lex.SetCommentRetentionState(true);
|
Lex.SetCommentRetentionState(true);
|
||||||
|
|
||||||
// Lex tokens until we hit the end of the range.
|
// 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;
|
llvm::SmallVector<CXToken, 32> CXTokens;
|
||||||
Token Tok;
|
Token Tok;
|
||||||
do {
|
do {
|
||||||
@@ -2135,12 +2134,12 @@ void clang_tokenize(CXTranslationUnit TU, CXSourceRange Range,
|
|||||||
std::pair<FileID, unsigned> LocInfo
|
std::pair<FileID, unsigned> LocInfo
|
||||||
= SourceMgr.getDecomposedLoc(Tok.getLocation());
|
= SourceMgr.getDecomposedLoc(Tok.getLocation());
|
||||||
bool Invalid = false;
|
bool Invalid = false;
|
||||||
std::pair<const char *, const char *> Buf
|
llvm::StringRef Buf
|
||||||
= CXXUnit->getSourceManager().getBufferData(LocInfo.first, &Invalid);
|
= CXXUnit->getSourceManager().getBufferData(LocInfo.first, &Invalid);
|
||||||
if (Invalid)
|
if (Invalid)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const char *StartPos= Buf.first + LocInfo.second;
|
const char *StartPos = Buf.data() + LocInfo.second;
|
||||||
IdentifierInfo *II
|
IdentifierInfo *II
|
||||||
= CXXUnit->getPreprocessor().LookUpIdentifierInfo(Tok, StartPos);
|
= CXXUnit->getPreprocessor().LookUpIdentifierInfo(Tok, StartPos);
|
||||||
CXTok.int_data[0] = II->getTokenID() == tok::identifier?
|
CXTok.int_data[0] = II->getTokenID() == tok::identifier?
|
||||||
|
|||||||
Reference in New Issue
Block a user