[cfe-commits] r66887 - in /cfe/trunk: include/clang/Driver/Action.h lib/Driver/Action.cpp
Daniel Dunbar
daniel at zuster.org
Fri Mar 13 05:17:08 PDT 2009
Author: ddunbar
Date: Fri Mar 13 07:17:08 2009
New Revision: 66887
URL: http://llvm.org/viewvc/llvm-project?rev=66887&view=rev
Log:
Driver: Add cast<> support for Action, and some other accessors.
Modified:
cfe/trunk/include/clang/Driver/Action.h
cfe/trunk/lib/Driver/Action.cpp
Modified: cfe/trunk/include/clang/Driver/Action.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Action.h?rev=66887&r1=66886&r2=66887&view=diff
==============================================================================
--- cfe/trunk/include/clang/Driver/Action.h (original)
+++ cfe/trunk/include/clang/Driver/Action.h Fri Mar 13 07:17:08 2009
@@ -29,28 +29,70 @@
/// 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 @@
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
Modified: cfe/trunk/lib/Driver/Action.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Action.cpp?rev=66887&r1=66886&r2=66887&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Action.cpp (original)
+++ cfe/trunk/lib/Driver/Action.cpp Fri Mar 13 07:17:08 2009
@@ -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;
+}
More information about the cfe-commits
mailing list