aboutsummaryrefslogtreecommitdiff
path: root/lib/Frontend
diff options
context:
space:
mode:
authorRoman Divacky <rdivacky@FreeBSD.org>2010-04-06 15:53:59 +0000
committerRoman Divacky <rdivacky@FreeBSD.org>2010-04-06 15:53:59 +0000
commit60bfabcd8ce617297c0d231f77d14ab507e98796 (patch)
tree59c928209f8007777dd96568b026bdfe200691de /lib/Frontend
parent2c56c396ce5990954f85194029eeb391bc3529ff (diff)
downloadsrc-60bfabcd8ce617297c0d231f77d14ab507e98796.tar.gz
src-60bfabcd8ce617297c0d231f77d14ab507e98796.zip
Notes
Diffstat (limited to 'lib/Frontend')
-rw-r--r--lib/Frontend/ASTMerge.cpp5
-rw-r--r--lib/Frontend/ASTUnit.cpp78
-rw-r--r--lib/Frontend/CompilerInstance.cpp15
-rw-r--r--lib/Frontend/FrontendAction.cpp5
-rw-r--r--lib/Frontend/PCHReader.cpp5
5 files changed, 68 insertions, 40 deletions
diff --git a/lib/Frontend/ASTMerge.cpp b/lib/Frontend/ASTMerge.cpp
index 2228ea45df33..b0faf0ae86b1 100644
--- a/lib/Frontend/ASTMerge.cpp
+++ b/lib/Frontend/ASTMerge.cpp
@@ -12,6 +12,7 @@
#include "clang/AST/ASTContext.h"
#include "clang/AST/ASTDiagnostic.h"
#include "clang/AST/ASTImporter.h"
+#include "clang/Basic/Diagnostic.h"
using namespace clang;
@@ -36,9 +37,9 @@ void ASTMergeAction::ExecuteAction() {
CI.getASTContext().getLangOptions());
CI.getDiagnostics().SetArgToStringFn(&FormatASTNodeDiagnosticArgument,
&CI.getASTContext());
+ llvm::IntrusiveRefCntPtr<Diagnostic> Diags(&CI.getDiagnostics());
for (unsigned I = 0, N = ASTFiles.size(); I != N; ++I) {
- ASTUnit *Unit = ASTUnit::LoadFromPCHFile(ASTFiles[I], CI.getDiagnostics(),
- false);
+ ASTUnit *Unit = ASTUnit::LoadFromPCHFile(ASTFiles[I], Diags, false);
if (!Unit)
continue;
diff --git a/lib/Frontend/ASTUnit.cpp b/lib/Frontend/ASTUnit.cpp
index 7243f709cc65..427bd6a9b803 100644
--- a/lib/Frontend/ASTUnit.cpp
+++ b/lib/Frontend/ASTUnit.cpp
@@ -35,10 +35,9 @@
#include "llvm/System/Path.h"
using namespace clang;
-ASTUnit::ASTUnit(Diagnostic &Diag, bool _MainFileIsAST)
- : SourceMgr(Diag), MainFileIsAST(_MainFileIsAST),
- ConcurrencyCheckValue(CheckUnlocked) {
-}
+ASTUnit::ASTUnit(bool _MainFileIsAST)
+ : MainFileIsAST(_MainFileIsAST), ConcurrencyCheckValue(CheckUnlocked) { }
+
ASTUnit::~ASTUnit() {
ConcurrencyCheckValue = CheckLocked;
for (unsigned I = 0, N = TemporaryFiles.size(); I != N; ++I)
@@ -142,18 +141,29 @@ const std::string &ASTUnit::getPCHFileName() {
}
ASTUnit *ASTUnit::LoadFromPCHFile(const std::string &Filename,
- Diagnostic &Diags,
+ llvm::IntrusiveRefCntPtr<Diagnostic> Diags,
bool OnlyLocalDecls,
RemappedFile *RemappedFiles,
unsigned NumRemappedFiles,
bool CaptureDiagnostics) {
- llvm::OwningPtr<ASTUnit> AST(new ASTUnit(Diags, true));
+ llvm::OwningPtr<ASTUnit> AST(new ASTUnit(true));
+
+ if (!Diags.getPtr()) {
+ // No diagnostics engine was provided, so create our own diagnostics object
+ // with the default options.
+ DiagnosticOptions DiagOpts;
+ Diags = CompilerInstance::createDiagnostics(DiagOpts, 0, 0);
+ }
+
AST->OnlyLocalDecls = OnlyLocalDecls;
+ AST->Diagnostics = Diags;
+ AST->FileMgr.reset(new FileManager);
+ AST->SourceMgr.reset(new SourceManager(AST->getDiagnostics()));
AST->HeaderInfo.reset(new HeaderSearch(AST->getFileManager()));
// If requested, capture diagnostics in the ASTUnit.
- CaptureDroppedDiagnostics Capture(CaptureDiagnostics, Diags,
- AST->Diagnostics);
+ CaptureDroppedDiagnostics Capture(CaptureDiagnostics, AST->getDiagnostics(),
+ AST->StoredDiagnostics);
for (unsigned I = 0; I != NumRemappedFiles; ++I) {
// Create the file entry for the file that we're mapping from.
@@ -162,7 +172,7 @@ ASTUnit *ASTUnit::LoadFromPCHFile(const std::string &Filename,
RemappedFiles[I].second->getBufferSize(),
0);
if (!FromFile) {
- Diags.Report(diag::err_fe_remap_missing_from_file)
+ AST->getDiagnostics().Report(diag::err_fe_remap_missing_from_file)
<< RemappedFiles[I].first;
delete RemappedFiles[I].second;
continue;
@@ -186,7 +196,7 @@ ASTUnit *ASTUnit::LoadFromPCHFile(const std::string &Filename,
llvm::OwningPtr<ExternalASTSource> Source;
Reader.reset(new PCHReader(AST->getSourceManager(), AST->getFileManager(),
- Diags));
+ AST->getDiagnostics()));
Reader->setListener(new PCHInfoCollector(LangInfo, HeaderInfo, TargetTriple,
Predefines, Counter));
@@ -196,7 +206,7 @@ ASTUnit *ASTUnit::LoadFromPCHFile(const std::string &Filename,
case PCHReader::Failure:
case PCHReader::IgnorePCH:
- Diags.Report(diag::err_fe_unable_to_load_pch);
+ AST->getDiagnostics().Report(diag::err_fe_unable_to_load_pch);
return NULL;
}
@@ -212,8 +222,10 @@ ASTUnit *ASTUnit::LoadFromPCHFile(const std::string &Filename,
TargetOpts.CPU = "";
TargetOpts.Features.clear();
TargetOpts.Triple = TargetTriple;
- AST->Target.reset(TargetInfo::CreateTargetInfo(Diags, TargetOpts));
- AST->PP.reset(new Preprocessor(Diags, LangInfo, *AST->Target.get(),
+ AST->Target.reset(TargetInfo::CreateTargetInfo(AST->getDiagnostics(),
+ TargetOpts));
+ AST->PP.reset(new Preprocessor(AST->getDiagnostics(), LangInfo,
+ *AST->Target.get(),
AST->getSourceManager(), HeaderInfo));
Preprocessor &PP = *AST->PP.get();
@@ -276,7 +288,7 @@ public:
}
ASTUnit *ASTUnit::LoadFromCompilerInvocation(CompilerInvocation *CI,
- Diagnostic &Diags,
+ llvm::IntrusiveRefCntPtr<Diagnostic> Diags,
bool OnlyLocalDecls,
bool CaptureDiagnostics) {
// Create the compiler instance to use for building the AST.
@@ -284,17 +296,23 @@ ASTUnit *ASTUnit::LoadFromCompilerInvocation(CompilerInvocation *CI,
llvm::OwningPtr<ASTUnit> AST;
llvm::OwningPtr<TopLevelDeclTrackerAction> Act;
+ if (!Diags.getPtr()) {
+ // No diagnostics engine was provided, so create our own diagnostics object
+ // with the default options.
+ DiagnosticOptions DiagOpts;
+ Diags = CompilerInstance::createDiagnostics(DiagOpts, 0, 0);
+ }
+
Clang.setInvocation(CI);
- Clang.setDiagnostics(&Diags);
- Clang.setDiagnosticClient(Diags.getClient());
+ Clang.setDiagnostics(Diags.getPtr());
+ Clang.setDiagnosticClient(Diags->getClient());
// Create the target instance.
Clang.setTarget(TargetInfo::CreateTargetInfo(Clang.getDiagnostics(),
Clang.getTargetOpts()));
if (!Clang.hasTarget()) {
Clang.takeDiagnosticClient();
- Clang.takeDiagnostics();
return 0;
}
@@ -310,14 +328,17 @@ ASTUnit *ASTUnit::LoadFromCompilerInvocation(CompilerInvocation *CI,
"FIXME: AST inputs not yet supported here!");
// Create the AST unit.
- AST.reset(new ASTUnit(Diags, false));
+ AST.reset(new ASTUnit(false));
+ AST->Diagnostics = Diags;
+ AST->FileMgr.reset(new FileManager);
+ AST->SourceMgr.reset(new SourceManager(AST->getDiagnostics()));
AST->OnlyLocalDecls = OnlyLocalDecls;
AST->OriginalSourceFile = Clang.getFrontendOpts().Inputs[0].second;
// Capture any diagnostics that would otherwise be dropped.
CaptureDroppedDiagnostics Capture(CaptureDiagnostics,
Clang.getDiagnostics(),
- AST->Diagnostics);
+ AST->StoredDiagnostics);
// Create a file manager object to provide access to and cache the filesystem.
Clang.setFileManager(&AST->getFileManager());
@@ -346,7 +367,6 @@ ASTUnit *ASTUnit::LoadFromCompilerInvocation(CompilerInvocation *CI,
Act->EndSourceFile();
Clang.takeDiagnosticClient();
- Clang.takeDiagnostics();
Clang.takeInvocation();
AST->Invocation.reset(Clang.takeInvocation());
@@ -356,18 +376,24 @@ error:
Clang.takeSourceManager();
Clang.takeFileManager();
Clang.takeDiagnosticClient();
- Clang.takeDiagnostics();
return 0;
}
ASTUnit *ASTUnit::LoadFromCommandLine(const char **ArgBegin,
const char **ArgEnd,
- Diagnostic &Diags,
+ llvm::IntrusiveRefCntPtr<Diagnostic> Diags,
llvm::StringRef ResourceFilesPath,
bool OnlyLocalDecls,
RemappedFile *RemappedFiles,
unsigned NumRemappedFiles,
bool CaptureDiagnostics) {
+ if (!Diags.getPtr()) {
+ // No diagnostics engine was provided, so create our own diagnostics object
+ // with the default options.
+ DiagnosticOptions DiagOpts;
+ Diags = CompilerInstance::createDiagnostics(DiagOpts, 0, 0);
+ }
+
llvm::SmallVector<const char *, 16> Args;
Args.push_back("<clang>"); // FIXME: Remove dummy argument.
Args.insert(Args.end(), ArgBegin, ArgEnd);
@@ -378,7 +404,7 @@ ASTUnit *ASTUnit::LoadFromCommandLine(const char **ArgBegin,
// FIXME: We shouldn't have to pass in the path info.
driver::Driver TheDriver("clang", "/", llvm::sys::getHostTriple(),
- "a.out", false, false, Diags);
+ "a.out", false, false, *Diags);
// Don't check that inputs exist, they have been remapped.
TheDriver.setCheckInputsExist(false);
@@ -393,13 +419,13 @@ ASTUnit *ASTUnit::LoadFromCommandLine(const char **ArgBegin,
llvm::SmallString<256> Msg;
llvm::raw_svector_ostream OS(Msg);
C->PrintJob(OS, C->getJobs(), "; ", true);
- Diags.Report(diag::err_fe_expected_compiler_job) << OS.str();
+ Diags->Report(diag::err_fe_expected_compiler_job) << OS.str();
return 0;
}
const driver::Command *Cmd = cast<driver::Command>(*Jobs.begin());
if (llvm::StringRef(Cmd->getCreator().getName()) != "clang") {
- Diags.Report(diag::err_fe_expected_clang_command);
+ Diags->Report(diag::err_fe_expected_clang_command);
return 0;
}
@@ -407,7 +433,7 @@ ASTUnit *ASTUnit::LoadFromCommandLine(const char **ArgBegin,
llvm::OwningPtr<CompilerInvocation> CI(new CompilerInvocation);
CompilerInvocation::CreateFromArgs(*CI, (const char**) CCArgs.data(),
(const char**) CCArgs.data()+CCArgs.size(),
- Diags);
+ *Diags);
// Override any files that need remapping
for (unsigned I = 0; I != NumRemappedFiles; ++I)
diff --git a/lib/Frontend/CompilerInstance.cpp b/lib/Frontend/CompilerInstance.cpp
index 879e9f681de9..1f915e3713d3 100644
--- a/lib/Frontend/CompilerInstance.cpp
+++ b/lib/Frontend/CompilerInstance.cpp
@@ -52,7 +52,7 @@ void CompilerInstance::setInvocation(CompilerInvocation *Value) {
}
void CompilerInstance::setDiagnostics(Diagnostic *Value) {
- Diagnostics.reset(Value);
+ Diagnostics = Value;
}
void CompilerInstance::setDiagnosticClient(DiagnosticClient *Value) {
@@ -130,15 +130,16 @@ static void SetUpBuildDumpLog(const DiagnosticOptions &DiagOpts,
}
void CompilerInstance::createDiagnostics(int Argc, char **Argv) {
- Diagnostics.reset(createDiagnostics(getDiagnosticOpts(), Argc, Argv));
+ Diagnostics = createDiagnostics(getDiagnosticOpts(), Argc, Argv);
if (Diagnostics)
DiagClient.reset(Diagnostics->getClient());
}
-Diagnostic *CompilerInstance::createDiagnostics(const DiagnosticOptions &Opts,
- int Argc, char **Argv) {
- llvm::OwningPtr<Diagnostic> Diags(new Diagnostic());
+llvm::IntrusiveRefCntPtr<Diagnostic>
+CompilerInstance::createDiagnostics(const DiagnosticOptions &Opts,
+ int Argc, char **Argv) {
+ llvm::IntrusiveRefCntPtr<Diagnostic> Diags(new Diagnostic());
// Create the diagnostic client for reporting errors or for
// implementing -verify.
@@ -152,7 +153,7 @@ Diagnostic *CompilerInstance::createDiagnostics(const DiagnosticOptions &Opts,
DiagClient.reset(new TextDiagnosticPrinter(llvm::errs(), Opts));
Diags->setClient(DiagClient.take());
Diags->Report(diag::err_fe_stderr_binary);
- return Diags.take();
+ return Diags;
} else {
DiagClient.reset(new BinaryDiagnosticSerializer(llvm::errs()));
}
@@ -171,7 +172,7 @@ Diagnostic *CompilerInstance::createDiagnostics(const DiagnosticOptions &Opts,
// Configure our handling of diagnostics.
ProcessWarningOptions(*Diags, Opts);
- return Diags.take();
+ return Diags;
}
// File Manager
diff --git a/lib/Frontend/FrontendAction.cpp b/lib/Frontend/FrontendAction.cpp
index 110612d03b58..87fc1227b2f2 100644
--- a/lib/Frontend/FrontendAction.cpp
+++ b/lib/Frontend/FrontendAction.cpp
@@ -45,8 +45,9 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI,
"Attempt to pass AST file to preprocessor only action!");
assert(hasASTSupport() && "This action does not have AST support!");
+ llvm::IntrusiveRefCntPtr<Diagnostic> Diags(&CI.getDiagnostics());
std::string Error;
- ASTUnit *AST = ASTUnit::LoadFromPCHFile(Filename, CI.getDiagnostics());
+ ASTUnit *AST = ASTUnit::LoadFromPCHFile(Filename, Diags);
if (!AST)
goto failure;
@@ -135,7 +136,7 @@ void FrontendAction::Execute() {
// simplest way to reuse the logic in ParseAST.
const char *EmptyStr = "";
llvm::MemoryBuffer *SB =
- llvm::MemoryBuffer::getMemBuffer(EmptyStr, EmptyStr, "<dummy input>");
+ llvm::MemoryBuffer::getMemBuffer(EmptyStr, "<dummy input>");
CI.getSourceManager().createMainFileIDForMemBuffer(SB);
} else {
if (!CI.InitializeSourceManager(getCurrentFile()))
diff --git a/lib/Frontend/PCHReader.cpp b/lib/Frontend/PCHReader.cpp
index 6d39952e9d27..b96c04d0a8e0 100644
--- a/lib/Frontend/PCHReader.cpp
+++ b/lib/Frontend/PCHReader.cpp
@@ -950,9 +950,8 @@ PCHReader::PCHReadResult PCHReader::ReadSLocEntryRecord(unsigned ID) {
}
llvm::MemoryBuffer *Buffer
- = llvm::MemoryBuffer::getMemBuffer(BlobStart,
- BlobStart + BlobLen - 1,
- Name);
+ = llvm::MemoryBuffer::getMemBuffer(llvm::StringRef(BlobStart, BlobLen - 1),
+ Name);
FileID BufferID = SourceMgr.createFileIDForMemBuffer(Buffer, ID, Offset);
if (strcmp(Name, "<built-in>") == 0) {