Give SourceManager a Diagnostic object with which to report errors,
and start simplifying the interfaces in SourceManager that can fail.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@98594 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/tools/CIndex/CIndex.cpp b/tools/CIndex/CIndex.cpp
index c570ee4..c100cae 100644
--- a/tools/CIndex/CIndex.cpp
+++ b/tools/CIndex/CIndex.cpp
@@ -1133,7 +1133,8 @@
// We failed to load the ASTUnit, but we can still deserialize the
// diagnostics and emit them.
FileManager FileMgr;
- SourceManager SourceMgr;
+ Diagnostic Diag;
+ SourceManager SourceMgr(Diag);
// FIXME: Faked LangOpts!
LangOptions LangOpts;
llvm::SmallVector<StoredDiagnostic, 4> Diags;
@@ -2042,10 +2043,10 @@
SourceLocation Loc = SourceLocation::getFromRawEncoding(CXTok.int_data[1]);
std::pair<FileID, unsigned> LocInfo
= CXXUnit->getSourceManager().getDecomposedLoc(Loc);
+ bool Invalid = false;
std::pair<const char *,const char *> Buffer
- = CXXUnit->getSourceManager().getBufferData(LocInfo.first,
- CXXUnit->getPreprocessor().getDiagnostics());
- if (!Buffer.first)
+ = CXXUnit->getSourceManager().getBufferData(LocInfo.first, &Invalid);
+ if (Invalid)
return createCXString("");
return createCXString(llvm::StringRef(Buffer.first+LocInfo.second,
@@ -2098,11 +2099,9 @@
return;
// Create a lexer
+ bool Invalid = false;
std::pair<const char *,const char *> Buffer
- = SourceMgr.getBufferData(BeginLocInfo.first,
- CXXUnit->getPreprocessor().getDiagnostics());
- if (!Buffer.first)
- return;
+ = SourceMgr.getBufferData(BeginLocInfo.first, &Invalid);
Lexer Lex(SourceMgr.getLocForStartOfFile(BeginLocInfo.first),
CXXUnit->getASTContext().getLangOptions(),
@@ -2135,10 +2134,10 @@
// Lookup the identifier to determine whether we have a keyword.
std::pair<FileID, unsigned> LocInfo
= SourceMgr.getDecomposedLoc(Tok.getLocation());
+ bool Invalid = false;
std::pair<const char *, const char *> Buf
- = CXXUnit->getSourceManager().getBufferData(LocInfo.first,
- CXXUnit->getPreprocessor().getDiagnostics());
- if (!Buf.first)
+ = CXXUnit->getSourceManager().getBufferData(LocInfo.first, &Invalid);
+ if (Invalid)
return;
const char *StartPos= Buf.first + LocInfo.second;
diff --git a/tools/CIndex/CIndexCodeCompletion.cpp b/tools/CIndex/CIndexCodeCompletion.cpp
index 3b7674e..264e506 100644
--- a/tools/CIndex/CIndexCodeCompletion.cpp
+++ b/tools/CIndex/CIndexCodeCompletion.cpp
@@ -187,6 +187,9 @@
/// \brief Diagnostics produced while performing code completion.
llvm::SmallVector<StoredDiagnostic, 8> Diagnostics;
+ /// \brief Diag object
+ Diagnostic Diag;
+
/// \brief Language options used to adjust source locations.
LangOptions LangOpts;
@@ -202,7 +205,7 @@
};
AllocatedCXCodeCompleteResults::AllocatedCXCodeCompleteResults()
- : CXCodeCompleteResults(), Buffer(0) { }
+ : CXCodeCompleteResults(), Buffer(0), SourceMgr(Diag) { }
AllocatedCXCodeCompleteResults::~AllocatedCXCodeCompleteResults() {
for (unsigned I = 0, N = NumResults; I != N; ++I)