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
This commit is contained in:
Stefanus Du Toit 2013-03-01 20:53:43 +00:00
parent 0943792a65
commit e9779bbef0
1 changed files with 21 additions and 25 deletions

View File

@ -49,6 +49,11 @@ static cl::opt<RiskLevel> MaxRiskLevel(
clEnumValEnd),
cl::init(RL_Reasonable));
static cl::opt<bool> 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<clang::SyntaxOnlyAction>()) !=
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<clang::SyntaxOnlyAction>())
!= 0) {
return 1;
}
}
if (EndSyntaxTool.run(newFrontendActionFactory<clang::SyntaxOnlyAction>()) !=
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) {