From: Daniel Dunbar Date: Fri, 13 Mar 2009 12:17:08 +0000 (+0000) Subject: Driver: Add cast<> support for Action, and some other accessors. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=85da0071a4ab7d6f06831d20bad79122d7407df7;p=clang Driver: Add cast<> support for Action, and some other accessors. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@66887 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Driver/Action.h b/include/clang/Driver/Action.h index d0c29aa908..9cd17f76b9 100644 --- a/include/clang/Driver/Action.h +++ b/include/clang/Driver/Action.h @@ -29,28 +29,70 @@ namespace driver { /// compilation. Actions can produce auxiliary files, but can only /// produce a single output to feed into subsequent actions. class Action { +public: + typedef ActionList::size_type size_type; + typedef ActionList::iterator iterator; + typedef ActionList::const_iterator const_iterator; + + enum ActionClass { + InputClass = 0, + BindArchClass, + PreprocessJobClass, + PrecompileJobClass, + AnalyzeJobClass, + CompileJobClass, + AssembleJobClass, + LinkJobClass, + LipoJobClass, + + JobClassFirst=PreprocessJobClass, + JobClassLast=LipoJobClass + }; + + static const char *getClassName(ActionClass AC); + +private: + ActionClass Kind; + /// The output type of this action. types::ID Type; ActionList Inputs; protected: - Action(types::ID _Type) : Type(_Type) {} - Action(Action *Input, types::ID _Type) : Type(_Type), - Inputs(&Input, &Input + 1) {} - Action(const ActionList &_Inputs, types::ID _Type) : Type(_Type), - Inputs(_Inputs) {} + Action(ActionClass _Kind, types::ID _Type) : Kind(_Kind), Type(_Type) {} + Action(ActionClass _Kind, Action *Input, types::ID _Type) + : Kind(_Kind), Type(_Type), Inputs(&Input, &Input + 1) {} + Action(ActionClass _Kind, const ActionList &_Inputs, types::ID _Type) + : Kind(_Kind), Type(_Type), Inputs(_Inputs) {} public: virtual ~Action(); - - types::ID getType() { return Type; } + + ActionClass getKind() const { return Kind; } + types::ID getType() const { return Type; } + + size_type size() const { return Inputs.size(); } + + iterator begin() { return Inputs.begin(); } + iterator end() { return Inputs.end(); } + const_iterator begin() const { return Inputs.begin(); } + const_iterator end() const { return Inputs.end(); } + + static bool classof(const Action *) { return true; } }; class InputAction : public Action { const Arg &Input; public: - InputAction(const Arg &_Input, types::ID _Type) : Action(_Type), + InputAction(const Arg &_Input, types::ID _Type) : Action(InputClass, _Type), Input(_Input) {} + + const Arg &getInputArg() const { return Input; } + + static bool classof(const Action *A) { + return A->getKind() == InputClass; + } + static bool classof(const InputAction *) { return true; } }; class BindArchAction : public Action { @@ -58,61 +100,112 @@ class BindArchAction : public Action { public: BindArchAction(Action *Input, const char *_ArchName) - : Action(Input, Input->getType()), ArchName(_ArchName) { + : Action(BindArchClass, Input, Input->getType()), ArchName(_ArchName) { } + + const char *getArchName() const { return ArchName; } + + static bool classof(const Action *A) { + return A->getKind() == BindArchClass; + } + static bool classof(const BindArchAction *) { return true; } }; class JobAction : public Action { protected: - JobAction(Action *Input, types::ID Type) : Action(Input, Type) {} - JobAction(const ActionList &Inputs, types::ID Type) : Action(Inputs, Type) {} + JobAction(ActionClass Kind, Action *Input, types::ID Type) + : Action(Kind, Input, Type) {} + JobAction(ActionClass Kind, const ActionList &Inputs, types::ID Type) + : Action(Kind, Inputs, Type) {} + +public: + static bool classof(const Action *A) { + return (A->getKind() >= JobClassFirst && + A->getKind() <= JobClassLast); + } + static bool classof(const JobAction *) { return true; } }; class PreprocessJobAction : public JobAction { public: PreprocessJobAction(Action *Input, types::ID OutputType) - : JobAction(Input, OutputType) { + : JobAction(PreprocessJobClass, Input, OutputType) { + } + + static bool classof(const Action *A) { + return A->getKind() == PreprocessJobClass; } + static bool classof(const PreprocessJobAction *) { return true; } }; class PrecompileJobAction : public JobAction { public: PrecompileJobAction(Action *Input, types::ID OutputType) - : JobAction(Input, OutputType) { + : JobAction(PrecompileJobClass, Input, OutputType) { + } + + static bool classof(const Action *A) { + return A->getKind() == PrecompileJobClass; } + static bool classof(const PrecompileJobAction *) { return true; } }; class AnalyzeJobAction : public JobAction { public: AnalyzeJobAction(Action *Input, types::ID OutputType) - : JobAction(Input, OutputType) { + : JobAction(AnalyzeJobClass, Input, OutputType) { + } + + static bool classof(const Action *A) { + return A->getKind() == AnalyzeJobClass; } + static bool classof(const AnalyzeJobAction *) { return true; } }; class CompileJobAction : public JobAction { public: CompileJobAction(Action *Input, types::ID OutputType) - : JobAction(Input, OutputType) { + : JobAction(CompileJobClass, Input, OutputType) { } + + static bool classof(const Action *A) { + return A->getKind() == CompileJobClass; + } + static bool classof(const CompileJobAction *) { return true; } }; class AssembleJobAction : public JobAction { public: AssembleJobAction(Action *Input, types::ID OutputType) - : JobAction(Input, OutputType) { + : JobAction(AssembleJobClass, Input, OutputType) { + } + + static bool classof(const Action *A) { + return A->getKind() == AssembleJobClass; } + static bool classof(const AssembleJobAction *) { return true; } }; class LinkJobAction : public JobAction { public: LinkJobAction(ActionList &Inputs, types::ID Type) - : JobAction(Inputs, Type) {} + : JobAction(LinkJobClass, Inputs, Type) {} + + static bool classof(const Action *A) { + return A->getKind() == LinkJobClass; + } + static bool classof(const LinkJobAction *) { return true; } }; class LipoJobAction : public JobAction { public: LipoJobAction(ActionList &Inputs, types::ID Type) - : JobAction(Inputs, Type) {} + : JobAction(LipoJobClass, Inputs, Type) {} + + static bool classof(const Action *A) { + return A->getKind() == LipoJobClass; + } + static bool classof(const LipoJobAction *) { return true; } }; } // end namespace driver diff --git a/lib/Driver/Action.cpp b/lib/Driver/Action.cpp index d9bfce1ad3..86d676f698 100644 --- a/lib/Driver/Action.cpp +++ b/lib/Driver/Action.cpp @@ -13,3 +13,20 @@ using namespace clang::driver; Action::~Action() {} + +const char *Action::getClassName(ActionClass AC) { + switch (AC) { + case InputClass: return "input"; + case BindArchClass: return "bind-arch"; + case PreprocessJobClass: return "preprocess"; + case PrecompileJobClass: return "precompile"; + case AnalyzeJobClass: return "analyze"; + case CompileJobClass: return "compile"; + case AssembleJobClass: return "assemble"; + case LinkJobClass: return "link"; + case LipoJobClass: return "lipo"; + } + + assert(0 && "invalid class"); + return 0; +}