diff options
author | Edwin Vane <edwin.vane@intel.com> | 2013-06-18 15:31:01 +0000 |
---|---|---|
committer | Edwin Vane <edwin.vane@intel.com> | 2013-06-18 15:31:01 +0000 |
commit | 62c013db6ce8dabac58a313c5e4ca05e75e45881 (patch) | |
tree | bb79b5905ac9a479c6f8b9b7c38bdb3a859fcfc3 /clang-tools-extra/cpp11-migrate/tool/Cpp11Migrate.cpp | |
parent | 302c0da6f138d1475b497a6e987787e94f15046f (diff) | |
download | bcm5719-llvm-62c013db6ce8dabac58a313c5e4ca05e75e45881.tar.gz bcm5719-llvm-62c013db6ce8dabac58a313c5e4ca05e75e45881.zip |
cpp11-migrate: Transform now responsible for applying replacements
To make it possible for replacements made to headers as part of transforming
one translation unit to not be visible to the transform of other translation
units, Transform now handles replacement application as part of its
end-of-source handling. Several things were simplified as a result:
- The duplicated code in every transform for applying replacements is now gone
and replaced with one location in Transform.
- RefactoringTool is no longer used since Transform houses the Replacements
structure.
- RewriterContainer is now a private implementation detail of Transform (also
renamed to RewriterManager since its behaviour is slightly different now with
respect to lifetime of objects).
- There's now no distinction between input and output file state.
Misc notes:
- Interface changes reflected in unit tests.
- Replacements for files other than the main file are assumed to be for headers
and stored as such.
llvm-svn: 184194
Diffstat (limited to 'clang-tools-extra/cpp11-migrate/tool/Cpp11Migrate.cpp')
-rw-r--r-- | clang-tools-extra/cpp11-migrate/tool/Cpp11Migrate.cpp | 35 |
1 files changed, 19 insertions, 16 deletions
diff --git a/clang-tools-extra/cpp11-migrate/tool/Cpp11Migrate.cpp b/clang-tools-extra/cpp11-migrate/tool/Cpp11Migrate.cpp index 15f5aa12f5c..773ba009a5d 100644 --- a/clang-tools-extra/cpp11-migrate/tool/Cpp11Migrate.cpp +++ b/clang-tools-extra/cpp11-migrate/tool/Cpp11Migrate.cpp @@ -130,17 +130,15 @@ int main(int argc, const char **argv) { return 1; } - FileOverrides FileStates1, FileStates2, - *InputFileStates = &FileStates1, *OutputFileStates = &FileStates2; - + FileOverrides FileStates; SourcePerfData PerfData; // Apply transforms. for (Transforms::const_iterator I = TransformManager.begin(), E = TransformManager.end(); I != E; ++I) { - if ((*I)->apply(*InputFileStates, OptionsParser.getCompilations(), - OptionsParser.getSourcePathList(), *OutputFileStates) != + if ((*I)->apply(FileStates, OptionsParser.getCompilations(), + OptionsParser.getSourcePathList()) != 0) { // FIXME: Improve ClangTool to not abort if just one file fails. return 1; @@ -161,24 +159,25 @@ int main(int argc, const char **argv) { } llvm::outs() << "\n"; } - std::swap(InputFileStates, OutputFileStates); - OutputFileStates->clear(); } if (FinalSyntaxCheck) - // Final state of files is pointed at by InputFileStates. if (!doSyntaxCheck(OptionsParser.getCompilations(), - OptionsParser.getSourcePathList(), *InputFileStates)) + OptionsParser.getSourcePathList(), FileStates)) return 1; // Write results to file. - for (FileOverrides::const_iterator I = InputFileStates->begin(), - E = InputFileStates->end(); + for (FileOverrides::const_iterator I = FileStates.begin(), + E = FileStates.end(); I != E; ++I) { - std::string ErrorInfo; - llvm::raw_fd_ostream FileStream(I->first.c_str(), ErrorInfo, - llvm::raw_fd_ostream::F_Binary); - FileStream << I->second.MainFileOverride; + if (I->second.isSourceOverriden()) { + llvm::errs() << "Writing source: " << I->first << "\n"; + + std::string ErrorInfo; + llvm::raw_fd_ostream FileStream(I->first.c_str(), ErrorInfo, + llvm::raw_fd_ostream::F_Binary); + FileStream << I->second.MainFileOverride; + } // FIXME: The Migrator shouldn't be responsible for writing headers // to disk. Instead, it should write replacement info and another tool @@ -188,7 +187,11 @@ int main(int argc, const char **argv) { for (HeaderOverrides::const_iterator HeaderI = I->second.Headers.begin(), HeaderE = I->second.Headers.end(); HeaderI != HeaderE; ++HeaderI) { - llvm::raw_fd_ostream HeaderStream(I->first.c_str(), ErrorInfo, + llvm::errs() << "Writing header: " << HeaderI->first << "\n"; + assert(!HeaderI->second.FileOverride.empty() && + "A header override should not be empty"); + std::string ErrorInfo; + llvm::raw_fd_ostream HeaderStream(HeaderI->first.c_str(), ErrorInfo, llvm::raw_fd_ostream::F_Binary); HeaderStream << HeaderI->second.FileOverride; } |