From 1b070d25ca6d0e18aced39ba82b3a1cfb6dde099 Mon Sep 17 00:00:00 2001 From: Alp Toker Date: Mon, 7 Jul 2014 07:47:20 +0000 Subject: [PATCH] Peel away old-style file remapping typedefs and cruft llvm-svn: 212438 --- clang/include/clang/Lex/PreprocessorOptions.h | 48 +--------------- clang/lib/Frontend/ASTUnit.cpp | 82 ++++++++++----------------- clang/lib/Frontend/CompilerInstance.cpp | 27 ++++----- clang/tools/arcmt-test/arcmt-test.cpp | 6 +- 4 files changed, 44 insertions(+), 119 deletions(-) diff --git a/clang/include/clang/Lex/PreprocessorOptions.h b/clang/include/clang/Lex/PreprocessorOptions.h index 1ab5a3e..135c87f 100644 --- a/clang/include/clang/Lex/PreprocessorOptions.h +++ b/clang/include/clang/Lex/PreprocessorOptions.h @@ -97,7 +97,7 @@ public: /// the system (the first part of each pair) and gives them the /// contents of other files on the system (the second part of each /// pair). - std::vector > RemappedFiles; + std::vector> RemappedFiles; /// \brief The set of file-to-buffer remappings, which take existing files /// on the system (the first part of each pair) and gives them the contents @@ -139,41 +139,6 @@ public: /// build it again. IntrusiveRefCntPtr FailedModules; - typedef std::vector >::iterator - remapped_file_iterator; - typedef std::vector >::const_iterator - const_remapped_file_iterator; - remapped_file_iterator remapped_file_begin() { - return RemappedFiles.begin(); - } - const_remapped_file_iterator remapped_file_begin() const { - return RemappedFiles.begin(); - } - remapped_file_iterator remapped_file_end() { - return RemappedFiles.end(); - } - const_remapped_file_iterator remapped_file_end() const { - return RemappedFiles.end(); - } - - typedef std::vector>::iterator - remapped_file_buffer_iterator; - typedef std::vector< - std::pair>::const_iterator - const_remapped_file_buffer_iterator; - remapped_file_buffer_iterator remapped_file_buffer_begin() { - return RemappedFileBuffers.begin(); - } - const_remapped_file_buffer_iterator remapped_file_buffer_begin() const { - return RemappedFileBuffers.begin(); - } - remapped_file_buffer_iterator remapped_file_buffer_end() { - return RemappedFileBuffers.end(); - } - const_remapped_file_buffer_iterator remapped_file_buffer_end() const { - return RemappedFileBuffers.end(); - } - public: PreprocessorOptions() : UsePredefines(true), DetailedRecord(false), DisablePCHValidation(false), @@ -193,20 +158,11 @@ public: void addRemappedFile(StringRef From, StringRef To) { RemappedFiles.push_back(std::make_pair(From, To)); } - - remapped_file_iterator eraseRemappedFile(remapped_file_iterator Remapped) { - return RemappedFiles.erase(Remapped); - } void addRemappedFile(StringRef From, llvm::MemoryBuffer *To) { RemappedFileBuffers.push_back(std::make_pair(From, To)); } - - remapped_file_buffer_iterator - eraseRemappedFile(remapped_file_buffer_iterator Remapped) { - return RemappedFileBuffers.erase(Remapped); - } - + void clearRemappedFiles() { RemappedFiles.clear(); RemappedFileBuffers.clear(); diff --git a/clang/lib/Frontend/ASTUnit.cpp b/clang/lib/Frontend/ASTUnit.cpp index f8c25ca..023794b 100644 --- a/clang/lib/Frontend/ASTUnit.cpp +++ b/clang/lib/Frontend/ASTUnit.cpp @@ -249,12 +249,8 @@ ASTUnit::~ASTUnit() { // parser. if (Invocation.get() && OwnsRemappedFileBuffers) { PreprocessorOptions &PPOpts = Invocation->getPreprocessorOpts(); - for (PreprocessorOptions::remapped_file_buffer_iterator - FB = PPOpts.remapped_file_buffer_begin(), - FBEnd = PPOpts.remapped_file_buffer_end(); - FB != FBEnd; - ++FB) - delete FB->second; + for (const auto &RB : PPOpts.RemappedFileBuffers) + delete RB.second; } delete SavedMainFileBuffer; @@ -1214,12 +1210,8 @@ ASTUnit::ComputePreamble(CompilerInvocation &Invocation, llvm::sys::fs::UniqueID MainFileID; if (!llvm::sys::fs::getUniqueID(MainFilePath, MainFileID)) { // Check whether there is a file-file remapping of the main file - for (PreprocessorOptions::remapped_file_iterator - M = PreprocessorOpts.remapped_file_begin(), - E = PreprocessorOpts.remapped_file_end(); - M != E; - ++M) { - std::string MPath(M->first); + for (const auto &RF : PreprocessorOpts.RemappedFiles) { + std::string MPath(RF.first); llvm::sys::fs::UniqueID MID; if (!llvm::sys::fs::getUniqueID(MPath, MID)) { if (MainFileID == MID) { @@ -1228,8 +1220,8 @@ ASTUnit::ComputePreamble(CompilerInvocation &Invocation, delete Buffer; CreatedBuffer = false; } - - Buffer = getBufferForFile(M->second); + + Buffer = getBufferForFile(RF.second); if (!Buffer) return std::make_pair(nullptr, std::make_pair(0, true)); CreatedBuffer = true; @@ -1239,12 +1231,8 @@ ASTUnit::ComputePreamble(CompilerInvocation &Invocation, // Check whether there is a file-buffer remapping. It supercedes the // file-file remapping. - for (PreprocessorOptions::remapped_file_buffer_iterator - M = PreprocessorOpts.remapped_file_buffer_begin(), - E = PreprocessorOpts.remapped_file_buffer_end(); - M != E; - ++M) { - std::string MPath(M->first); + for (const auto &RB : PreprocessorOpts.RemappedFileBuffers) { + std::string MPath(RB.first); llvm::sys::fs::UniqueID MID; if (!llvm::sys::fs::getUniqueID(MPath, MID)) { if (MainFileID == MID) { @@ -1253,8 +1241,8 @@ ASTUnit::ComputePreamble(CompilerInvocation &Invocation, delete Buffer; CreatedBuffer = false; } - - Buffer = const_cast(M->second); + + Buffer = const_cast(RB.second); } } } @@ -1420,29 +1408,27 @@ llvm::MemoryBuffer *ASTUnit::getMainBufferWithPrecompiledPreamble( // First, make a record of those files that have been overridden via // remapping or unsaved_files. llvm::StringMap OverriddenFiles; - for (PreprocessorOptions::remapped_file_iterator - R = PreprocessorOpts.remapped_file_begin(), - REnd = PreprocessorOpts.remapped_file_end(); - !AnyFileChanged && R != REnd; - ++R) { + for (const auto &R : PreprocessorOpts.RemappedFiles) { + if (AnyFileChanged) + break; + vfs::Status Status; - if (FileMgr->getNoncachedStatValue(R->second, Status)) { + if (FileMgr->getNoncachedStatValue(R.second, Status)) { // If we can't stat the file we're remapping to, assume that something // horrible happened. AnyFileChanged = true; break; } - OverriddenFiles[R->first] = PreambleFileHash::createForFile( + OverriddenFiles[R.first] = PreambleFileHash::createForFile( Status.getSize(), Status.getLastModificationTime().toEpochTime()); } - for (PreprocessorOptions::remapped_file_buffer_iterator - R = PreprocessorOpts.remapped_file_buffer_begin(), - REnd = PreprocessorOpts.remapped_file_buffer_end(); - !AnyFileChanged && R != REnd; - ++R) { - OverriddenFiles[R->first] = - PreambleFileHash::createForMemoryBuffer(R->second); + + for (const auto &RB : PreprocessorOpts.RemappedFileBuffers) { + if (AnyFileChanged) + break; + OverriddenFiles[RB.first] = + PreambleFileHash::createForMemoryBuffer(RB.second); } // Check whether anything has changed. @@ -1568,8 +1554,7 @@ llvm::MemoryBuffer *ASTUnit::getMainBufferWithPrecompiledPreamble( llvm::sys::fs::remove(FrontendOpts.OutputFile); Preamble.clear(); PreambleRebuildCounter = DefaultPreambleRebuildInterval; - PreprocessorOpts.eraseRemappedFile( - PreprocessorOpts.remapped_file_buffer_end() - 1); + PreprocessorOpts.RemappedFileBuffers.pop_back(); return nullptr; } @@ -1615,8 +1600,7 @@ llvm::MemoryBuffer *ASTUnit::getMainBufferWithPrecompiledPreamble( llvm::sys::fs::remove(FrontendOpts.OutputFile); Preamble.clear(); PreambleRebuildCounter = DefaultPreambleRebuildInterval; - PreprocessorOpts.eraseRemappedFile( - PreprocessorOpts.remapped_file_buffer_end() - 1); + PreprocessorOpts.RemappedFileBuffers.pop_back(); return nullptr; } @@ -1644,8 +1628,7 @@ llvm::MemoryBuffer *ASTUnit::getMainBufferWithPrecompiledPreamble( Preamble.clear(); TopLevelDeclsInPreamble.clear(); PreambleRebuildCounter = DefaultPreambleRebuildInterval; - PreprocessorOpts.eraseRemappedFile( - PreprocessorOpts.remapped_file_buffer_end() - 1); + PreprocessorOpts.RemappedFileBuffers.pop_back(); return nullptr; } @@ -1672,9 +1655,8 @@ llvm::MemoryBuffer *ASTUnit::getMainBufferWithPrecompiledPreamble( } PreambleRebuildCounter = 1; - PreprocessorOpts.eraseRemappedFile( - PreprocessorOpts.remapped_file_buffer_end() - 1); - + PreprocessorOpts.RemappedFileBuffers.pop_back(); + // If the hash of top-level entities differs from the hash of the top-level // entities the last time we rebuilt the preamble, clear out the completion // cache. @@ -2070,13 +2052,9 @@ bool ASTUnit::Reparse(ArrayRef RemappedFiles) { // Remap files. PreprocessorOptions &PPOpts = Invocation->getPreprocessorOpts(); - for (PreprocessorOptions::remapped_file_buffer_iterator - R = PPOpts.remapped_file_buffer_begin(), - REnd = PPOpts.remapped_file_buffer_end(); - R != REnd; - ++R) { - delete R->second; - } + for (const auto &RB : PPOpts.RemappedFileBuffers) + delete RB.second; + Invocation->getPreprocessorOpts().clearRemappedFiles(); for (unsigned I = 0, N = RemappedFiles.size(); I != N; ++I) { Invocation->getPreprocessorOpts().addRemappedFile(RemappedFiles[I].first, diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp index e8b46e7..7cea9e4 100644 --- a/clang/lib/Frontend/CompilerInstance.cpp +++ b/clang/lib/Frontend/CompilerInstance.cpp @@ -241,44 +241,37 @@ static void InitializeFileRemapping(DiagnosticsEngine &Diags, FileManager &FileMgr, const PreprocessorOptions &InitOpts) { // Remap files in the source manager (with buffers). - for (PreprocessorOptions::const_remapped_file_buffer_iterator - Remap = InitOpts.remapped_file_buffer_begin(), - RemapEnd = InitOpts.remapped_file_buffer_end(); - Remap != RemapEnd; ++Remap) { + for (const auto &RB : InitOpts.RemappedFileBuffers) { // Create the file entry for the file that we're mapping from. const FileEntry *FromFile = - FileMgr.getVirtualFile(Remap->first, Remap->second->getBufferSize(), 0); + FileMgr.getVirtualFile(RB.first, RB.second->getBufferSize(), 0); if (!FromFile) { - Diags.Report(diag::err_fe_remap_missing_from_file) << Remap->first; + Diags.Report(diag::err_fe_remap_missing_from_file) << RB.first; if (!InitOpts.RetainRemappedFileBuffers) - delete Remap->second; + delete RB.second; continue; } // Override the contents of the "from" file with the contents of // the "to" file. - SourceMgr.overrideFileContents(FromFile, Remap->second, + SourceMgr.overrideFileContents(FromFile, RB.second, InitOpts.RetainRemappedFileBuffers); } // Remap files in the source manager (with other files). - for (PreprocessorOptions::const_remapped_file_iterator - Remap = InitOpts.remapped_file_begin(), - RemapEnd = InitOpts.remapped_file_end(); - Remap != RemapEnd; ++Remap) { + for (const auto &RF : InitOpts.RemappedFiles) { // Find the file that we're mapping to. - const FileEntry *ToFile = FileMgr.getFile(Remap->second); + const FileEntry *ToFile = FileMgr.getFile(RF.second); if (!ToFile) { - Diags.Report(diag::err_fe_remap_missing_to_file) << Remap->first - << Remap->second; + Diags.Report(diag::err_fe_remap_missing_to_file) << RF.first << RF.second; continue; } // Create the file entry for the file that we're mapping from. const FileEntry *FromFile = - FileMgr.getVirtualFile(Remap->first, ToFile->getSize(), 0); + FileMgr.getVirtualFile(RF.first, ToFile->getSize(), 0); if (!FromFile) { - Diags.Report(diag::err_fe_remap_missing_from_file) << Remap->first; + Diags.Report(diag::err_fe_remap_missing_from_file) << RF.first; continue; } diff --git a/clang/tools/arcmt-test/arcmt-test.cpp b/clang/tools/arcmt-test/arcmt-test.cpp index 27da45f..a59a869 100644 --- a/clang/tools/arcmt-test/arcmt-test.cpp +++ b/clang/tools/arcmt-test/arcmt-test.cpp @@ -139,10 +139,8 @@ static void printResult(FileRemapper &remapper, raw_ostream &OS) { PreprocessorOptions PPOpts; remapper.applyMappings(PPOpts); // The changed files will be in memory buffers, print them. - for (unsigned i = 0, e = PPOpts.RemappedFileBuffers.size(); i != e; ++i) { - const llvm::MemoryBuffer *mem = PPOpts.RemappedFileBuffers[i].second; - OS << mem->getBuffer(); - } + for (const auto &RB : PPOpts.RemappedFileBuffers) + OS << RB.second->getBuffer(); } static bool performTransformations(StringRef resourcesPath, -- 2.7.4