]> granicus.if.org Git - clang/commitdiff
Driver: Add cast<> support for Action, and some other accessors.
authorDaniel Dunbar <daniel@zuster.org>
Fri, 13 Mar 2009 12:17:08 +0000 (12:17 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Fri, 13 Mar 2009 12:17:08 +0000 (12:17 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@66887 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Driver/Action.h
lib/Driver/Action.cpp

index d0c29aa908367ad5373d83363ba63f3914d1788c..9cd17f76b9cfcd58306329e3a811c611b4f5c535 100644 (file)
@@ -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
index d9bfce1ad3e57cfa60957e425220cbd14ce26b96..86d676f698a675e66bf4efd229c1ebbda9e21234 100644 (file)
 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;
+}