diff options
| author | Douglas Gregor <dgregor@apple.com> | 2010-03-15 22:54:52 +0000 | 
|---|---|---|
| committer | Douglas Gregor <dgregor@apple.com> | 2010-03-15 22:54:52 +0000 | 
| commit | 802b77601e50161f0b0d2451a722e11f3b49cdfb (patch) | |
| tree | fa9b72b5282af43966aff1b27012e481accbf26b /clang/tools | |
| parent | 45c1505bf60a17a02846a823fac6d8544a27501c (diff) | |
| download | bcm5719-llvm-802b77601e50161f0b0d2451a722e11f3b49cdfb.tar.gz bcm5719-llvm-802b77601e50161f0b0d2451a722e11f3b49cdfb.zip | |
Introduce a new BufferResult class to act as the return type of
SourceManager's getBuffer() (and similar) operations. This abstract
can be used to force callers to cope with errors in getBuffer(), such
as missing files and changed files. Fix a bunch of callers to use the
new interface.
Add some very basic checks for file consistency (file size,
modification time) into ContentCache::getBuffer(), although these
checks don't help much until we've updated the main callers (e.g.,
SourceManager::getSpelling()).
llvm-svn: 98585
Diffstat (limited to 'clang/tools')
| -rw-r--r-- | clang/tools/CIndex/CIndex.cpp | 23 | 
1 files changed, 17 insertions, 6 deletions
| diff --git a/clang/tools/CIndex/CIndex.cpp b/clang/tools/CIndex/CIndex.cpp index b52a32ed9b5..c570ee4935d 100644 --- a/clang/tools/CIndex/CIndex.cpp +++ b/clang/tools/CIndex/CIndex.cpp @@ -2043,7 +2043,10 @@ CXString clang_getTokenSpelling(CXTranslationUnit TU, CXToken CXTok) {    std::pair<FileID, unsigned> LocInfo      = CXXUnit->getSourceManager().getDecomposedLoc(Loc);    std::pair<const char *,const char *> Buffer -    = CXXUnit->getSourceManager().getBufferData(LocInfo.first); +    = CXXUnit->getSourceManager().getBufferData(LocInfo.first, +                                  CXXUnit->getPreprocessor().getDiagnostics()); +  if (!Buffer.first) +    return createCXString("");    return createCXString(llvm::StringRef(Buffer.first+LocInfo.second,                                          CXTok.int_data[2])); @@ -2096,7 +2099,11 @@ void clang_tokenize(CXTranslationUnit TU, CXSourceRange Range,    // Create a lexer    std::pair<const char *,const char *> Buffer -    = SourceMgr.getBufferData(BeginLocInfo.first); +    = SourceMgr.getBufferData(BeginLocInfo.first,  +                              CXXUnit->getPreprocessor().getDiagnostics()); +  if (!Buffer.first) +    return; +      Lexer Lex(SourceMgr.getLocForStartOfFile(BeginLocInfo.first),              CXXUnit->getASTContext().getLangOptions(),              Buffer.first, Buffer.first + BeginLocInfo.second, Buffer.second); @@ -2125,12 +2132,16 @@ void clang_tokenize(CXTranslationUnit TU, CXSourceRange Range,        CXTok.int_data[0] = CXToken_Literal;        CXTok.ptr_data = (void *)Tok.getLiteralData();      } else if (Tok.is(tok::identifier)) { -      // Lookup the identifier to determine whether we have a +      // Lookup the identifier to determine whether we have a keyword.        std::pair<FileID, unsigned> LocInfo          = SourceMgr.getDecomposedLoc(Tok.getLocation()); -      const char *StartPos -        = CXXUnit->getSourceManager().getBufferData(LocInfo.first).first + -          LocInfo.second; +      std::pair<const char *, const char *> Buf +        = CXXUnit->getSourceManager().getBufferData(LocInfo.first, +                                  CXXUnit->getPreprocessor().getDiagnostics()); +      if (!Buf.first) +        return; +       +      const char *StartPos= Buf.first + LocInfo.second;        IdentifierInfo *II          = CXXUnit->getPreprocessor().LookUpIdentifierInfo(Tok, StartPos);        CXTok.int_data[0] = II->getTokenID() == tok::identifier? | 

