From: Chris Lattner Date: Mon, 27 Apr 2009 21:25:27 +0000 (+0000) Subject: unnest some code, decoupling fixit rewriting from ast stuff. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1aee61a7138cd1df44f149528911930ac56819d4;p=clang unnest some code, decoupling fixit rewriting from ast stuff. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@70250 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/tools/clang-cc/clang-cc.cpp b/tools/clang-cc/clang-cc.cpp index 6f159e0615..f124298cbf 100644 --- a/tools/clang-cc/clang-cc.cpp +++ b/tools/clang-cc/clang-cc.cpp @@ -1723,39 +1723,38 @@ static void ProcessInputFile(Preprocessor &PP, PreprocessorFactory &PPF, break; } - if (Consumer) { - llvm::OwningPtr ContextOwner; - - if (FixItAtLocations.size() > 0) { - // Even without the "-fixit" flag, with may have some specific - // locations where the user has requested fixes. Process those - // locations now. - if (!FixItRewrite) - FixItRewrite = new FixItRewriter(PP.getDiagnostics(), - PP.getSourceManager(), - PP.getLangOptions()); - - bool AddedFixitLocation = false; - for (unsigned Idx = 0, Last = FixItAtLocations.size(); - Idx != Last; ++Idx) { - RequestedSourceLocation Requested; - if (FixItAtLocations[Idx].ResolveLocation(PP.getFileManager(), - Requested)) { - fprintf(stderr, "FIX-IT could not find file \"%s\"\n", - FixItAtLocations[Idx].FileName.c_str()); - } else { - FixItRewrite->addFixItLocation(Requested); - AddedFixitLocation = true; - } + if (FixItAtLocations.size() > 0) { + // Even without the "-fixit" flag, with may have some specific + // locations where the user has requested fixes. Process those + // locations now. + if (!FixItRewrite) + FixItRewrite = new FixItRewriter(PP.getDiagnostics(), + PP.getSourceManager(), + PP.getLangOptions()); + + bool AddedFixitLocation = false; + for (unsigned Idx = 0, Last = FixItAtLocations.size(); + Idx != Last; ++Idx) { + RequestedSourceLocation Requested; + if (FixItAtLocations[Idx].ResolveLocation(PP.getFileManager(), + Requested)) { + fprintf(stderr, "FIX-IT could not find file \"%s\"\n", + FixItAtLocations[Idx].FileName.c_str()); + } else { + FixItRewrite->addFixItLocation(Requested); + AddedFixitLocation = true; } + } - if (!AddedFixitLocation) { - // All of the fix-it locations were bad. Don't fix anything. - delete FixItRewrite; - FixItRewrite = 0; - } + if (!AddedFixitLocation) { + // All of the fix-it locations were bad. Don't fix anything. + delete FixItRewrite; + FixItRewrite = 0; } + } + llvm::OwningPtr ContextOwner; + if (Consumer) { ContextOwner.reset(new ASTContext(PP.getLangOptions(), PP.getSourceManager(), PP.getTargetInfo(), @@ -1764,7 +1763,7 @@ static void ProcessInputFile(Preprocessor &PP, PreprocessorFactory &PPF, /* FreeMemory = */ !DisableFree, /* size_reserve = */0, /* InitializeBuiltins = */ImplicitIncludePCH.empty())); - + if (!ImplicitIncludePCH.empty()) { // The user has asked us to include a precompiled header. Load // the precompiled header into the AST context. @@ -1809,16 +1808,17 @@ static void ProcessInputFile(Preprocessor &PP, PreprocessorFactory &PPF, ParseAST(PP, Consumer.get(), *ContextOwner.get(), Stats, CompleteTranslationUnit); - - if (FixItRewrite) - FixItRewrite->WriteFixedFile(InFile, OutputFile); - - // If in -disable-free mode, don't deallocate these when they go out of - // scope. - if (DisableFree) - ContextOwner.take(); } + if (FixItRewrite) + FixItRewrite->WriteFixedFile(InFile, OutputFile); + + // If in -disable-free mode, don't deallocate ASTContext. + if (DisableFree) + ContextOwner.take(); + else + ContextOwner.reset(); // Delete ASTContext + if (VerifyDiagnostics) if (CheckDiagnostics(PP)) exit(1);