summaryrefslogtreecommitdiffstats
path: root/contrib/llvm/tools/clang/lib/Frontend/FrontendActions.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/llvm/tools/clang/lib/Frontend/FrontendActions.cpp')
-rw-r--r--contrib/llvm/tools/clang/lib/Frontend/FrontendActions.cpp103
1 files changed, 56 insertions, 47 deletions
diff --git a/contrib/llvm/tools/clang/lib/Frontend/FrontendActions.cpp b/contrib/llvm/tools/clang/lib/Frontend/FrontendActions.cpp
index 407ccea..b1e806a 100644
--- a/contrib/llvm/tools/clang/lib/Frontend/FrontendActions.cpp
+++ b/contrib/llvm/tools/clang/lib/Frontend/FrontendActions.cpp
@@ -48,8 +48,9 @@ void InitOnlyAction::ExecuteAction() {
std::unique_ptr<ASTConsumer>
ASTPrintAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) {
- if (raw_ostream *OS = CI.createDefaultOutputFile(false, InFile))
- return CreateASTPrinter(OS, CI.getFrontendOpts().ASTDumpFilter);
+ if (std::unique_ptr<raw_ostream> OS =
+ CI.createDefaultOutputFile(false, InFile))
+ return CreateASTPrinter(std::move(OS), CI.getFrontendOpts().ASTDumpFilter);
return nullptr;
}
@@ -80,7 +81,7 @@ std::unique_ptr<ASTConsumer>
GeneratePCHAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) {
std::string Sysroot;
std::string OutputFile;
- raw_pwrite_stream *OS =
+ std::unique_ptr<raw_pwrite_stream> OS =
ComputeASTConsumerArguments(CI, InFile, Sysroot, OutputFile);
if (!OS)
return nullptr;
@@ -92,16 +93,21 @@ GeneratePCHAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) {
std::vector<std::unique_ptr<ASTConsumer>> Consumers;
Consumers.push_back(llvm::make_unique<PCHGenerator>(
CI.getPreprocessor(), OutputFile, nullptr, Sysroot,
- Buffer, CI.getFrontendOpts().ModuleFileExtensions));
+ Buffer, CI.getFrontendOpts().ModuleFileExtensions,
+ /*AllowASTWithErrors*/false,
+ /*IncludeTimestamps*/
+ +CI.getFrontendOpts().IncludeTimestamps));
Consumers.push_back(CI.getPCHContainerWriter().CreatePCHContainerGenerator(
- CI, InFile, OutputFile, OS, Buffer));
+ CI, InFile, OutputFile, std::move(OS), Buffer));
return llvm::make_unique<MultiplexConsumer>(std::move(Consumers));
}
-raw_pwrite_stream *GeneratePCHAction::ComputeASTConsumerArguments(
- CompilerInstance &CI, StringRef InFile, std::string &Sysroot,
- std::string &OutputFile) {
+std::unique_ptr<raw_pwrite_stream>
+GeneratePCHAction::ComputeASTConsumerArguments(CompilerInstance &CI,
+ StringRef InFile,
+ std::string &Sysroot,
+ std::string &OutputFile) {
Sysroot = CI.getHeaderSearchOpts().Sysroot;
if (CI.getFrontendOpts().RelocatablePCH && Sysroot.empty()) {
CI.getDiagnostics().Report(diag::err_relocatable_without_isysroot);
@@ -111,7 +117,7 @@ raw_pwrite_stream *GeneratePCHAction::ComputeASTConsumerArguments(
// We use createOutputFile here because this is exposed via libclang, and we
// must disable the RemoveFileOnSignal behavior.
// We use a temporary to avoid race conditions.
- raw_pwrite_stream *OS =
+ std::unique_ptr<raw_pwrite_stream> OS =
CI.createOutputFile(CI.getFrontendOpts().OutputFile, /*Binary=*/true,
/*RemoveFileOnSignal=*/false, InFile,
/*Extension=*/"", /*useTemporary=*/true);
@@ -127,7 +133,7 @@ GenerateModuleAction::CreateASTConsumer(CompilerInstance &CI,
StringRef InFile) {
std::string Sysroot;
std::string OutputFile;
- raw_pwrite_stream *OS =
+ std::unique_ptr<raw_pwrite_stream> OS =
ComputeASTConsumerArguments(CI, InFile, Sysroot, OutputFile);
if (!OS)
return nullptr;
@@ -142,7 +148,7 @@ GenerateModuleAction::CreateASTConsumer(CompilerInstance &CI,
/*IncludeTimestamps=*/
+CI.getFrontendOpts().BuildingImplicitModule));
Consumers.push_back(CI.getPCHContainerWriter().CreatePCHContainerGenerator(
- CI, InFile, OutputFile, OS, Buffer));
+ CI, InFile, OutputFile, std::move(OS), Buffer));
return llvm::make_unique<MultiplexConsumer>(std::move(Consumers));
}
@@ -152,10 +158,10 @@ operator+=(SmallVectorImpl<char> &Includes, StringRef RHS) {
return Includes;
}
-static std::error_code addHeaderInclude(StringRef HeaderName,
- SmallVectorImpl<char> &Includes,
- const LangOptions &LangOpts,
- bool IsExternC) {
+static void addHeaderInclude(StringRef HeaderName,
+ SmallVectorImpl<char> &Includes,
+ const LangOptions &LangOpts,
+ bool IsExternC) {
if (IsExternC && LangOpts.CPlusPlus)
Includes += "extern \"C\" {\n";
if (LangOpts.ObjC1)
@@ -168,7 +174,6 @@ static std::error_code addHeaderInclude(StringRef HeaderName,
Includes += "\"\n";
if (IsExternC && LangOpts.CPlusPlus)
Includes += "}\n";
- return std::error_code();
}
/// \brief Collect the set of header includes needed to construct the given
@@ -194,38 +199,34 @@ collectModuleHeaderIncludes(const LangOptions &LangOpts, FileManager &FileMgr,
// file relative to the module build directory (the directory containing
// the module map file) so this will find the same file that we found
// while parsing the module map.
- if (std::error_code Err = addHeaderInclude(H.NameAsWritten, Includes,
- LangOpts, Module->IsExternC))
- return Err;
+ addHeaderInclude(H.NameAsWritten, Includes, LangOpts, Module->IsExternC);
}
}
// Note that Module->PrivateHeaders will not be a TopHeader.
if (Module::Header UmbrellaHeader = Module->getUmbrellaHeader()) {
Module->addTopHeader(UmbrellaHeader.Entry);
- if (Module->Parent) {
+ if (Module->Parent)
// Include the umbrella header for submodules.
- if (std::error_code Err = addHeaderInclude(UmbrellaHeader.NameAsWritten,
- Includes, LangOpts,
- Module->IsExternC))
- return Err;
- }
+ addHeaderInclude(UmbrellaHeader.NameAsWritten, Includes, LangOpts,
+ Module->IsExternC);
} else if (Module::DirectoryName UmbrellaDir = Module->getUmbrellaDir()) {
// Add all of the headers we find in this subdirectory.
std::error_code EC;
SmallString<128> DirNative;
llvm::sys::path::native(UmbrellaDir.Entry->getName(), DirNative);
- for (llvm::sys::fs::recursive_directory_iterator Dir(DirNative, EC),
- DirEnd;
- Dir != DirEnd && !EC; Dir.increment(EC)) {
+
+ vfs::FileSystem &FS = *FileMgr.getVirtualFileSystem();
+ for (vfs::recursive_directory_iterator Dir(FS, DirNative, EC), End;
+ Dir != End && !EC; Dir.increment(EC)) {
// Check whether this entry has an extension typically associated with
// headers.
- if (!llvm::StringSwitch<bool>(llvm::sys::path::extension(Dir->path()))
+ if (!llvm::StringSwitch<bool>(llvm::sys::path::extension(Dir->getName()))
.Cases(".h", ".H", ".hh", ".hpp", true)
.Default(false))
continue;
- const FileEntry *Header = FileMgr.getFile(Dir->path());
+ const FileEntry *Header = FileMgr.getFile(Dir->getName());
// FIXME: This shouldn't happen unless there is a file system race. Is
// that worth diagnosing?
if (!Header)
@@ -238,7 +239,7 @@ collectModuleHeaderIncludes(const LangOptions &LangOpts, FileManager &FileMgr,
// Compute the relative path from the directory to this file.
SmallVector<StringRef, 16> Components;
- auto PathIt = llvm::sys::path::rbegin(Dir->path());
+ auto PathIt = llvm::sys::path::rbegin(Dir->getName());
for (int I = 0; I != Dir.level() + 1; ++I, ++PathIt)
Components.push_back(*PathIt);
SmallString<128> RelativeHeader(UmbrellaDir.NameAsWritten);
@@ -248,9 +249,7 @@ collectModuleHeaderIncludes(const LangOptions &LangOpts, FileManager &FileMgr,
// Include this header as part of the umbrella directory.
Module->addTopHeader(Header);
- if (std::error_code Err = addHeaderInclude(RelativeHeader, Includes,
- LangOpts, Module->IsExternC))
- return Err;
+ addHeaderInclude(RelativeHeader, Includes, LangOpts, Module->IsExternC);
}
if (EC)
@@ -270,6 +269,8 @@ collectModuleHeaderIncludes(const LangOptions &LangOpts, FileManager &FileMgr,
bool GenerateModuleAction::BeginSourceFileAction(CompilerInstance &CI,
StringRef Filename) {
+ CI.getLangOpts().CompilingModule = true;
+
// Find the module map file.
const FileEntry *ModuleMap =
CI.getFileManager().getFile(Filename, /*openFile*/true);
@@ -354,10 +355,9 @@ bool GenerateModuleAction::BeginSourceFileAction(CompilerInstance &CI,
SmallString<256> HeaderContents;
std::error_code Err = std::error_code();
if (Module::Header UmbrellaHeader = Module->getUmbrellaHeader())
- Err = addHeaderInclude(UmbrellaHeader.NameAsWritten, HeaderContents,
- CI.getLangOpts(), Module->IsExternC);
- if (!Err)
- Err = collectModuleHeaderIncludes(
+ addHeaderInclude(UmbrellaHeader.NameAsWritten, HeaderContents,
+ CI.getLangOpts(), Module->IsExternC);
+ Err = collectModuleHeaderIncludes(
CI.getLangOpts(), FileMgr,
CI.getPreprocessor().getHeaderSearchInfo().getModuleMap(), Module,
HeaderContents);
@@ -381,9 +381,11 @@ bool GenerateModuleAction::BeginSourceFileAction(CompilerInstance &CI,
return true;
}
-raw_pwrite_stream *GenerateModuleAction::ComputeASTConsumerArguments(
- CompilerInstance &CI, StringRef InFile, std::string &Sysroot,
- std::string &OutputFile) {
+std::unique_ptr<raw_pwrite_stream>
+GenerateModuleAction::ComputeASTConsumerArguments(CompilerInstance &CI,
+ StringRef InFile,
+ std::string &Sysroot,
+ std::string &OutputFile) {
// If no output file was provided, figure out where this module would go
// in the module cache.
if (CI.getFrontendOpts().OutputFile.empty()) {
@@ -396,7 +398,7 @@ raw_pwrite_stream *GenerateModuleAction::ComputeASTConsumerArguments(
// We use createOutputFile here because this is exposed via libclang, and we
// must disable the RemoveFileOnSignal behavior.
// We use a temporary to avoid race conditions.
- raw_pwrite_stream *OS =
+ std::unique_ptr<raw_pwrite_stream> OS =
CI.createOutputFile(CI.getFrontendOpts().OutputFile, /*Binary=*/true,
/*RemoveFileOnSignal=*/false, InFile,
/*Extension=*/"", /*useTemporary=*/true,
@@ -408,6 +410,9 @@ raw_pwrite_stream *GenerateModuleAction::ComputeASTConsumerArguments(
return OS;
}
+SyntaxOnlyAction::~SyntaxOnlyAction() {
+}
+
std::unique_ptr<ASTConsumer>
SyntaxOnlyAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) {
return llvm::make_unique<ASTConsumer>();
@@ -647,11 +652,12 @@ void DumpTokensAction::ExecuteAction() {
void GeneratePTHAction::ExecuteAction() {
CompilerInstance &CI = getCompilerInstance();
- raw_pwrite_stream *OS = CI.createDefaultOutputFile(true, getCurrentFile());
+ std::unique_ptr<raw_pwrite_stream> OS =
+ CI.createDefaultOutputFile(true, getCurrentFile());
if (!OS)
return;
- CacheTokens(CI.getPreprocessor(), OS);
+ CacheTokens(CI.getPreprocessor(), OS.get());
}
void PreprocessOnlyAction::ExecuteAction() {
@@ -707,14 +713,16 @@ void PrintPreprocessedAction::ExecuteAction() {
} else if (*cur == 0x0A) // LF
break;
- ++cur, ++next;
+ ++cur;
+ ++next;
}
}
- raw_ostream *OS = CI.createDefaultOutputFile(BinaryMode, getCurrentFile());
+ std::unique_ptr<raw_ostream> OS =
+ CI.createDefaultOutputFile(BinaryMode, getCurrentFile());
if (!OS) return;
- DoPrintPreprocessedInput(CI.getPreprocessor(), OS,
+ DoPrintPreprocessedInput(CI.getPreprocessor(), OS.get(),
CI.getPreprocessorOutputOpts());
}
@@ -737,6 +745,7 @@ void PrintPreambleAction::ExecuteAction() {
case IK_PreprocessedObjCXX:
case IK_AST:
case IK_LLVM_IR:
+ case IK_RenderScript:
// We can't do anything with these.
return;
}
OpenPOWER on IntegriCloud