[cfe-commits] r133161 - in /cfe/trunk: include/clang/ARCMigrate/ARCMTActions.h include/clang/Frontend/FrontendAction.h lib/ARCMigrate/ARCMTActions.cpp lib/ARCMigrate/CMakeLists.txt lib/Frontend/CMakeLists.txt lib/Frontend/CompilerInstance.cpp lib/Frontend/FrontendAction.cpp lib/FrontendTool/CMakeLists.txt lib/FrontendTool/ExecuteCompilerInvocation.cpp
Argyrios Kyrtzidis
kyrtzidis at apple.com
Thu Jun 16 10:53:13 PDT 2011
That's great, thanks!
Could you also please remove the ARCMigrate dependency from
c-index-test: Makefile
libclang: Makefile/CMakeLists.txt
?
On Jun 16, 2011, at 9:17 AM, Chandler Carruth wrote:
> Author: chandlerc
> Date: Thu Jun 16 11:17:05 2011
> New Revision: 133161
>
> URL: http://llvm.org/viewvc/llvm-project?rev=133161&view=rev
> Log:
> Raise the ARCMT functionality in Clang into proper FrontendActions.
> These are somewhat special in that they wrap any other FrontendAction,
> running various ARC transformations or checks prior to the standard
> action's run. To implement them easily, this extends FrontendAction to
> have a WrapperFrontendAction utility class which forwards all calls by
> default to an inner action setup at construction time. This is then
> subclassed to override the specific behavior needed by the different
> ARCMT tools.
>
> Finally, FrontendTool is taught how to create these wrapper actions from
> the existing flags and options structures.
>
> The result is that clangFrontend no longer depends on clangARCMigrate.
> This is very important, as clangARCMigrate *heavily* depends on
> clangFrontend. Fundamentally ARCMigrate is at the same layer as
> a library like Rewrite, sitting firmly on top of the Frontend, but tied
> together with the FrontendTool when building the clang binary itself.
>
> Added:
> cfe/trunk/include/clang/ARCMigrate/ARCMTActions.h
> cfe/trunk/lib/ARCMigrate/ARCMTActions.cpp
> Modified:
> cfe/trunk/include/clang/Frontend/FrontendAction.h
> cfe/trunk/lib/ARCMigrate/CMakeLists.txt
> cfe/trunk/lib/Frontend/CMakeLists.txt
> cfe/trunk/lib/Frontend/CompilerInstance.cpp
> cfe/trunk/lib/Frontend/FrontendAction.cpp
> cfe/trunk/lib/FrontendTool/CMakeLists.txt
> cfe/trunk/lib/FrontendTool/ExecuteCompilerInvocation.cpp
>
> Added: cfe/trunk/include/clang/ARCMigrate/ARCMTActions.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ARCMigrate/ARCMTActions.h?rev=133161&view=auto
> ==============================================================================
> --- cfe/trunk/include/clang/ARCMigrate/ARCMTActions.h (added)
> +++ cfe/trunk/include/clang/ARCMigrate/ARCMTActions.h Thu Jun 16 11:17:05 2011
> @@ -0,0 +1,46 @@
> +//===--- ARCMTActions.h - ARC Migrate Tool Frontend Actions -----*- C++ -*-===//
> +//
> +// The LLVM Compiler Infrastructure
> +//
> +// This file is distributed under the University of Illinois Open Source
> +// License. See LICENSE.TXT for details.
> +//
> +//===----------------------------------------------------------------------===//
> +
> +#ifndef LLVM_CLANG_ARCMIGRATE_ARCMT_ACTION_H
> +#define LLVM_CLANG_ARCMIGRATE_ARCMT_ACTION_H
> +
> +#include "clang/Frontend/FrontendAction.h"
> +#include "llvm/ADT/OwningPtr.h"
> +
> +namespace clang {
> +namespace arcmt {
> +
> +class CheckAction : public WrapperFrontendAction {
> +protected:
> + virtual void ExecuteAction();
> +
> +public:
> + CheckAction(FrontendAction *WrappedAction);
> +};
> +
> +class TransformationAction : public WrapperFrontendAction {
> +protected:
> + virtual void ExecuteAction();
> +
> +public:
> + TransformationAction(FrontendAction *WrappedAction);
> +};
> +
> +class InMemoryTransformationAction : public WrapperFrontendAction {
> +protected:
> + virtual void ExecuteAction();
> +
> +public:
> + InMemoryTransformationAction(FrontendAction *WrappedAction);
> +};
> +
> +}
> +}
> +
> +#endif
>
> Modified: cfe/trunk/include/clang/Frontend/FrontendAction.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/FrontendAction.h?rev=133161&r1=133160&r2=133161&view=diff
> ==============================================================================
> --- cfe/trunk/include/clang/Frontend/FrontendAction.h (original)
> +++ cfe/trunk/include/clang/Frontend/FrontendAction.h Thu Jun 16 11:17:05 2011
> @@ -51,6 +51,7 @@
> llvm::OwningPtr<ASTUnit> CurrentASTUnit;
> CompilerInstance *Instance;
> friend class ASTMergeAction;
> + friend class WrapperFrontendAction;
>
> private:
> ASTConsumer* CreateWrappedASTConsumer(CompilerInstance &CI,
> @@ -253,6 +254,35 @@
> virtual bool usesPreprocessorOnly() const { return true; }
> };
>
> +/// WrapperFrontendAction - A frontend action which simply wraps some other
> +/// runtime specified frontend action. Deriving from this class allows an
> +/// action to inject custom logic around some existing action's behavior. It
> +/// implements every virtual method in the FrontendAction interface by
> +/// forwarding to the wrapped action.
> +class WrapperFrontendAction : public FrontendAction {
> + llvm::OwningPtr<FrontendAction> WrappedAction;
> +
> +protected:
> + virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
> + llvm::StringRef InFile);
> + virtual bool BeginSourceFileAction(CompilerInstance &CI,
> + llvm::StringRef Filename);
> + virtual void ExecuteAction();
> + virtual void EndSourceFileAction();
> +
> +public:
> + /// Construct a WrapperFrontendAction from an existing action, taking
> + /// ownership of it.
> + WrapperFrontendAction(FrontendAction *WrappedAction);
> +
> + virtual bool usesPreprocessorOnly() const;
> + virtual bool usesCompleteTranslationUnit();
> + virtual bool hasPCHSupport() const;
> + virtual bool hasASTFileSupport() const;
> + virtual bool hasIRSupport() const;
> + virtual bool hasCodeCompletionSupport() const;
> +};
> +
> } // end namespace clang
>
> #endif
>
> Added: cfe/trunk/lib/ARCMigrate/ARCMTActions.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ARCMigrate/ARCMTActions.cpp?rev=133161&view=auto
> ==============================================================================
> --- cfe/trunk/lib/ARCMigrate/ARCMTActions.cpp (added)
> +++ cfe/trunk/lib/ARCMigrate/ARCMTActions.cpp Thu Jun 16 11:17:05 2011
> @@ -0,0 +1,58 @@
> +//===--- ARCMTActions.cpp - ARC Migrate Tool Frontend Actions ---*- C++ -*-===//
> +//
> +// The LLVM Compiler Infrastructure
> +//
> +// This file is distributed under the University of Illinois Open Source
> +// License. See LICENSE.TXT for details.
> +//
> +//===----------------------------------------------------------------------===//
> +
> +#include "clang/ARCMigrate/ARCMTActions.h"
> +#include "clang/ARCMigrate/ARCMT.h"
> +#include "clang/Frontend/CompilerInstance.h"
> +
> +using namespace clang;
> +using namespace arcmt;
> +
> +void CheckAction::ExecuteAction() {
> + CompilerInstance &CI = getCompilerInstance();
> + if (arcmt::checkForManualIssues(CI.getInvocation(), getCurrentFile(),
> + getCurrentFileKind(),
> + CI.getDiagnostics().getClient()))
> + return;
> +
> + // We only want to see warnings reported from arcmt::checkForManualIssues.
> + CI.getDiagnostics().setIgnoreAllWarnings(true);
> + WrapperFrontendAction::ExecuteAction();
> +}
> +
> +CheckAction::CheckAction(FrontendAction *WrappedAction)
> + : WrapperFrontendAction(WrappedAction) {}
> +
> +void TransformationAction::ExecuteAction() {
> + CompilerInstance &CI = getCompilerInstance();
> + if (arcmt::applyTransformations(CI.getInvocation(), getCurrentFile(),
> + getCurrentFileKind(),
> + CI.getDiagnostics().getClient()))
> + return;
> +
> + WrapperFrontendAction::ExecuteAction();
> +}
> +
> +TransformationAction::TransformationAction(FrontendAction *WrappedAction)
> + : WrapperFrontendAction(WrappedAction) {}
> +
> +void InMemoryTransformationAction::ExecuteAction() {
> + CompilerInstance &CI = getCompilerInstance();
> + if (arcmt::applyTransformationsInMemory(CI.getInvocation(), getCurrentFile(),
> + getCurrentFileKind(),
> + CI.getDiagnostics().getClient()))
> + return;
> +
> + WrapperFrontendAction::ExecuteAction();
> +}
> +
> +InMemoryTransformationAction::InMemoryTransformationAction(
> + FrontendAction *WrappedAction)
> + : WrapperFrontendAction(WrappedAction) {}
> +
>
> Modified: cfe/trunk/lib/ARCMigrate/CMakeLists.txt
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ARCMigrate/CMakeLists.txt?rev=133161&r1=133160&r2=133161&view=diff
> ==============================================================================
> --- cfe/trunk/lib/ARCMigrate/CMakeLists.txt (original)
> +++ cfe/trunk/lib/ARCMigrate/CMakeLists.txt Thu Jun 16 11:17:05 2011
> @@ -2,6 +2,7 @@
>
> add_clang_library(clangARCMigrate
> ARCMT.cpp
> + ARCMTActions.cpp
> FileRemapper.cpp
> TransformActions.cpp
> Transforms.cpp
>
> Modified: cfe/trunk/lib/Frontend/CMakeLists.txt
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CMakeLists.txt?rev=133161&r1=133160&r2=133161&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Frontend/CMakeLists.txt (original)
> +++ cfe/trunk/lib/Frontend/CMakeLists.txt Thu Jun 16 11:17:05 2011
> @@ -1,5 +1,4 @@
> set( LLVM_USED_LIBS
> - clangARCMigrate
> clangAST
> clangBasic
> clangDriver
>
> Modified: cfe/trunk/lib/Frontend/CompilerInstance.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInstance.cpp?rev=133161&r1=133160&r2=133161&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Frontend/CompilerInstance.cpp (original)
> +++ cfe/trunk/lib/Frontend/CompilerInstance.cpp Thu Jun 16 11:17:05 2011
> @@ -26,7 +26,6 @@
> #include "clang/Frontend/TextDiagnosticPrinter.h"
> #include "clang/Frontend/VerifyDiagnosticsClient.h"
> #include "clang/Frontend/Utils.h"
> -#include "clang/ARCMigrate/ARCMT.h"
> #include "clang/Serialization/ASTReader.h"
> #include "clang/Sema/CodeCompleteConsumer.h"
> #include "llvm/Support/FileSystem.h"
> @@ -597,34 +596,6 @@
> if (hasSourceManager())
> getSourceManager().clearIDTables();
>
> - switch (getFrontendOpts().ARCMTAction) {
> - default:
> - break;
> -
> - case FrontendOptions::ARCMT_Check:
> - if (arcmt::checkForManualIssues(getInvocation(), InFile,
> - getFrontendOpts().Inputs[i].first,
> - getDiagnostics().getClient()))
> - continue;
> - // We only want to see warnings reported from arcmt::checkForManualIssues.
> - getDiagnostics().setIgnoreAllWarnings(true);
> - break;
> -
> - case FrontendOptions::ARCMT_Modify:
> - if (arcmt::applyTransformations(getInvocation(), InFile,
> - getFrontendOpts().Inputs[i].first,
> - getDiagnostics().getClient()))
> - continue;
> - break;
> -
> - case FrontendOptions::ARCMT_ModifyInMemory:
> - if (arcmt::applyTransformationsInMemory(getInvocation(), InFile,
> - getFrontendOpts().Inputs[i].first,
> - getDiagnostics().getClient()))
> - continue;
> - break;
> - }
> -
> if (Act.BeginSourceFile(*this, InFile, getFrontendOpts().Inputs[i].first)) {
> Act.Execute();
> Act.EndSourceFile();
>
> Modified: cfe/trunk/lib/Frontend/FrontendAction.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/FrontendAction.cpp?rev=133161&r1=133160&r2=133161&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Frontend/FrontendAction.cpp (original)
> +++ cfe/trunk/lib/Frontend/FrontendAction.cpp Thu Jun 16 11:17:05 2011
> @@ -381,3 +381,41 @@
> llvm::StringRef InFile) {
> llvm_unreachable("Invalid CreateASTConsumer on preprocessor action!");
> }
> +
> +ASTConsumer *WrapperFrontendAction::CreateASTConsumer(CompilerInstance &CI,
> + llvm::StringRef InFile) {
> + return WrappedAction->CreateASTConsumer(CI, InFile);
> +}
> +bool WrapperFrontendAction::BeginSourceFileAction(CompilerInstance &CI,
> + llvm::StringRef Filename) {
> + return WrappedAction->BeginSourceFileAction(CI, Filename);
> +}
> +void WrapperFrontendAction::ExecuteAction() {
> + WrappedAction->ExecuteAction();
> +}
> +void WrapperFrontendAction::EndSourceFileAction() {
> + WrappedAction->EndSourceFileAction();
> +}
> +
> +bool WrapperFrontendAction::usesPreprocessorOnly() const {
> + return WrappedAction->usesPreprocessorOnly();
> +}
> +bool WrapperFrontendAction::usesCompleteTranslationUnit() {
> + return WrappedAction->usesCompleteTranslationUnit();
> +}
> +bool WrapperFrontendAction::hasPCHSupport() const {
> + return WrappedAction->hasPCHSupport();
> +}
> +bool WrapperFrontendAction::hasASTFileSupport() const {
> + return WrappedAction->hasASTFileSupport();
> +}
> +bool WrapperFrontendAction::hasIRSupport() const {
> + return WrappedAction->hasIRSupport();
> +}
> +bool WrapperFrontendAction::hasCodeCompletionSupport() const {
> + return WrappedAction->hasCodeCompletionSupport();
> +}
> +
> +WrapperFrontendAction::WrapperFrontendAction(FrontendAction *WrappedAction)
> + : WrappedAction(WrappedAction) {}
> +
>
> Modified: cfe/trunk/lib/FrontendTool/CMakeLists.txt
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/FrontendTool/CMakeLists.txt?rev=133161&r1=133160&r2=133161&view=diff
> ==============================================================================
> --- cfe/trunk/lib/FrontendTool/CMakeLists.txt (original)
> +++ cfe/trunk/lib/FrontendTool/CMakeLists.txt Thu Jun 16 11:17:05 2011
> @@ -1,5 +1,6 @@
> set(LLVM_USED_LIBS clangDriver clangFrontend clangRewrite clangCodeGen
> - clangStaticAnalyzerFrontend clangStaticAnalyzerCheckers clangStaticAnalyzerCore)
> + clangStaticAnalyzerFrontend clangStaticAnalyzerCheckers clangStaticAnalyzerCore
> + clangARCMigrate)
>
> add_clang_library(clangFrontendTool
> ExecuteCompilerInvocation.cpp
>
> Modified: cfe/trunk/lib/FrontendTool/ExecuteCompilerInvocation.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/FrontendTool/ExecuteCompilerInvocation.cpp?rev=133161&r1=133160&r2=133161&view=diff
> ==============================================================================
> --- cfe/trunk/lib/FrontendTool/ExecuteCompilerInvocation.cpp (original)
> +++ cfe/trunk/lib/FrontendTool/ExecuteCompilerInvocation.cpp Thu Jun 16 11:17:05 2011
> @@ -14,6 +14,7 @@
>
> #include "clang/FrontendTool/Utils.h"
> #include "clang/StaticAnalyzer/Frontend/FrontendActions.h"
> +#include "clang/ARCMigrate/ARCMTActions.h"
> #include "clang/CodeGen/CodeGenAction.h"
> #include "clang/Driver/CC1Options.h"
> #include "clang/Driver/OptTable.h"
> @@ -89,6 +90,21 @@
> if (!Act)
> return 0;
>
> + // Potentially wrap the base FE action in an ARC Migrate Tool action.
> + switch (CI.getFrontendOpts().ARCMTAction) {
> + case FrontendOptions::ARCMT_None:
> + break;
> + case FrontendOptions::ARCMT_Check:
> + Act = new arcmt::CheckAction(Act);
> + break;
> + case FrontendOptions::ARCMT_Modify:
> + Act = new arcmt::TransformationAction(Act);
> + break;
> + case FrontendOptions::ARCMT_ModifyInMemory:
> + Act = new arcmt::InMemoryTransformationAction(Act);
> + break;
> + }
> +
> // If there are any AST files to merge, create a frontend action
> // adaptor to perform the merge.
> if (!CI.getFrontendOpts().ASTMergeFiles.empty())
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
More information about the cfe-commits
mailing list