From b7f8c7a32c4b630a4f7fe73a5418b30831651323 Mon Sep 17 00:00:00 2001 From: Dmitri Gribenko Date: Sat, 8 Feb 2014 00:38:15 +0000 Subject: [PATCH] ASTUnit: remove dead code in remapping files ASTUnit contains code to remap files to other files on disk. This code is not used. We only remap files to MemoryBuffers. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@201010 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Frontend/ASTUnit.h | 4 +- lib/Frontend/ASTUnit.cpp | 95 ++++++++------------------------ 2 files changed, 23 insertions(+), 76 deletions(-) diff --git a/include/clang/Frontend/ASTUnit.h b/include/clang/Frontend/ASTUnit.h index b53d4f51e2..4a64b24b38 100644 --- a/include/clang/Frontend/ASTUnit.h +++ b/include/clang/Frontend/ASTUnit.h @@ -671,11 +671,9 @@ public: /// \brief Determine what kind of translation unit this AST represents. TranslationUnitKind getTranslationUnitKind() const { return TUKind; } - typedef llvm::PointerUnion - FilenameOrMemBuf; /// \brief A mapping from a file name to the memory buffer that stores the /// remapped contents of that file. - typedef std::pair RemappedFile; + typedef std::pair RemappedFile; /// \brief Create a ASTUnit. Gets ownership of the passed CompilerInvocation. static ASTUnit *create(CompilerInvocation *CI, diff --git a/lib/Frontend/ASTUnit.cpp b/lib/Frontend/ASTUnit.cpp index f57a4bc01a..37838ea46f 100644 --- a/lib/Frontend/ASTUnit.cpp +++ b/lib/Frontend/ASTUnit.cpp @@ -710,54 +710,24 @@ ASTUnit *ASTUnit::LoadFromASTFile(const std::string &Filename, AST->getDiagnostics(), AST->ASTFileLangOpts, /*Target=*/0)); - - for (unsigned I = 0, N = RemappedFiles.size(); I != N; ++I) { - FilenameOrMemBuf fileOrBuf = RemappedFiles[I].second; - if (const llvm::MemoryBuffer * - memBuf = fileOrBuf.dyn_cast()) { - // Create the file entry for the file that we're mapping from. - const FileEntry *FromFile - = AST->getFileManager().getVirtualFile(RemappedFiles[I].first, - memBuf->getBufferSize(), - 0); - if (!FromFile) { - AST->getDiagnostics().Report(diag::err_fe_remap_missing_from_file) - << RemappedFiles[I].first; - delete memBuf; - continue; - } - - // Override the contents of the "from" file with the contents of - // the "to" file. - AST->getSourceManager().overrideFileContents(FromFile, memBuf); - - } else { - const char *fname = fileOrBuf.get(); - const FileEntry *ToFile = AST->FileMgr->getFile(fname); - if (!ToFile) { - AST->getDiagnostics().Report(diag::err_fe_remap_missing_to_file) - << RemappedFiles[I].first << fname; - continue; - } - // Create the file entry for the file that we're mapping from. - const FileEntry *FromFile - = AST->getFileManager().getVirtualFile(RemappedFiles[I].first, - ToFile->getSize(), - 0); - if (!FromFile) { - AST->getDiagnostics().Report(diag::err_fe_remap_missing_from_file) + for (unsigned I = 0, N = RemappedFiles.size(); I != N; ++I) { + const llvm::MemoryBuffer *MemBuf = RemappedFiles[I].second; + // Create the file entry for the file that we're mapping from. + const FileEntry *FromFile = AST->getFileManager().getVirtualFile( + RemappedFiles[I].first, MemBuf->getBufferSize(), 0); + if (!FromFile) { + AST->getDiagnostics().Report(diag::err_fe_remap_missing_from_file) << RemappedFiles[I].first; - delete memBuf; - continue; - } - - // Override the contents of the "from" file with the contents of - // the "to" file. - AST->getSourceManager().overrideFileContents(FromFile, ToFile); + delete MemBuf; + continue; } + + // Override the contents of the "from" file with the contents of + // the "to" file. + AST->getSourceManager().overrideFileContents(FromFile, MemBuf); } - + // Gather Info for preprocessor construction later on. HeaderSearch &HeaderInfo = *AST->HeaderInfo.get(); @@ -2055,14 +2025,8 @@ ASTUnit *ASTUnit::LoadFromCommandLine(const char **ArgBegin, // Override any files that need remapping for (unsigned I = 0, N = RemappedFiles.size(); I != N; ++I) { - FilenameOrMemBuf fileOrBuf = RemappedFiles[I].second; - if (const llvm::MemoryBuffer * - memBuf = fileOrBuf.dyn_cast()) { - CI->getPreprocessorOpts().addRemappedFile(RemappedFiles[I].first, memBuf); - } else { - const char *fname = fileOrBuf.get(); - CI->getPreprocessorOpts().addRemappedFile(RemappedFiles[I].first, fname); - } + CI->getPreprocessorOpts().addRemappedFile(RemappedFiles[I].first, + RemappedFiles[I].second); } PreprocessorOptions &PPOpts = CI->getPreprocessorOpts(); PPOpts.RemappedFilesKeepOriginalName = RemappedFilesKeepOriginalName; @@ -2132,18 +2096,10 @@ bool ASTUnit::Reparse(ArrayRef RemappedFiles) { } Invocation->getPreprocessorOpts().clearRemappedFiles(); for (unsigned I = 0, N = RemappedFiles.size(); I != N; ++I) { - FilenameOrMemBuf fileOrBuf = RemappedFiles[I].second; - if (const llvm::MemoryBuffer * - memBuf = fileOrBuf.dyn_cast()) { - Invocation->getPreprocessorOpts().addRemappedFile(RemappedFiles[I].first, - memBuf); - } else { - const char *fname = fileOrBuf.get(); - Invocation->getPreprocessorOpts().addRemappedFile(RemappedFiles[I].first, - fname); - } + Invocation->getPreprocessorOpts().addRemappedFile(RemappedFiles[I].first, + RemappedFiles[I].second); } - + // If we have a preamble file lying around, or if we might try to // build a precompiled preamble, do so now. llvm::MemoryBuffer *OverrideMainBuffer = 0; @@ -2497,17 +2453,10 @@ void ASTUnit::CodeComplete(StringRef File, unsigned Line, unsigned Column, PreprocessorOpts.clearRemappedFiles(); PreprocessorOpts.RetainRemappedFileBuffers = true; for (unsigned I = 0, N = RemappedFiles.size(); I != N; ++I) { - FilenameOrMemBuf fileOrBuf = RemappedFiles[I].second; - if (const llvm::MemoryBuffer * - memBuf = fileOrBuf.dyn_cast()) { - PreprocessorOpts.addRemappedFile(RemappedFiles[I].first, memBuf); - OwnedBuffers.push_back(memBuf); - } else { - const char *fname = fileOrBuf.get(); - PreprocessorOpts.addRemappedFile(RemappedFiles[I].first, fname); - } + PreprocessorOpts.addRemappedFile(RemappedFiles[I].first, + RemappedFiles[I].second); } - + // Use the code completion consumer we were given, but adding any cached // code-completion results. AugmentedCodeCompleteConsumer *AugmentedConsumer -- 2.40.0