aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Frontend
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2011-05-02 19:39:53 +0000
committerDimitry Andric <dim@FreeBSD.org>2011-05-02 19:39:53 +0000
commit01af97d3b23bded2b2b21af19bbc6e4cce49e5b3 (patch)
tree64a10f4c4154739d4a8191d7e1b52ce497f4ebd6 /lib/Frontend
parentc3b054d250cdca485c71845089c316e10610ebad (diff)
downloadsrc-01af97d3b23bded2b2b21af19bbc6e4cce49e5b3.tar.gz
src-01af97d3b23bded2b2b21af19bbc6e4cce49e5b3.zip
Vendor import of clang trunk r130700:vendor/clang/clang-r130700
Notes
Notes: svn path=/vendor/clang/dist/; revision=221339 svn path=/vendor/clang/clang-r130700/; revision=221340; tag=vendor/clang/clang-r130700
Diffstat (limited to 'lib/Frontend')
-rw-r--r--lib/Frontend/ASTConsumers.cpp39
-rw-r--r--lib/Frontend/ASTUnit.cpp463
-rw-r--r--lib/Frontend/CMakeLists.txt6
-rw-r--r--lib/Frontend/CacheTokens.cpp6
-rw-r--r--lib/Frontend/CompilerInstance.cpp107
-rw-r--r--lib/Frontend/CompilerInvocation.cpp117
-rw-r--r--lib/Frontend/CreateInvocationFromCommandLine.cpp90
-rw-r--r--lib/Frontend/DeclXML.cpp183
-rw-r--r--lib/Frontend/DependencyFile.cpp2
-rw-r--r--lib/Frontend/DocumentXML.cpp381
-rw-r--r--lib/Frontend/FrontendAction.cpp31
-rw-r--r--lib/Frontend/FrontendActions.cpp7
-rw-r--r--lib/Frontend/HeaderIncludeGen.cpp32
-rw-r--r--lib/Frontend/InitHeaderSearch.cpp124
-rw-r--r--lib/Frontend/InitPreprocessor.cpp37
-rw-r--r--lib/Frontend/LogDiagnosticPrinter.cpp146
-rw-r--r--lib/Frontend/MultiplexConsumer.cpp19
-rw-r--r--lib/Frontend/PrintPreprocessedOutput.cpp2
-rw-r--r--lib/Frontend/StmtXML.cpp439
-rw-r--r--lib/Frontend/TextDiagnosticPrinter.cpp34
-rw-r--r--lib/Frontend/TypeXML.cpp119
21 files changed, 861 insertions, 1523 deletions
diff --git a/lib/Frontend/ASTConsumers.cpp b/lib/Frontend/ASTConsumers.cpp
index 92fb1e8cbeb0..ecd6ef442aea 100644
--- a/lib/Frontend/ASTConsumers.cpp
+++ b/lib/Frontend/ASTConsumers.cpp
@@ -12,7 +12,6 @@
//===----------------------------------------------------------------------===//
#include "clang/Frontend/ASTConsumers.h"
-#include "clang/Frontend/DocumentXML.h"
#include "clang/Basic/Diagnostic.h"
#include "clang/Basic/SourceManager.h"
#include "clang/Basic/FileManager.h"
@@ -51,39 +50,6 @@ ASTConsumer *clang::CreateASTPrinter(llvm::raw_ostream* out) {
return new ASTPrinter(out);
}
-//===----------------------------------------------------------------------===//
-/// ASTPrinterXML - XML-printer of ASTs
-
-namespace {
- class ASTPrinterXML : public ASTConsumer {
- DocumentXML Doc;
-
- public:
- ASTPrinterXML(llvm::raw_ostream& o) : Doc("CLANG_XML", o) {}
-
- void Initialize(ASTContext &Context) {
- Doc.initialize(Context);
- }
-
- virtual void HandleTranslationUnit(ASTContext &Ctx) {
- Doc.addSubNode("TranslationUnit");
- for (DeclContext::decl_iterator
- D = Ctx.getTranslationUnitDecl()->decls_begin(),
- DEnd = Ctx.getTranslationUnitDecl()->decls_end();
- D != DEnd;
- ++D)
- Doc.PrintDecl(*D);
- Doc.toParent();
- Doc.finalize();
- }
- };
-} // end anonymous namespace
-
-
-ASTConsumer *clang::CreateASTPrinterXML(llvm::raw_ostream* out) {
- return new ASTPrinterXML(out ? *out : llvm::outs());
-}
-
ASTConsumer *clang::CreateASTDumper() {
return new ASTPrinter(0, true);
}
@@ -369,8 +335,9 @@ void DeclContextPrinter::PrintDeclContext(const DeclContext* DC,
Out << "<field> " << FD << '\n';
break;
}
- case Decl::Typedef: {
- TypedefDecl* TD = cast<TypedefDecl>(*I);
+ case Decl::Typedef:
+ case Decl::TypeAlias: {
+ TypedefNameDecl* TD = cast<TypedefNameDecl>(*I);
Out << "<typedef> " << TD << '\n';
break;
}
diff --git a/lib/Frontend/ASTUnit.cpp b/lib/Frontend/ASTUnit.cpp
index a7942e6090c8..2a1244841e3b 100644
--- a/lib/Frontend/ASTUnit.cpp
+++ b/lib/Frontend/ASTUnit.cpp
@@ -20,6 +20,8 @@
#include "clang/Driver/Compilation.h"
#include "clang/Driver/Driver.h"
#include "clang/Driver/Job.h"
+#include "clang/Driver/ArgList.h"
+#include "clang/Driver/Options.h"
#include "clang/Driver/Tool.h"
#include "clang/Frontend/CompilerInstance.h"
#include "clang/Frontend/FrontendActions.h"
@@ -34,6 +36,7 @@
#include "clang/Basic/TargetOptions.h"
#include "clang/Basic/TargetInfo.h"
#include "clang/Basic/Diagnostic.h"
+#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringSet.h"
#include "llvm/Support/Atomic.h"
@@ -42,6 +45,7 @@
#include "llvm/Support/Path.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Support/Timer.h"
+#include "llvm/Support/CrashRecoveryContext.h"
#include <cstdlib>
#include <cstdio>
#include <sys/stat.h>
@@ -90,8 +94,10 @@ const unsigned DefaultPreambleRebuildInterval = 5;
static llvm::sys::cas_flag ActiveASTUnitObjects;
ASTUnit::ASTUnit(bool _MainFileIsAST)
- : CaptureDiagnostics(false), MainFileIsAST(_MainFileIsAST),
+ : OnlyLocalDecls(false), CaptureDiagnostics(false),
+ MainFileIsAST(_MainFileIsAST),
CompleteTranslationUnit(true), WantTiming(getenv("LIBCLANG_TIMING")),
+ OwnsRemappedFileBuffers(true),
NumStoredDiagnosticsFromDriver(0),
ConcurrencyCheckValue(CheckUnlocked),
PreambleRebuildCounter(0), SavedMainFileBuffer(0), PreambleBuffer(0),
@@ -116,7 +122,7 @@ ASTUnit::~ASTUnit() {
// perform this operation here because we explicitly request that the
// compiler instance *not* free these buffers for each invocation of the
// parser.
- if (Invocation.get()) {
+ if (Invocation.getPtr() && OwnsRemappedFileBuffers) {
PreprocessorOptions &PPOpts = Invocation->getPreprocessorOpts();
for (PreprocessorOptions::remapped_file_buffer_iterator
FB = PPOpts.remapped_file_buffer_begin(),
@@ -496,33 +502,69 @@ ASTUnit *ASTUnit::LoadFromASTFile(const std::string &Filename,
unsigned NumRemappedFiles,
bool CaptureDiagnostics) {
llvm::OwningPtr<ASTUnit> AST(new ASTUnit(true));
+
+ // Recover resources if we crash before exiting this method.
+ llvm::CrashRecoveryContextCleanupRegistrar<ASTUnit>
+ ASTUnitCleanup(AST.get());
+ llvm::CrashRecoveryContextCleanupRegistrar<Diagnostic,
+ llvm::CrashRecoveryContextReleaseRefCleanup<Diagnostic> >
+ DiagCleanup(Diags.getPtr());
+
ConfigureDiags(Diags, 0, 0, *AST, CaptureDiagnostics);
AST->OnlyLocalDecls = OnlyLocalDecls;
AST->CaptureDiagnostics = CaptureDiagnostics;
AST->Diagnostics = Diags;
- AST->FileMgr.reset(new FileManager(FileSystemOpts));
- AST->SourceMgr.reset(new SourceManager(AST->getDiagnostics(),
- AST->getFileManager()));
+ AST->FileMgr = new FileManager(FileSystemOpts);
+ AST->SourceMgr = new SourceManager(AST->getDiagnostics(),
+ AST->getFileManager());
AST->HeaderInfo.reset(new HeaderSearch(AST->getFileManager()));
for (unsigned I = 0; I != NumRemappedFiles; ++I) {
- // Create the file entry for the file that we're mapping from.
- const FileEntry *FromFile
- = AST->getFileManager().getVirtualFile(RemappedFiles[I].first,
- RemappedFiles[I].second->getBufferSize(),
- 0);
- if (!FromFile) {
- AST->getDiagnostics().Report(diag::err_fe_remap_missing_from_file)
- << RemappedFiles[I].first;
- delete RemappedFiles[I].second;
- continue;
+ FilenameOrMemBuf fileOrBuf = RemappedFiles[I].second;
+ if (const llvm::MemoryBuffer *
+ memBuf = fileOrBuf.dyn_cast<const llvm::MemoryBuffer *>()) {
+ // Create the file entry for the file that we're mapping from.
+ const FileEntry *FromFile
+ = AST->getFileManager().getVirtualFile(RemappedFiles[I].first,
+ memBuf->getBufferSize(),
+ 0);
+ if (!FromFile) {
+ AST->getDiagnostics().Report(diag::err_fe_remap_missing_from_file)
+ << RemappedFiles[I].first;
+ delete memBuf;
+ continue;
+ }
+
+ // Override the contents of the "from" file with the contents of
+ // the "to" file.
+ AST->getSourceManager().overrideFileContents(FromFile, memBuf);
+
+ } else {
+ const char *fname = fileOrBuf.get<const char *>();
+ const FileEntry *ToFile = AST->FileMgr->getFile(fname);
+ if (!ToFile) {
+ AST->getDiagnostics().Report(diag::err_fe_remap_missing_to_file)
+ << RemappedFiles[I].first << fname;
+ continue;
+ }
+
+ // Create the file entry for the file that we're mapping from.
+ const FileEntry *FromFile
+ = AST->getFileManager().getVirtualFile(RemappedFiles[I].first,
+ ToFile->getSize(),
+ 0);
+ if (!FromFile) {
+ AST->getDiagnostics().Report(diag::err_fe_remap_missing_from_file)
+ << RemappedFiles[I].first;
+ delete memBuf;
+ continue;
+ }
+
+ // Override the contents of the "from" file with the contents of
+ // the "to" file.
+ AST->getSourceManager().overrideFileContents(FromFile, ToFile);
}
-
- // Override the contents of the "from" file with the contents of
- // the "to" file.
- AST->getSourceManager().overrideFileContents(FromFile,
- RemappedFiles[I].second);
}
// Gather Info for preprocessor construction later on.
@@ -563,12 +605,11 @@ ASTUnit *ASTUnit::LoadFromASTFile(const std::string &Filename,
TargetOpts.CPU = "";
TargetOpts.Features.clear();
TargetOpts.Triple = TargetTriple;
- 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();
+ AST->Target = TargetInfo::CreateTargetInfo(AST->getDiagnostics(),
+ TargetOpts);
+ AST->PP = new Preprocessor(AST->getDiagnostics(), LangInfo, *AST->Target,
+ AST->getSourceManager(), HeaderInfo);
+ Preprocessor &PP = *AST->PP;
PP.setPredefines(Reader->getSuggestedPredefines());
PP.setCounterValue(Counter);
@@ -576,14 +617,14 @@ ASTUnit *ASTUnit::LoadFromASTFile(const std::string &Filename,
// Create and initialize the ASTContext.
- AST->Ctx.reset(new ASTContext(LangInfo,
- AST->getSourceManager(),
- *AST->Target.get(),
- PP.getIdentifierTable(),
- PP.getSelectorTable(),
- PP.getBuiltinInfo(),
- /* size_reserve = */0));
- ASTContext &Context = *AST->Ctx.get();
+ AST->Ctx = new ASTContext(LangInfo,
+ AST->getSourceManager(),
+ *AST->Target,
+ PP.getIdentifierTable(),
+ PP.getSelectorTable(),
+ PP.getBuiltinInfo(),
+ /* size_reserve = */0);
+ ASTContext &Context = *AST->Ctx;
Reader->InitializeContext(Context);
@@ -803,25 +844,30 @@ bool ASTUnit::Parse(llvm::MemoryBuffer *OverrideMainBuffer) {
delete SavedMainFileBuffer;
SavedMainFileBuffer = 0;
- if (!Invocation.get()) {
+ if (!Invocation) {
delete OverrideMainBuffer;
return true;
}
// Create the compiler instance to use for building the AST.
- CompilerInstance Clang;
- Clang.setInvocation(Invocation.take());
- OriginalSourceFile = Clang.getFrontendOpts().Inputs[0].second;
+ llvm::OwningPtr<CompilerInstance> Clang(new CompilerInstance());
+
+ // Recover resources if we crash before exiting this method.
+ llvm::CrashRecoveryContextCleanupRegistrar<CompilerInstance>
+ CICleanup(Clang.get());
+
+ Clang->setInvocation(&*Invocation);
+ OriginalSourceFile = Clang->getFrontendOpts().Inputs[0].second;
// Set up diagnostics, capturing any diagnostics that would
// otherwise be dropped.
- Clang.setDiagnostics(&getDiagnostics());
+ Clang->setDiagnostics(&getDiagnostics());
// Create the target instance.
- Clang.getTargetOpts().Features = TargetFeatures;
- Clang.setTarget(TargetInfo::CreateTargetInfo(Clang.getDiagnostics(),
- Clang.getTargetOpts()));
- if (!Clang.hasTarget()) {
+ Clang->getTargetOpts().Features = TargetFeatures;
+ Clang->setTarget(TargetInfo::CreateTargetInfo(Clang->getDiagnostics(),
+ Clang->getTargetOpts()));
+ if (!Clang->hasTarget()) {
delete OverrideMainBuffer;
return true;
}
@@ -830,23 +876,23 @@ bool ASTUnit::Parse(llvm::MemoryBuffer *OverrideMainBuffer) {
//
// FIXME: We shouldn't need to do this, the target should be immutable once
// created. This complexity should be lifted elsewhere.
- Clang.getTarget().setForcedLangOptions(Clang.getLangOpts());
+ Clang->getTarget().setForcedLangOptions(Clang->getLangOpts());
- assert(Clang.getFrontendOpts().Inputs.size() == 1 &&
+ assert(Clang->getFrontendOpts().Inputs.size() == 1 &&
"Invocation must have exactly one source file!");
- assert(Clang.getFrontendOpts().Inputs[0].first != IK_AST &&
+ assert(Clang->getFrontendOpts().Inputs[0].first != IK_AST &&
"FIXME: AST inputs not yet supported here!");
- assert(Clang.getFrontendOpts().Inputs[0].first != IK_LLVM_IR &&
+ assert(Clang->getFrontendOpts().Inputs[0].first != IK_LLVM_IR &&
"IR inputs not support here!");
// Configure the various subsystems.
// FIXME: Should we retain the previous file manager?
- FileSystemOpts = Clang.getFileSystemOpts();
- FileMgr.reset(new FileManager(Clang.getFileSystemOpts()));
- SourceMgr.reset(new SourceManager(getDiagnostics(), *FileMgr));
+ FileSystemOpts = Clang->getFileSystemOpts();
+ FileMgr = new FileManager(FileSystemOpts);
+ SourceMgr = new SourceManager(getDiagnostics(), *FileMgr);
TheSema.reset();
- Ctx.reset();
- PP.reset();
+ Ctx = 0;
+ PP = 0;
// Clear out old caches and data.
TopLevelDecls.clear();
@@ -863,14 +909,14 @@ bool ASTUnit::Parse(llvm::MemoryBuffer *OverrideMainBuffer) {
}
// Create a file manager object to provide access to and cache the filesystem.
- Clang.setFileManager(&getFileManager());
+ Clang->setFileManager(&getFileManager());
// Create the source manager.
- Clang.setSourceManager(&getSourceManager());
+ Clang->setSourceManager(&getSourceManager());
// If the main file has been overridden due to the use of a preamble,
// make that override happen and introduce the preamble.
- PreprocessorOptions &PreprocessorOpts = Clang.getPreprocessorOpts();
+ PreprocessorOptions &PreprocessorOpts = Clang->getPreprocessorOpts();
std::string PriorImplicitPCHInclude;
if (OverrideMainBuffer) {
PreprocessorOpts.addRemappedFile(OriginalSourceFile, OverrideMainBuffer);
@@ -901,23 +947,27 @@ bool ASTUnit::Parse(llvm::MemoryBuffer *OverrideMainBuffer) {
PreprocessorOpts.PrecompiledPreambleBytes.second = false;
}
- llvm::OwningPtr<TopLevelDeclTrackerAction> Act;
- Act.reset(new TopLevelDeclTrackerAction(*this));
- if (!Act->BeginSourceFile(Clang, Clang.getFrontendOpts().Inputs[0].second,
- Clang.getFrontendOpts().Inputs[0].first))
+ llvm::OwningPtr<TopLevelDeclTrackerAction> Act(
+ new TopLevelDeclTrackerAction(*this));
+
+ // Recover resources if we crash before exiting this method.
+ llvm::CrashRecoveryContextCleanupRegistrar<TopLevelDeclTrackerAction>
+ ActCleanup(Act.get());
+
+ if (!Act->BeginSourceFile(*Clang.get(), Clang->getFrontendOpts().Inputs[0].second,
+ Clang->getFrontendOpts().Inputs[0].first))
goto error;
Act->Execute();
- // Steal the created target, context, and preprocessor, and take back the
- // source and file managers.
- TheSema.reset(Clang.takeSema());
- Consumer.reset(Clang.takeASTConsumer());
- Ctx.reset(Clang.takeASTContext());
- PP.reset(Clang.takePreprocessor());
- Clang.takeSourceManager();
- Clang.takeFileManager();
- Target.reset(Clang.takeTarget());
+ // Steal the created target, context, and preprocessor.
+ TheSema.reset(Clang->takeSema());
+ Consumer.reset(Clang->takeASTConsumer());
+ Ctx = &Clang->getASTContext();
+ PP = &Clang->getPreprocessor();
+ Clang->setSourceManager(0);
+ Clang->setFileManager(0);
+ Target = &Clang->getTarget();
Act->EndSourceFile();
@@ -928,9 +978,8 @@ bool ASTUnit::Parse(llvm::MemoryBuffer *OverrideMainBuffer) {
PreprocessorOpts.ImplicitPCHInclude = PriorImplicitPCHInclude;
}
- Invocation.reset(Clang.takeInvocation());
return false;
-
+
error:
// Remove the overridden buffer we used for the preamble.
if (OverrideMainBuffer) {
@@ -942,9 +991,6 @@ error:
}
StoredDiagnostics.clear();
- Clang.takeSourceManager();
- Clang.takeFileManager();
- Invocation.reset(Clang.takeInvocation());
return true;
}
@@ -1146,7 +1192,7 @@ llvm::MemoryBuffer *ASTUnit::getMainBufferWithPrecompiledPreamble(
!AnyFileChanged && R != REnd;
++R) {
struct stat StatBuf;
- if (stat(R->second.c_str(), &StatBuf)) {
+ if (FileMgr->getNoncachedStatValue(R->second, StatBuf)) {
// If we can't stat the file we're remapping to, assume that something
// horrible happened.
AnyFileChanged = true;
@@ -1184,7 +1230,7 @@ llvm::MemoryBuffer *ASTUnit::getMainBufferWithPrecompiledPreamble(
// The file was not remapped; check whether it has changed on disk.
struct stat StatBuf;
- if (stat(F->first(), &StatBuf)) {
+ if (FileMgr->getNoncachedStatValue(F->first(), StatBuf)) {
// If we can't stat the file, assume that something horrible happened.
AnyFileChanged = true;
} else if (StatBuf.st_size != F->second.first ||
@@ -1292,18 +1338,23 @@ llvm::MemoryBuffer *ASTUnit::getMainBufferWithPrecompiledPreamble(
PreprocessorOpts.PrecompiledPreambleBytes.second = false;
// Create the compiler instance to use for building the precompiled preamble.
- CompilerInstance Clang;
- Clang.setInvocation(&PreambleInvocation);
- OriginalSourceFile = Clang.getFrontendOpts().Inputs[0].second;
+ llvm::OwningPtr<CompilerInstance> Clang(new CompilerInstance());
+
+ // Recover resources if we crash before exiting this method.
+ llvm::CrashRecoveryContextCleanupRegistrar<CompilerInstance>
+ CICleanup(Clang.get());
+
+ Clang->setInvocation(&PreambleInvocation);
+ OriginalSourceFile = Clang->getFrontendOpts().Inputs[0].second;
// Set up diagnostics, capturing all of the diagnostics produced.
- Clang.setDiagnostics(&getDiagnostics());
+ Clang->setDiagnostics(&getDiagnostics());
// Create the target instance.
- Clang.getTargetOpts().Features = TargetFeatures;
- Clang.setTarget(TargetInfo::CreateTargetInfo(Clang.getDiagnostics(),
- Clang.getTargetOpts()));
- if (!Clang.hasTarget()) {
+ Clang->getTargetOpts().Features = TargetFeatures;
+ Clang->setTarget(TargetInfo::CreateTargetInfo(Clang->getDiagnostics(),
+ Clang->getTargetOpts()));
+ if (!Clang->hasTarget()) {
llvm::sys::Path(FrontendOpts.OutputFile).eraseFromDisk();
Preamble.clear();
PreambleRebuildCounter = DefaultPreambleRebuildInterval;
@@ -1316,18 +1367,18 @@ llvm::MemoryBuffer *ASTUnit::getMainBufferWithPrecompiledPreamble(
//
// FIXME: We shouldn't need to do this, the target should be immutable once
// created. This complexity should be lifted elsewhere.
- Clang.getTarget().setForcedLangOptions(Clang.getLangOpts());
+ Clang->getTarget().setForcedLangOptions(Clang->getLangOpts());
- assert(Clang.getFrontendOpts().Inputs.size() == 1 &&
+ assert(Clang->getFrontendOpts().Inputs.size() == 1 &&
"Invocation must have exactly one source file!");
- assert(Clang.getFrontendOpts().Inputs[0].first != IK_AST &&
+ assert(Clang->getFrontendOpts().Inputs[0].first != IK_AST &&
"FIXME: AST inputs not yet supported here!");
- assert(Clang.getFrontendOpts().Inputs[0].first != IK_LLVM_IR &&
+ assert(Clang->getFrontendOpts().Inputs[0].first != IK_LLVM_IR &&
"IR inputs not support here!");
// Clear out old caches and data.
getDiagnostics().Reset();
- ProcessWarningOptions(getDiagnostics(), Clang.getDiagnosticOpts());
+ ProcessWarningOptions(getDiagnostics(), Clang->getDiagnosticOpts());
StoredDiagnostics.erase(
StoredDiagnostics.begin() + NumStoredDiagnosticsFromDriver,
StoredDiagnostics.end());
@@ -1337,17 +1388,16 @@ llvm::MemoryBuffer *ASTUnit::getMainBufferWithPrecompiledPreamble(
PreprocessedEntitiesInPreamble.clear();
// Create a file manager object to provide access to and cache the filesystem.
- Clang.setFileManager(new FileManager(Clang.getFileSystemOpts()));
+ Clang->setFileManager(new FileManager(Clang->getFileSystemOpts()));
// Create the source manager.
- Clang.setSourceManager(new SourceManager(getDiagnostics(),
- Clang.getFileManager()));
+ Clang->setSourceManager(new SourceManager(getDiagnostics(),
+ Clang->getFileManager()));
llvm::OwningPtr<PrecompilePreambleAction> Act;
Act.reset(new PrecompilePreambleAction(*this));
- if (!Act->BeginSourceFile(Clang, Clang.getFrontendOpts().Inputs[0].second,
- Clang.getFrontendOpts().Inputs[0].first)) {
- Clang.takeInvocation();
+ if (!Act->BeginSourceFile(*Clang.get(), Clang->getFrontendOpts().Inputs[0].second,
+ Clang->getFrontendOpts().Inputs[0].first)) {
llvm::sys::Path(FrontendOpts.OutputFile).eraseFromDisk();
Preamble.clear();
PreambleRebuildCounter = DefaultPreambleRebuildInterval;
@@ -1358,8 +1408,7 @@ llvm::MemoryBuffer *ASTUnit::getMainBufferWithPrecompiledPreamble(
Act->Execute();
Act->EndSourceFile();
- Clang.takeInvocation();
-
+
if (Diagnostics->hasErrorOccurred()) {
// There were errors parsing the preamble, so no precompiled header was
// generated. Forget that we even tried.
@@ -1383,14 +1432,14 @@ llvm::MemoryBuffer *ASTUnit::getMainBufferWithPrecompiledPreamble(
// Keep track of all of the files that the source manager knows about,
// so we can verify whether they have changed or not.
FilesInPreamble.clear();
- SourceManager &SourceMgr = Clang.getSourceManager();
+ SourceManager &SourceMgr = Clang->getSourceManager();
const llvm::MemoryBuffer *MainFileBuffer
= SourceMgr.getBuffer(SourceMgr.getMainFileID());
for (SourceManager::fileinfo_iterator F = SourceMgr.fileinfo_begin(),
FEnd = SourceMgr.fileinfo_end();
F != FEnd;
++F) {
- const FileEntry *File = F->second->Entry;
+ const FileEntry *File = F->second->OrigEntry;
if (!File || F->second->getRawBuffer() == MainFileBuffer)
continue;
@@ -1491,6 +1540,20 @@ llvm::StringRef ASTUnit::getMainFileName() const {
return Invocation->getFrontendOpts().Inputs[0].second;
}
+ASTUnit *ASTUnit::create(CompilerInvocation *CI,
+ llvm::IntrusiveRefCntPtr<Diagnostic> Diags) {
+ llvm::OwningPtr<ASTUnit> AST;
+ AST.reset(new ASTUnit(false));
+ ConfigureDiags(Diags, 0, 0, *AST, /*CaptureDiagnostics=*/false);
+ AST->Diagnostics = Diags;
+ AST->Invocation = CI;
+ AST->FileSystemOpts = CI->getFileSystemOpts();
+ AST->FileMgr = new FileManager(AST->FileSystemOpts);
+ AST->SourceMgr = new SourceManager(*Diags, *AST->FileMgr);
+
+ return AST.take();
+}
+
bool ASTUnit::LoadFromCompilerInvocation(bool PrecompilePreamble) {
if (!Invocation)
return true;
@@ -1513,6 +1576,10 @@ bool ASTUnit::LoadFromCompilerInvocation(bool PrecompilePreamble) {
SimpleTimer ParsingTimer(WantTiming);
ParsingTimer.setOutput("Parsing " + getMainFileName());
+ // Recover resources if we crash before exiting this method.
+ llvm::CrashRecoveryContextCleanupRegistrar<llvm::MemoryBuffer>
+ MemBufferCleanup(OverrideMainBuffer);
+
return Parse(OverrideMainBuffer);
}
@@ -1532,8 +1599,15 @@ ASTUnit *ASTUnit::LoadFromCompilerInvocation(CompilerInvocation *CI,
AST->CaptureDiagnostics = CaptureDiagnostics;
AST->CompleteTranslationUnit = CompleteTranslationUnit;
AST->ShouldCacheCodeCompletionResults = CacheCodeCompletionResults;
- AST->Invocation.reset(CI);
+ AST->Invocation = CI;
+ // Recover resources if we crash before exiting this method.
+ llvm::CrashRecoveryContextCleanupRegistrar<ASTUnit>
+ ASTUnitCleanup(AST.get());
+ llvm::CrashRecoveryContextCleanupRegistrar<Diagnostic,
+ llvm::CrashRecoveryContextReleaseRefCleanup<Diagnostic> >
+ DiagCleanup(Diags.getPtr());
+
return AST->LoadFromCompilerInvocation(PrecompilePreamble)? 0 : AST.take();
}
@@ -1545,6 +1619,7 @@ ASTUnit *ASTUnit::LoadFromCommandLine(const char **ArgBegin,
bool CaptureDiagnostics,
RemappedFile *RemappedFiles,
unsigned NumRemappedFiles,
+ bool RemappedFilesKeepOriginalName,
bool PrecompilePreamble,
bool CompleteTranslationUnit,
bool CacheCodeCompletionResults,
@@ -1557,63 +1632,35 @@ ASTUnit *ASTUnit::LoadFromCommandLine(const char **ArgBegin,
Diags = CompilerInstance::createDiagnostics(DiagOpts, ArgEnd - ArgBegin,
ArgBegin);
}
-
- llvm::SmallVector<const char *, 16> Args;
- Args.push_back("<clang>"); // FIXME: Remove dummy argument.
- Args.insert(Args.end(), ArgBegin, ArgEnd);
-
- // FIXME: Find a cleaner way to force the driver into restricted modes. We
- // also want to force it to use clang.
- Args.push_back("-fsyntax-only");
llvm::SmallVector<StoredDiagnostic, 4> StoredDiagnostics;
- llvm::OwningPtr<CompilerInvocation> CI;
+ llvm::IntrusiveRefCntPtr<CompilerInvocation> CI;
{
CaptureDroppedDiagnostics Capture(CaptureDiagnostics, *Diags,
StoredDiagnostics);
- // FIXME: We shouldn't have to pass in the path info.
- driver::Driver TheDriver("clang", llvm::sys::getHostTriple(),
- "a.out", false, false, *Diags);
-
- // Don't check that inputs exist, they have been remapped.
- TheDriver.setCheckInputsExist(false);
-
- llvm::OwningPtr<driver::Compilation> C(
- TheDriver.BuildCompilation(Args.size(), Args.data()));
-
- // We expect to get back exactly one command job, if we didn't something
- // failed.
- const driver::JobList &Jobs = C->getJobs();
- if (Jobs.size() != 1 || !isa<driver::Command>(Jobs.begin())) {
- 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();
+ CI = clang::createInvocationFromCommandLine(
+ llvm::ArrayRef<const char *>(ArgBegin, ArgEnd-ArgBegin),
+ Diags);
+ if (!CI)
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);
- return 0;
- }
-
- const driver::ArgStringList &CCArgs = Cmd->getArguments();
- CI.reset(new CompilerInvocation);
- CompilerInvocation::CreateFromArgs(*CI,
- const_cast<const char **>(CCArgs.data()),
- const_cast<const char **>(CCArgs.data()) +
- CCArgs.size(),
- *Diags);
}
// Override any files that need remapping
- for (unsigned I = 0; I != NumRemappedFiles; ++I)
- CI->getPreprocessorOpts().addRemappedFile(RemappedFiles[I].first,
- RemappedFiles[I].second);
+ for (unsigned I = 0; I != NumRemappedFiles; ++I) {
+ FilenameOrMemBuf fileOrBuf = RemappedFiles[I].second;
+ if (const llvm::MemoryBuffer *
+ memBuf = fileOrBuf.dyn_cast<const llvm::MemoryBuffer *>()) {
+ CI->getPreprocessorOpts().addRemappedFile(RemappedFiles[I].first, memBuf);
+ } else {
+ const char *fname = fileOrBuf.get<const char *>();
+ CI->getPreprocessorOpts().addRemappedFile(RemappedFiles[I].first, fname);
+ }
+ }
+ CI->getPreprocessorOpts().RemappedFilesKeepOriginalName =
+ RemappedFilesKeepOriginalName;
// Override the resources path.
CI->getHeaderSearchOpts().ResourceDir = ResourceFilesPath;
@@ -1633,8 +1680,9 @@ ASTUnit *ASTUnit::LoadFromCommandLine(const char **ArgBegin,
AST.reset(new ASTUnit(false));
ConfigureDiags(Diags, ArgBegin, ArgEnd, *AST, CaptureDiagnostics);
AST->Diagnostics = Diags;
-
- AST->FileMgr.reset(new FileManager(FileSystemOptions()));
+
+ AST->FileSystemOpts = CI->getFileSystemOpts();
+ AST->FileMgr = new FileManager(AST->FileSystemOpts);
AST->OnlyLocalDecls = OnlyLocalDecls;
AST->CaptureDiagnostics = CaptureDiagnostics;
AST->CompleteTranslationUnit = CompleteTranslationUnit;
@@ -1642,12 +1690,23 @@ ASTUnit *ASTUnit::LoadFromCommandLine(const char **ArgBegin,
AST->NumStoredDiagnosticsFromDriver = StoredDiagnostics.size();
AST->NumStoredDiagnosticsInPreamble = StoredDiagnostics.size();
AST->StoredDiagnostics.swap(StoredDiagnostics);
- AST->Invocation.reset(CI.take());
+ AST->Invocation = CI;
+
+ // Recover resources if we crash before exiting this method.
+ llvm::CrashRecoveryContextCleanupRegistrar<ASTUnit>
+ ASTUnitCleanup(AST.get());
+ llvm::CrashRecoveryContextCleanupRegistrar<CompilerInvocation,
+ llvm::CrashRecoveryContextReleaseRefCleanup<CompilerInvocation> >
+ CICleanup(CI.getPtr());
+ llvm::CrashRecoveryContextCleanupRegistrar<Diagnostic,
+ llvm::CrashRecoveryContextReleaseRefCleanup<Diagnostic> >
+ DiagCleanup(Diags.getPtr());
+
return AST->LoadFromCompilerInvocation(PrecompilePreamble) ? 0 : AST.take();
}
bool ASTUnit::Reparse(RemappedFile *RemappedFiles, unsigned NumRemappedFiles) {
- if (!Invocation.get())
+ if (!Invocation)
return true;
SimpleTimer ParsingTimer(WantTiming);
@@ -1664,9 +1723,18 @@ bool ASTUnit::Reparse(RemappedFile *RemappedFiles, unsigned NumRemappedFiles) {
delete R->second;
}
Invocation->getPreprocessorOpts().clearRemappedFiles();
- for (unsigned I = 0; I != NumRemappedFiles; ++I)
- Invocation->getPreprocessorOpts().addRemappedFile(RemappedFiles[I].first,
- RemappedFiles[I].second);
+ for (unsigned I = 0; I != NumRemappedFiles; ++I) {
+ FilenameOrMemBuf fileOrBuf = RemappedFiles[I].second;
+ if (const llvm::MemoryBuffer *
+ memBuf = fileOrBuf.dyn_cast<const llvm::MemoryBuffer *>()) {
+ Invocation->getPreprocessorOpts().addRemappedFile(RemappedFiles[I].first,
+ memBuf);
+ } else {
+ const char *fname = fileOrBuf.get<const char *>();
+ Invocation->getPreprocessorOpts().addRemappedFile(RemappedFiles[I].first,
+ fname);
+ }
+ }
// If we have a preamble file lying around, or if we might try to
// build a precompiled preamble, do so now.
@@ -1934,16 +2002,18 @@ void ASTUnit::CodeComplete(llvm::StringRef File, unsigned Line, unsigned Column,
SourceManager &SourceMgr, FileManager &FileMgr,
llvm::SmallVectorImpl<StoredDiagnostic> &StoredDiagnostics,
llvm::SmallVectorImpl<const llvm::MemoryBuffer *> &OwnedBuffers) {
- if (!Invocation.get())
+ if (!Invocation)
return;
SimpleTimer CompletionTimer(WantTiming);
CompletionTimer.setOutput("Code completion @ " + File + ":" +
llvm::Twine(Line) + ":" + llvm::Twine(Column));
- CompilerInvocation CCInvocation(*Invocation);
- FrontendOptions &FrontendOpts = CCInvocation.getFrontendOpts();
- PreprocessorOptions &PreprocessorOpts = CCInvocation.getPreprocessorOpts();
+ llvm::IntrusiveRefCntPtr<CompilerInvocation>
+ CCInvocation(new CompilerInvocation(*Invocation));
+
+ FrontendOptions &FrontendOpts = CCInvocation->getFrontendOpts();
+ PreprocessorOptions &PreprocessorOpts = CCInvocation->getPreprocessorOpts();
FrontendOpts.ShowMacrosInCodeCompletion
= IncludeMacros && CachedCompletionResults.empty();
@@ -1955,25 +2025,30 @@ void ASTUnit::CodeComplete(llvm::StringRef File, unsigned Line, unsigned Column,
FrontendOpts.CodeCompletionAt.Column = Column;
// Set the language options appropriately.
- LangOpts = CCInvocation.getLangOpts();
+ LangOpts = CCInvocation->getLangOpts();
- CompilerInstance Clang;
- Clang.setInvocation(&CCInvocation);
- OriginalSourceFile = Clang.getFrontendOpts().Inputs[0].second;
+ llvm::OwningPtr<CompilerInstance> Clang(new CompilerInstance());
+
+ // Recover resources if we crash before exiting this method.
+ llvm::CrashRecoveryContextCleanupRegistrar<CompilerInstance>
+ CICleanup(Clang.get());
+
+ Clang->setInvocation(&*CCInvocation);
+ OriginalSourceFile = Clang->getFrontendOpts().Inputs[0].second;
// Set up diagnostics, capturing any diagnostics produced.
- Clang.setDiagnostics(&Diag);
- ProcessWarningOptions(Diag, CCInvocation.getDiagnosticOpts());
+ Clang->setDiagnostics(&Diag);
+ ProcessWarningOptions(Diag, CCInvocation->getDiagnosticOpts());
CaptureDroppedDiagnostics Capture(true,
- Clang.getDiagnostics(),
+ Clang->getDiagnostics(),
StoredDiagnostics);
// Create the target instance.
- Clang.getTargetOpts().Features = TargetFeatures;
- Clang.setTarget(TargetInfo::CreateTargetInfo(Clang.getDiagnostics(),
- Clang.getTargetOpts()));
- if (!Clang.hasTarget()) {
- Clang.takeInvocation();
+ Clang->getTargetOpts().Features = TargetFeatures;
+ Clang->setTarget(TargetInfo::CreateTargetInfo(Clang->getDiagnostics(),
+ Clang->getTargetOpts()));
+ if (!Clang->hasTarget()) {
+ Clang->setInvocation(0);
return;
}
@@ -1981,27 +2056,33 @@ void ASTUnit::CodeComplete(llvm::StringRef File, unsigned Line, unsigned Column,
//
// FIXME: We shouldn't need to do this, the target should be immutable once
// created. This complexity should be lifted elsewhere.
- Clang.getTarget().setForcedLangOptions(Clang.getLangOpts());
+ Clang->getTarget().setForcedLangOptions(Clang->getLangOpts());
- assert(Clang.getFrontendOpts().Inputs.size() == 1 &&
+ assert(Clang->getFrontendOpts().Inputs.size() == 1 &&
"Invocation must have exactly one source file!");
- assert(Clang.getFrontendOpts().Inputs[0].first != IK_AST &&
+ assert(Clang->getFrontendOpts().Inputs[0].first != IK_AST &&
"FIXME: AST inputs not yet supported here!");
- assert(Clang.getFrontendOpts().Inputs[0].first != IK_LLVM_IR &&
+ assert(Clang->getFrontendOpts().Inputs[0].first != IK_LLVM_IR &&
"IR inputs not support here!");
// Use the source and file managers that we were given.
- Clang.setFileManager(&FileMgr);
- Clang.setSourceManager(&SourceMgr);
+ Clang->setFileManager(&FileMgr);
+ Clang->setSourceManager(&SourceMgr);
// Remap files.
PreprocessorOpts.clearRemappedFiles();
PreprocessorOpts.RetainRemappedFileBuffers = true;
for (unsigned I = 0; I != NumRemappedFiles; ++I) {
- PreprocessorOpts.addRemappedFile(RemappedFiles[I].first,
- RemappedFiles[I].second);
- OwnedBuffers.push_back(RemappedFiles[I].second);
+ FilenameOrMemBuf fileOrBuf = RemappedFiles[I].second;
+ if (const llvm::MemoryBuffer *
+ memBuf = fileOrBuf.dyn_cast<const llvm::MemoryBuffer *>()) {
+ PreprocessorOpts.addRemappedFile(RemappedFiles[I].first, memBuf);
+ OwnedBuffers.push_back(memBuf);
+ } else {
+ const char *fname = fileOrBuf.get<const char *>();
+ PreprocessorOpts.addRemappedFile(RemappedFiles[I].first, fname);
+ }
}
// Use the code completion consumer we were given, but adding any cached
@@ -2011,7 +2092,7 @@ void ASTUnit::CodeComplete(llvm::StringRef File, unsigned Line, unsigned Column,
FrontendOpts.ShowMacrosInCodeCompletion,
FrontendOpts.ShowCodePatternsInCodeCompletion,
FrontendOpts.ShowGlobalSymbolsInCodeCompletion);
- Clang.setCodeCompletionConsumer(AugmentedConsumer);
+ Clang->setCodeCompletionConsumer(AugmentedConsumer);
// If we have a precompiled preamble, try to use it. We only allow
// the use of the precompiled preamble if we're if the completion
@@ -2026,7 +2107,7 @@ void ASTUnit::CodeComplete(llvm::StringRef File, unsigned Line, unsigned Column,
if (const FileStatus *MainStatus = MainPath.getFileStatus())
if (CompleteFileStatus->getUniqueID() == MainStatus->getUniqueID())
OverrideMainBuffer
- = getMainBufferWithPrecompiledPreamble(CCInvocation, false,
+ = getMainBufferWithPrecompiledPreamble(*CCInvocation, false,
Line - 1);
}
@@ -2063,16 +2144,11 @@ void ASTUnit::CodeComplete(llvm::StringRef File, unsigned Line, unsigned Column,
llvm::OwningPtr<SyntaxOnlyAction> Act;
Act.reset(new SyntaxOnlyAction);
- if (Act->BeginSourceFile(Clang, Clang.getFrontendOpts().Inputs[0].second,
- Clang.getFrontendOpts().Inputs[0].first)) {
+ if (Act->BeginSourceFile(*Clang.get(), Clang->getFrontendOpts().Inputs[0].second,
+ Clang->getFrontendOpts().Inputs[0].first)) {
Act->Execute();
Act->EndSourceFile();
}
-
- // Steal back our resources.
- Clang.takeFileManager();
- Clang.takeSourceManager();
- Clang.takeInvocation();
}
bool ASTUnit::Save(llvm::StringRef File) {
@@ -2086,7 +2162,16 @@ bool ASTUnit::Save(llvm::StringRef File) {
llvm::raw_fd_ostream::F_Binary);
if (!ErrorInfo.empty() || Out.has_error())
return true;
-
+
+ serialize(Out);
+ Out.close();
+ return Out.has_error();
+}
+
+bool ASTUnit::serialize(llvm::raw_ostream &OS) {
+ if (getDiagnostics().hasErrorOccurred())
+ return true;
+
std::vector<unsigned char> Buffer;
llvm::BitstreamWriter Stream(Buffer);
ASTWriter Writer(Stream);
@@ -2094,7 +2179,7 @@ bool ASTUnit::Save(llvm::StringRef File) {
// Write the generated bitstream to "Out".
if (!Buffer.empty())
- Out.write((char *)&Buffer.front(), Buffer.size());
- Out.close();
- return Out.has_error();
+ OS.write((char *)&Buffer.front(), Buffer.size());
+
+ return false;
}
diff --git a/lib/Frontend/CMakeLists.txt b/lib/Frontend/CMakeLists.txt
index 9f197b4f8762..9d49e9039d91 100644
--- a/lib/Frontend/CMakeLists.txt
+++ b/lib/Frontend/CMakeLists.txt
@@ -16,10 +16,9 @@ add_clang_library(clangFrontend
CacheTokens.cpp
CompilerInstance.cpp
CompilerInvocation.cpp
- DeclXML.cpp
+ CreateInvocationFromCommandLine.cpp
DependencyFile.cpp
DiagChecker.cpp
- DocumentXML.cpp
FrontendAction.cpp
FrontendActions.cpp
FrontendOptions.cpp
@@ -27,12 +26,11 @@ add_clang_library(clangFrontend
InitHeaderSearch.cpp
InitPreprocessor.cpp
LangStandards.cpp
+ LogDiagnosticPrinter.cpp
MultiplexConsumer.cpp
PrintPreprocessedOutput.cpp
- StmtXML.cpp
TextDiagnosticBuffer.cpp
TextDiagnosticPrinter.cpp
- TypeXML.cpp
VerifyDiagnosticsClient.cpp
Warnings.cpp
)
diff --git a/lib/Frontend/CacheTokens.cpp b/lib/Frontend/CacheTokens.cpp
index ee3fdd834334..06a1fd29838b 100644
--- a/lib/Frontend/CacheTokens.cpp
+++ b/lib/Frontend/CacheTokens.cpp
@@ -288,12 +288,12 @@ PTHEntry PTHWriter::LexTokens(Lexer& L) {
if ((Tok.isAtStartOfLine() || Tok.is(tok::eof)) &&
ParsingPreprocessorDirective) {
- // Insert an eom token into the token cache. It has the same
+ // Insert an eod token into the token cache. It has the same
// position as the next token that is not on the same line as the
// preprocessor directive. Observe that we continue processing
// 'Tok' when we exit this branch.
Token Tmp = Tok;
- Tmp.setKind(tok::eom);
+ Tmp.setKind(tok::eod);
Tmp.clearFlag(Token::StartOfLine);
Tmp.setIdentifierInfo(0);
EmitToken(Tmp);
@@ -473,7 +473,7 @@ void PTHWriter::GeneratePTH(const std::string &MainFile) {
for (SourceManager::fileinfo_iterator I = SM.fileinfo_begin(),
E = SM.fileinfo_end(); I != E; ++I) {
const SrcMgr::ContentCache &C = *I->second;
- const FileEntry *FE = C.Entry;
+ const FileEntry *FE = C.OrigEntry;
// FIXME: Handle files with non-absolute paths.
if (llvm::sys::path::is_relative(FE->getName()))
diff --git a/lib/Frontend/CompilerInstance.cpp b/lib/Frontend/CompilerInstance.cpp
index fd593de560c0..ace3c5adb100 100644
--- a/lib/Frontend/CompilerInstance.cpp
+++ b/lib/Frontend/CompilerInstance.cpp
@@ -22,6 +22,7 @@
#include "clang/Frontend/ChainedDiagnosticClient.h"
#include "clang/Frontend/FrontendAction.h"
#include "clang/Frontend/FrontendDiagnostic.h"
+#include "clang/Frontend/LogDiagnosticPrinter.h"
#include "clang/Frontend/TextDiagnosticPrinter.h"
#include "clang/Frontend/VerifyDiagnosticsClient.h"
#include "clang/Frontend/Utils.h"
@@ -47,7 +48,7 @@ CompilerInstance::~CompilerInstance() {
}
void CompilerInstance::setInvocation(CompilerInvocation *Value) {
- Invocation.reset(Value);
+ Invocation = Value;
}
void CompilerInstance::setDiagnostics(Diagnostic *Value) {
@@ -55,24 +56,20 @@ void CompilerInstance::setDiagnostics(Diagnostic *Value) {
}
void CompilerInstance::setTarget(TargetInfo *Value) {
- Target.reset(Value);
+ Target = Value;
}
void CompilerInstance::setFileManager(FileManager *Value) {
- FileMgr.reset(Value);
+ FileMgr = Value;
}
-void CompilerInstance::setSourceManager(SourceManager *Value) {
- SourceMgr.reset(Value);
+void CompilerInstance::setSourceManager(SourceManager *Value) {
+ SourceMgr = Value;
}
-void CompilerInstance::setPreprocessor(Preprocessor *Value) {
- PP.reset(Value);
-}
+void CompilerInstance::setPreprocessor(Preprocessor *Value) { PP = Value; }
-void CompilerInstance::setASTContext(ASTContext *Value) {
- Context.reset(Value);
-}
+void CompilerInstance::setASTContext(ASTContext *Value) { Context = Value; }
void CompilerInstance::setSema(Sema *S) {
TheSema.reset(S);
@@ -110,15 +107,47 @@ static void SetUpBuildDumpLog(const DiagnosticOptions &DiagOpts,
Diags.setClient(new ChainedDiagnosticClient(Diags.takeClient(), Logger));
}
+static void SetUpDiagnosticLog(const DiagnosticOptions &DiagOpts,
+ const CodeGenOptions *CodeGenOpts,
+ Diagnostic &Diags) {
+ std::string ErrorInfo;
+ bool OwnsStream = false;
+ llvm::raw_ostream *OS = &llvm::errs();
+ if (DiagOpts.DiagnosticLogFile != "-") {
+ // Create the output stream.
+ llvm::raw_fd_ostream *FileOS(
+ new llvm::raw_fd_ostream(DiagOpts.DiagnosticLogFile.c_str(),
+ ErrorInfo, llvm::raw_fd_ostream::F_Append));
+ if (!ErrorInfo.empty()) {
+ Diags.Report(diag::warn_fe_cc_log_diagnostics_failure)
+ << DiagOpts.DumpBuildInformation << ErrorInfo;
+ } else {
+ FileOS->SetUnbuffered();
+ FileOS->SetUseAtomicWrites(true);
+ OS = FileOS;
+ OwnsStream = true;
+ }
+ }
+
+ // Chain in the diagnostic client which will log the diagnostics.
+ LogDiagnosticPrinter *Logger = new LogDiagnosticPrinter(*OS, DiagOpts,
+ OwnsStream);
+ if (CodeGenOpts)
+ Logger->setDwarfDebugFlags(CodeGenOpts->DwarfDebugFlags);
+ Diags.setClient(new ChainedDiagnosticClient(Diags.takeClient(), Logger));
+}
+
void CompilerInstance::createDiagnostics(int Argc, const char* const *Argv,
DiagnosticClient *Client) {
- Diagnostics = createDiagnostics(getDiagnosticOpts(), Argc, Argv, Client);
+ Diagnostics = createDiagnostics(getDiagnosticOpts(), Argc, Argv, Client,
+ &getCodeGenOpts());
}
llvm::IntrusiveRefCntPtr<Diagnostic>
CompilerInstance::createDiagnostics(const DiagnosticOptions &Opts,
int Argc, const char* const *Argv,
- DiagnosticClient *Client) {
+ DiagnosticClient *Client,
+ const CodeGenOptions *CodeGenOpts) {
llvm::IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs());
llvm::IntrusiveRefCntPtr<Diagnostic> Diags(new Diagnostic(DiagID));
@@ -133,6 +162,10 @@ CompilerInstance::createDiagnostics(const DiagnosticOptions &Opts,
if (Opts.VerifyDiagnostics)
Diags->setClient(new VerifyDiagnosticsClient(*Diags, Diags->takeClient()));
+ // Chain in -diagnostic-log-file dumper, if requested.
+ if (!Opts.DiagnosticLogFile.empty())
+ SetUpDiagnosticLog(Opts, CodeGenOpts, *Diags);
+
if (!Opts.DumpBuildInformation.empty())
SetUpBuildDumpLog(Opts, Argc, Argv, *Diags);
@@ -145,23 +178,23 @@ CompilerInstance::createDiagnostics(const DiagnosticOptions &Opts,
// File Manager
void CompilerInstance::createFileManager() {
- FileMgr.reset(new FileManager(getFileSystemOpts()));
+ FileMgr = new FileManager(getFileSystemOpts());
}
// Source Manager
void CompilerInstance::createSourceManager(FileManager &FileMgr) {
- SourceMgr.reset(new SourceManager(getDiagnostics(), FileMgr));
+ SourceMgr = new SourceManager(getDiagnostics(), FileMgr);
}
// Preprocessor
void CompilerInstance::createPreprocessor() {
- PP.reset(createPreprocessor(getDiagnostics(), getLangOpts(),
- getPreprocessorOpts(), getHeaderSearchOpts(),
- getDependencyOutputOpts(), getTarget(),
- getFrontendOpts(), getSourceManager(),
- getFileManager()));
+ PP = createPreprocessor(getDiagnostics(), getLangOpts(),
+ getPreprocessorOpts(), getHeaderSearchOpts(),
+ getDependencyOutputOpts(), getTarget(),
+ getFrontendOpts(), getSourceManager(),
+ getFileManager());
}
Preprocessor *
@@ -209,7 +242,8 @@ CompilerInstance::createPreprocessor(Diagnostic &Diags,
llvm::StringRef OutputPath = DepOpts.HeaderIncludeOutputFile;
if (OutputPath == "-")
OutputPath = "";
- AttachHeaderIncludeGen(*PP, /*ShowAllHeaders=*/true, OutputPath);
+ AttachHeaderIncludeGen(*PP, /*ShowAllHeaders=*/true, OutputPath,
+ /*ShowDepth=*/false);
}
return PP;
@@ -219,10 +253,10 @@ CompilerInstance::createPreprocessor(Diagnostic &Diags,
void CompilerInstance::createASTContext() {
Preprocessor &PP = getPreprocessor();
- Context.reset(new ASTContext(getLangOpts(), PP.getSourceManager(),
- getTarget(), PP.getIdentifierTable(),
- PP.getSelectorTable(), PP.getBuiltinInfo(),
- /*size_reserve=*/ 0));
+ Context = new ASTContext(getLangOpts(), PP.getSourceManager(),
+ getTarget(), PP.getIdentifierTable(),
+ PP.getSelectorTable(), PP.getBuiltinInfo(),
+ /*size_reserve=*/ 0);
}
// ExternalASTSource
@@ -362,19 +396,22 @@ void CompilerInstance::clearOutputFiles(bool EraseFiles) {
it = OutputFiles.begin(), ie = OutputFiles.end(); it != ie; ++it) {
delete it->OS;
if (!it->TempFilename.empty()) {
- llvm::sys::Path TempPath(it->TempFilename);
- if (EraseFiles)
- TempPath.eraseFromDisk();
- else {
- std::string Error;
- llvm::sys::Path NewOutFile(it->Filename);
+ if (EraseFiles) {
+ bool existed;
+ llvm::sys::fs::remove(it->TempFilename, existed);
+ } else {
+ llvm::SmallString<128> NewOutFile(it->Filename);
+
// If '-working-directory' was passed, the output filename should be
// relative to that.
- FileManager::FixupRelativePath(NewOutFile, getFileSystemOpts());
- if (TempPath.renamePathOnDisk(NewOutFile, &Error)) {
+ FileMgr->FixupRelativePath(NewOutFile);
+ if (llvm::error_code ec = llvm::sys::fs::rename(it->TempFilename,
+ NewOutFile.str())) {
getDiagnostics().Report(diag::err_fe_unable_to_rename_temp)
- << it->TempFilename << it->Filename << Error;
- TempPath.eraseFromDisk();
+ << it->TempFilename << it->Filename << ec.message();
+
+ bool existed;
+ llvm::sys::fs::remove(it->TempFilename, existed);
}
}
} else if (!it->Filename.empty() && EraseFiles)
diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp
index b9d15ad01ab1..1d4cd15ac480 100644
--- a/lib/Frontend/CompilerInvocation.cpp
+++ b/lib/Frontend/CompilerInvocation.cpp
@@ -30,16 +30,6 @@
#include "llvm/Support/Path.h"
using namespace clang;
-static const char *getAnalysisName(Analyses Kind) {
- switch (Kind) {
- default:
- llvm_unreachable("Unknown analysis kind!");
-#define ANALYSIS(NAME, CMDFLAG, DESC, SCOPE)\
- case NAME: return "-" CMDFLAG;
-#include "clang/Frontend/Analyses.def"
- }
-}
-
static const char *getAnalysisStoreName(AnalysisStores Kind) {
switch (Kind) {
default:
@@ -76,8 +66,6 @@ static const char *getAnalysisDiagClientName(AnalysisDiagClients Kind) {
static void AnalyzerOptsToArgs(const AnalyzerOptions &Opts,
std::vector<std::string> &Res) {
- for (unsigned i = 0, e = Opts.AnalysisList.size(); i != e; ++i)
- Res.push_back(getAnalysisName(Opts.AnalysisList[i]));
if (Opts.ShowCheckerHelp)
Res.push_back("-analyzer-checker-help");
if (Opts.AnalysisStoreOpt != BasicStoreModel) {
@@ -102,8 +90,6 @@ static void AnalyzerOptsToArgs(const AnalyzerOptions &Opts,
Res.push_back("-analyzer-display-progress");
if (Opts.AnalyzeNestedBlocks)
Res.push_back("-analyzer-opt-analyze-nested-blocks");
- if (Opts.AnalyzerStats)
- Res.push_back("-analyzer-stats");
if (Opts.EagerlyAssume)
Res.push_back("-analyzer-eagerly-assume");
if (!Opts.PurgeDead)
@@ -112,12 +98,8 @@ static void AnalyzerOptsToArgs(const AnalyzerOptions &Opts,
Res.push_back("-trim-egraph");
if (Opts.VisualizeEGDot)
Res.push_back("-analyzer-viz-egraph-graphviz");
- if (Opts.VisualizeEGDot)
+ if (Opts.VisualizeEGUbi)
Res.push_back("-analyzer-viz-egraph-ubigraph");
- if (Opts.EnableExperimentalChecks)
- Res.push_back("-analyzer-experimental-checks");
- if (Opts.BufferOverflows)
- Res.push_back("-analyzer-check-buffer-overflows");
for (unsigned i = 0, e = Opts.CheckersControlList.size(); i != e; ++i) {
const std::pair<std::string, bool> &opt = Opts.CheckersControlList[i];
@@ -141,17 +123,23 @@ static void CodeGenOptsToArgs(const CodeGenOptions &Opts,
Res.push_back("-dwarf-debug-flags");
Res.push_back(Opts.DwarfDebugFlags);
}
+ if (Opts.EmitGcovArcs)
+ Res.push_back("-femit-coverage-data");
+ if (Opts.EmitGcovNotes)
+ Res.push_back("-femit-coverage-notes");
if (!Opts.MergeAllConstants)
Res.push_back("-fno-merge-all-constants");
if (Opts.NoCommon)
Res.push_back("-fno-common");
+ if (Opts.ForbidGuardVariables)
+ Res.push_back("-fforbid-guard-variables");
if (Opts.NoImplicitFloat)
Res.push_back("-no-implicit-float");
if (Opts.OmitLeafFramePointer)
Res.push_back("-momit-leaf-frame-pointer");
if (Opts.OptimizeSize) {
assert(Opts.OptimizationLevel == 2 && "Invalid options!");
- Res.push_back("-Os");
+ Opts.OptimizeSize == 1 ? Res.push_back("-Os") : Res.push_back("-Oz");
} else if (Opts.OptimizationLevel != 0)
Res.push_back("-O" + llvm::utostr(Opts.OptimizationLevel));
if (!Opts.MainFileName.empty()) {
@@ -213,6 +201,10 @@ static void CodeGenOptsToArgs(const CodeGenOptions &Opts,
}
if (Opts.RelaxAll)
Res.push_back("-mrelax-all");
+ if (Opts.SaveTempLabels)
+ Res.push_back("-msave-temp-labels");
+ if (Opts.NoDwarf2CFIAsm)
+ Res.push_back("-fno-dwarf2-cfi-asm");
if (Opts.SoftFloat)
Res.push_back("-msoft-float");
if (Opts.UnwindTables)
@@ -223,6 +215,10 @@ static void CodeGenOptsToArgs(const CodeGenOptions &Opts,
}
if (!Opts.VerifyModule)
Res.push_back("-disable-llvm-verifier");
+ for (unsigned i = 0, e = Opts.BackendOptions.size(); i != e; ++i) {
+ Res.push_back("-backend-option");
+ Res.push_back(Opts.BackendOptions[i]);
+ }
}
static void DependencyOutputOptsToArgs(const DependencyOutputOptions &Opts,
@@ -273,6 +269,8 @@ static void DiagnosticOptsToArgs(const DiagnosticOptions &Opts,
Res.push_back("-fcolor-diagnostics");
if (Opts.VerifyDiagnostics)
Res.push_back("-verify");
+ if (Opts.ShowNames)
+ Res.push_back("-fdiagnostics-show-name");
if (Opts.ShowOptionNames)
Res.push_back("-fdiagnostics-show-option");
if (Opts.ShowCategories == 1)
@@ -283,6 +281,10 @@ static void DiagnosticOptsToArgs(const DiagnosticOptions &Opts,
Res.push_back("-ferror-limit");
Res.push_back(llvm::utostr(Opts.ErrorLimit));
}
+ if (!Opts.DiagnosticLogFile.empty()) {
+ Res.push_back("-diagnostic-log-file");
+ Res.push_back(Opts.DiagnosticLogFile);
+ }
if (Opts.MacroBacktraceLimit
!= DiagnosticOptions::DefaultMacroBacktraceLimit) {
Res.push_back("-fmacro-backtrace-limit");
@@ -340,7 +342,6 @@ static const char *getActionName(frontend::ActionKind Kind) {
case frontend::ASTDump: return "-ast-dump";
case frontend::ASTDumpXML: return "-ast-dump-xml";
case frontend::ASTPrint: return "-ast-print";
- case frontend::ASTPrintXML: return "-ast-print-xml";
case frontend::ASTView: return "-ast-view";
case frontend::BoostCon: return "-boostcon";
case frontend::CreateModule: return "-create-module";
@@ -578,7 +579,7 @@ static void LangOptsToArgs(const LangOptions &Opts,
if (Opts.WritableStrings)
Res.push_back("-fwritable-strings");
if (Opts.ConstStrings)
- Res.push_back("-Wwrite-strings");
+ Res.push_back("-fconst-strings");
if (!Opts.LaxVectorConversions)
Res.push_back("-fno-lax-vector-conversions");
if (Opts.AltiVec)
@@ -591,6 +592,8 @@ static void LangOptsToArgs(const LangOptions &Opts,
Res.push_back("-fcxx-exceptions");
if (Opts.SjLjExceptions)
Res.push_back("-fsjlj-exceptions");
+ if (Opts.TraditionalCPP)
+ Res.push_back("-traditional-cpp");
if (!Opts.RTTI)
Res.push_back("-fno-rtti");
if (Opts.MSBitfields)
@@ -687,6 +690,14 @@ static void LangOptsToArgs(const LangOptions &Opts,
Res.push_back("-fconstant-string-class");
Res.push_back(Opts.ObjCConstantStringClass);
}
+ if (Opts.FakeAddressSpaceMap)
+ Res.push_back("-ffake-address-space-map");
+ if (Opts.ParseUnknownAnytype)
+ Res.push_back("-funknown-anytype");
+ if (Opts.DelayedTemplateParsing)
+ Res.push_back("-fdelayed-template-parsing");
+ if (Opts.Deprecated)
+ Res.push_back("-fdeprecated-macro");
}
static void PreprocessorOptsToArgs(const PreprocessorOptions &Opts,
@@ -723,6 +734,10 @@ static void PreprocessorOptsToArgs(const PreprocessorOptions &Opts,
assert(Opts.ImplicitPTHInclude == Opts.TokenCache &&
"Unsupported option combination!");
}
+ for (unsigned i = 0, e = Opts.ChainedIncludes.size(); i != e; ++i) {
+ Res.push_back("-chain-include");
+ Res.push_back(Opts.ChainedIncludes[i]);
+ }
for (unsigned i = 0, e = Opts.RemappedFiles.size(); i != e; ++i) {
Res.push_back("-remap-file");
Res.push_back(Opts.RemappedFiles[i].first + ";" +
@@ -802,8 +817,8 @@ static unsigned getOptimizationLevel(ArgList &Args, InputKind IK,
unsigned DefaultOpt = 0;
if (IK == IK_OpenCL && !Args.hasArg(OPT_cl_opt_disable))
DefaultOpt = 2;
- // -Os implies -O2
- return Args.hasArg(OPT_Os) ? 2 :
+ // -Os/-Oz implies -O2
+ return (Args.hasArg(OPT_Os) || Args.hasArg (OPT_Oz)) ? 2 :
Args.getLastArgIntValue(OPT_O, DefaultOpt, Diags);
}
@@ -811,11 +826,6 @@ static void ParseAnalyzerArgs(AnalyzerOptions &Opts, ArgList &Args,
Diagnostic &Diags) {
using namespace cc1options;
- Opts.AnalysisList.clear();
-#define ANALYSIS(NAME, CMDFLAG, DESC, SCOPE) \
- if (Args.hasArg(OPT_analysis_##NAME)) Opts.AnalysisList.push_back(NAME);
-#include "clang/Frontend/Analyses.def"
-
if (Arg *A = Args.getLastArg(OPT_analyzer_store)) {
llvm::StringRef Name = A->getValue(Args);
AnalysisStores Value = llvm::StringSwitch<AnalysisStores>(Name)
@@ -868,20 +878,17 @@ static void ParseAnalyzerArgs(AnalyzerOptions &Opts, ArgList &Args,
Opts.AnalyzerDisplayProgress = Args.hasArg(OPT_analyzer_display_progress);
Opts.AnalyzeNestedBlocks =
Args.hasArg(OPT_analyzer_opt_analyze_nested_blocks);
- Opts.AnalyzerStats = Args.hasArg(OPT_analysis_AnalyzerStats);
Opts.PurgeDead = !Args.hasArg(OPT_analyzer_no_purge_dead);
Opts.EagerlyAssume = Args.hasArg(OPT_analyzer_eagerly_assume);
Opts.AnalyzeSpecificFunction = Args.getLastArgValue(OPT_analyze_function);
Opts.UnoptimizedCFG = Args.hasArg(OPT_analysis_UnoptimizedCFG);
Opts.CFGAddImplicitDtors = Args.hasArg(OPT_analysis_CFGAddImplicitDtors);
Opts.CFGAddInitializers = Args.hasArg(OPT_analysis_CFGAddInitializers);
- Opts.EnableExperimentalChecks = Args.hasArg(OPT_analyzer_experimental_checks);
Opts.TrimGraph = Args.hasArg(OPT_trim_egraph);
Opts.MaxNodes = Args.getLastArgIntValue(OPT_analyzer_max_nodes, 150000,Diags);
Opts.MaxLoop = Args.getLastArgIntValue(OPT_analyzer_max_loop, 4, Diags);
Opts.EagerlyTrimEGraph = !Args.hasArg(OPT_analyzer_no_eagerly_trim_egraph);
Opts.InlineCall = Args.hasArg(OPT_analyzer_inline_call);
- Opts.BufferOverflows = Args.hasArg(OPT_analysis_WarnBufferOverflows);
Opts.CheckersControlList.clear();
for (arg_iterator it = Args.filtered_begin(OPT_analyzer_checker,
@@ -919,12 +926,14 @@ static void ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, InputKind IK,
Opts.LimitDebugInfo = Args.hasArg(OPT_flimit_debug_info);
Opts.DisableLLVMOpts = Args.hasArg(OPT_disable_llvm_optzns);
Opts.DisableRedZone = Args.hasArg(OPT_disable_red_zone);
+ Opts.ForbidGuardVariables = Args.hasArg(OPT_fforbid_guard_variables);
Opts.RelaxedAliasing = Args.hasArg(OPT_relaxed_aliasing);
Opts.DwarfDebugFlags = Args.getLastArgValue(OPT_dwarf_debug_flags);
Opts.MergeAllConstants = !Args.hasArg(OPT_fno_merge_all_constants);
Opts.NoCommon = Args.hasArg(OPT_fno_common);
Opts.NoImplicitFloat = Args.hasArg(OPT_no_implicit_float);
Opts.OptimizeSize = Args.hasArg(OPT_Os);
+ Opts.OptimizeSize = Args.hasArg(OPT_Oz) ? 2 : Opts.OptimizeSize;
Opts.SimplifyLibCalls = !(Args.hasArg(OPT_fno_builtin) ||
Args.hasArg(OPT_ffreestanding));
Opts.UnrollLoops = Args.hasArg(OPT_funroll_loops) ||
@@ -943,9 +952,12 @@ static void ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, InputKind IK,
Opts.NoInfsFPMath = Opts.NoNaNsFPMath = Args.hasArg(OPT_cl_finite_math_only)||
Args.hasArg(OPT_cl_fast_relaxed_math);
Opts.NoZeroInitializedInBSS = Args.hasArg(OPT_mno_zero_initialized_in_bss);
+ Opts.BackendOptions = Args.getAllArgValues(OPT_backend_option);
Opts.NumRegisterParameters = Args.getLastArgIntValue(OPT_mregparm, 0, Diags);
Opts.RelaxAll = Args.hasArg(OPT_mrelax_all);
Opts.OmitLeafFramePointer = Args.hasArg(OPT_momit_leaf_frame_pointer);
+ Opts.SaveTempLabels = Args.hasArg(OPT_msave_temp_labels);
+ Opts.NoDwarf2CFIAsm = Args.hasArg(OPT_fno_dwarf2_cfi_asm);
Opts.SoftFloat = Args.hasArg(OPT_msoft_float);
Opts.UnsafeFPMath = Args.hasArg(OPT_cl_unsafe_math_optimizations) ||
Args.hasArg(OPT_cl_fast_relaxed_math);
@@ -960,6 +972,8 @@ static void ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, InputKind IK,
Opts.InstrumentFunctions = Args.hasArg(OPT_finstrument_functions);
Opts.InstrumentForProfiling = Args.hasArg(OPT_pg);
+ Opts.EmitGcovArcs = Args.hasArg(OPT_femit_coverage_data);
+ Opts.EmitGcovNotes = Args.hasArg(OPT_femit_coverage_notes);
if (Arg *A = Args.getLastArg(OPT_fobjc_dispatch_method_EQ)) {
llvm::StringRef Name = A->getValue(Args);
@@ -989,6 +1003,7 @@ static void ParseDependencyOutputArgs(DependencyOutputOptions &Opts,
static void ParseDiagnosticArgs(DiagnosticOptions &Opts, ArgList &Args,
Diagnostic &Diags) {
using namespace cc1options;
+ Opts.DiagnosticLogFile = Args.getLastArgValue(OPT_diagnostic_log_file);
Opts.IgnoreWarnings = Args.hasArg(OPT_w);
Opts.NoRewriteMacros = Args.hasArg(OPT_Wno_rewrite_macros);
Opts.Pedantic = Args.hasArg(OPT_pedantic);
@@ -998,8 +1013,16 @@ static void ParseDiagnosticArgs(DiagnosticOptions &Opts, ArgList &Args,
Opts.ShowColumn = !Args.hasArg(OPT_fno_show_column);
Opts.ShowFixits = !Args.hasArg(OPT_fno_diagnostics_fixit_info);
Opts.ShowLocation = !Args.hasArg(OPT_fno_show_source_location);
+ Opts.ShowNames = Args.hasArg(OPT_fdiagnostics_show_name);
Opts.ShowOptionNames = Args.hasArg(OPT_fdiagnostics_show_option);
+ // Default behavior is to not to show note include stacks.
+ Opts.ShowNoteIncludeStack = false;
+ if (Arg *A = Args.getLastArg(OPT_fdiagnostics_show_note_include_stack,
+ OPT_fno_diagnostics_show_note_include_stack))
+ if (A->getOption().matches(OPT_fdiagnostics_show_note_include_stack))
+ Opts.ShowNoteIncludeStack = true;
+
llvm::StringRef ShowOverloads =
Args.getLastArgValue(OPT_fshow_overloads_EQ, "all");
if (ShowOverloads == "best")
@@ -1065,8 +1088,6 @@ static InputKind ParseFrontendArgs(FrontendOptions &Opts, ArgList &Args,
Opts.ProgramAction = frontend::ASTDumpXML; break;
case OPT_ast_print:
Opts.ProgramAction = frontend::ASTPrint; break;
- case OPT_ast_print_xml:
- Opts.ProgramAction = frontend::ASTPrintXML; break;
case OPT_ast_view:
Opts.ProgramAction = frontend::ASTView; break;
case OPT_boostcon:
@@ -1177,8 +1198,6 @@ static InputKind ParseFrontendArgs(FrontendOptions &Opts, ArgList &Args,
DashX = llvm::StringSwitch<InputKind>(A->getValue(Args))
.Case("c", IK_C)
.Case("cl", IK_OpenCL)
- .Case("c", IK_C)
- .Case("cl", IK_OpenCL)
.Case("cuda", IK_CUDA)
.Case("c++", IK_CXX)
.Case("objective-c", IK_ObjC)
@@ -1187,6 +1206,7 @@ static InputKind ParseFrontendArgs(FrontendOptions &Opts, ArgList &Args,
.Case("assembler-with-cpp", IK_Asm)
.Case("c++-cpp-output", IK_PreprocessedCXX)
.Case("objective-c-cpp-output", IK_PreprocessedObjC)
+ .Case("objc-cpp-output", IK_PreprocessedObjC)
.Case("objective-c++-cpp-output", IK_PreprocessedObjCXX)
.Case("c-header", IK_C)
.Case("objective-c-header", IK_ObjC)
@@ -1286,7 +1306,7 @@ static void ParseHeaderSearchArgs(HeaderSearchOptions &Opts, ArgList &Args) {
void CompilerInvocation::setLangDefaults(LangOptions &Opts, InputKind IK,
LangStandard::Kind LangStd) {
- // Set some properties which depend soley on the input kind; it would be nice
+ // Set some properties which depend solely on the input kind; it would be nice
// to move these to the language standard, and have the driver resolve the
// input kind + language standard.
if (IK == IK_Asm) {
@@ -1330,6 +1350,7 @@ void CompilerInvocation::setLangDefaults(LangOptions &Opts, InputKind IK,
const LangStandard &Std = LangStandard::getLangStandardForKind(LangStd);
Opts.BCPLComment = Std.hasBCPLComments();
Opts.C99 = Std.isC99();
+ Opts.C1X = Std.isC1X();
Opts.CPlusPlus = Std.isCPlusPlus();
Opts.CPlusPlus0x = Std.isCPlusPlus0x();
Opts.Digraphs = Std.hasDigraphs();
@@ -1421,6 +1442,9 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK,
if (Args.hasArg(OPT_pthread))
Opts.POSIXThreads = 1;
+ if (Args.hasArg(OPT_fdelayed_template_parsing))
+ Opts.DelayedTemplateParsing = 1;
+
llvm::StringRef Vis = Args.getLastArgValue(OPT_fvisibility, "default");
if (Vis == "default")
Opts.setVisibilityMode(DefaultVisibility);
@@ -1455,7 +1479,8 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK,
Opts.MSCVersion = Args.getLastArgIntValue(OPT_fmsc_version, 0, Diags);
Opts.Borland = Args.hasArg(OPT_fborland_extensions);
Opts.WritableStrings = Args.hasArg(OPT_fwritable_strings);
- Opts.ConstStrings = Args.hasArg(OPT_Wwrite_strings);
+ Opts.ConstStrings = Args.hasFlag(OPT_fconst_strings, OPT_fno_const_strings,
+ Opts.ConstStrings);
if (Args.hasArg(OPT_fno_lax_vector_conversions))
Opts.LaxVectorConversions = 0;
if (Args.hasArg(OPT_fno_threadsafe_statics))
@@ -1464,6 +1489,7 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK,
Opts.ObjCExceptions = Args.hasArg(OPT_fobjc_exceptions);
Opts.CXXExceptions = Args.hasArg(OPT_fcxx_exceptions);
Opts.SjLjExceptions = Args.hasArg(OPT_fsjlj_exceptions);
+ Opts.TraditionalCPP = Args.hasArg(OPT_traditional_cpp);
Opts.RTTI = !Args.hasArg(OPT_fno_rtti);
Opts.Blocks = Args.hasArg(OPT_fblocks);
@@ -1479,6 +1505,7 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK,
Opts.MathErrno = Args.hasArg(OPT_fmath_errno);
Opts.InstantiationDepth = Args.getLastArgIntValue(OPT_ftemplate_depth, 1024,
Diags);
+ Opts.DelayedTemplateParsing = Args.hasArg(OPT_fdelayed_template_parsing);
Opts.NumLargeByValueCopy = Args.getLastArgIntValue(OPT_Wlarge_by_value_copy,
0, Diags);
Opts.MSBitfields = Args.hasArg(OPT_mms_bitfields);
@@ -1501,6 +1528,14 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK,
Opts.SinglePrecisionConstants = Args.hasArg(OPT_cl_single_precision_constant);
Opts.FastRelaxedMath = Args.hasArg(OPT_cl_fast_relaxed_math);
Opts.OptimizeSize = 0;
+ Opts.MRTD = Args.hasArg(OPT_mrtd);
+ Opts.FakeAddressSpaceMap = Args.hasArg(OPT_ffake_address_space_map);
+ Opts.ParseUnknownAnytype = Args.hasArg(OPT_funknown_anytype);
+
+ // Record whether the __DEPRECATED define was requested.
+ Opts.Deprecated = Args.hasFlag(OPT_fdeprecated_macro,
+ OPT_fno_deprecated_macro,
+ Opts.Deprecated);
// FIXME: Eliminate this dependency.
unsigned Opt = getOptimizationLevel(Args, IK, Diags);
@@ -1590,6 +1625,12 @@ static void ParsePreprocessorArgs(PreprocessorOptions &Opts, ArgList &Args,
Opts.Includes.push_back(A->getValue(Args));
}
+ for (arg_iterator it = Args.filtered_begin(OPT_chain_include),
+ ie = Args.filtered_end(); it != ie; ++it) {
+ const Arg *A = *it;
+ Opts.ChainedIncludes.push_back(A->getValue(Args));
+ }
+
// Include 'altivec.h' if -faltivec option present
if (Args.hasArg(OPT_faltivec))
Opts.Includes.push_back("altivec.h");
diff --git a/lib/Frontend/CreateInvocationFromCommandLine.cpp b/lib/Frontend/CreateInvocationFromCommandLine.cpp
new file mode 100644
index 000000000000..0005f910d214
--- /dev/null
+++ b/lib/Frontend/CreateInvocationFromCommandLine.cpp
@@ -0,0 +1,90 @@
+//===--- CreateInvocationFromCommandLine.cpp - CompilerInvocation from Args ==//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// Construct a compiler invocation object for command line driver arguments
+//
+//===----------------------------------------------------------------------===//
+
+#include "clang/Frontend/Utils.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Frontend/DiagnosticOptions.h"
+#include "clang/Frontend/FrontendDiagnostic.h"
+#include "clang/Driver/Compilation.h"
+#include "clang/Driver/Driver.h"
+#include "clang/Driver/ArgList.h"
+#include "clang/Driver/Options.h"
+#include "clang/Driver/Tool.h"
+#include "llvm/Support/Host.h"
+using namespace clang;
+
+/// createInvocationFromCommandLine - Construct a compiler invocation object for
+/// a command line argument vector.
+///
+/// \return A CompilerInvocation, or 0 if none was built for the given
+/// argument vector.
+CompilerInvocation *
+clang::createInvocationFromCommandLine(llvm::ArrayRef<const char *> ArgList,
+ llvm::IntrusiveRefCntPtr<Diagnostic> Diags) {
+ if (!Diags.getPtr()) {
+ // No diagnostics engine was provided, so create our own diagnostics object
+ // with the default options.
+ DiagnosticOptions DiagOpts;
+ Diags = CompilerInstance::createDiagnostics(DiagOpts, ArgList.size(),
+ ArgList.begin());
+ }
+
+ llvm::SmallVector<const char *, 16> Args;
+ Args.push_back("<clang>"); // FIXME: Remove dummy argument.
+ Args.insert(Args.end(), ArgList.begin(), ArgList.end());
+
+ // FIXME: Find a cleaner way to force the driver into restricted modes. We
+ // also want to force it to use clang.
+ Args.push_back("-fsyntax-only");
+
+ // FIXME: We shouldn't have to pass in the path info.
+ driver::Driver TheDriver("clang", llvm::sys::getHostTriple(),
+ "a.out", false, false, *Diags);
+
+ // Don't check that inputs exist, they may have been remapped.
+ TheDriver.setCheckInputsExist(false);
+
+ llvm::OwningPtr<driver::Compilation> C(TheDriver.BuildCompilation(Args));
+
+ // Just print the cc1 options if -### was present.
+ if (C->getArgs().hasArg(driver::options::OPT__HASH_HASH_HASH)) {
+ C->PrintJob(llvm::errs(), C->getJobs(), "\n", true);
+ return 0;
+ }
+
+ // We expect to get back exactly one command job, if we didn't something
+ // failed.
+ const driver::JobList &Jobs = C->getJobs();
+ if (Jobs.size() != 1 || !isa<driver::Command>(Jobs.begin())) {
+ 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();
+ 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);
+ return 0;
+ }
+
+ const driver::ArgStringList &CCArgs = Cmd->getArguments();
+ CompilerInvocation *CI = new CompilerInvocation();
+ CompilerInvocation::CreateFromArgs(*CI,
+ const_cast<const char **>(CCArgs.data()),
+ const_cast<const char **>(CCArgs.data()) +
+ CCArgs.size(),
+ *Diags);
+ return CI;
+}
diff --git a/lib/Frontend/DeclXML.cpp b/lib/Frontend/DeclXML.cpp
deleted file mode 100644
index 8d3d225a4b38..000000000000
--- a/lib/Frontend/DeclXML.cpp
+++ /dev/null
@@ -1,183 +0,0 @@
-//===--- DeclXML.cpp - XML implementation for Decl ASTs -------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//
-// This file implements the XML document class, which provides the means to
-// dump out the AST in a XML form that exposes type details and other fields.
-//
-//===----------------------------------------------------------------------===//
-
-#include "clang/Frontend/DocumentXML.h"
-#include "clang/AST/DeclVisitor.h"
-#include "clang/AST/Expr.h"
-
-namespace clang {
-
-//---------------------------------------------------------
-class DocumentXML::DeclPrinter : public DeclVisitor<DocumentXML::DeclPrinter> {
- DocumentXML& Doc;
-
- void addSubNodes(FunctionDecl* FD) {
- for (unsigned i = 0, e = FD->getNumParams(); i != e; ++i) {
- Visit(FD->getParamDecl(i));
- Doc.toParent();
- }
- }
-
- void addFunctionBody(FunctionDecl* FD) {
- if (FD->isThisDeclarationADefinition()) {
- Doc.addSubNode("Body");
- Doc.PrintStmt(FD->getBody());
- Doc.toParent();
- }
- }
-
- void addSubNodes(RecordDecl* RD) {
- for (RecordDecl::decl_iterator i = RD->decls_begin(),
- e = RD->decls_end(); i != e; ++i) {
- if (!(*i)->isImplicit()) {
- Visit(*i);
- Doc.toParent();
- }
- }
- }
-
- void addSubNodes(CXXRecordDecl* RD) {
- addSubNodes(cast<RecordDecl>(RD));
-
- if (RD->isDefinition()) {
- // FIXME: This breaks XML generation
- //Doc.addAttribute("num_bases", RD->getNumBases());
-
- for (CXXRecordDecl::base_class_iterator
- base = RD->bases_begin(),
- bend = RD->bases_end();
- base != bend;
- ++base) {
- Doc.addSubNode("Base");
- Doc.addAttribute("id", base->getType());
- AccessSpecifier as = base->getAccessSpecifierAsWritten();
- const char* as_name = "";
- switch(as) {
- case AS_none: as_name = ""; break;
- case AS_public: as_name = "public"; break;
- case AS_protected: as_name = "protected"; break;
- case AS_private: as_name = "private"; break;
- }
- Doc.addAttributeOptional("access", as_name);
- Doc.addAttribute("is_virtual", base->isVirtual());
- Doc.toParent();
- }
- }
- }
-
- void addSubNodes(EnumDecl* ED) {
- for (EnumDecl::enumerator_iterator i = ED->enumerator_begin(),
- e = ED->enumerator_end(); i != e; ++i) {
- Visit(*i);
- Doc.toParent();
- }
- }
-
- void addSubNodes(EnumConstantDecl* ECD) {
- if (ECD->getInitExpr())
- Doc.PrintStmt(ECD->getInitExpr());
- }
-
- void addSubNodes(FieldDecl* FdD) {
- if (FdD->isBitField())
- Doc.PrintStmt(FdD->getBitWidth());
- }
-
- void addSubNodes(VarDecl* V) {
- if (V->getInit())
- Doc.PrintStmt(V->getInit());
- }
-
- void addSubNodes(ParmVarDecl* argDecl) {
- if (argDecl->getDefaultArg())
- Doc.PrintStmt(argDecl->getDefaultArg());
- }
-
- void addSubNodes(DeclContext* ns) {
-
- for (DeclContext::decl_iterator
- d = ns->decls_begin(),
- dend = ns->decls_end();
- d != dend;
- ++d) {
- Visit(*d);
- Doc.toParent();
- }
- }
-
- void addSpecialAttribute(const char* pName, EnumDecl* ED) {
- const QualType& enumType = ED->getIntegerType();
- if (!enumType.isNull())
- Doc.addAttribute(pName, enumType);
- }
-
- void addIdAttribute(LinkageSpecDecl* ED) {
- Doc.addAttribute("id", ED);
- }
-
- void addIdAttribute(NamedDecl* ND) {
- Doc.addAttribute("id", ND);
- }
-
-public:
- DeclPrinter(DocumentXML& doc) : Doc(doc) {}
-
-#define NODE_XML( CLASS, NAME ) \
- void Visit##CLASS(CLASS* T) \
- { \
- Doc.addSubNode(NAME);
-
-#define ID_ATTRIBUTE_XML addIdAttribute(T);
-#define ATTRIBUTE_XML( FN, NAME ) Doc.addAttribute(NAME, T->FN);
-#define ATTRIBUTE_OPT_XML( FN, NAME ) Doc.addAttributeOptional(NAME, T->FN);
-#define ATTRIBUTE_FILE_LOCATION_XML Doc.addLocation(T->getLocation());
-#define ATTRIBUTE_SPECIAL_XML( FN, NAME ) addSpecialAttribute(NAME, T);
-
-#define ATTRIBUTE_ENUM_XML( FN, NAME ) \
- { \
- const char* pAttributeName = NAME; \
- const bool optional = false; \
- switch (T->FN) { \
- default: assert(0 && "unknown enum value");
-
-#define ATTRIBUTE_ENUM_OPT_XML( FN, NAME ) \
- { \
- const char* pAttributeName = NAME; \
- const bool optional = true; \
- switch (T->FN) { \
- default: assert(0 && "unknown enum value");
-
-#define ENUM_XML( VALUE, NAME ) case VALUE: if ((!optional) || NAME[0]) Doc.addAttribute(pAttributeName, NAME); break;
-#define END_ENUM_XML } }
-#define END_NODE_XML }
-
-#define SUB_NODE_XML( CLASS ) addSubNodes(T);
-#define SUB_NODE_SEQUENCE_XML( CLASS ) addSubNodes(T);
-#define SUB_NODE_OPT_XML( CLASS ) addSubNodes(T);
-
-#define SUB_NODE_FN_BODY_XML addFunctionBody(T);
-
-#include "clang/Frontend/DeclXML.def"
-};
-
-
-//---------------------------------------------------------
-void DocumentXML::writeDeclToXML(Decl *D) {
- DeclPrinter(*this).Visit(D);
- toParent();
-}
-
-//---------------------------------------------------------
-} // NS clang
-
diff --git a/lib/Frontend/DependencyFile.cpp b/lib/Frontend/DependencyFile.cpp
index bc5a55df0860..5c3a23128a14 100644
--- a/lib/Frontend/DependencyFile.cpp
+++ b/lib/Frontend/DependencyFile.cpp
@@ -171,7 +171,7 @@ void DependencyFileCallback::OutputDependencyFile() {
*OS << '\n';
// Create phony targets if requested.
- if (PhonyTarget) {
+ if (PhonyTarget && !Files.empty()) {
// Skip the first entry, this is always the input file itself.
for (std::vector<std::string>::iterator I = Files.begin() + 1,
E = Files.end(); I != E; ++I) {
diff --git a/lib/Frontend/DocumentXML.cpp b/lib/Frontend/DocumentXML.cpp
deleted file mode 100644
index a09db0be473e..000000000000
--- a/lib/Frontend/DocumentXML.cpp
+++ /dev/null
@@ -1,381 +0,0 @@
-//===--- DocumentXML.cpp - XML document for ASTs --------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//
-// This file implements the XML document class, which provides the means to
-// dump out the AST in a XML form that exposes type details and other fields.
-//
-//===----------------------------------------------------------------------===//
-
-#include "clang/Frontend/DocumentXML.h"
-#include "clang/AST/Decl.h"
-#include "clang/AST/DeclCXX.h"
-#include "clang/AST/ASTContext.h"
-#include "clang/Basic/SourceManager.h"
-#include "llvm/ADT/StringExtras.h"
-#include "llvm/Config/config.h"
-#include <cstdio>
-
-namespace clang {
-
-//---------------------------------------------------------
-DocumentXML::DocumentXML(const std::string& rootName, llvm::raw_ostream& out) :
- Out(out),
- Ctx(0),
- HasCurrentNodeSubNodes(false) {
- NodeStack.push(rootName);
- Out << "<?xml version=\"1.0\"?>\n<" << rootName;
-}
-
-//---------------------------------------------------------
-DocumentXML& DocumentXML::addSubNode(const std::string& name) {
- if (!HasCurrentNodeSubNodes)
- Out << ">\n";
- NodeStack.push(name);
- HasCurrentNodeSubNodes = false;
- Indent();
- Out << "<" << NodeStack.top();
- return *this;
-}
-
-//---------------------------------------------------------
-void DocumentXML::Indent() {
- for (size_t i = 0, e = (NodeStack.size() - 1) * 2; i < e; ++i)
- Out << ' ';
-}
-
-//---------------------------------------------------------
-DocumentXML& DocumentXML::toParent() {
- assert(NodeStack.size() > 1 && "too much backtracking");
-
- if (HasCurrentNodeSubNodes) {
- Indent();
- Out << "</" << NodeStack.top() << ">\n";
- } else
- Out << "/>\n";
- NodeStack.pop();
- HasCurrentNodeSubNodes = true;
- return *this;
-}
-
-//---------------------------------------------------------
-namespace {
-
-enum tIdType { ID_NORMAL, ID_FILE, ID_LABEL, ID_LAST };
-
-unsigned getNewId(tIdType idType) {
- static unsigned int idCounts[ID_LAST] = { 0 };
- return ++idCounts[idType];
-}
-
-//---------------------------------------------------------
-inline std::string getPrefixedId(unsigned uId, tIdType idType) {
- static const char idPrefix[ID_LAST] = { '_', 'f', 'l' };
- char buffer[20];
- char* BufPtr = llvm::utohex_buffer(uId, buffer + 20);
- *--BufPtr = idPrefix[idType];
- return BufPtr;
-}
-
-//---------------------------------------------------------
-template<class T, class V>
-bool addToMap(T& idMap, const V& value, tIdType idType = ID_NORMAL) {
- typename T::iterator i = idMap.find(value);
- bool toAdd = i == idMap.end();
- if (toAdd)
- idMap.insert(typename T::value_type(value, getNewId(idType)));
- return toAdd;
-}
-
-} // anon NS
-
-
-//---------------------------------------------------------
-std::string DocumentXML::escapeString(const char* pStr,
- std::string::size_type len) {
- std::string value;
- value.reserve(len + 1);
- char buffer[16];
- for (unsigned i = 0; i < len; ++i) {
- switch (char C = pStr[i]) {
- default:
- if (isprint(C))
- value += C;
- else {
-#ifdef LLVM_ON_WIN32
- sprintf(buffer, "\\%03o", C);
-#else
- snprintf(buffer, sizeof(buffer), "\\%03o", C);
-#endif
- value += buffer;
- }
- break;
-
- case '\n': value += "\\n"; break;
- case '\t': value += "\\t"; break;
- case '\a': value += "\\a"; break;
- case '\b': value += "\\b"; break;
- case '\r': value += "\\r"; break;
-
- case '&': value += "&amp;"; break;
- case '<': value += "&lt;"; break;
- case '>': value += "&gt;"; break;
- case '"': value += "&quot;"; break;
- case '\'': value += "&apos;"; break;
-
- }
- }
- return value;
-}
-
-//---------------------------------------------------------
-void DocumentXML::finalize() {
- assert(NodeStack.size() == 1 && "not completely backtracked");
-
- addSubNode("ReferenceSection");
- addSubNode("Types");
-
- for (XML::IdMap<QualType>::iterator i = Types.begin(), e = Types.end();
- i != e; ++i) {
- if (i->first.hasLocalQualifiers()) {
- writeTypeToXML(i->first);
- addAttribute("id", getPrefixedId(i->second, ID_NORMAL));
- toParent();
- }
- }
-
- for (XML::IdMap<const Type*>::iterator i = BasicTypes.begin(),
- e = BasicTypes.end(); i != e; ++i) {
- writeTypeToXML(i->first);
- addAttribute("id", getPrefixedId(i->second, ID_NORMAL));
- toParent();
- }
-
-
- toParent().addSubNode("Contexts");
-
- for (XML::IdMap<const DeclContext*>::iterator i = Contexts.begin(),
- e = Contexts.end(); i != e; ++i) {
- addSubNode(i->first->getDeclKindName());
- addAttribute("id", getPrefixedId(i->second, ID_NORMAL));
- if (const NamedDecl *ND = dyn_cast<NamedDecl>(i->first))
- addAttribute("name", ND->getNameAsString());
- if (const TagDecl *TD = dyn_cast<TagDecl>(i->first))
- addAttribute("type", getPrefixedId(BasicTypes[TD->getTypeForDecl()], ID_NORMAL));
- else if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(i->first))
- addAttribute("type", getPrefixedId(BasicTypes[FD->getType()->getAs<FunctionType>()], ID_NORMAL));
-
- if (const DeclContext* parent = i->first->getParent())
- addAttribute("context", parent);
- toParent();
- }
-
- toParent().addSubNode("Files");
-
- for (XML::IdMap<std::string>::iterator i = SourceFiles.begin(),
- e = SourceFiles.end(); i != e; ++i) {
- addSubNode("File");
- addAttribute("id", getPrefixedId(i->second, ID_FILE));
- addAttribute("name", escapeString(i->first.c_str(), i->first.size()));
- toParent();
- }
-
- toParent().toParent();
-
- // write the root closing node (which has always subnodes)
- Out << "</" << NodeStack.top() << ">\n";
-}
-
-//---------------------------------------------------------
-void DocumentXML::addAttribute(const char* pAttributeName,
- const QualType& pType) {
- addTypeRecursively(pType);
- addAttribute(pAttributeName, getPrefixedId(Types[pType], ID_NORMAL));
-}
-
-//---------------------------------------------------------
-void DocumentXML::addPtrAttribute(const char* pAttributeName,
- const Type* pType) {
- addTypeRecursively(pType);
- addAttribute(pAttributeName, getPrefixedId(BasicTypes[pType], ID_NORMAL));
-}
-
-//---------------------------------------------------------
-void DocumentXML::addPtrAttribute(const char* pAttributeName,
- const NestedNameSpecifier* pNNS) {
- switch (pNNS->getKind()) {
- case NestedNameSpecifier::Identifier: {
- IdentifierInfo *ii = pNNS->getAsIdentifier();
- // FIXME how should we handle those ?
- addPtrAttribute(pAttributeName, ii->getName().data());
- break;
- }
- case NestedNameSpecifier::Namespace: {
- addPtrAttribute(pAttributeName, pNNS->getAsNamespace());
- break;
- }
- case NestedNameSpecifier::NamespaceAlias: {
- addPtrAttribute(pAttributeName, pNNS->getAsNamespaceAlias());
- break;
- }
- case NestedNameSpecifier::TypeSpec: {
- addPtrAttribute(pAttributeName, pNNS->getAsType());
- break;
- }
- case NestedNameSpecifier::TypeSpecWithTemplate: {
- addPtrAttribute(pAttributeName, pNNS->getAsType());
- break;
- }
- case NestedNameSpecifier::Global: {
- addPtrAttribute(pAttributeName, "::");
- break;
- }
- }
-}
-
-//---------------------------------------------------------
-void DocumentXML::addTypeRecursively(const QualType& pType)
-{
- if (addToMap(Types, pType))
- {
- addTypeRecursively(pType.getTypePtr());
- // beautifier: a non-qualified type shall be transparent
- if (!pType.hasLocalQualifiers())
- {
- Types[pType] = BasicTypes[pType.getTypePtr()];
- }
- }
-}
-
-//---------------------------------------------------------
-void DocumentXML::addTypeRecursively(const Type* pType)
-{
- if (addToMap(BasicTypes, pType))
- {
- addParentTypes(pType);
-/*
- // FIXME: doesn't work in the immediate streaming approach
- if (const VariableArrayType *VAT = dyn_cast<VariableArrayType>(pType))
- {
- addSubNode("VariableArraySizeExpression");
- PrintStmt(VAT->getSizeExpr());
- toParent();
- }
-*/
- }
-}
-
-//---------------------------------------------------------
-void DocumentXML::addPtrAttribute(const char* pName, const DeclContext* DC)
-{
- addContextsRecursively(DC);
- addAttribute(pName, getPrefixedId(Contexts[DC], ID_NORMAL));
-}
-
-//---------------------------------------------------------
-void DocumentXML::addPtrAttribute(const char* pAttributeName, const NamedDecl* D)
-{
- if (const DeclContext* DC = dyn_cast<DeclContext>(D))
- {
- addContextsRecursively(DC);
- addAttribute(pAttributeName, getPrefixedId(Contexts[DC], ID_NORMAL));
- }
- else
- {
- addToMap(Decls, D);
- addAttribute(pAttributeName, getPrefixedId(Decls[D], ID_NORMAL));
- }
-}
-
-//---------------------------------------------------------
-void DocumentXML::addPtrAttribute(const char* pName, const NamespaceDecl* D)
-{
- addPtrAttribute(pName, static_cast<const DeclContext*>(D));
-}
-
-//---------------------------------------------------------
-void DocumentXML::addContextsRecursively(const DeclContext *DC)
-{
- if (DC != 0 && addToMap(Contexts, DC))
- {
- addContextsRecursively(DC->getParent());
- }
-}
-
-//---------------------------------------------------------
-void DocumentXML::addSourceFileAttribute(const std::string& fileName)
-{
- addToMap(SourceFiles, fileName, ID_FILE);
- addAttribute("file", getPrefixedId(SourceFiles[fileName], ID_FILE));
-}
-
-
-//---------------------------------------------------------
-void DocumentXML::addPtrAttribute(const char* pName, const LabelStmt* L)
-{
- addToMap(Labels, L, ID_LABEL);
- addAttribute(pName, getPrefixedId(Labels[L], ID_LABEL));
-}
-
-
-//---------------------------------------------------------
-PresumedLoc DocumentXML::addLocation(const SourceLocation& Loc)
-{
- SourceManager& SM = Ctx->getSourceManager();
- SourceLocation SpellingLoc = SM.getSpellingLoc(Loc);
- PresumedLoc PLoc;
- if (!SpellingLoc.isInvalid())
- {
- PLoc = SM.getPresumedLoc(SpellingLoc);
- if (PLoc.isValid()) {
- addSourceFileAttribute(PLoc.getFilename());
- addAttribute("line", PLoc.getLine());
- addAttribute("col", PLoc.getColumn());
- }
- }
- // else there is no error in some cases (eg. CXXThisExpr)
- return PLoc;
-}
-
-//---------------------------------------------------------
-void DocumentXML::addLocationRange(const SourceRange& R)
-{
- PresumedLoc PStartLoc = addLocation(R.getBegin());
- if (R.getBegin() != R.getEnd())
- {
- SourceManager& SM = Ctx->getSourceManager();
- SourceLocation SpellingLoc = SM.getSpellingLoc(R.getEnd());
- if (!SpellingLoc.isInvalid())
- {
- PresumedLoc PLoc = SM.getPresumedLoc(SpellingLoc);
- if (PLoc.isInvalid()) {
- } else if (PStartLoc.isInvalid() ||
- strcmp(PLoc.getFilename(), PStartLoc.getFilename()) != 0) {
- addToMap(SourceFiles, PLoc.getFilename(), ID_FILE);
- addAttribute("endfile", PLoc.getFilename());
- addAttribute("endline", PLoc.getLine());
- addAttribute("endcol", PLoc.getColumn());
- } else if (PLoc.getLine() != PStartLoc.getLine()) {
- addAttribute("endline", PLoc.getLine());
- addAttribute("endcol", PLoc.getColumn());
- } else {
- addAttribute("endcol", PLoc.getColumn());
- }
- }
- }
-}
-
-//---------------------------------------------------------
-void DocumentXML::PrintDecl(Decl *D)
-{
- writeDeclToXML(D);
-}
-
-//---------------------------------------------------------
-} // NS clang
-
diff --git a/lib/Frontend/FrontendAction.cpp b/lib/Frontend/FrontendAction.cpp
index e3d8b8594190..42da44c2c720 100644
--- a/lib/Frontend/FrontendAction.cpp
+++ b/lib/Frontend/FrontendAction.cpp
@@ -20,6 +20,7 @@
#include "clang/Frontend/MultiplexConsumer.h"
#include "clang/Parse/ParseAST.h"
#include "clang/Serialization/ASTDeserializationListener.h"
+#include "clang/Serialization/ChainedIncludesSource.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Timer.h"
#include "llvm/Support/ErrorHandling.h"
@@ -209,8 +210,16 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI,
CI.getASTContext().setASTMutationListener(Consumer->GetASTMutationListener());
- /// Use PCH?
- if (!CI.getPreprocessorOpts().ImplicitPCHInclude.empty()) {
+ if (!CI.getPreprocessorOpts().ChainedIncludes.empty()) {
+ // Convert headers to PCH and chain them.
+ llvm::OwningPtr<ExternalASTSource> source;
+ source.reset(ChainedIncludesSource::create(CI));
+ if (!source)
+ goto failure;
+ CI.getASTContext().setExternalSource(source);
+
+ } else if (!CI.getPreprocessorOpts().ImplicitPCHInclude.empty()) {
+ // Use PCH.
assert(hasPCHSupport() && "This action does not have PCH support!");
ASTDeserializationListener *DeserialListener
= CI.getInvocation().getFrontendOpts().ChainedPCH ?
@@ -249,10 +258,10 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI,
// matching EndSourceFile().
failure:
if (isCurrentFileAST()) {
- CI.takeASTContext();
- CI.takePreprocessor();
- CI.takeSourceManager();
- CI.takeFileManager();
+ CI.setASTContext(0);
+ CI.setPreprocessor(0);
+ CI.setSourceManager(0);
+ CI.setFileManager(0);
}
CI.getDiagnosticClient().EndSourceFile();
@@ -304,7 +313,7 @@ void FrontendAction::EndSourceFile() {
CI.takeASTConsumer();
if (!isCurrentFileAST()) {
CI.takeSema();
- CI.takeASTContext();
+ CI.resetAndLeakASTContext();
}
} else {
if (!isCurrentFileAST()) {
@@ -333,10 +342,10 @@ void FrontendAction::EndSourceFile() {
if (isCurrentFileAST()) {
CI.takeSema();
- CI.takeASTContext();
- CI.takePreprocessor();
- CI.takeSourceManager();
- CI.takeFileManager();
+ CI.resetAndLeakASTContext();
+ CI.resetAndLeakPreprocessor();
+ CI.resetAndLeakSourceManager();
+ CI.resetAndLeakFileManager();
}
setCompilerInstance(0);
diff --git a/lib/Frontend/FrontendActions.cpp b/lib/Frontend/FrontendActions.cpp
index d8e7d2904500..7b06c7e49acf 100644
--- a/lib/Frontend/FrontendActions.cpp
+++ b/lib/Frontend/FrontendActions.cpp
@@ -47,13 +47,6 @@ ASTConsumer *ASTPrintAction::CreateASTConsumer(CompilerInstance &CI,
return 0;
}
-ASTConsumer *ASTPrintXMLAction::CreateASTConsumer(CompilerInstance &CI,
- llvm::StringRef InFile) {
- if (llvm::raw_ostream *OS = CI.createDefaultOutputFile(false, InFile, "xml"))
- return CreateASTPrinterXML(OS);
- return 0;
-}
-
ASTConsumer *ASTDumpAction::CreateASTConsumer(CompilerInstance &CI,
llvm::StringRef InFile) {
return CreateASTDumper();
diff --git a/lib/Frontend/HeaderIncludeGen.cpp b/lib/Frontend/HeaderIncludeGen.cpp
index 45ff1d2e412f..51dec967cd6b 100644
--- a/lib/Frontend/HeaderIncludeGen.cpp
+++ b/lib/Frontend/HeaderIncludeGen.cpp
@@ -22,13 +22,16 @@ class HeaderIncludesCallback : public PPCallbacks {
bool HasProcessedPredefines;
bool OwnsOutputFile;
bool ShowAllHeaders;
+ bool ShowDepth;
public:
HeaderIncludesCallback(const Preprocessor *PP, bool ShowAllHeaders_,
- llvm::raw_ostream *OutputFile_, bool OwnsOutputFile_)
+ llvm::raw_ostream *OutputFile_, bool OwnsOutputFile_,
+ bool ShowDepth_)
: SM(PP->getSourceManager()), OutputFile(OutputFile_),
CurrentIncludeDepth(0), HasProcessedPredefines(false),
- OwnsOutputFile(OwnsOutputFile_), ShowAllHeaders(ShowAllHeaders_) {}
+ OwnsOutputFile(OwnsOutputFile_), ShowAllHeaders(ShowAllHeaders_),
+ ShowDepth(ShowDepth_) {}
~HeaderIncludesCallback() {
if (OwnsOutputFile)
@@ -41,7 +44,7 @@ public:
}
void clang::AttachHeaderIncludeGen(Preprocessor &PP, bool ShowAllHeaders,
- llvm::StringRef OutputPath) {
+ llvm::StringRef OutputPath, bool ShowDepth) {
llvm::raw_ostream *OutputFile = &llvm::errs();
bool OwnsOutputFile = false;
@@ -63,7 +66,8 @@ void clang::AttachHeaderIncludeGen(Preprocessor &PP, bool ShowAllHeaders,
}
PP.addPPCallbacks(new HeaderIncludesCallback(&PP, ShowAllHeaders,
- OutputFile, OwnsOutputFile));
+ OutputFile, OwnsOutputFile,
+ ShowDepth));
}
void HeaderIncludesCallback::FileChanged(SourceLocation Loc,
@@ -78,15 +82,18 @@ void HeaderIncludesCallback::FileChanged(SourceLocation Loc,
// Adjust the current include depth.
if (Reason == PPCallbacks::EnterFile) {
++CurrentIncludeDepth;
- } else {
+ } else if (Reason == PPCallbacks::ExitFile) {
if (CurrentIncludeDepth)
--CurrentIncludeDepth;
// We track when we are done with the predefines by watching for the first
- // place where we drop back to a nesting depth of 0.
- if (CurrentIncludeDepth == 0 && !HasProcessedPredefines)
+ // place where we drop back to a nesting depth of 1.
+ if (CurrentIncludeDepth == 1 && !HasProcessedPredefines)
HasProcessedPredefines = true;
- }
+
+ return;
+ } else
+ return;
// Show the header if we are (a) past the predefines, or (b) showing all
// headers and in the predefines at a depth past the initial file and command
@@ -102,9 +109,12 @@ void HeaderIncludesCallback::FileChanged(SourceLocation Loc,
Lexer::Stringify(Filename);
llvm::SmallString<256> Msg;
- for (unsigned i = 0; i != CurrentIncludeDepth; ++i)
- Msg += '.';
- Msg += ' ';
+ if (ShowDepth) {
+ // The main source file is at depth 1, so skip one dot.
+ for (unsigned i = 1; i != CurrentIncludeDepth; ++i)
+ Msg += '.';
+ Msg += ' ';
+ }
Msg += Filename;
Msg += '\n';
diff --git a/lib/Frontend/InitHeaderSearch.cpp b/lib/Frontend/InitHeaderSearch.cpp
index 2e3162c0a32e..c552512dc957 100644
--- a/lib/Frontend/InitHeaderSearch.cpp
+++ b/lib/Frontend/InitHeaderSearch.cpp
@@ -76,6 +76,10 @@ public:
llvm::StringRef Arch,
llvm::StringRef Version);
+ /// AddMinGW64CXXPaths - Add the necessary paths to support
+ /// libstdc++ of x86_64-w64-mingw32 aka mingw-w64.
+ void AddMinGW64CXXPaths(llvm::StringRef Base);
+
/// AddDelimitedPaths - Add a list of paths delimited by the system PATH
/// separator. The processing follows that of the CPATH variable for gcc.
void AddDelimitedPaths(llvm::StringRef String);
@@ -113,8 +117,13 @@ void InitHeaderSearch::AddPath(const llvm::Twine &Path,
llvm::StringRef MappedPathStr = Path.toStringRef(MappedPathStorage);
// Handle isysroot.
- if (Group == System && !IgnoreSysRoot &&
+ if ((Group == System || Group == CXXSystem) && !IgnoreSysRoot &&
+#if defined(_WIN32)
+ !MappedPathStr.empty() &&
+ llvm::sys::path::is_separator(MappedPathStr[0]) &&
+#else
llvm::sys::path::is_absolute(MappedPathStr) &&
+#endif
IsNotEmptyOrRoot) {
MappedPathStorage.clear();
MappedPathStr =
@@ -207,6 +216,15 @@ void InitHeaderSearch::AddMinGWCPlusPlusIncludePaths(llvm::StringRef Base,
CXXSystem, true, false, false);
}
+void InitHeaderSearch::AddMinGW64CXXPaths(llvm::StringRef Base) {
+ AddPath(Base,
+ CXXSystem, true, false, false);
+ AddPath(Base + "/x86_64-w64-mingw32",
+ CXXSystem, true, false, false);
+ AddPath(Base + "/backward",
+ CXXSystem, true, false, false);
+}
+
// FIXME: This probably should goto to some platform utils place.
#ifdef _MSC_VER
@@ -428,6 +446,7 @@ void InitHeaderSearch::AddDefaultCIncludePaths(const llvm::Triple &triple,
llvm::Triple::OSType os = triple.getOS();
switch (os) {
+ case llvm::Triple::FreeBSD:
case llvm::Triple::NetBSD:
break;
default:
@@ -533,6 +552,11 @@ void InitHeaderSearch::AddDefaultCIncludePaths(const llvm::Triple &triple,
AddPath("/usr/include/w32api", System, true, false, false);
break;
case llvm::Triple::MinGW32:
+ // FIXME: We should be aware of i686-w64-mingw32.
+ if (triple.getArch() == llvm::Triple::x86_64)
+ AddPath("c:/mingw/x86_64-w64-mingw32/include",
+ System, true, false, false);
+ AddPath("/mingw/include", System, true, false, false);
AddPath("c:/mingw/include", System, true, false, false);
break;
default:
@@ -559,36 +583,8 @@ AddDefaultCPlusPlusIncludePaths(const llvm::Triple &triple) {
return;
}
// FIXME: temporary hack: hard-coded paths.
- switch (os) {
- case llvm::Triple::Cygwin:
- // Cygwin-1.7
- AddMinGWCPlusPlusIncludePaths("/usr/lib/gcc", "i686-pc-cygwin", "4.3.4");
- // g++-4 / Cygwin-1.5
- AddMinGWCPlusPlusIncludePaths("/usr/lib/gcc", "i686-pc-cygwin", "4.3.2");
- // FIXME: Do we support g++-3.4.4?
- AddMinGWCPlusPlusIncludePaths("/usr/lib/gcc", "i686-pc-cygwin", "3.4.4");
- break;
- case llvm::Triple::MinGW32:
- // mingw-w64-20110207
- AddPath("c:/MinGW/include/c++/4.5.3", CXXSystem, true, false, false);
- AddPath("c:/MinGW/include/c++/4.5.3/x86_64-w64-mingw32", CXXSystem, true,
- false, false);
- AddPath("c:/MinGW/include/c++/4.5.3/backward", CXXSystem, true, false,
- false);
- // mingw-w64-20101129
- AddPath("c:/MinGW/include/c++/4.5.2", CXXSystem, true, false, false);
- AddPath("c:/MinGW/include/c++/4.5.2/x86_64-w64-mingw32", CXXSystem, true,
- false, false);
- AddPath("c:/MinGW/include/c++/4.5.2/backward", CXXSystem, true, false,
- false);
- // Try gcc 4.5.0
- AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.5.0");
- // Try gcc 4.4.0
- AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.4.0");
- // Try gcc 4.3.0
- AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.3.0");
- break;
- case llvm::Triple::Darwin:
+
+ if (triple.isOSDarwin()) {
switch (triple.getArch()) {
default: break;
@@ -618,6 +614,34 @@ AddDefaultCPlusPlusIncludePaths(const llvm::Triple &triple) {
"arm-apple-darwin10", "v6", "", triple);
break;
}
+ return;
+ }
+
+ switch (os) {
+ case llvm::Triple::Cygwin:
+ // Cygwin-1.7
+ AddMinGWCPlusPlusIncludePaths("/usr/lib/gcc", "i686-pc-cygwin", "4.3.4");
+ // g++-4 / Cygwin-1.5
+ AddMinGWCPlusPlusIncludePaths("/usr/lib/gcc", "i686-pc-cygwin", "4.3.2");
+ // FIXME: Do we support g++-3.4.4?
+ AddMinGWCPlusPlusIncludePaths("/usr/lib/gcc", "i686-pc-cygwin", "3.4.4");
+ break;
+ case llvm::Triple::MinGW32:
+ // FIXME: We should be aware of i686-w64-mingw32.
+ if (triple.getArch() == llvm::Triple::x86_64) {
+ // mingw-w64-20110207
+ AddMinGW64CXXPaths("c:/mingw/x86_64-w64-mingw32/include/c++/4.5.3");
+ // mingw-w64-20101129
+ AddMinGW64CXXPaths("c:/mingw/x86_64-w64-mingw32/include/c++/4.5.2");
+ }
+ // Try gcc 4.5.2 (MSYS)
+ AddMinGWCPlusPlusIncludePaths("/mingw/lib/gcc", "mingw32", "4.5.2");
+ // Try gcc 4.5.0
+ AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.5.0");
+ // Try gcc 4.4.0
+ AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.4.0");
+ // Try gcc 4.3.0
+ AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.3.0");
break;
case llvm::Triple::DragonFly:
AddPath("/usr/include/c++/4.1", CXXSystem, true, false, false);
@@ -665,6 +689,11 @@ AddDefaultCPlusPlusIncludePaths(const llvm::Triple &triple) {
//===------------------------------------------------------------------===//
// Redhat based distros.
//===------------------------------------------------------------------===//
+ // Fedora 15
+ AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.6.0",
+ "x86_64-redhat-linux", "32", "", triple);
+ AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.6.0",
+ "i686-redhat-linux", "", "", triple);
// Fedora 14
AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.5.1",
"x86_64-redhat-linux", "32", "", triple);
@@ -737,7 +766,26 @@ AddDefaultCPlusPlusIncludePaths(const llvm::Triple &triple) {
"i686-pc-linux-gnu", "", "", triple);
AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3.1",
"x86_64-unknown-linux-gnu", "", "", triple);
- // Gentoo x86 2010.0 stable
+
+ // Arch Linux gcc 4.6
+ AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.6.0",
+ "i686-pc-linux-gnu", "", "", triple);
+ AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.6.0",
+ "x86_64-unknown-linux-gnu", "", "", triple);
+
+ // Gentoo x86 gcc 4.5.2
+ AddGnuCPlusPlusIncludePaths(
+ "/usr/lib/gcc/i686-pc-linux-gnu/4.5.2/include/g++-v4",
+ "i686-pc-linux-gnu", "", "", triple);
+ // Gentoo x86 gcc 4.4.5
+ AddGnuCPlusPlusIncludePaths(
+ "/usr/lib/gcc/i686-pc-linux-gnu/4.4.5/include/g++-v4",
+ "i686-pc-linux-gnu", "", "", triple);
+ // Gentoo x86 gcc 4.4.4
+ AddGnuCPlusPlusIncludePaths(
+ "/usr/lib/gcc/i686-pc-linux-gnu/4.4.4/include/g++-v4",
+ "i686-pc-linux-gnu", "", "", triple);
+ // Gentoo x86 2010.0 stable
AddGnuCPlusPlusIncludePaths(
"/usr/lib/gcc/i686-pc-linux-gnu/4.4.3/include/g++-v4",
"i686-pc-linux-gnu", "", "", triple);
@@ -753,7 +801,15 @@ AddDefaultCPlusPlusIncludePaths(const llvm::Triple &triple) {
AddGnuCPlusPlusIncludePaths(
"/usr/lib/gcc/i686-pc-linux-gnu/4.1.2/include/g++-v4",
"i686-pc-linux-gnu", "", "", triple);
+ // Gentoo x86 llvm-gcc trunk
+ AddGnuCPlusPlusIncludePaths(
+ "/usr/lib/llvm-gcc-4.2-9999/include/c++/4.2.1",
+ "i686-pc-linux-gnu", "", "", triple);
+ // Gentoo amd64 gcc 4.5.2
+ AddGnuCPlusPlusIncludePaths(
+ "/usr/lib/gcc/x86_64-pc-linux-gnu/4.5.2/include/g++-v4",
+ "x86_64-pc-linux-gnu", "32", "", triple);
// Gentoo amd64 gcc 4.4.5
AddGnuCPlusPlusIncludePaths(
"/usr/lib/gcc/x86_64-pc-linux-gnu/4.4.5/include/g++-v4",
@@ -773,7 +829,7 @@ AddDefaultCPlusPlusIncludePaths(const llvm::Triple &triple) {
// Gentoo amd64 stable
AddGnuCPlusPlusIncludePaths(
"/usr/lib/gcc/x86_64-pc-linux-gnu/4.1.2/include/g++-v4",
- "i686-pc-linux-gnu", "", "", triple);
+ "x86_64-pc-linux-gnu", "", "", triple);
// Gentoo amd64 llvm-gcc trunk
AddGnuCPlusPlusIncludePaths(
@@ -822,7 +878,7 @@ void InitHeaderSearch::AddDefaultSystemIncludePaths(const LangOptions &Lang,
AddDefaultCIncludePaths(triple, HSOpts);
// Add the default framework include paths on Darwin.
- if (triple.getOS() == llvm::Triple::Darwin) {
+ if (triple.isOSDarwin()) {
AddPath("/System/Library/Frameworks", System, true, false, true);
AddPath("/Library/Frameworks", System, true, false, true);
}
diff --git a/lib/Frontend/InitPreprocessor.cpp b/lib/Frontend/InitPreprocessor.cpp
index 91b5280a87ef..abe251d67df2 100644
--- a/lib/Frontend/InitPreprocessor.cpp
+++ b/lib/Frontend/InitPreprocessor.cpp
@@ -247,13 +247,18 @@ static void InitializePredefinedMacros(const TargetInfo &TI,
Builder.defineMacro("__GNUC_PATCHLEVEL__", "1");
Builder.defineMacro("__GNUC__", "4");
Builder.defineMacro("__GXX_ABI_VERSION", "1002");
- Builder.defineMacro("__VERSION__", "\"4.2.1 Compatible Clang Compiler\"");
+
+ // As sad as it is, enough software depends on the __VERSION__ for version
+ // checks that it is necessary to report 4.2.1 (the base GCC version we claim
+ // compatibility with) first.
+ Builder.defineMacro("__VERSION__", "\"4.2.1 Compatible " +
+ llvm::Twine(getClangFullCPPVersion()) + "\"");
// Initialize language-specific preprocessor defines.
// These should all be defined in the preprocessor according to the
// current language configuration.
- if (!LangOpts.Microsoft)
+ if (!LangOpts.Microsoft && !LangOpts.TraditionalCPP)
Builder.defineMacro("__STDC__");
if (LangOpts.AsmPreprocessor)
Builder.defineMacro("__ASSEMBLER__");
@@ -313,8 +318,10 @@ static void InitializePredefinedMacros(const TargetInfo &TI,
if (LangOpts.SjLjExceptions)
Builder.defineMacro("__USING_SJLJ_EXCEPTIONS__");
- if (LangOpts.CPlusPlus) {
+ if (LangOpts.Deprecated)
Builder.defineMacro("__DEPRECATED");
+
+ if (LangOpts.CPlusPlus) {
Builder.defineMacro("__GNUG__", "4");
Builder.defineMacro("__GXX_WEAK__");
if (LangOpts.GNUMode)
@@ -328,12 +335,6 @@ static void InitializePredefinedMacros(const TargetInfo &TI,
}
if (LangOpts.Microsoft) {
- // Filter out some microsoft extensions when trying to parse in ms-compat
- // mode.
- Builder.defineMacro("__int8", "__INT8_TYPE__");
- Builder.defineMacro("__int16", "__INT16_TYPE__");
- Builder.defineMacro("__int32", "__INT32_TYPE__");
- Builder.defineMacro("__int64", "__INT64_TYPE__");
// Both __PRETTY_FUNCTION__ and __FUNCTION__ are GCC extensions, however
// VC++ appears to only like __FUNCTION__.
Builder.defineMacro("__PRETTY_FUNCTION__", "__FUNCTION__");
@@ -414,6 +415,9 @@ static void InitializePredefinedMacros(const TargetInfo &TI,
if (!LangOpts.CharIsSigned)
Builder.defineMacro("__CHAR_UNSIGNED__");
+ if (!TargetInfo::isTypeSigned(TI.getWIntType()))
+ Builder.defineMacro("__WINT_UNSIGNED__");
+
// Define exact-width integer types for stdint.h
Builder.defineMacro("__INT" + llvm::Twine(TI.getCharWidth()) + "_TYPE__",
"char");
@@ -531,20 +535,13 @@ static void InitializeFileRemapping(Diagnostic &Diags,
continue;
}
- // Load the contents of the file we're mapping to.
- std::string ErrorStr;
- const llvm::MemoryBuffer *Buffer
- = FileMgr.getBufferForFile(ToFile->getName(), &ErrorStr);
- if (!Buffer) {
- Diags.Report(diag::err_fe_error_opening)
- << Remap->second << ErrorStr;
- continue;
- }
-
// Override the contents of the "from" file with the contents of
// the "to" file.
- SourceMgr.overrideFileContents(FromFile, Buffer);
+ SourceMgr.overrideFileContents(FromFile, ToFile);
}
+
+ SourceMgr.setOverridenFilesKeepOriginalName(
+ InitOpts.RemappedFilesKeepOriginalName);
}
/// InitializePreprocessor - Initialize the preprocessor getting it and the
diff --git a/lib/Frontend/LogDiagnosticPrinter.cpp b/lib/Frontend/LogDiagnosticPrinter.cpp
new file mode 100644
index 000000000000..954bad4e7c54
--- /dev/null
+++ b/lib/Frontend/LogDiagnosticPrinter.cpp
@@ -0,0 +1,146 @@
+//===--- LogDiagnosticPrinter.cpp - Log Diagnostic Printer ----------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "clang/Frontend/LogDiagnosticPrinter.h"
+#include "clang/Basic/FileManager.h"
+#include "clang/Basic/SourceManager.h"
+#include "llvm/ADT/SmallString.h"
+#include "llvm/Support/raw_ostream.h"
+using namespace clang;
+
+LogDiagnosticPrinter::LogDiagnosticPrinter(llvm::raw_ostream &os,
+ const DiagnosticOptions &diags,
+ bool _OwnsOutputStream)
+ : OS(os), LangOpts(0), DiagOpts(&diags),
+ OwnsOutputStream(_OwnsOutputStream) {
+}
+
+LogDiagnosticPrinter::~LogDiagnosticPrinter() {
+ if (OwnsOutputStream)
+ delete &OS;
+}
+
+static llvm::StringRef getLevelName(Diagnostic::Level Level) {
+ switch (Level) {
+ default:
+ return "<unknown>";
+ case Diagnostic::Ignored: return "ignored";
+ case Diagnostic::Note: return "note";
+ case Diagnostic::Warning: return "warning";
+ case Diagnostic::Error: return "error";
+ case Diagnostic::Fatal: return "fatal error";
+ }
+}
+
+void LogDiagnosticPrinter::EndSourceFile() {
+ // We emit all the diagnostics in EndSourceFile. However, we don't emit any
+ // entry if no diagnostics were present.
+ //
+ // Note that DiagnosticClient has no "end-of-compilation" callback, so we will
+ // miss any diagnostics which are emitted after and outside the translation
+ // unit processing.
+ if (Entries.empty())
+ return;
+
+ // Write to a temporary string to ensure atomic write of diagnostic object.
+ llvm::SmallString<512> Msg;
+ llvm::raw_svector_ostream OS(Msg);
+
+ OS << "<dict>\n";
+ if (!MainFilename.empty()) {
+ OS << " <key>main-file</key>\n"
+ << " <string>" << MainFilename << "</string>\n";
+ }
+ if (!DwarfDebugFlags.empty()) {
+ OS << " <key>dwarf-debug-flags</key>\n"
+ << " <string>" << DwarfDebugFlags << "</string>\n";
+ }
+ OS << " <key>diagnostics</key>\n";
+ OS << " <array>\n";
+ for (unsigned i = 0, e = Entries.size(); i != e; ++i) {
+ DiagEntry &DE = Entries[i];
+
+ OS << " <dict>\n";
+ OS << " <key>level</key>\n"
+ << " <string>" << getLevelName(DE.DiagnosticLevel) << "</string>\n";
+ if (!DE.Filename.empty()) {
+ OS << " <key>filename</key>\n"
+ << " <string>" << DE.Filename << "</string>\n";
+ }
+ if (DE.Line != 0) {
+ OS << " <key>line</key>\n"
+ << " <integer>" << DE.Line << "</integer>\n";
+ }
+ if (DE.Column != 0) {
+ OS << " <key>column</key>\n"
+ << " <integer>" << DE.Column << "</integer>\n";
+ }
+ if (!DE.Message.empty()) {
+ OS << " <key>message</key>\n"
+ << " <string>" << DE.Message << "</string>\n";
+ }
+ OS << " </dict>\n";
+ }
+ OS << " </array>\n";
+ OS << "</dict>\n";
+
+ this->OS << OS.str();
+}
+
+void LogDiagnosticPrinter::HandleDiagnostic(Diagnostic::Level Level,
+ const DiagnosticInfo &Info) {
+ // Default implementation (Warnings/errors count).
+ DiagnosticClient::HandleDiagnostic(Level, Info);
+
+ // Initialize the main file name, if we haven't already fetched it.
+ if (MainFilename.empty()) {
+ const SourceManager &SM = Info.getSourceManager();
+ FileID FID = SM.getMainFileID();
+ if (!FID.isInvalid()) {
+ const FileEntry *FE = SM.getFileEntryForID(FID);
+ if (FE && FE->getName())
+ MainFilename = FE->getName();
+ }
+ }
+
+ // Create the diag entry.
+ DiagEntry DE;
+ DE.DiagnosticID = Info.getID();
+ DE.DiagnosticLevel = Level;
+
+ // Format the message.
+ llvm::SmallString<100> MessageStr;
+ Info.FormatDiagnostic(MessageStr);
+ DE.Message = MessageStr.str();
+
+ // Set the location information.
+ DE.Filename = "";
+ DE.Line = DE.Column = 0;
+ if (Info.getLocation().isValid()) {
+ const SourceManager &SM = Info.getSourceManager();
+ PresumedLoc PLoc = SM.getPresumedLoc(Info.getLocation());
+
+ if (PLoc.isInvalid()) {
+ // At least print the file name if available:
+ FileID FID = SM.getFileID(Info.getLocation());
+ if (!FID.isInvalid()) {
+ const FileEntry *FE = SM.getFileEntryForID(FID);
+ if (FE && FE->getName())
+ DE.Filename = FE->getName();
+ }
+ } else {
+ DE.Filename = PLoc.getFilename();
+ DE.Line = PLoc.getLine();
+ DE.Column = PLoc.getColumn();
+ }
+ }
+
+ // Record the diagnostic entry.
+ Entries.push_back(DE);
+}
diff --git a/lib/Frontend/MultiplexConsumer.cpp b/lib/Frontend/MultiplexConsumer.cpp
index 3649c3c99728..5aa65d7a60aa 100644
--- a/lib/Frontend/MultiplexConsumer.cpp
+++ b/lib/Frontend/MultiplexConsumer.cpp
@@ -95,6 +95,10 @@ public:
virtual void AddedCXXImplicitMember(const CXXRecordDecl *RD, const Decl *D);
virtual void AddedCXXTemplateSpecialization(const ClassTemplateDecl *TD,
const ClassTemplateSpecializationDecl *D);
+ virtual void AddedCXXTemplateSpecialization(const FunctionTemplateDecl *TD,
+ const FunctionDecl *D);
+ virtual void CompletedImplicitDefinition(const FunctionDecl *D);
+ virtual void StaticDataMemberInstantiated(const VarDecl *D);
private:
std::vector<ASTMutationListener*> Listeners;
};
@@ -125,6 +129,21 @@ void MultiplexASTMutationListener::AddedCXXTemplateSpecialization(
for (size_t i = 0, e = Listeners.size(); i != e; ++i)
Listeners[i]->AddedCXXTemplateSpecialization(TD, D);
}
+void MultiplexASTMutationListener::AddedCXXTemplateSpecialization(
+ const FunctionTemplateDecl *TD, const FunctionDecl *D) {
+ for (size_t i = 0, e = Listeners.size(); i != e; ++i)
+ Listeners[i]->AddedCXXTemplateSpecialization(TD, D);
+}
+void MultiplexASTMutationListener::CompletedImplicitDefinition(
+ const FunctionDecl *D) {
+ for (size_t i = 0, e = Listeners.size(); i != e; ++i)
+ Listeners[i]->CompletedImplicitDefinition(D);
+}
+void MultiplexASTMutationListener::StaticDataMemberInstantiated(
+ const VarDecl *D) {
+ for (size_t i = 0, e = Listeners.size(); i != e; ++i)
+ Listeners[i]->StaticDataMemberInstantiated(D);
+}
} // end namespace clang
diff --git a/lib/Frontend/PrintPreprocessedOutput.cpp b/lib/Frontend/PrintPreprocessedOutput.cpp
index 922d743adf4e..b46e04749ba3 100644
--- a/lib/Frontend/PrintPreprocessedOutput.cpp
+++ b/lib/Frontend/PrintPreprocessedOutput.cpp
@@ -432,7 +432,7 @@ struct UnknownPragmaHandler : public PragmaHandler {
Callbacks->OS.write(Prefix, strlen(Prefix));
Callbacks->SetEmittedTokensOnThisLine();
// Read and print all of the pragma tokens.
- while (PragmaTok.isNot(tok::eom)) {
+ while (PragmaTok.isNot(tok::eod)) {
if (PragmaTok.hasLeadingSpace())
Callbacks->OS << ' ';
std::string TokSpell = PP.getSpelling(PragmaTok);
diff --git a/lib/Frontend/StmtXML.cpp b/lib/Frontend/StmtXML.cpp
deleted file mode 100644
index c113cc18dc1c..000000000000
--- a/lib/Frontend/StmtXML.cpp
+++ /dev/null
@@ -1,439 +0,0 @@
-//===--- StmtXML.cpp - XML implementation for Stmt ASTs ------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//
-// This file implements the Stmt::dumpXML methods, which dump out the
-// AST to an XML document.
-//
-//===----------------------------------------------------------------------===//
-
-#include "clang/Frontend/DocumentXML.h"
-#include "clang/AST/StmtVisitor.h"
-#include "clang/AST/DeclObjC.h"
-#include "clang/AST/DeclCXX.h"
-#include "clang/Basic/SourceManager.h"
-using namespace clang;
-
-//===----------------------------------------------------------------------===//
-// StmtXML Visitor
-//===----------------------------------------------------------------------===//
-
-namespace {
- class StmtXML : public StmtVisitor<StmtXML> {
- DocumentXML& Doc;
-
- //static const char *getOpcodeStr(UnaryOperator::Opcode Op);
- //static const char *getOpcodeStr(BinaryOperator::Opcode Op);
-
-
- void addSpecialAttribute(const char* pName, StringLiteral* Str) {
- Doc.addAttribute(pName, Doc.escapeString(Str->getString().data(),
- Str->getString().size()));
- }
-
- void addSpecialAttribute(const char* pName, SizeOfAlignOfExpr* S) {
- if (S->isArgumentType())
- Doc.addAttribute(pName, S->getArgumentType());
- }
-
- void addSpecialAttribute(const char* pName, CXXTypeidExpr* S) {
- if (S->isTypeOperand())
- Doc.addAttribute(pName, S->getTypeOperand());
- }
-
-
- public:
- StmtXML(DocumentXML& doc)
- : Doc(doc) {
- }
-
- void DumpSubTree(Stmt *S) {
- if (S) {
- Visit(S);
- if (DeclStmt* DS = dyn_cast<DeclStmt>(S)) {
- for (DeclStmt::decl_iterator DI = DS->decl_begin(),
- DE = DS->decl_end(); DI != DE; ++DI) {
- Doc.PrintDecl(*DI);
- }
- } else {
- for (Stmt::child_range i = S->children(); i; ++i)
- DumpSubTree(*i);
- }
- Doc.toParent();
- } else {
- Doc.addSubNode("NULL").toParent();
- }
- }
-
-
-#define NODE_XML( CLASS, NAME ) \
- void Visit##CLASS(CLASS* S) \
- { \
- typedef CLASS tStmtType; \
- Doc.addSubNode(NAME);
-
-#define ATTRIBUTE_XML( FN, NAME ) Doc.addAttribute(NAME, S->FN);
-#define TYPE_ATTRIBUTE_XML( FN ) ATTRIBUTE_XML(FN, "type")
-#define ATTRIBUTE_OPT_XML( FN, NAME ) Doc.addAttributeOptional(NAME, S->FN);
-#define ATTRIBUTE_SPECIAL_XML( FN, NAME ) addSpecialAttribute(NAME, S);
-#define ATTRIBUTE_FILE_LOCATION_XML Doc.addLocationRange(S->getSourceRange());
-
-
-#define ATTRIBUTE_ENUM_XML( FN, NAME ) \
- { \
- const char* pAttributeName = NAME; \
- const bool optional = false; \
- switch (S->FN) { \
- default: assert(0 && "unknown enum value");
-
-#define ATTRIBUTE_ENUM_OPT_XML( FN, NAME ) \
- { \
- const char* pAttributeName = NAME; \
- const bool optional = true; \
- switch (S->FN) { \
- default: assert(0 && "unknown enum value");
-
-#define ENUM_XML( VALUE, NAME ) case VALUE: if ((!optional) || NAME[0]) Doc.addAttribute(pAttributeName, NAME); break;
-#define END_ENUM_XML } }
-#define END_NODE_XML }
-
-#define ID_ATTRIBUTE_XML Doc.addAttribute("id", S);
-#define SUB_NODE_XML( CLASS )
-#define SUB_NODE_SEQUENCE_XML( CLASS )
-#define SUB_NODE_OPT_XML( CLASS )
-
-#include "clang/Frontend/StmtXML.def"
-
-#if (0)
- // Stmts.
- void VisitStmt(Stmt *Node);
- void VisitDeclStmt(DeclStmt *Node);
- void VisitLabelStmt(LabelStmt *Node);
- void VisitGotoStmt(GotoStmt *Node);
-
- // Exprs
- void VisitExpr(Expr *Node);
- void VisitDeclRefExpr(DeclRefExpr *Node);
- void VisitPredefinedExpr(PredefinedExpr *Node);
- void VisitCharacterLiteral(CharacterLiteral *Node);
- void VisitIntegerLiteral(IntegerLiteral *Node);
- void VisitFloatingLiteral(FloatingLiteral *Node);
- void VisitStringLiteral(StringLiteral *Str);
- void VisitUnaryOperator(UnaryOperator *Node);
- void VisitOffsetOfExpr(OffsetOfExpr *Node);
- void VisitSizeOfAlignOfExpr(SizeOfAlignOfExpr *Node);
- void VisitMemberExpr(MemberExpr *Node);
- void VisitExtVectorElementExpr(ExtVectorElementExpr *Node);
- void VisitBinaryOperator(BinaryOperator *Node);
- void VisitCompoundAssignOperator(CompoundAssignOperator *Node);
- void VisitAddrLabelExpr(AddrLabelExpr *Node);
-
- // C++
- void VisitCXXNamedCastExpr(CXXNamedCastExpr *Node);
- void VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *Node);
- void VisitCXXThisExpr(CXXThisExpr *Node);
- void VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *Node);
-
- // ObjC
- void VisitObjCEncodeExpr(ObjCEncodeExpr *Node);
- void VisitObjCMessageExpr(ObjCMessageExpr* Node);
- void VisitObjCSelectorExpr(ObjCSelectorExpr *Node);
- void VisitObjCProtocolExpr(ObjCProtocolExpr *Node);
- void VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *Node);
- void VisitObjCImplicitSetterGetterRefExpr(
- ObjCImplicitSetterGetterRefExpr *Node);
- void VisitObjCIvarRefExpr(ObjCIvarRefExpr *Node);
-#endif
- };
-}
-
-//===----------------------------------------------------------------------===//
-// Stmt printing methods.
-//===----------------------------------------------------------------------===//
-#if (0)
-void StmtXML::VisitStmt(Stmt *Node) {
- // nothing special to do
-}
-
-void StmtXML::VisitDeclStmt(DeclStmt *Node) {
- for (DeclStmt::decl_iterator DI = Node->decl_begin(), DE = Node->decl_end();
- DI != DE; ++DI) {
- Doc.PrintDecl(*DI);
- }
-}
-
-void StmtXML::VisitLabelStmt(LabelStmt *Node) {
- Doc.addAttribute("name", Node->getName());
-}
-
-void StmtXML::VisitGotoStmt(GotoStmt *Node) {
- Doc.addAttribute("name", Node->getLabel()->getName());
-}
-
-//===----------------------------------------------------------------------===//
-// Expr printing methods.
-//===----------------------------------------------------------------------===//
-
-void StmtXML::VisitExpr(Expr *Node) {
- DumpExpr(Node);
-}
-
-void StmtXML::VisitDeclRefExpr(DeclRefExpr *Node) {
- DumpExpr(Node);
-
- const char* pKind;
- switch (Node->getDecl()->getKind()) {
- case Decl::Function: pKind = "FunctionDecl"; break;
- case Decl::Var: pKind = "Var"; break;
- case Decl::ParmVar: pKind = "ParmVar"; break;
- case Decl::EnumConstant: pKind = "EnumConstant"; break;
- case Decl::Typedef: pKind = "Typedef"; break;
- case Decl::Record: pKind = "Record"; break;
- case Decl::Enum: pKind = "Enum"; break;
- case Decl::CXXRecord: pKind = "CXXRecord"; break;
- case Decl::ObjCInterface: pKind = "ObjCInterface"; break;
- case Decl::ObjCClass: pKind = "ObjCClass"; break;
- default: pKind = "Decl"; break;
- }
-
- Doc.addAttribute("kind", pKind);
- Doc.addAttribute("name", Node->getDecl()->getNameAsString());
- Doc.addRefAttribute(Node->getDecl());
-}
-
-void StmtXML::VisitPredefinedExpr(PredefinedExpr *Node) {
- DumpExpr(Node);
- switch (Node->getIdentType()) {
- default: assert(0 && "unknown case");
- case PredefinedExpr::Func: Doc.addAttribute("predefined", " __func__"); break;
- case PredefinedExpr::Function: Doc.addAttribute("predefined", " __FUNCTION__"); break;
- case PredefinedExpr::PrettyFunction: Doc.addAttribute("predefined", " __PRETTY_FUNCTION__");break;
- }
-}
-
-void StmtXML::VisitCharacterLiteral(CharacterLiteral *Node) {
- DumpExpr(Node);
- Doc.addAttribute("value", Node->getValue());
-}
-
-void StmtXML::VisitIntegerLiteral(IntegerLiteral *Node) {
- DumpExpr(Node);
- bool isSigned = Node->getType()->isSignedIntegerType();
- Doc.addAttribute("value", Node->getValue().toString(10, isSigned));
-}
-
-void StmtXML::VisitFloatingLiteral(FloatingLiteral *Node) {
- DumpExpr(Node);
- // FIXME: output float as written in source (no approximation or the like)
- //Doc.addAttribute("value", Node->getValueAsApproximateDouble()));
- Doc.addAttribute("value", "FIXME");
-}
-
-void StmtXML::VisitStringLiteral(StringLiteral *Str) {
- DumpExpr(Str);
- if (Str->isWide())
- Doc.addAttribute("is_wide", "1");
-
- Doc.addAttribute("value", Doc.escapeString(Str->getStrData(), Str->getByteLength()));
-}
-
-
-const char *StmtXML::getOpcodeStr(UnaryOperator::Opcode Op) {
- switch (Op) {
- default: assert(0 && "Unknown unary operator");
- case UnaryOperator::PostInc: return "postinc";
- case UnaryOperator::PostDec: return "postdec";
- case UnaryOperator::PreInc: return "preinc";
- case UnaryOperator::PreDec: return "predec";
- case UnaryOperator::AddrOf: return "addrof";
- case UnaryOperator::Deref: return "deref";
- case UnaryOperator::Plus: return "plus";
- case UnaryOperator::Minus: return "minus";
- case UnaryOperator::Not: return "not";
- case UnaryOperator::LNot: return "lnot";
- case UnaryOperator::Real: return "__real";
- case UnaryOperator::Imag: return "__imag";
- case UnaryOperator::Extension: return "__extension__";
- }
-}
-
-
-const char *StmtXML::getOpcodeStr(BinaryOperator::Opcode Op) {
- switch (Op) {
- default: assert(0 && "Unknown binary operator");
- case BinaryOperator::PtrMemD: return "ptrmemd";
- case BinaryOperator::PtrMemI: return "ptrmemi";
- case BinaryOperator::Mul: return "mul";
- case BinaryOperator::Div: return "div";
- case BinaryOperator::Rem: return "rem";
- case BinaryOperator::Add: return "add";
- case BinaryOperator::Sub: return "sub";
- case BinaryOperator::Shl: return "shl";
- case BinaryOperator::Shr: return "shr";
- case BinaryOperator::LT: return "lt";
- case BinaryOperator::GT: return "gt";
- case BinaryOperator::LE: return "le";
- case BinaryOperator::GE: return "ge";
- case BinaryOperator::EQ: return "eq";
- case BinaryOperator::NE: return "ne";
- case BinaryOperator::And: return "and";
- case BinaryOperator::Xor: return "xor";
- case BinaryOperator::Or: return "or";
- case BinaryOperator::LAnd: return "land";
- case BinaryOperator::LOr: return "lor";
- case BinaryOperator::Assign: return "assign";
- case BinaryOperator::MulAssign: return "mulassign";
- case BinaryOperator::DivAssign: return "divassign";
- case BinaryOperator::RemAssign: return "remassign";
- case BinaryOperator::AddAssign: return "addassign";
- case BinaryOperator::SubAssign: return "subassign";
- case BinaryOperator::ShlAssign: return "shlassign";
- case BinaryOperator::ShrAssign: return "shrassign";
- case BinaryOperator::AndAssign: return "andassign";
- case BinaryOperator::XorAssign: return "xorassign";
- case BinaryOperator::OrAssign: return "orassign";
- case BinaryOperator::Comma: return "comma";
- }
-}
-
-void StmtXML::VisitUnaryOperator(UnaryOperator *Node) {
- DumpExpr(Node);
- Doc.addAttribute("op_code", getOpcodeStr(Node->getOpcode()));
-}
-
-void StmtXML::OffsetOfExpr(OffsetOfExpr *Node) {
- DumpExpr(Node);
-}
-
-void StmtXML::VisitSizeOfAlignOfExpr(SizeOfAlignOfExpr *Node) {
- DumpExpr(Node);
- Doc.addAttribute("is_sizeof", Node->isSizeOf() ? "sizeof" : "alignof");
- Doc.addAttribute("is_type", Node->isArgumentType() ? "1" : "0");
- if (Node->isArgumentType())
- DumpTypeExpr(Node->getArgumentType());
-}
-
-void StmtXML::VisitMemberExpr(MemberExpr *Node) {
- DumpExpr(Node);
- Doc.addAttribute("is_deref", Node->isArrow() ? "1" : "0");
- Doc.addAttribute("name", Node->getMemberDecl()->getNameAsString());
- Doc.addRefAttribute(Node->getMemberDecl());
-}
-
-void StmtXML::VisitExtVectorElementExpr(ExtVectorElementExpr *Node) {
- DumpExpr(Node);
- Doc.addAttribute("name", Node->getAccessor().getName());
-}
-
-void StmtXML::VisitBinaryOperator(BinaryOperator *Node) {
- DumpExpr(Node);
- Doc.addAttribute("op_code", getOpcodeStr(Node->getOpcode()));
-}
-
-void StmtXML::VisitCompoundAssignOperator(CompoundAssignOperator *Node) {
- VisitBinaryOperator(Node);
-/* FIXME: is this needed in the AST?
- DumpExpr(Node);
- CurrentNode = CurrentNode->addSubNode("ComputeLHSTy");
- DumpType(Node->getComputationLHSType());
- CurrentNode = CurrentNode->Parent->addSubNode("ComputeResultTy");
- DumpType(Node->getComputationResultType());
- Doc.toParent();
-*/
-}
-
-// GNU extensions.
-
-void StmtXML::VisitAddrLabelExpr(AddrLabelExpr *Node) {
- DumpExpr(Node);
- Doc.addAttribute("name", Node->getLabel()->getName());
-}
-
-//===----------------------------------------------------------------------===//
-// C++ Expressions
-//===----------------------------------------------------------------------===//
-
-void StmtXML::VisitCXXNamedCastExpr(CXXNamedCastExpr *Node) {
- DumpExpr(Node);
- Doc.addAttribute("kind", Node->getCastName());
- DumpTypeExpr(Node->getTypeAsWritten());
-}
-
-void StmtXML::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *Node) {
- DumpExpr(Node);
- Doc.addAttribute("value", Node->getValue() ? "true" : "false");
-}
-
-void StmtXML::VisitCXXThisExpr(CXXThisExpr *Node) {
- DumpExpr(Node);
-}
-
-void StmtXML::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *Node) {
- DumpExpr(Node);
- DumpTypeExpr(Node->getTypeAsWritten());
-}
-
-//===----------------------------------------------------------------------===//
-// Obj-C Expressions
-//===----------------------------------------------------------------------===//
-
-void StmtXML::VisitObjCMessageExpr(ObjCMessageExpr* Node) {
- DumpExpr(Node);
- Doc.addAttribute("selector", Node->getSelector().getAsString());
- IdentifierInfo* clsName = Node->getClassName();
- if (clsName)
- Doc.addAttribute("class", clsName->getName());
-}
-
-void StmtXML::VisitObjCEncodeExpr(ObjCEncodeExpr *Node) {
- DumpExpr(Node);
- DumpTypeExpr(Node->getEncodedType());
-}
-
-void StmtXML::VisitObjCSelectorExpr(ObjCSelectorExpr *Node) {
- DumpExpr(Node);
- Doc.addAttribute("selector", Node->getSelector().getAsString());
-}
-
-void StmtXML::VisitObjCProtocolExpr(ObjCProtocolExpr *Node) {
- DumpExpr(Node);
- Doc.addAttribute("protocol", Node->getProtocol()->getNameAsString());
-}
-
-void StmtXML::VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *Node) {
- DumpExpr(Node);
- Doc.addAttribute("property", Node->getProperty()->getNameAsString());
-}
-
-void StmtXML::VisitObjCImplicitSetterGetterRefExpr(
- ObjCImplicitSetterGetterRefExpr *Node) {
- DumpExpr(Node);
- ObjCMethodDecl *Getter = Node->getGetterMethod();
- ObjCMethodDecl *Setter = Node->getSetterMethod();
- Doc.addAttribute("Getter", Getter->getSelector().getAsString());
- Doc.addAttribute("Setter", Setter ? Setter->getSelector().getAsString().c_str() : "(null)");
-}
-
-void StmtXML::VisitObjCIvarRefExpr(ObjCIvarRefExpr *Node) {
- DumpExpr(Node);
- Doc.addAttribute("kind", Node->getDecl()->getDeclKindName());
- Doc.addAttribute("decl", Node->getDecl()->getNameAsString());
- if (Node->isFreeIvar())
- Doc.addAttribute("isFreeIvar", "1");
-}
-#endif
-//===----------------------------------------------------------------------===//
-// Stmt method implementations
-//===----------------------------------------------------------------------===//
-
-/// dumpAll - This does a dump of the specified AST fragment and all subtrees.
-void DocumentXML::PrintStmt(const Stmt *S) {
- StmtXML P(*this);
- P.DumpSubTree(const_cast<Stmt*>(S));
-}
-
diff --git a/lib/Frontend/TextDiagnosticPrinter.cpp b/lib/Frontend/TextDiagnosticPrinter.cpp
index 084915311dcc..47c942ca8dfa 100644
--- a/lib/Frontend/TextDiagnosticPrinter.cpp
+++ b/lib/Frontend/TextDiagnosticPrinter.cpp
@@ -53,8 +53,11 @@ TextDiagnosticPrinter::~TextDiagnosticPrinter() {
delete &OS;
}
-void TextDiagnosticPrinter::
-PrintIncludeStack(SourceLocation Loc, const SourceManager &SM) {
+void TextDiagnosticPrinter::PrintIncludeStack(Diagnostic::Level Level,
+ SourceLocation Loc,
+ const SourceManager &SM) {
+ if (!DiagOpts->ShowNoteIncludeStack && Level == Diagnostic::Note) return;
+
if (Loc.isInvalid()) return;
PresumedLoc PLoc = SM.getPresumedLoc(Loc);
@@ -62,7 +65,7 @@ PrintIncludeStack(SourceLocation Loc, const SourceManager &SM) {
return;
// Print out the other include frames first.
- PrintIncludeStack(PLoc.getIncludeLoc(), SM);
+ PrintIncludeStack(Level, PLoc.getIncludeLoc(), SM);
if (DiagOpts->ShowLocation)
OS << "In file included from " << PLoc.getFilename()
@@ -289,7 +292,8 @@ static void SelectInterestingSourceRegion(std::string &SourceLine,
}
}
-void TextDiagnosticPrinter::EmitCaretDiagnostic(SourceLocation Loc,
+void TextDiagnosticPrinter::EmitCaretDiagnostic(Diagnostic::Level Level,
+ SourceLocation Loc,
CharSourceRange *Ranges,
unsigned NumRanges,
const SourceManager &SM,
@@ -313,7 +317,7 @@ void TextDiagnosticPrinter::EmitCaretDiagnostic(SourceLocation Loc,
SourceLocation OneLevelUp = SM.getImmediateInstantiationRange(Loc).first;
// FIXME: Map ranges?
- EmitCaretDiagnostic(OneLevelUp, Ranges, NumRanges, SM, 0, 0, Columns,
+ EmitCaretDiagnostic(Level, OneLevelUp, Ranges, NumRanges, SM, 0, 0, Columns,
OnMacroInst + 1, MacroSkipStart, MacroSkipEnd);
// Map the location.
@@ -339,7 +343,7 @@ void TextDiagnosticPrinter::EmitCaretDiagnostic(SourceLocation Loc,
// "included from" lines.
if (LastWarningLoc != PLoc.getIncludeLoc()) {
LastWarningLoc = PLoc.getIncludeLoc();
- PrintIncludeStack(LastWarningLoc, SM);
+ PrintIncludeStack(Level, LastWarningLoc, SM);
}
if (DiagOpts->ShowLocation) {
@@ -351,8 +355,9 @@ void TextDiagnosticPrinter::EmitCaretDiagnostic(SourceLocation Loc,
}
OS << "note: instantiated from:\n";
- EmitCaretDiagnostic(Loc, Ranges, NumRanges, SM, Hints, NumHints, Columns,
- OnMacroInst + 1, MacroSkipStart, MacroSkipEnd);
+ EmitCaretDiagnostic(Level, Loc, Ranges, NumRanges, SM, Hints, NumHints,
+ Columns, OnMacroInst + 1, MacroSkipStart,
+ MacroSkipEnd);
return;
}
@@ -805,12 +810,12 @@ void TextDiagnosticPrinter::HandleDiagnostic(Diagnostic::Level Level,
// "included from" lines.
if (LastWarningLoc != PLoc.getIncludeLoc()) {
LastWarningLoc = PLoc.getIncludeLoc();
- PrintIncludeStack(LastWarningLoc, SM);
+ PrintIncludeStack(Level, LastWarningLoc, SM);
StartOfLocationInfo = OS.tell();
}
// Compute the column number.
- if (DiagOpts->ShowLocation && PLoc.isValid()) {
+ if (DiagOpts->ShowLocation) {
if (DiagOpts->ShowColors)
OS.changeColor(savedColor, true);
@@ -903,6 +908,13 @@ void TextDiagnosticPrinter::HandleDiagnostic(Diagnostic::Level Level,
llvm::SmallString<100> OutStr;
Info.FormatDiagnostic(OutStr);
+ if (DiagOpts->ShowNames &&
+ !DiagnosticIDs::isBuiltinNote(Info.getID())) {
+ OutStr += " [";
+ OutStr += DiagnosticIDs::getName(Info.getID());
+ OutStr += "]";
+ }
+
std::string OptionName;
if (DiagOpts->ShowOptionNames) {
// Was this a warning mapped to an error using -Werror or pragma?
@@ -1034,7 +1046,7 @@ void TextDiagnosticPrinter::HandleDiagnostic(Diagnostic::Level Level,
}
}
- EmitCaretDiagnostic(LastLoc, Ranges, NumRanges, LastLoc.getManager(),
+ EmitCaretDiagnostic(Level, LastLoc, Ranges, NumRanges, LastLoc.getManager(),
Info.getFixItHints(),
Info.getNumFixItHints(),
DiagOpts->MessageLength,
diff --git a/lib/Frontend/TypeXML.cpp b/lib/Frontend/TypeXML.cpp
deleted file mode 100644
index a8c8f75d4b7f..000000000000
--- a/lib/Frontend/TypeXML.cpp
+++ /dev/null
@@ -1,119 +0,0 @@
-//===--- DocumentXML.cpp - XML document for ASTs --------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//
-// This file implements the XML document class, which provides the means to
-// dump out the AST in a XML form that exposes type details and other fields.
-//
-//===----------------------------------------------------------------------===//
-
-#include "clang/Frontend/DocumentXML.h"
-#include "clang/AST/TypeVisitor.h"
-#include "clang/AST/Type.h"
-#include "clang/AST/Decl.h"
-
-namespace clang {
- namespace XML {
- namespace {
-
-//---------------------------------------------------------
-class TypeWriter : public TypeVisitor<TypeWriter> {
- DocumentXML& Doc;
-
-public:
- TypeWriter(DocumentXML& doc) : Doc(doc) {}
-
-#define NODE_XML( CLASS, NAME ) \
- void Visit##CLASS(const CLASS* T) { \
- Doc.addSubNode(NAME);
-
-#define ID_ATTRIBUTE_XML // done by the Document class itself
-#define ATTRIBUTE_XML( FN, NAME ) Doc.addAttribute(NAME, T->FN);
-#define TYPE_ATTRIBUTE_XML( FN ) ATTRIBUTE_XML(FN, "type")
-#define CONTEXT_ATTRIBUTE_XML( FN ) ATTRIBUTE_XML(FN, "context")
-#define ATTRIBUTE_OPT_XML( FN, NAME ) Doc.addAttributeOptional(NAME, T->FN);
-
-#define ATTRIBUTE_ENUM_XML( FN, NAME ) \
- { \
- const char* pAttributeName = NAME; \
- const bool optional = false; \
- switch (T->FN) { \
- default: assert(0 && "unknown enum value");
-
-#define ATTRIBUTE_ENUM_OPT_XML( FN, NAME ) \
- { \
- const char* pAttributeName = NAME; \
- const bool optional = true; \
- switch (T->FN) { \
- default: assert(0 && "unknown enum value");
-
-#define ENUM_XML( VALUE, NAME ) case VALUE: if ((!optional) || NAME[0]) Doc.addAttribute(pAttributeName, NAME); break;
-#define END_ENUM_XML } }
-#define END_NODE_XML }
-
-#include "clang/Frontend/TypeXML.def"
-
-};
-
-//---------------------------------------------------------
- } // anon clang
- } // NS XML
-
-//---------------------------------------------------------
-class DocumentXML::TypeAdder : public TypeVisitor<DocumentXML::TypeAdder> {
- DocumentXML& Doc;
-
- void addIfType(const Type* pType) {
- Doc.addTypeRecursively(pType);
- }
-
- void addIfType(const QualType& pType) {
- Doc.addTypeRecursively(pType);
- }
-
- template<class T> void addIfType(T) {}
-
-public:
- TypeAdder(DocumentXML& doc) : Doc(doc) {}
-
-#define NODE_XML( CLASS, NAME ) \
- void Visit##CLASS(const CLASS* T) \
- {
-
-#define ID_ATTRIBUTE_XML
-#define TYPE_ATTRIBUTE_XML( FN ) Doc.addTypeRecursively(T->FN);
-#define CONTEXT_ATTRIBUTE_XML( FN )
-#define ATTRIBUTE_XML( FN, NAME ) addIfType(T->FN);
-#define ATTRIBUTE_OPT_XML( FN, NAME )
-#define ATTRIBUTE_ENUM_XML( FN, NAME )
-#define ATTRIBUTE_ENUM_OPT_XML( FN, NAME )
-#define ENUM_XML( VALUE, NAME )
-#define END_ENUM_XML
-#define END_NODE_XML }
-
-#include "clang/Frontend/TypeXML.def"
-};
-
-//---------------------------------------------------------
-void DocumentXML::addParentTypes(const Type* pType) {
- TypeAdder(*this).Visit(pType);
-}
-
-//---------------------------------------------------------
-void DocumentXML::writeTypeToXML(const Type* pType) {
- XML::TypeWriter(*this).Visit(const_cast<Type*>(pType));
-}
-
-//---------------------------------------------------------
-void DocumentXML::writeTypeToXML(const QualType& pType) {
- XML::TypeWriter(*this).VisitQualType(const_cast<QualType*>(&pType));
-}
-
-//---------------------------------------------------------
-} // NS clang
-