aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2010-03-16 00:06:06 +0000
committerDouglas Gregor <dgregor@apple.com>2010-03-16 00:06:06 +0000
commitf715ca12bfc9fddfde75f98a197424434428b821 (patch)
treebd19f3ce3d9a7850942f25d25c03633954e91faa /tools
parentf9b0a58a103784495309543dce4469e44861b4cc (diff)
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
Diffstat (limited to 'tools')
-rw-r--r--tools/CIndex/CIndex.cpp21
-rw-r--r--tools/CIndex/CIndexCodeCompletion.cpp5
2 files changed, 14 insertions, 12 deletions
diff --git a/tools/CIndex/CIndex.cpp b/tools/CIndex/CIndex.cpp
index c570ee4935..c100caeecb 100644
--- a/tools/CIndex/CIndex.cpp
+++ b/tools/CIndex/CIndex.cpp
@@ -1133,7 +1133,8 @@ clang_createTranslationUnitFromSourceFile(CXIndex CIdx,
// 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 @@ CXString clang_getTokenSpelling(CXTranslationUnit TU, CXToken CXTok) {
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 @@ void clang_tokenize(CXTranslationUnit TU, CXSourceRange Range,
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 @@ void clang_tokenize(CXTranslationUnit TU, CXSourceRange Range,
// 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 3b7674ec0d..264e5064dd 100644
--- a/tools/CIndex/CIndexCodeCompletion.cpp
+++ b/tools/CIndex/CIndexCodeCompletion.cpp
@@ -187,6 +187,9 @@ struct AllocatedCXCodeCompleteResults : public CXCodeCompleteResults {
/// \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 @@ struct AllocatedCXCodeCompleteResults : public CXCodeCompleteResults {
};
AllocatedCXCodeCompleteResults::AllocatedCXCodeCompleteResults()
- : CXCodeCompleteResults(), Buffer(0) { }
+ : CXCodeCompleteResults(), Buffer(0), SourceMgr(Diag) { }
AllocatedCXCodeCompleteResults::~AllocatedCXCodeCompleteResults() {
for (unsigned I = 0, N = NumResults; I != N; ++I)