@@ -89,6 +89,17 @@ using namespace solidity;
89
89
using namespace solidity ::util;
90
90
using namespace solidity ::langutil;
91
91
92
+ namespace
93
+ {
94
+
95
+ std::vector<frontend::InputMode> ValidInputModes{
96
+ frontend::InputMode::Compiler,
97
+ frontend::InputMode::CompilerWithASTImport,
98
+ frontend::InputMode::CompilerWithEvmAssemblyJsonImport
99
+ };
100
+
101
+ } // anonymous namespace
102
+
92
103
namespace solidity ::frontend
93
104
{
94
105
@@ -161,11 +172,7 @@ static bool coloredOutput(CommandLineOptions const& _options)
161
172
162
173
void CommandLineInterface::handleBinary (string const & _contract)
163
174
{
164
- solAssert (
165
- m_options.input .mode == InputMode::Compiler ||
166
- m_options.input .mode == InputMode::CompilerWithASTImport ||
167
- m_options.input .mode == InputMode::CompilerWithEvmAssemblyJsonImport
168
- );
175
+ solAssert (any_of (m_options.input .mode , ValidInputModes));
169
176
170
177
if (m_options.compiler .outputs .binary )
171
178
{
@@ -191,11 +198,7 @@ void CommandLineInterface::handleBinary(string const& _contract)
191
198
192
199
void CommandLineInterface::handleOpcode (string const & _contract)
193
200
{
194
- solAssert (
195
- m_options.input .mode == InputMode::Compiler ||
196
- m_options.input .mode == InputMode::CompilerWithASTImport ||
197
- m_options.input .mode == InputMode::CompilerWithEvmAssemblyJsonImport
198
- );
201
+ solAssert (any_of (m_options.input .mode , ValidInputModes));
199
202
200
203
if (!m_options.output .dir .empty ())
201
204
createFile (m_compiler->filesystemFriendlyName (_contract) + " .opcode" , evmasm::disassemble (m_compiler->object (_contract).bytecode ));
@@ -209,11 +212,7 @@ void CommandLineInterface::handleOpcode(string const& _contract)
209
212
210
213
void CommandLineInterface::handleIR (string const & _contractName)
211
214
{
212
- solAssert (
213
- m_options.input .mode == InputMode::Compiler ||
214
- m_options.input .mode == InputMode::CompilerWithASTImport ||
215
- m_options.input .mode == InputMode::CompilerWithEvmAssemblyJsonImport
216
- );
215
+ solAssert (any_of (m_options.input .mode , ValidInputModes));
217
216
218
217
if (!m_options.compiler .outputs .ir )
219
218
return ;
@@ -229,11 +228,7 @@ void CommandLineInterface::handleIR(string const& _contractName)
229
228
230
229
void CommandLineInterface::handleIROptimized (string const & _contractName)
231
230
{
232
- solAssert (
233
- m_options.input .mode == InputMode::Compiler ||
234
- m_options.input .mode == InputMode::CompilerWithASTImport ||
235
- m_options.input .mode == InputMode::CompilerWithEvmAssemblyJsonImport
236
- );
231
+ solAssert (any_of (m_options.input .mode , ValidInputModes));
237
232
238
233
if (!m_options.compiler .outputs .irOptimized )
239
234
return ;
@@ -249,11 +244,7 @@ void CommandLineInterface::handleIROptimized(string const& _contractName)
249
244
250
245
void CommandLineInterface::handleEwasm (string const & _contractName)
251
246
{
252
- solAssert (
253
- m_options.input .mode == InputMode::Compiler ||
254
- m_options.input .mode == InputMode::CompilerWithASTImport ||
255
- m_options.input .mode == InputMode::CompilerWithEvmAssemblyJsonImport
256
- );
247
+ solAssert (any_of (m_options.input .mode , ValidInputModes));
257
248
258
249
if (!m_options.compiler .outputs .ewasm )
259
250
return ;
@@ -276,11 +267,7 @@ void CommandLineInterface::handleEwasm(string const& _contractName)
276
267
277
268
void CommandLineInterface::handleBytecode (string const & _contract)
278
269
{
279
- solAssert (
280
- m_options.input .mode == InputMode::Compiler ||
281
- m_options.input .mode == InputMode::CompilerWithASTImport ||
282
- m_options.input .mode == InputMode::CompilerWithEvmAssemblyJsonImport
283
- );
270
+ solAssert (any_of (m_options.input .mode , ValidInputModes));
284
271
285
272
if (m_options.compiler .outputs .opcodes )
286
273
handleOpcode (_contract);
@@ -290,11 +277,7 @@ void CommandLineInterface::handleBytecode(string const& _contract)
290
277
291
278
void CommandLineInterface::handleSignatureHashes (string const & _contract)
292
279
{
293
- solAssert (
294
- m_options.input .mode == InputMode::Compiler ||
295
- m_options.input .mode == InputMode::CompilerWithASTImport ||
296
- m_options.input .mode == InputMode::CompilerWithEvmAssemblyJsonImport
297
- );
280
+ solAssert (any_of (m_options.input .mode , ValidInputModes));
298
281
299
282
if (!m_options.compiler .outputs .signatureHashes )
300
283
return ;
@@ -326,11 +309,7 @@ void CommandLineInterface::handleSignatureHashes(string const& _contract)
326
309
327
310
void CommandLineInterface::handleMetadata (string const & _contract)
328
311
{
329
- solAssert (
330
- m_options.input .mode == InputMode::Compiler ||
331
- m_options.input .mode == InputMode::CompilerWithASTImport ||
332
- m_options.input .mode == InputMode::CompilerWithEvmAssemblyJsonImport
333
- );
312
+ solAssert (any_of (m_options.input .mode , ValidInputModes));
334
313
335
314
if (!m_options.compiler .outputs .metadata )
336
315
return ;
@@ -344,11 +323,7 @@ void CommandLineInterface::handleMetadata(string const& _contract)
344
323
345
324
void CommandLineInterface::handleABI (string const & _contract)
346
325
{
347
- solAssert (
348
- m_options.input .mode == InputMode::Compiler ||
349
- m_options.input .mode == InputMode::CompilerWithASTImport ||
350
- m_options.input .mode == InputMode::CompilerWithEvmAssemblyJsonImport
351
- );
326
+ solAssert (any_of (m_options.input .mode , ValidInputModes));
352
327
353
328
if (!m_options.compiler .outputs .abi )
354
329
return ;
@@ -362,11 +337,7 @@ void CommandLineInterface::handleABI(string const& _contract)
362
337
363
338
void CommandLineInterface::handleStorageLayout (string const & _contract)
364
339
{
365
- solAssert (
366
- m_options.input .mode == InputMode::Compiler ||
367
- m_options.input .mode == InputMode::CompilerWithASTImport ||
368
- m_options.input .mode == InputMode::CompilerWithEvmAssemblyJsonImport
369
- );
340
+ solAssert (any_of (m_options.input .mode , ValidInputModes));
370
341
371
342
if (!m_options.compiler .outputs .storageLayout )
372
343
return ;
@@ -380,11 +351,7 @@ void CommandLineInterface::handleStorageLayout(string const& _contract)
380
351
381
352
void CommandLineInterface::handleNatspec (bool _natspecDev, string const & _contract)
382
353
{
383
- solAssert (
384
- m_options.input .mode == InputMode::Compiler ||
385
- m_options.input .mode == InputMode::CompilerWithASTImport ||
386
- m_options.input .mode == InputMode::CompilerWithEvmAssemblyJsonImport
387
- );
354
+ solAssert (any_of (m_options.input .mode , ValidInputModes));
388
355
389
356
bool enabled = false ;
390
357
std::string suffix;
@@ -427,11 +394,7 @@ void CommandLineInterface::handleNatspec(bool _natspecDev, string const& _contra
427
394
428
395
void CommandLineInterface::handleGasEstimation (string const & _contract)
429
396
{
430
- solAssert (
431
- m_options.input .mode == InputMode::Compiler ||
432
- m_options.input .mode == InputMode::CompilerWithASTImport ||
433
- m_options.input .mode == InputMode::CompilerWithEvmAssemblyJsonImport
434
- );
397
+ solAssert (any_of (m_options.input .mode , ValidInputModes));
435
398
436
399
Json::Value estimates = m_compiler->gasEstimates (_contract);
437
400
sout () << " Gas estimation:" << endl;
@@ -475,11 +438,7 @@ void CommandLineInterface::readInputFiles()
475
438
{
476
439
solAssert (!m_standardJsonInput.has_value ());
477
440
478
- if (
479
- m_options.input .mode == InputMode::Help ||
480
- m_options.input .mode == InputMode::License ||
481
- m_options.input .mode == InputMode::Version
482
- )
441
+ if (any_of (m_options.input .mode , {InputMode::Help, InputMode::License, InputMode::Version}))
483
442
return ;
484
443
485
444
m_fileReader.setBasePath (m_options.input .basePath );
@@ -747,11 +706,7 @@ void CommandLineInterface::printLicense()
747
706
748
707
void CommandLineInterface::compile ()
749
708
{
750
- solAssert (
751
- m_options.input .mode == InputMode::Compiler ||
752
- m_options.input .mode == InputMode::CompilerWithASTImport ||
753
- m_options.input .mode == InputMode::CompilerWithEvmAssemblyJsonImport
754
- );
709
+ solAssert (any_of (m_options.input .mode , ValidInputModes));
755
710
756
711
m_compiler = make_unique<CompilerStack>(m_fileReader.reader ());
757
712
@@ -869,11 +824,7 @@ void CommandLineInterface::compile()
869
824
870
825
void CommandLineInterface::handleCombinedJSON ()
871
826
{
872
- solAssert (
873
- m_options.input .mode == InputMode::Compiler ||
874
- m_options.input .mode == InputMode::CompilerWithASTImport ||
875
- m_options.input .mode == InputMode::CompilerWithEvmAssemblyJsonImport
876
- );
827
+ solAssert (any_of (m_options.input .mode , ValidInputModes));
877
828
878
829
if (!m_options.compiler .combinedJsonRequests .has_value ())
879
830
return ;
@@ -965,11 +916,7 @@ void CommandLineInterface::handleCombinedJSON()
965
916
966
917
void CommandLineInterface::handleAst ()
967
918
{
968
- solAssert (
969
- m_options.input .mode == InputMode::Compiler ||
970
- m_options.input .mode == InputMode::CompilerWithASTImport ||
971
- m_options.input .mode == InputMode::CompilerWithEvmAssemblyJsonImport
972
- );
919
+ solAssert (any_of (m_options.input .mode , ValidInputModes));
973
920
974
921
if (!m_options.compiler .outputs .astCompactJson )
975
922
return ;
@@ -1194,7 +1141,7 @@ void CommandLineInterface::assemble(yul::YulStack::Language _language, yul::YulS
1194
1141
serr () << " No binary representation found." << endl;
1195
1142
}
1196
1143
1197
- solAssert (_targetMachine == yul::YulStack::Machine::Ewasm || _targetMachine == yul::YulStack::Machine::EVM);
1144
+ solAssert (any_of ( _targetMachine, { yul::YulStack::Machine::Ewasm, yul::YulStack::Machine::EVM}) );
1198
1145
if (
1199
1146
(_targetMachine == yul::YulStack::Machine::EVM && m_options.compiler .outputs .asm_ ) ||
1200
1147
(_targetMachine == yul::YulStack::Machine::Ewasm && m_options.compiler .outputs .ewasm )
@@ -1211,11 +1158,7 @@ void CommandLineInterface::assemble(yul::YulStack::Language _language, yul::YulS
1211
1158
1212
1159
void CommandLineInterface::outputCompilationResults ()
1213
1160
{
1214
- solAssert (
1215
- m_options.input .mode == InputMode::Compiler ||
1216
- m_options.input .mode == InputMode::CompilerWithASTImport ||
1217
- m_options.input .mode == InputMode::CompilerWithEvmAssemblyJsonImport
1218
- );
1161
+ solAssert (any_of (m_options.input .mode , ValidInputModes));
1219
1162
1220
1163
handleCombinedJSON ();
1221
1164
0 commit comments