Skip to content

Commit f8f9dca

Browse files
author
David Ungar
authored
Merge pull request #15446 from davidungar/PR-18-14-ActionClass
NFC: Use enum class for ActionClass.
2 parents fe75380 + a3ee808 commit f8f9dca

File tree

3 files changed

+62
-52
lines changed

3 files changed

+62
-52
lines changed

include/swift/Driver/Action.h

Lines changed: 45 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class Action {
3838
using iterator = ArrayRef<const Action *>::iterator;
3939
using const_iterator = ArrayRef<const Action *>::const_iterator;
4040

41-
enum ActionClass {
41+
enum class Kind : unsigned {
4242
Input = 0,
4343
CompileJob,
4444
InterpretJob,
@@ -52,23 +52,24 @@ class Action {
5252
VerifyDebugInfoJob,
5353
GeneratePCHJob,
5454

55-
JobFirst=CompileJob,
56-
JobLast=GeneratePCHJob
55+
JobFirst = CompileJob,
56+
JobLast = GeneratePCHJob
5757
};
5858

59-
static const char *getClassName(ActionClass AC);
59+
static const char *getClassName(Kind AC);
6060

6161
private:
62-
unsigned Kind : 4;
62+
unsigned RawKind : 4;
6363
unsigned Type : 28;
6464

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

6969
protected:
70-
Action(ActionClass Kind, file_types::ID Type) : Kind(Kind), Type(Type) {
71-
assert(Kind == getKind() && "not enough bits");
70+
Action(Kind K, file_types::ID Type)
71+
: RawKind(unsigned(K)), Type(Type) {
72+
assert(K == getKind() && "not enough bits");
7273
assert(Type == getType() && "not enough bits");
7374
}
7475

@@ -77,7 +78,7 @@ class Action {
7778

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

80-
ActionClass getKind() const { return static_cast<ActionClass>(Kind); }
81+
Kind getKind() const { return static_cast<Kind>(RawKind); }
8182
file_types::ID getType() const { return static_cast<file_types::ID>(Type); }
8283
};
8384

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

8889
public:
8990
InputAction(const llvm::opt::Arg &Input, file_types::ID Type)
90-
: Action(Action::Input, Type), Input(Input) {}
91+
: Action(Action::Kind::Input, Type), Input(Input) {}
9192
const llvm::opt::Arg &getInputArg() const { return Input; }
9293

9394
static bool classof(const Action *A) {
94-
return A->getKind() == Action::Input;
95+
return A->getKind() == Action::Kind::Input;
9596
}
9697
};
9798

9899
class JobAction : public Action {
99100
TinyPtrVector<const Action *> Inputs;
100101
virtual void anchor();
101102
protected:
102-
JobAction(ActionClass Kind, ArrayRef<const Action *> Inputs,
103+
JobAction(Kind Kind, ArrayRef<const Action *> Inputs,
103104
file_types::ID Type)
104105
: Action(Kind, Type), Inputs(Inputs) {}
105106

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

122123
static bool classof(const Action *A) {
123-
return (A->getKind() >= ActionClass::JobFirst &&
124-
A->getKind() <= ActionClass::JobLast);
124+
return (A->getKind() >= Kind::JobFirst &&
125+
A->getKind() <= Kind::JobLast);
125126
}
126127
};
127128

@@ -152,17 +153,19 @@ class CompileJobAction : public JobAction {
152153

153154
public:
154155
CompileJobAction(file_types::ID OutputType)
155-
: JobAction(Action::CompileJob, None, OutputType), inputInfo() {}
156+
: JobAction(Action::Kind::CompileJob, None, OutputType),
157+
inputInfo() {}
156158

157159
CompileJobAction(Action *Input, file_types::ID OutputType, InputInfo info)
158-
: JobAction(Action::CompileJob, Input, OutputType), inputInfo(info) {}
160+
: JobAction(Action::Kind::CompileJob, Input, OutputType),
161+
inputInfo(info) {}
159162

160163
InputInfo getInputInfo() const {
161164
return inputInfo;
162165
}
163166

164167
static bool classof(const Action *A) {
165-
return A->getKind() == Action::CompileJob;
168+
return A->getKind() == Action::Kind::CompileJob;
166169
}
167170
};
168171

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

173176
public:
174177
explicit InterpretJobAction()
175-
: JobAction(Action::InterpretJob, llvm::None, file_types::TY_Nothing) {}
178+
: JobAction(Action::Kind::InterpretJob, llvm::None,
179+
file_types::TY_Nothing) {}
176180

177181
static bool classof(const Action *A) {
178-
return A->getKind() == Action::InterpretJob;
182+
return A->getKind() == Action::Kind::InterpretJob;
179183
}
180184
};
181185

@@ -190,10 +194,10 @@ class BackendJobAction : public JobAction {
190194
public:
191195
BackendJobAction(const Action *Input, file_types::ID OutputType,
192196
size_t InputIndex)
193-
: JobAction(Action::BackendJob, Input, OutputType),
197+
: JobAction(Action::Kind::BackendJob, Input, OutputType),
194198
InputIndex(InputIndex) {}
195199
static bool classof(const Action *A) {
196-
return A->getKind() == Action::BackendJob;
200+
return A->getKind() == Action::Kind::BackendJob;
197201
}
198202

199203
virtual size_t getInputIndex() const { return InputIndex; }
@@ -211,70 +215,74 @@ class REPLJobAction : public JobAction {
211215
Mode RequestedMode;
212216
public:
213217
REPLJobAction(Mode mode)
214-
: JobAction(Action::REPLJob, llvm::None, file_types::TY_Nothing),
218+
: JobAction(Action::Kind::REPLJob, llvm::None,
219+
file_types::TY_Nothing),
215220
RequestedMode(mode) {}
216221

217222
Mode getRequestedMode() const { return RequestedMode; }
218223

219224
static bool classof(const Action *A) {
220-
return A->getKind() == Action::REPLJob;
225+
return A->getKind() == Action::Kind::REPLJob;
221226
}
222227
};
223228

224229
class MergeModuleJobAction : public JobAction {
225230
virtual void anchor();
226231
public:
227232
MergeModuleJobAction(ArrayRef<const Action *> Inputs)
228-
: JobAction(Action::MergeModuleJob, Inputs,
233+
: JobAction(Action::Kind::MergeModuleJob, Inputs,
229234
file_types::TY_SwiftModuleFile) {}
230235

231236
static bool classof(const Action *A) {
232-
return A->getKind() == Action::MergeModuleJob;
237+
return A->getKind() == Action::Kind::MergeModuleJob;
233238
}
234239
};
235240

236241
class ModuleWrapJobAction : public JobAction {
237242
virtual void anchor();
238243
public:
239244
ModuleWrapJobAction(ArrayRef<const Action *> Inputs)
240-
: JobAction(Action::ModuleWrapJob, Inputs, file_types::TY_Object) {}
245+
: JobAction(Action::Kind::ModuleWrapJob, Inputs,
246+
file_types::TY_Object) {}
241247

242248
static bool classof(const Action *A) {
243-
return A->getKind() == Action::ModuleWrapJob;
249+
return A->getKind() == Action::Kind::ModuleWrapJob;
244250
}
245251
};
246252

247253
class AutolinkExtractJobAction : public JobAction {
248254
virtual void anchor();
249255
public:
250256
AutolinkExtractJobAction(ArrayRef<const Action *> Inputs)
251-
: JobAction(Action::AutolinkExtractJob, Inputs,
257+
: JobAction(Action::Kind::AutolinkExtractJob, Inputs,
252258
file_types::TY_AutolinkFile) {}
253259

254260
static bool classof(const Action *A) {
255-
return A->getKind() == Action::AutolinkExtractJob;
261+
return A->getKind() == Action::Kind::AutolinkExtractJob;
256262
}
257263
};
258264

259265
class GenerateDSYMJobAction : public JobAction {
260266
virtual void anchor();
261267
public:
262268
explicit GenerateDSYMJobAction(const Action *Input)
263-
: JobAction(Action::GenerateDSYMJob, Input, file_types::TY_dSYM) {}
269+
: JobAction(Action::Kind::GenerateDSYMJob, Input,
270+
file_types::TY_dSYM) {}
264271

265272
static bool classof(const Action *A) {
266-
return A->getKind() == Action::GenerateDSYMJob;
273+
return A->getKind() == Action::Kind::GenerateDSYMJob;
267274
}
268275
};
269276

270277
class VerifyDebugInfoJobAction : public JobAction {
271278
virtual void anchor();
272279
public:
273280
explicit VerifyDebugInfoJobAction(const Action *Input)
274-
: JobAction(Action::VerifyDebugInfoJob, Input, file_types::TY_Nothing) {}
281+
: JobAction(Action::Kind::VerifyDebugInfoJob, Input,
282+
file_types::TY_Nothing) {}
275283

276284
static bool classof(const Action *A) {
277-
return A->getKind() == Action::VerifyDebugInfoJob;
285+
return A->getKind() == Action::Kind::VerifyDebugInfoJob;
278286
}
279287
};
280288

@@ -284,7 +292,7 @@ class GeneratePCHJobAction : public JobAction {
284292
virtual void anchor();
285293
public:
286294
GeneratePCHJobAction(const Action *Input, StringRef persistentPCHDir)
287-
: JobAction(Action::GeneratePCHJob, Input,
295+
: JobAction(Action::Kind::GeneratePCHJob, Input,
288296
persistentPCHDir.empty() ? file_types::TY_PCH
289297
: file_types::TY_Nothing),
290298
PersistentPCHDir(persistentPCHDir) {}
@@ -293,7 +301,7 @@ class GeneratePCHJobAction : public JobAction {
293301
StringRef getPersistentPCHDir() const { return PersistentPCHDir; }
294302

295303
static bool classof(const Action *A) {
296-
return A->getKind() == Action::GeneratePCHJob;
304+
return A->getKind() == Action::Kind::GeneratePCHJob;
297305
}
298306
};
299307

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

304312
public:
305313
LinkJobAction(ArrayRef<const Action *> Inputs, LinkKind K)
306-
: JobAction(Action::LinkJob, Inputs, file_types::TY_Image), Kind(K) {
314+
: JobAction(Action::Kind::LinkJob, Inputs, file_types::TY_Image),
315+
Kind(K) {
307316
assert(Kind != LinkKind::None);
308317
}
309318

310319
LinkKind getKind() const { return Kind; }
311320

312321
static bool classof(const Action *A) {
313-
return A->getKind() == Action::LinkJob;
322+
return A->getKind() == Action::Kind::LinkJob;
314323
}
315324
};
316325

lib/Driver/Action.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,20 @@
1818
using namespace swift::driver;
1919
using namespace llvm::opt;
2020

21-
const char *Action::getClassName(ActionClass AC) {
21+
const char *Action::getClassName(Kind AC) {
2222
switch (AC) {
23-
case Input: return "input";
24-
case CompileJob: return "compile";
25-
case InterpretJob: return "interpret";
26-
case BackendJob: return "backend";
27-
case MergeModuleJob: return "merge-module";
28-
case ModuleWrapJob: return "modulewrap";
29-
case AutolinkExtractJob: return "swift-autolink-extract";
30-
case REPLJob: return "repl";
31-
case LinkJob: return "link";
32-
case GenerateDSYMJob: return "generate-dSYM";
33-
case VerifyDebugInfoJob: return "verify-debug-info";
34-
case GeneratePCHJob: return "generate-pch";
23+
case Kind::Input: return "input";
24+
case Kind::CompileJob: return "compile";
25+
case Kind::InterpretJob: return "interpret";
26+
case Kind::BackendJob: return "backend";
27+
case Kind::MergeModuleJob: return "merge-module";
28+
case Kind::ModuleWrapJob: return "modulewrap";
29+
case Kind::AutolinkExtractJob: return "swift-autolink-extract";
30+
case Kind::REPLJob: return "repl";
31+
case Kind::LinkJob: return "link";
32+
case Kind::GenerateDSYMJob: return "generate-dSYM";
33+
case Kind::VerifyDebugInfoJob: return "verify-debug-info";
34+
case Kind::GeneratePCHJob: return "generate-pch";
3535
}
3636

3737
llvm_unreachable("invalid class");

lib/Driver/ToolChain.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,9 @@ ToolChain::constructJob(const JobAction &JA,
7474

7575
auto invocationInfo = [&]() -> InvocationInfo {
7676
switch (JA.getKind()) {
77-
#define CASE(K) case Action::K: \
78-
return constructInvocation(cast<K##Action>(JA), context);
77+
#define CASE(K) \
78+
case Action::Kind::K: \
79+
return constructInvocation(cast<K##Action>(JA), context);
7980
CASE(CompileJob)
8081
CASE(InterpretJob)
8182
CASE(BackendJob)
@@ -88,7 +89,7 @@ ToolChain::constructJob(const JobAction &JA,
8889
CASE(AutolinkExtractJob)
8990
CASE(REPLJob)
9091
#undef CASE
91-
case Action::Input:
92+
case Action::Kind::Input:
9293
llvm_unreachable("not a JobAction");
9394
}
9495

0 commit comments

Comments
 (0)