From e9779bbef0bb470442dc409f5cca396767a01b02 Mon Sep 17 00:00:00 2001 From: Stefanus Du Toit Date: Fri, 1 Mar 2013 20:53:43 +0000 Subject: [PATCH] cpp11-migrate: Reduce the number of parsing passes. Previously we would check the syntax of the file before we transform it, but that's redundant since it'll be checked as part of the transformation. Remove that check completely. We also had an unconditional syntax check after transforming. This is only really useful to debug cpp11-migrate, since users will end up compiling the transformed source anyways, and the transformations *should* never introduce a failure. Made this an option, accessible via "-final-syntax-check". Resolves PR 15380. llvm-svn: 176376 --- clang-tools-extra/cpp11-migrate/Cpp11Migrate.cpp | 44 +++++++++++------------- 1 file changed, 20 insertions(+), 24 deletions(-) diff --git a/clang-tools-extra/cpp11-migrate/Cpp11Migrate.cpp b/clang-tools-extra/cpp11-migrate/Cpp11Migrate.cpp index 92ef180..71ffa71 100644 --- a/clang-tools-extra/cpp11-migrate/Cpp11Migrate.cpp +++ b/clang-tools-extra/cpp11-migrate/Cpp11Migrate.cpp @@ -49,6 +49,11 @@ static cl::opt MaxRiskLevel( clEnumValEnd), cl::init(RL_Reasonable)); +static cl::opt FinalSyntaxCheck( + "final-syntax-check", + cl::desc("Check for correct syntax after applying transformations"), + cl::init(false)); + class EndSyntaxArgumentsAdjuster : public ArgumentsAdjuster { CommandLineArguments Adjust(const CommandLineArguments &Args) { CommandLineArguments AdjustedArgs = Args; @@ -74,16 +79,6 @@ int main(int argc, const char **argv) { return 1; } - // Initial syntax check. - ClangTool SyntaxTool(OptionsParser.getCompilations(), - OptionsParser.getSourcePathList()); - - // First, let's check to make sure there were no errors. - if (SyntaxTool.run(newFrontendActionFactory()) != - 0) { - return 1; - } - FileContentsByPath FileStates1, FileStates2, *InputFileStates = &FileStates1, *OutputFileStates = &FileStates2; @@ -104,25 +99,26 @@ int main(int argc, const char **argv) { // Final state of files is pointed at by InputFileStates. - // Final Syntax check. - ClangTool EndSyntaxTool(OptionsParser.getCompilations(), - OptionsParser.getSourcePathList()); + if (FinalSyntaxCheck) { + ClangTool EndSyntaxTool(OptionsParser.getCompilations(), + OptionsParser.getSourcePathList()); - // Add c++11 support to clang. - EndSyntaxTool.setArgumentsAdjuster(new EndSyntaxArgumentsAdjuster); + // Add c++11 support to clang. + EndSyntaxTool.setArgumentsAdjuster(new EndSyntaxArgumentsAdjuster); - for (FileContentsByPath::const_iterator I = InputFileStates->begin(), - E = InputFileStates->end(); - I != E; ++I) { - EndSyntaxTool.mapVirtualFile(I->first, I->second); - } + for (FileContentsByPath::const_iterator I = InputFileStates->begin(), + E = InputFileStates->end(); + I != E; ++I) { + EndSyntaxTool.mapVirtualFile(I->first, I->second); + } - if (EndSyntaxTool.run(newFrontendActionFactory()) != - 0) { - return 1; + if (EndSyntaxTool.run(newFrontendActionFactory()) + != 0) { + return 1; + } } - // Syntax check passed, write results to file. + // Write results to file. for (FileContentsByPath::const_iterator I = InputFileStates->begin(), E = InputFileStates->end(); I != E; ++I) { -- 2.7.4