[clang-tools-extra] r176376 - cpp11-migrate: Reduce the number of parsing passes.

Stefanus Du Toit stefanus.dutoit at rapidmind.com
Fri Mar 1 12:53:43 PST 2013


Author: sdt
Date: Fri Mar  1 14:53:43 2013
New Revision: 176376

URL: http://llvm.org/viewvc/llvm-project?rev=176376&view=rev
Log:
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.


Modified:
    clang-tools-extra/trunk/cpp11-migrate/Cpp11Migrate.cpp

Modified: clang-tools-extra/trunk/cpp11-migrate/Cpp11Migrate.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/cpp11-migrate/Cpp11Migrate.cpp?rev=176376&r1=176375&r2=176376&view=diff
==============================================================================
--- clang-tools-extra/trunk/cpp11-migrate/Cpp11Migrate.cpp (original)
+++ clang-tools-extra/trunk/cpp11-migrate/Cpp11Migrate.cpp Fri Mar  1 14:53:43 2013
@@ -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());
-
-  // 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);
-  }
+  if (FinalSyntaxCheck) {
+    ClangTool EndSyntaxTool(OptionsParser.getCompilations(),
+                            OptionsParser.getSourcePathList());
+
+    // 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);
+    }
 
-  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) {





More information about the cfe-commits mailing list