]> granicus.if.org Git - clang/commitdiff
Driver: Remove the Job class. NFC
authorJustin Bogner <mail@justinbogner.com>
Thu, 2 Jul 2015 22:52:08 +0000 (22:52 +0000)
committerJustin Bogner <mail@justinbogner.com>
Thu, 2 Jul 2015 22:52:08 +0000 (22:52 +0000)
We had a strange relationship here where we made a list of Jobs
inherit from a single Job, but there weren't actually any places where
this arbitrary nesting was used or needed.

Simplify all of this by removing Job entirely and updating all of the
users to either work with a JobList or a single Command.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@241310 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Driver/Compilation.h
include/clang/Driver/Driver.h
include/clang/Driver/Job.h
lib/Driver/Compilation.cpp
lib/Driver/Driver.cpp
lib/Driver/Job.cpp
lib/Tooling/CompilationDatabase.cpp

index 5574e2ca0533681ad22bae1ab486d160956ffdb6..f0c1bedb3989002d256c278fa12de4bda8136f5a 100644 (file)
@@ -169,8 +169,9 @@ public:
   ///
   /// \param FailingCommands - For non-zero results, this will be a vector of
   /// failing commands and their associated result code.
-  void ExecuteJob(const Job &J,
-     SmallVectorImpl< std::pair<int, const Command *> > &FailingCommands) const;
+  void ExecuteJobs(
+      const JobList &Jobs,
+      SmallVectorImpl<std::pair<int, const Command *>> &FailingCommands) const;
 
   /// initCompilationForDiagnostics - Remove stale state and suppress output
   /// so compilation can be reexecuted to generate additional diagnostic
index 577826ed6a0edfdfadccaee495bde7223c438a28..15c194b0984810dc208955a61d3815606abda0ea 100644 (file)
@@ -42,7 +42,7 @@ namespace driver {
   class Command;
   class Compilation;
   class InputInfo;
-  class Job;
+  class JobList;
   class JobAction;
   class SanitizerArgs;
   class ToolChain;
@@ -195,7 +195,7 @@ private:
                            llvm::opt::Arg **FinalPhaseArg = nullptr) const;
 
   // Before executing jobs, sets up response files for commands that need them.
-  void setUpResponseFiles(Compilation &C, Job &J);
+  void setUpResponseFiles(Compilation &C, Command &Cmd);
 
   void generatePrefixedToolNames(const char *Tool, const ToolChain &TC,
                                  SmallVectorImpl<std::string> &Names) const;
index dda3ab5864dd9ceecd363dea87ab3cd6d22248d8..8fc2e8d3a5b901441a81381fa73a8b37077ec446 100644 (file)
@@ -37,37 +37,9 @@ struct CrashReportInfo {
       : Filename(Filename), VFSPath(VFSPath) {}
 };
 
-class Job {
-public:
-  enum JobClass {
-    CommandClass,
-    FallbackCommandClass,
-    JobListClass
-  };
-
-private:
-  JobClass Kind;
-
-protected:
-  Job(JobClass Kind) : Kind(Kind) {}
-public:
-  virtual ~Job();
-
-  JobClass getKind() const { return Kind; }
-
-  /// Print - Print this Job in -### format.
-  ///
-  /// \param OS - The stream to print on.
-  /// \param Terminator - A string to print at the end of the line.
-  /// \param Quote - Should separate arguments be quoted.
-  /// \param CrashInfo - Details for inclusion in a crash report.
-  virtual void Print(llvm::raw_ostream &OS, const char *Terminator, bool Quote,
-                     CrashReportInfo *CrashInfo = nullptr) const = 0;
-};
-
 /// Command - An executable path/name and argument vector to
 /// execute.
-class Command : public Job {
+class Command {
   /// Source - The action which caused the creation of this job.
   const Action &Source;
 
@@ -108,9 +80,10 @@ class Command : public Job {
 public:
   Command(const Action &Source, const Tool &Creator, const char *Executable,
           const llvm::opt::ArgStringList &Arguments);
+  virtual ~Command() {}
 
-  void Print(llvm::raw_ostream &OS, const char *Terminator, bool Quote,
-             CrashReportInfo *CrashInfo = nullptr) const override;
+  virtual void Print(llvm::raw_ostream &OS, const char *Terminator, bool Quote,
+                     CrashReportInfo *CrashInfo = nullptr) const;
 
   virtual int Execute(const StringRef **Redirects, std::string *ErrMsg,
                       bool *ExecutionFailed) const;
@@ -133,11 +106,6 @@ public:
   const char *getExecutable() const { return Executable; }
 
   const llvm::opt::ArgStringList &getArguments() const { return Arguments; }
-
-  static bool classof(const Job *J) {
-    return J->getKind() == CommandClass ||
-           J->getKind() == FallbackCommandClass;
-  }
 };
 
 /// Like Command, but with a fallback which is executed in case
@@ -154,18 +122,14 @@ public:
   int Execute(const StringRef **Redirects, std::string *ErrMsg,
               bool *ExecutionFailed) const override;
 
-  static bool classof(const Job *J) {
-    return J->getKind() == FallbackCommandClass;
-  }
-
 private:
   std::unique_ptr<Command> Fallback;
 };
 
 /// JobList - A sequence of jobs to perform.
-class JobList : public Job {
+class JobList {
 public:
-  typedef SmallVector<std::unique_ptr<Job>, 4> list_type;
+  typedef SmallVector<std::unique_ptr<Command>, 4> list_type;
   typedef list_type::size_type size_type;
   typedef llvm::pointee_iterator<list_type::iterator> iterator;
   typedef llvm::pointee_iterator<list_type::const_iterator> const_iterator;
@@ -174,14 +138,11 @@ private:
   list_type Jobs;
 
 public:
-  JobList();
-  ~JobList() override {}
-
   void Print(llvm::raw_ostream &OS, const char *Terminator,
-             bool Quote, CrashReportInfo *CrashInfo = nullptr) const override;
+             bool Quote, CrashReportInfo *CrashInfo = nullptr) const;
 
   /// Add a job to the list (taking ownership).
-  void addJob(std::unique_ptr<Job> J) { Jobs.push_back(std::move(J)); }
+  void addJob(std::unique_ptr<Command> J) { Jobs.push_back(std::move(J)); }
 
   /// Clear the job list.
   void clear();
@@ -193,10 +154,6 @@ public:
   const_iterator begin() const { return Jobs.begin(); }
   iterator end() { return Jobs.end(); }
   const_iterator end() const { return Jobs.end(); }
-
-  static bool classof(const Job *J) {
-    return J->getKind() == JobListClass;
-  }
 };
 
 } // end namespace driver
index 2bcbd5cf943ce95892253d3a8bcda6dbe22d21e1..101d1fcc832ae98bc3f71249ff44630e2750cb57 100644 (file)
@@ -192,18 +192,14 @@ static bool InputsOk(const Command &C,
   return !ActionFailed(&C.getSource(), FailingCommands);
 }
 
-void Compilation::ExecuteJob(const Job &J,
-                             FailingCommandList &FailingCommands) const {
-  if (const Command *C = dyn_cast<Command>(&J)) {
-    if (!InputsOk(*C, FailingCommands))
-      return;
+void Compilation::ExecuteJobs(const JobList &Jobs,
+                              FailingCommandList &FailingCommands) const {
+  for (const auto &Job : Jobs) {
+    if (!InputsOk(Job, FailingCommands))
+      continue;
     const Command *FailingCommand = nullptr;
-    if (int Res = ExecuteCommand(*C, FailingCommand))
+    if (int Res = ExecuteCommand(Job, FailingCommand))
       FailingCommands.push_back(std::make_pair(Res, FailingCommand));
-  } else {
-    const JobList *Jobs = cast<JobList>(&J);
-    for (const auto &Job : *Jobs)
-      ExecuteJob(Job, FailingCommands);
   }
 }
 
index a146ba0f4605817dd70e26e68f50d8a990fdf3ec..b9dc35d6219a61da3482670c0536f74f24544f2d 100644 (file)
@@ -500,7 +500,7 @@ void Driver::generateCompilationDiagnostics(Compilation &C,
 
   // Generate preprocessed output.
   SmallVector<std::pair<int, const Command *>, 4> FailingCommands;
-  C.ExecuteJob(C.getJobs(), FailingCommands);
+  C.ExecuteJobs(C.getJobs(), FailingCommands);
 
   // If any of the preprocessing commands failed, clean up and exit.
   if (!FailingCommands.empty()) {
@@ -560,26 +560,16 @@ void Driver::generateCompilationDiagnostics(Compilation &C,
       << "\n\n********************";
 }
 
-void Driver::setUpResponseFiles(Compilation &C, Job &J) {
-  if (JobList *Jobs = dyn_cast<JobList>(&J)) {
-    for (auto &Job : *Jobs)
-      setUpResponseFiles(C, Job);
-    return;
-  }
-
-  Command *CurCommand = dyn_cast<Command>(&J);
-  if (!CurCommand)
-    return;
-
+void Driver::setUpResponseFiles(Compilation &C, Command &Cmd) {
   // Since argumentsFitWithinSystemLimits() may underestimate system's capacity
   // if the tool does not support response files, there is a chance/ that things
   // will just work without a response file, so we silently just skip it.
-  if (CurCommand->getCreator().getResponseFilesSupport() == Tool::RF_None ||
-      llvm::sys::argumentsFitWithinSystemLimits(CurCommand->getArguments()))
+  if (Cmd.getCreator().getResponseFilesSupport() == Tool::RF_None ||
+      llvm::sys::argumentsFitWithinSystemLimits(Cmd.getArguments()))
     return;
 
   std::string TmpName = GetTemporaryPath("response", "txt");
-  CurCommand->setResponseFile(
+  Cmd.setResponseFile(
       C.addTempFile(C.getArgs().MakeArgString(TmpName.c_str())));
 }
 
@@ -597,9 +587,10 @@ int Driver::ExecuteCompilation(
     return 1;
 
   // Set up response file names for each command, if necessary
-  setUpResponseFiles(C, C.getJobs());
+  for (auto &Job : C.getJobs())
+    setUpResponseFiles(C, Job);
 
-  C.ExecuteJob(C.getJobs(), FailingCommands);
+  C.ExecuteJobs(C.getJobs(), FailingCommands);
 
   // Remove temp files.
   C.CleanupFileList(C.getTempFiles());
index 4b5b839e524d4c60c1511047231e142f9b68a401..ac18e1eb56a17c5e44d5eece731ef7bacd413e86 100644 (file)
@@ -25,12 +25,10 @@ using llvm::raw_ostream;
 using llvm::StringRef;
 using llvm::ArrayRef;
 
-Job::~Job() {}
-
 Command::Command(const Action &Source, const Tool &Creator,
                  const char *Executable, const ArgStringList &Arguments)
-    : Job(CommandClass), Source(Source), Creator(Creator),
-      Executable(Executable), Arguments(Arguments), ResponseFile(nullptr) {}
+    : Source(Source), Creator(Creator), Executable(Executable),
+      Arguments(Arguments), ResponseFile(nullptr) {}
 
 static int skipArgs(const char *Flag, bool HaveCrashVFS) {
   // These flags are all of the form -Flag <Arg> and are treated as two
@@ -293,8 +291,6 @@ int FallbackCommand::Execute(const StringRef **Redirects, std::string *ErrMsg,
   return SecondaryStatus;
 }
 
-JobList::JobList() : Job(JobListClass) {}
-
 void JobList::Print(raw_ostream &OS, const char *Terminator, bool Quote,
                     CrashReportInfo *CrashInfo) const {
   for (const auto &Job : *this)
index 4483b189ca9f47a0e5a5e4ba73f604f4942e2e32..2272be632b9ea3fed920c048a5be97700e2d249b 100644 (file)
@@ -250,14 +250,11 @@ static bool stripPositionalArgs(std::vector<const char *> Args,
 
   CompileJobAnalyzer CompileAnalyzer;
 
-  for (const auto &Job : Jobs) {
-    if (Job.getKind() == driver::Job::CommandClass) {
-      const driver::Command &Cmd = cast<driver::Command>(Job);
-      // Collect only for Assemble jobs. If we do all jobs we get duplicates
-      // since Link jobs point to Assemble jobs as inputs.
-      if (Cmd.getSource().getKind() == driver::Action::AssembleJobClass)
-        CompileAnalyzer.run(&Cmd.getSource());
-    }
+  for (const auto &Cmd : Jobs) {
+    // Collect only for Assemble jobs. If we do all jobs we get duplicates
+    // since Link jobs point to Assemble jobs as inputs.
+    if (Cmd.getSource().getKind() == driver::Action::AssembleJobClass)
+      CompileAnalyzer.run(&Cmd.getSource());
   }
 
   if (CompileAnalyzer.Inputs.empty()) {