diff options
Diffstat (limited to 'contrib/llvm/tools/clang/lib/Frontend/DependencyFile.cpp')
-rw-r--r-- | contrib/llvm/tools/clang/lib/Frontend/DependencyFile.cpp | 36 |
1 files changed, 23 insertions, 13 deletions
diff --git a/contrib/llvm/tools/clang/lib/Frontend/DependencyFile.cpp b/contrib/llvm/tools/clang/lib/Frontend/DependencyFile.cpp index 0b9c0d4..6ea8f51 100644 --- a/contrib/llvm/tools/clang/lib/Frontend/DependencyFile.cpp +++ b/contrib/llvm/tools/clang/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<bool>(Filename) + .Case("<built-in>", true) + .Case("<stdin>", true) + .Default(false); +} + bool DependencyCollector::sawDependency(StringRef Filename, bool FromModule, bool IsSystem, bool IsModuleFile, bool IsMissing) { - return Filename != "<built-in>" && (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<DepCollectorPPCallbacks>(*this, PP.getSourceManager())); } void DependencyCollector::attachToASTReader(ASTReader &R) { - R.addListener(new DepCollectorASTListener(*this)); + R.addListener(llvm::make_unique<DepCollectorASTListener>(*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<PPCallbacks>(Callback)); return new DependencyFileGenerator(Callback); } void DependencyFileGenerator::AttachToASTReader(ASTReader &R) { DFGImpl *I = reinterpret_cast<DFGImpl *>(Impl); assert(I && "missing implementation"); - R.addListener(new DFGASTReaderListener(*I)); + R.addListener(llvm::make_unique<DFGASTReaderListener>(*I)); } /// FileMatchesDepCriteria - Determine whether the given Filename should be /// considered as a dependency. bool DFGImpl::FileMatchesDepCriteria(const char *Filename, SrcMgr::CharacteristicKind FileType) { - if (strcmp("<built-in>", 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; } |