From c86b984ea8ecb3e944dc3de48539f4c1f65851ea Mon Sep 17 00:00:00 2001 From: dim Date: Sun, 18 Jan 2015 16:23:48 +0000 Subject: Vendor import of clang RELEASE_360/rc1 tag r226102 (effectively, 3.6.0 RC1): https://llvm.org/svn/llvm-project/cfe/tags/RELEASE_360/rc1@226102 --- lib/Frontend/DependencyFile.cpp | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) (limited to 'lib/Frontend/DependencyFile.cpp') diff --git a/lib/Frontend/DependencyFile.cpp b/lib/Frontend/DependencyFile.cpp index 0b9c0d4..6ea8f51 100644 --- a/lib/Frontend/DependencyFile.cpp +++ b/lib/Frontend/DependencyFile.cpp @@ -22,6 +22,7 @@ #include "clang/Lex/Preprocessor.h" #include "clang/Serialization/ASTReader.h" #include "llvm/ADT/StringSet.h" +#include "llvm/ADT/StringSwitch.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/Path.h" #include "llvm/Support/raw_ostream.h" @@ -108,23 +109,32 @@ struct DepCollectorASTListener : public ASTReaderListener { void DependencyCollector::maybeAddDependency(StringRef Filename, bool FromModule, bool IsSystem, bool IsModuleFile, bool IsMissing) { - if (Seen.insert(Filename) && + if (Seen.insert(Filename).second && sawDependency(Filename, FromModule, IsSystem, IsModuleFile, IsMissing)) Dependencies.push_back(Filename); } +static bool isSpecialFilename(StringRef Filename) { + return llvm::StringSwitch(Filename) + .Case("", true) + .Case("", true) + .Default(false); +} + bool DependencyCollector::sawDependency(StringRef Filename, bool FromModule, bool IsSystem, bool IsModuleFile, bool IsMissing) { - return Filename != "" && (needSystemDependencies() || !IsSystem); + return !isSpecialFilename(Filename) && + (needSystemDependencies() || !IsSystem); } DependencyCollector::~DependencyCollector() { } void DependencyCollector::attachToPreprocessor(Preprocessor &PP) { - PP.addPPCallbacks(new DepCollectorPPCallbacks(*this, PP.getSourceManager())); + PP.addPPCallbacks( + llvm::make_unique(*this, PP.getSourceManager())); } void DependencyCollector::attachToASTReader(ASTReader &R) { - R.addListener(new DepCollectorASTListener(*this)); + R.addListener(llvm::make_unique(*this)); } namespace { @@ -203,21 +213,21 @@ DependencyFileGenerator *DependencyFileGenerator::CreateAndAttachToPreprocessor( PP.SetSuppressIncludeNotFoundError(true); DFGImpl *Callback = new DFGImpl(&PP, Opts); - PP.addPPCallbacks(Callback); // PP owns the Callback + PP.addPPCallbacks(std::unique_ptr(Callback)); return new DependencyFileGenerator(Callback); } void DependencyFileGenerator::AttachToASTReader(ASTReader &R) { DFGImpl *I = reinterpret_cast(Impl); assert(I && "missing implementation"); - R.addListener(new DFGASTReaderListener(*I)); + R.addListener(llvm::make_unique(*I)); } /// FileMatchesDepCriteria - Determine whether the given Filename should be /// considered as a dependency. bool DFGImpl::FileMatchesDepCriteria(const char *Filename, SrcMgr::CharacteristicKind FileType) { - if (strcmp("", Filename) == 0) + if (isSpecialFilename(Filename)) return false; if (IncludeSystemHeaders) @@ -275,7 +285,7 @@ void DFGImpl::InclusionDirective(SourceLocation HashLoc, } void DFGImpl::AddFilename(StringRef Filename) { - if (FilesSet.insert(Filename)) + if (FilesSet.insert(Filename).second) Files.push_back(Filename); } @@ -297,11 +307,11 @@ void DFGImpl::OutputDependencyFile() { return; } - std::string Err; - llvm::raw_fd_ostream OS(OutputFile.c_str(), Err, llvm::sys::fs::F_Text); - if (!Err.empty()) { - PP->getDiagnostics().Report(diag::err_fe_error_opening) - << OutputFile << Err; + std::error_code EC; + llvm::raw_fd_ostream OS(OutputFile, EC, llvm::sys::fs::F_Text); + if (EC) { + PP->getDiagnostics().Report(diag::err_fe_error_opening) << OutputFile + << EC.message(); return; } -- cgit v1.1