summaryrefslogtreecommitdiffstats
path: root/clang/lib
diff options
context:
space:
mode:
Diffstat (limited to 'clang/lib')
-rw-r--r--clang/lib/AST/ASTContext.cpp22
-rw-r--r--clang/lib/Basic/SourceManager.cpp25
-rw-r--r--clang/lib/Frontend/ASTUnit.cpp9
-rw-r--r--clang/lib/Frontend/CompilerInstance.cpp2
-rw-r--r--clang/lib/Frontend/RewriteObjC.cpp18
-rw-r--r--clang/lib/Frontend/TextDiagnosticPrinter.cpp11
-rw-r--r--clang/lib/Lex/Lexer.cpp8
-rw-r--r--clang/lib/Lex/TokenLexer.cpp5
-rw-r--r--clang/lib/Rewrite/HTMLRewrite.cpp12
-rw-r--r--clang/lib/Rewrite/Rewriter.cpp13
-rw-r--r--clang/lib/Sema/SemaChecking.cpp5
11 files changed, 51 insertions, 79 deletions
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 6d90884ba94..07243365bf4 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -423,12 +423,13 @@ namespace {
/// (which requires a < after the Doxygen-comment delimiter). Otherwise,
/// we only return true when we find a non-member comment.
static bool
-isDoxygenComment(SourceManager &SourceMgr, Diagnostic &Diags,
- SourceRange Comment, bool Member = false) {
+isDoxygenComment(SourceManager &SourceMgr, SourceRange Comment,
+ bool Member = false) {
+ bool Invalid = false;
const char *BufferStart
= SourceMgr.getBufferData(SourceMgr.getFileID(Comment.getBegin()),
- Diags).first;
- if (!BufferStart)
+ &Invalid).first;
+ if (Invalid)
return false;
const char *Start = BufferStart + SourceMgr.getFileOffset(Comment.getBegin());
@@ -448,7 +449,7 @@ isDoxygenComment(SourceManager &SourceMgr, Diagnostic &Diags,
/// \brief Retrieve the comment associated with the given declaration, if
/// it has one.
-const char *ASTContext::getCommentForDecl(const Decl *D, Diagnostic &Diags) {
+const char *ASTContext::getCommentForDecl(const Decl *D) {
if (!D)
return 0;
@@ -492,15 +493,16 @@ const char *ASTContext::getCommentForDecl(const Decl *D, Diagnostic &Diags) {
// beginning of the file buffer.
std::pair<FileID, unsigned> DeclStartDecomp
= SourceMgr.getDecomposedLoc(DeclStartLoc);
+ bool Invalid = false;
const char *FileBufferStart
- = SourceMgr.getBufferData(DeclStartDecomp.first, Diags).first;
- if (!FileBufferStart)
+ = SourceMgr.getBufferData(DeclStartDecomp.first, &Invalid).first;
+ if (Invalid)
return 0;
// First check whether we have a comment for a member.
if (LastComment != Comments.end() &&
!isa<TagDecl>(D) && !isa<NamespaceDecl>(D) &&
- isDoxygenComment(SourceMgr, Diags, *LastComment, true)) {
+ isDoxygenComment(SourceMgr, *LastComment, true)) {
std::pair<FileID, unsigned> LastCommentEndDecomp
= SourceMgr.getDecomposedLoc(LastComment->getEnd());
if (DeclStartDecomp.first == LastCommentEndDecomp.first &&
@@ -532,7 +534,7 @@ const char *ASTContext::getCommentForDecl(const Decl *D, Diagnostic &Diags) {
return 0;
// Check that we actually have a Doxygen comment.
- if (!isDoxygenComment(SourceMgr, Diags, *LastComment))
+ if (!isDoxygenComment(SourceMgr, *LastComment))
return 0;
// Compute the starting line for the declaration and for the end of the
@@ -567,7 +569,7 @@ const char *ASTContext::getCommentForDecl(const Decl *D, Diagnostic &Diags) {
}
// If this comment is not a Doxygen comment, we're done.
- if (!isDoxygenComment(SourceMgr, Diags, *FirstComment)) {
+ if (!isDoxygenComment(SourceMgr, *FirstComment)) {
++FirstComment;
break;
}
diff --git a/clang/lib/Basic/SourceManager.cpp b/clang/lib/Basic/SourceManager.cpp
index b69ba53f7b2..ac2fe3d69e3 100644
--- a/clang/lib/Basic/SourceManager.cpp
+++ b/clang/lib/Basic/SourceManager.cpp
@@ -21,6 +21,7 @@
#include "llvm/System/Path.h"
#include <algorithm>
#include <string>
+#include <cstring>
#include <cstdio>
using namespace clang;
@@ -532,19 +533,17 @@ bool SourceManager::overrideFileContents(const FileEntry *SourceFile,
}
std::pair<const char*, const char*>
-SourceManager::getBufferData(FileID FID, llvm::StringRef &FileName,
- std::string &Error) const {
- const llvm::MemoryBuffer *Buf = getBuffer(FID).getBuffer(FileName, Error);
- if (!Error.empty())
- return std::make_pair((const char *)0, (const char *)0);
- return std::make_pair(Buf->getBufferStart(), Buf->getBufferEnd());
-}
-
-std::pair<const char*, const char*>
-SourceManager::getBufferData(FileID FID, Diagnostic &Diags) const {
- const llvm::MemoryBuffer *Buf = getBuffer(FID).getBuffer(Diags);
- if (!Buf)
- return std::make_pair((const char *)0, (const char *)0);
+SourceManager::getBufferData(FileID FID, bool *Invalid) const {
+ if (Invalid)
+ *Invalid = false;
+
+ const llvm::MemoryBuffer *Buf = getBuffer(FID).getBuffer(Diag);
+ if (!Buf) {
+ if (*Invalid)
+ *Invalid = true;
+ const char *FakeText = "";
+ return std::make_pair(FakeText, FakeText + strlen(FakeText));
+ }
return std::make_pair(Buf->getBufferStart(), Buf->getBufferEnd());
}
diff --git a/clang/lib/Frontend/ASTUnit.cpp b/clang/lib/Frontend/ASTUnit.cpp
index 63cf98d3da5..3bf1fab1c27 100644
--- a/clang/lib/Frontend/ASTUnit.cpp
+++ b/clang/lib/Frontend/ASTUnit.cpp
@@ -35,8 +35,9 @@
#include "llvm/System/Path.h"
using namespace clang;
-ASTUnit::ASTUnit(bool _MainFileIsAST)
- : MainFileIsAST(_MainFileIsAST), ConcurrencyCheckValue(CheckUnlocked) {
+ASTUnit::ASTUnit(Diagnostic &Diag, bool _MainFileIsAST)
+ : SourceMgr(Diag), MainFileIsAST(_MainFileIsAST),
+ ConcurrencyCheckValue(CheckUnlocked) {
}
ASTUnit::~ASTUnit() {
ConcurrencyCheckValue = CheckLocked;
@@ -146,7 +147,7 @@ ASTUnit *ASTUnit::LoadFromPCHFile(const std::string &Filename,
RemappedFile *RemappedFiles,
unsigned NumRemappedFiles,
bool CaptureDiagnostics) {
- llvm::OwningPtr<ASTUnit> AST(new ASTUnit(true));
+ llvm::OwningPtr<ASTUnit> AST(new ASTUnit(Diags, true));
AST->OnlyLocalDecls = OnlyLocalDecls;
AST->HeaderInfo.reset(new HeaderSearch(AST->getFileManager()));
@@ -311,7 +312,7 @@ ASTUnit *ASTUnit::LoadFromCompilerInvocation(CompilerInvocation *CI,
"FIXME: AST inputs not yet supported here!");
// Create the AST unit.
- AST.reset(new ASTUnit(false));
+ AST.reset(new ASTUnit(Diags, false));
AST->OnlyLocalDecls = OnlyLocalDecls;
AST->OriginalSourceFile = Clang.getFrontendOpts().Inputs[0].second;
diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp
index 25b804aba7f..c43118ce56b 100644
--- a/clang/lib/Frontend/CompilerInstance.cpp
+++ b/clang/lib/Frontend/CompilerInstance.cpp
@@ -185,7 +185,7 @@ void CompilerInstance::createFileManager() {
// Source Manager
void CompilerInstance::createSourceManager() {
- SourceMgr.reset(new SourceManager());
+ SourceMgr.reset(new SourceManager(getDiagnostics()));
}
// Preprocessor
diff --git a/clang/lib/Frontend/RewriteObjC.cpp b/clang/lib/Frontend/RewriteObjC.cpp
index cd3d4ee0b96..88890038510 100644
--- a/clang/lib/Frontend/RewriteObjC.cpp
+++ b/clang/lib/Frontend/RewriteObjC.cpp
@@ -706,11 +706,7 @@ void RewriteObjC::HandleTopLevelSingleDecl(Decl *D) {
void RewriteObjC::RewriteInclude() {
SourceLocation LocStart = SM->getLocForStartOfFile(MainFileID);
- std::pair<const char*, const char*> MainBuf = SM->getBufferData(MainFileID,
- Diags);
- if (!MainBuf.first)
- return;
-
+ std::pair<const char*, const char*> MainBuf = SM->getBufferData(MainFileID);
const char *MainBufStart = MainBuf.first;
const char *MainBufEnd = MainBuf.second;
size_t ImportLen = strlen("import");
@@ -735,11 +731,7 @@ void RewriteObjC::RewriteInclude() {
}
void RewriteObjC::RewriteTabs() {
- std::pair<const char*, const char*> MainBuf = SM->getBufferData(MainFileID,
- Diags);
- if (!MainBuf.first)
- return;
-
+ std::pair<const char*, const char*> MainBuf = SM->getBufferData(MainFileID);
const char *MainBufStart = MainBuf.first;
const char *MainBufEnd = MainBuf.second;
@@ -981,11 +973,7 @@ void RewriteObjC::RewriteCategoryDecl(ObjCCategoryDecl *CatDecl) {
}
void RewriteObjC::RewriteProtocolDecl(ObjCProtocolDecl *PDecl) {
- std::pair<const char*, const char*> MainBuf = SM->getBufferData(MainFileID,
- Diags);
- if (!MainBuf.first)
- return;
-
+ 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/clang/lib/Frontend/TextDiagnosticPrinter.cpp b/clang/lib/Frontend/TextDiagnosticPrinter.cpp
index 2b243fad248..946a6caa151 100644
--- a/clang/lib/Frontend/TextDiagnosticPrinter.cpp
+++ b/clang/lib/Frontend/TextDiagnosticPrinter.cpp
@@ -330,15 +330,14 @@ void TextDiagnosticPrinter::EmitCaretDiagnostic(SourceLocation Loc,
unsigned FileOffset = LocInfo.second;
// Get information about the buffer it points into.
- llvm::StringRef ErrorFileName;
- std::string ErrorStr;
+ bool Invalid = false;
std::pair<const char*, const char*> BufferInfo = SM.getBufferData(FID,
- ErrorFileName,
- ErrorStr);
- const char *BufStart = BufferInfo.first;
- if (!BufStart)
+ &Invalid);
+ 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/clang/lib/Lex/Lexer.cpp b/clang/lib/Lex/Lexer.cpp
index 149041559ab..d311b7e5ddc 100644
--- a/clang/lib/Lex/Lexer.cpp
+++ b/clang/lib/Lex/Lexer.cpp
@@ -229,12 +229,10 @@ unsigned Lexer::MeasureTokenLength(SourceLocation Loc,
// the token this macro expanded to.
Loc = SM.getInstantiationLoc(Loc);
std::pair<FileID, unsigned> LocInfo = SM.getDecomposedLoc(Loc);
- llvm::StringRef FileName;
- std::string ErrorStr;
+ bool Invalid = false;
std::pair<const char *,const char *> Buffer = SM.getBufferData(LocInfo.first,
- FileName,
- ErrorStr);
- if (!Buffer.first)
+ &Invalid);
+ if (Invalid)
return 0;
const char *StrData = Buffer.first+LocInfo.second;
diff --git a/clang/lib/Lex/TokenLexer.cpp b/clang/lib/Lex/TokenLexer.cpp
index 7ccaa89fe3e..8f687655430 100644
--- a/clang/lib/Lex/TokenLexer.cpp
+++ b/clang/lib/Lex/TokenLexer.cpp
@@ -439,9 +439,10 @@ bool TokenLexer::PasteTokens(Token &Tok) {
SourceManager &SourceMgr = PP.getSourceManager();
FileID LocFileID = SourceMgr.getFileID(ResultTokLoc);
+ bool Invalid = false;
const char *ScratchBufStart
- = SourceMgr.getBufferData(LocFileID, PP.getDiagnostics()).first;
- if (!ScratchBufStart)
+ = SourceMgr.getBufferData(LocFileID, &Invalid).first;
+ if (Invalid)
return false;
// Make a lexer to lex this string from. Lex just this one token.
diff --git a/clang/lib/Rewrite/HTMLRewrite.cpp b/clang/lib/Rewrite/HTMLRewrite.cpp
index 6fe3fc07db2..f325121d08d 100644
--- a/clang/lib/Rewrite/HTMLRewrite.cpp
+++ b/clang/lib/Rewrite/HTMLRewrite.cpp
@@ -22,7 +22,6 @@
#include "llvm/ADT/OwningPtr.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/raw_ostream.h"
-#include <cstdio>
using namespace clang;
@@ -44,15 +43,10 @@ void html::HighlightRange(Rewriter &R, SourceLocation B, SourceLocation E,
// Include the whole end token in the range.
EOffset += Lexer::MeasureTokenLength(E, R.getSourceMgr(), R.getLangOpts());
- llvm::StringRef FileName;
- std::string ErrorStr;
- const char *BufferStart = SM.getBufferData(FID, FileName, ErrorStr).first;
- if (!BufferStart) {
- // FIXME: Add a diagnostic object somewhere?
- fprintf(stderr, "error: cannot open file '%s': %s\n",
- FileName.str().c_str(), ErrorStr.c_str());
+ bool Invalid = false;
+ const char *BufferStart = SM.getBufferData(FID, &Invalid).first;
+ if (Invalid)
return;
- }
HighlightRange(R.getEditBuffer(FID), BOffset, EOffset,
BufferStart, StartTag, EndTag);
diff --git a/clang/lib/Rewrite/Rewriter.cpp b/clang/lib/Rewrite/Rewriter.cpp
index 50f9fa14f16..9744496ac4f 100644
--- a/clang/lib/Rewrite/Rewriter.cpp
+++ b/clang/lib/Rewrite/Rewriter.cpp
@@ -18,7 +18,6 @@
#include "clang/Lex/Lexer.h"
#include "clang/Basic/SourceManager.h"
#include "llvm/Support/raw_ostream.h"
-#include <cstdio>
using namespace clang;
void RewriteBuffer::RemoveText(unsigned OrigOffset, unsigned Size) {
@@ -166,17 +165,7 @@ RewriteBuffer &Rewriter::getEditBuffer(FileID FID) {
return I->second;
I = RewriteBuffers.insert(I, std::make_pair(FID, RewriteBuffer()));
- llvm::StringRef FileName;
- std::string ErrorStr;
-
- std::pair<const char*, const char*> MB
- = SourceMgr->getBufferData(FID, FileName, ErrorStr);
- if (!MB.first) {
- // FIXME: Add a diagnostic object somewhere?
- fprintf(stderr, "error: cannot open file '%s': %s\n",
- FileName.str().c_str(), ErrorStr.c_str());
- }
-
+ std::pair<const char*, const char*> MB = SourceMgr->getBufferData(FID);
I->second.Initialize(MB.first, MB.second);
return I->second;
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 7e66d7e910d..5ec01d00116 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -59,9 +59,10 @@ SourceLocation Sema::getLocationOfStringLiteralByte(const StringLiteral *SL,
// Re-lex the token to get its length and original spelling.
std::pair<FileID, unsigned> LocInfo =
SourceMgr.getDecomposedLoc(StrTokSpellingLoc);
+ bool Invalid = false;
std::pair<const char *,const char *> Buffer =
- SourceMgr.getBufferData(LocInfo.first, Diags);
- if (!Buffer.first)
+ SourceMgr.getBufferData(LocInfo.first, &Invalid);
+ if (Invalid)
return StrTokSpellingLoc;
const char *StrData = Buffer.first+LocInfo.second;
OpenPOWER on IntegriCloud