diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2015-01-18 16:23:48 +0000 | 
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2015-01-18 16:23:48 +0000 | 
| commit | 06d4ba388873e6d1cfa9cd715a8935ecc8cd2097 (patch) | |
| tree | 3eb853da77d46cc77c4b017525a422f9ddb1385b /lib/Frontend/DependencyFile.cpp | |
| parent | 30d791273d07fac9c0c1641a0731191bca6e8606 (diff) | |
Notes
Diffstat (limited to 'lib/Frontend/DependencyFile.cpp')
| -rw-r--r-- | lib/Frontend/DependencyFile.cpp | 36 | 
1 files changed, 23 insertions, 13 deletions
diff --git a/lib/Frontend/DependencyFile.cpp b/lib/Frontend/DependencyFile.cpp index 0b9c0d47dc36..6ea8f5193ef7 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<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;    }  | 
