Skip to content

NFC: Use enum class for ActionClass. #15446

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 45 additions & 36 deletions include/swift/Driver/Action.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class Action {
typedef ArrayRef<const Action *>::iterator iterator;
typedef ArrayRef<const Action *>::const_iterator const_iterator;

enum ActionClass {
enum class Kind : unsigned {
Input = 0,
CompileJob,
InterpretJob,
Expand All @@ -52,23 +52,24 @@ class Action {
VerifyDebugInfoJob,
GeneratePCHJob,

JobFirst=CompileJob,
JobLast=GeneratePCHJob
JobFirst = CompileJob,
JobLast = GeneratePCHJob
};

static const char *getClassName(ActionClass AC);
static const char *getClassName(Kind AC);

private:
unsigned Kind : 4;
unsigned RawKind : 4;
unsigned Type : 28;

friend class Compilation;
/// Actions must be created through Compilation::createAction.
void *operator new(size_t size) { return ::operator new(size); };

protected:
Action(ActionClass Kind, file_types::ID Type) : Kind(Kind), Type(Type) {
assert(Kind == getKind() && "not enough bits");
Action(Kind K, file_types::ID Type)
: RawKind(unsigned(K)), Type(Type) {
assert(K == getKind() && "not enough bits");
assert(Type == getType() && "not enough bits");
}

Expand All @@ -77,7 +78,7 @@ class Action {

const char *getClassName() const { return Action::getClassName(getKind()); }

ActionClass getKind() const { return static_cast<ActionClass>(Kind); }
Kind getKind() const { return static_cast<Kind>(RawKind); }
file_types::ID getType() const { return static_cast<file_types::ID>(Type); }
};

Expand All @@ -87,19 +88,19 @@ class InputAction : public Action {

public:
InputAction(const llvm::opt::Arg &Input, file_types::ID Type)
: Action(Action::Input, Type), Input(Input) {}
: Action(Action::Kind::Input, Type), Input(Input) {}
const llvm::opt::Arg &getInputArg() const { return Input; }

static bool classof(const Action *A) {
return A->getKind() == Action::Input;
return A->getKind() == Action::Kind::Input;
}
};

class JobAction : public Action {
TinyPtrVector<const Action *> Inputs;
virtual void anchor();
protected:
JobAction(ActionClass Kind, ArrayRef<const Action *> Inputs,
JobAction(Kind Kind, ArrayRef<const Action *> Inputs,
file_types::ID Type)
: Action(Kind, Type), Inputs(Inputs) {}

Expand All @@ -120,8 +121,8 @@ class JobAction : public Action {
virtual size_t getInputIndex() const { return 0; }

static bool classof(const Action *A) {
return (A->getKind() >= ActionClass::JobFirst &&
A->getKind() <= ActionClass::JobLast);
return (A->getKind() >= Kind::JobFirst &&
A->getKind() <= Kind::JobLast);
}
};

Expand Down Expand Up @@ -152,17 +153,19 @@ class CompileJobAction : public JobAction {

public:
CompileJobAction(file_types::ID OutputType)
: JobAction(Action::CompileJob, None, OutputType), inputInfo() {}
: JobAction(Action::Kind::CompileJob, None, OutputType),
inputInfo() {}

CompileJobAction(Action *Input, file_types::ID OutputType, InputInfo info)
: JobAction(Action::CompileJob, Input, OutputType), inputInfo(info) {}
: JobAction(Action::Kind::CompileJob, Input, OutputType),
inputInfo(info) {}

InputInfo getInputInfo() const {
return inputInfo;
}

static bool classof(const Action *A) {
return A->getKind() == Action::CompileJob;
return A->getKind() == Action::Kind::CompileJob;
}
};

Expand All @@ -172,10 +175,11 @@ class InterpretJobAction : public JobAction {

public:
explicit InterpretJobAction()
: JobAction(Action::InterpretJob, llvm::None, file_types::TY_Nothing) {}
: JobAction(Action::Kind::InterpretJob, llvm::None,
file_types::TY_Nothing) {}

static bool classof(const Action *A) {
return A->getKind() == Action::InterpretJob;
return A->getKind() == Action::Kind::InterpretJob;
}
};

Expand All @@ -190,10 +194,10 @@ class BackendJobAction : public JobAction {
public:
BackendJobAction(const Action *Input, file_types::ID OutputType,
size_t InputIndex)
: JobAction(Action::BackendJob, Input, OutputType),
: JobAction(Action::Kind::BackendJob, Input, OutputType),
InputIndex(InputIndex) {}
static bool classof(const Action *A) {
return A->getKind() == Action::BackendJob;
return A->getKind() == Action::Kind::BackendJob;
}

virtual size_t getInputIndex() const { return InputIndex; }
Expand All @@ -211,70 +215,74 @@ class REPLJobAction : public JobAction {
Mode RequestedMode;
public:
REPLJobAction(Mode mode)
: JobAction(Action::REPLJob, llvm::None, file_types::TY_Nothing),
: JobAction(Action::Kind::REPLJob, llvm::None,
file_types::TY_Nothing),
RequestedMode(mode) {}

Mode getRequestedMode() const { return RequestedMode; }

static bool classof(const Action *A) {
return A->getKind() == Action::REPLJob;
return A->getKind() == Action::Kind::REPLJob;
}
};

class MergeModuleJobAction : public JobAction {
virtual void anchor();
public:
MergeModuleJobAction(ArrayRef<const Action *> Inputs)
: JobAction(Action::MergeModuleJob, Inputs,
: JobAction(Action::Kind::MergeModuleJob, Inputs,
file_types::TY_SwiftModuleFile) {}

static bool classof(const Action *A) {
return A->getKind() == Action::MergeModuleJob;
return A->getKind() == Action::Kind::MergeModuleJob;
}
};

class ModuleWrapJobAction : public JobAction {
virtual void anchor();
public:
ModuleWrapJobAction(ArrayRef<const Action *> Inputs)
: JobAction(Action::ModuleWrapJob, Inputs, file_types::TY_Object) {}
: JobAction(Action::Kind::ModuleWrapJob, Inputs,
file_types::TY_Object) {}

static bool classof(const Action *A) {
return A->getKind() == Action::ModuleWrapJob;
return A->getKind() == Action::Kind::ModuleWrapJob;
}
};

class AutolinkExtractJobAction : public JobAction {
virtual void anchor();
public:
AutolinkExtractJobAction(ArrayRef<const Action *> Inputs)
: JobAction(Action::AutolinkExtractJob, Inputs,
: JobAction(Action::Kind::AutolinkExtractJob, Inputs,
file_types::TY_AutolinkFile) {}

static bool classof(const Action *A) {
return A->getKind() == Action::AutolinkExtractJob;
return A->getKind() == Action::Kind::AutolinkExtractJob;
}
};

class GenerateDSYMJobAction : public JobAction {
virtual void anchor();
public:
explicit GenerateDSYMJobAction(const Action *Input)
: JobAction(Action::GenerateDSYMJob, Input, file_types::TY_dSYM) {}
: JobAction(Action::Kind::GenerateDSYMJob, Input,
file_types::TY_dSYM) {}

static bool classof(const Action *A) {
return A->getKind() == Action::GenerateDSYMJob;
return A->getKind() == Action::Kind::GenerateDSYMJob;
}
};

class VerifyDebugInfoJobAction : public JobAction {
virtual void anchor();
public:
explicit VerifyDebugInfoJobAction(const Action *Input)
: JobAction(Action::VerifyDebugInfoJob, Input, file_types::TY_Nothing) {}
: JobAction(Action::Kind::VerifyDebugInfoJob, Input,
file_types::TY_Nothing) {}

static bool classof(const Action *A) {
return A->getKind() == Action::VerifyDebugInfoJob;
return A->getKind() == Action::Kind::VerifyDebugInfoJob;
}
};

Expand All @@ -284,7 +292,7 @@ class GeneratePCHJobAction : public JobAction {
virtual void anchor();
public:
GeneratePCHJobAction(const Action *Input, StringRef persistentPCHDir)
: JobAction(Action::GeneratePCHJob, Input,
: JobAction(Action::Kind::GeneratePCHJob, Input,
persistentPCHDir.empty() ? file_types::TY_PCH
: file_types::TY_Nothing),
PersistentPCHDir(persistentPCHDir) {}
Expand All @@ -293,7 +301,7 @@ class GeneratePCHJobAction : public JobAction {
StringRef getPersistentPCHDir() const { return PersistentPCHDir; }

static bool classof(const Action *A) {
return A->getKind() == Action::GeneratePCHJob;
return A->getKind() == Action::Kind::GeneratePCHJob;
}
};

Expand All @@ -303,14 +311,15 @@ class LinkJobAction : public JobAction {

public:
LinkJobAction(ArrayRef<const Action *> Inputs, LinkKind K)
: JobAction(Action::LinkJob, Inputs, file_types::TY_Image), Kind(K) {
: JobAction(Action::Kind::LinkJob, Inputs, file_types::TY_Image),
Kind(K) {
assert(Kind != LinkKind::None);
}

LinkKind getKind() const { return Kind; }

static bool classof(const Action *A) {
return A->getKind() == Action::LinkJob;
return A->getKind() == Action::Kind::LinkJob;
}
};

Expand Down
26 changes: 13 additions & 13 deletions lib/Driver/Action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,20 @@
using namespace swift::driver;
using namespace llvm::opt;

const char *Action::getClassName(ActionClass AC) {
const char *Action::getClassName(Kind AC) {
switch (AC) {
case Input: return "input";
case CompileJob: return "compile";
case InterpretJob: return "interpret";
case BackendJob: return "backend";
case MergeModuleJob: return "merge-module";
case ModuleWrapJob: return "modulewrap";
case AutolinkExtractJob: return "swift-autolink-extract";
case REPLJob: return "repl";
case LinkJob: return "link";
case GenerateDSYMJob: return "generate-dSYM";
case VerifyDebugInfoJob: return "verify-debug-info";
case GeneratePCHJob: return "generate-pch";
case Kind::Input: return "input";
case Kind::CompileJob: return "compile";
case Kind::InterpretJob: return "interpret";
case Kind::BackendJob: return "backend";
case Kind::MergeModuleJob: return "merge-module";
case Kind::ModuleWrapJob: return "modulewrap";
case Kind::AutolinkExtractJob: return "swift-autolink-extract";
case Kind::REPLJob: return "repl";
case Kind::LinkJob: return "link";
case Kind::GenerateDSYMJob: return "generate-dSYM";
case Kind::VerifyDebugInfoJob: return "verify-debug-info";
case Kind::GeneratePCHJob: return "generate-pch";
}

llvm_unreachable("invalid class");
Expand Down
7 changes: 4 additions & 3 deletions lib/Driver/ToolChain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,9 @@ ToolChain::constructJob(const JobAction &JA,

auto invocationInfo = [&]() -> InvocationInfo {
switch (JA.getKind()) {
#define CASE(K) case Action::K: \
return constructInvocation(cast<K##Action>(JA), context);
#define CASE(K) \
case Action::Kind::K: \
return constructInvocation(cast<K##Action>(JA), context);
CASE(CompileJob)
CASE(InterpretJob)
CASE(BackendJob)
Expand All @@ -88,7 +89,7 @@ ToolChain::constructJob(const JobAction &JA,
CASE(AutolinkExtractJob)
CASE(REPLJob)
#undef CASE
case Action::Input:
case Action::Kind::Input:
llvm_unreachable("not a JobAction");
}

Expand Down