@@ -88,6 +88,16 @@ using namespace solidity;
88
88
using namespace solidity ::util;
89
89
using namespace solidity ::langutil;
90
90
91
+ namespace
92
+ {
93
+
94
+ std::set<frontend::InputMode> ValidInputModes{
95
+ frontend::InputMode::Compiler,
96
+ frontend::InputMode::CompilerWithASTImport
97
+ };
98
+
99
+ } // anonymous namespace
100
+
91
101
namespace solidity ::frontend
92
102
{
93
103
@@ -160,7 +170,7 @@ static bool coloredOutput(CommandLineOptions const& _options)
160
170
161
171
void CommandLineInterface::handleBinary (string const & _contract)
162
172
{
163
- solAssert (m_options. input . mode == InputMode::Compiler || m_options.input .mode == InputMode::CompilerWithASTImport, " " );
173
+ solAssert (ValidInputModes. count ( m_options.input .mode ) == 1 );
164
174
165
175
if (m_options.compiler .outputs .binary )
166
176
{
@@ -186,7 +196,7 @@ void CommandLineInterface::handleBinary(string const& _contract)
186
196
187
197
void CommandLineInterface::handleOpcode (string const & _contract)
188
198
{
189
- solAssert (m_options. input . mode == InputMode::Compiler || m_options.input .mode == InputMode::CompilerWithASTImport, " " );
199
+ solAssert (ValidInputModes. count ( m_options.input .mode ) == 1 );
190
200
191
201
if (!m_options.output .dir .empty ())
192
202
createFile (m_compiler->filesystemFriendlyName (_contract) + " .opcode" , evmasm::disassemble (m_compiler->object (_contract).bytecode ));
@@ -200,7 +210,7 @@ void CommandLineInterface::handleOpcode(string const& _contract)
200
210
201
211
void CommandLineInterface::handleIR (string const & _contractName)
202
212
{
203
- solAssert (m_options. input . mode == InputMode::Compiler || m_options.input .mode == InputMode::CompilerWithASTImport, " " );
213
+ solAssert (ValidInputModes. count ( m_options.input .mode ) == 1 );
204
214
205
215
if (!m_options.compiler .outputs .ir )
206
216
return ;
@@ -216,7 +226,7 @@ void CommandLineInterface::handleIR(string const& _contractName)
216
226
217
227
void CommandLineInterface::handleIROptimized (string const & _contractName)
218
228
{
219
- solAssert (m_options. input . mode == InputMode::Compiler || m_options.input .mode == InputMode::CompilerWithASTImport, " " );
229
+ solAssert (ValidInputModes. count ( m_options.input .mode ) == 1 );
220
230
221
231
if (!m_options.compiler .outputs .irOptimized )
222
232
return ;
@@ -232,7 +242,7 @@ void CommandLineInterface::handleIROptimized(string const& _contractName)
232
242
233
243
void CommandLineInterface::handleEwasm (string const & _contractName)
234
244
{
235
- solAssert (m_options. input . mode == InputMode::Compiler || m_options.input .mode == InputMode::CompilerWithASTImport, " " );
245
+ solAssert (ValidInputModes. count ( m_options.input .mode ) == 1 );
236
246
237
247
if (!m_options.compiler .outputs .ewasm )
238
248
return ;
@@ -255,7 +265,7 @@ void CommandLineInterface::handleEwasm(string const& _contractName)
255
265
256
266
void CommandLineInterface::handleBytecode (string const & _contract)
257
267
{
258
- solAssert (m_options. input . mode == InputMode::Compiler || m_options.input .mode == InputMode::CompilerWithASTImport, " " );
268
+ solAssert (ValidInputModes. count ( m_options.input .mode ) == 1 );
259
269
260
270
if (m_options.compiler .outputs .opcodes )
261
271
handleOpcode (_contract);
@@ -265,7 +275,7 @@ void CommandLineInterface::handleBytecode(string const& _contract)
265
275
266
276
void CommandLineInterface::handleSignatureHashes (string const & _contract)
267
277
{
268
- solAssert (m_options. input . mode == InputMode::Compiler || m_options.input .mode == InputMode::CompilerWithASTImport, " " );
278
+ solAssert (ValidInputModes. count ( m_options.input .mode ) == 1 );
269
279
270
280
if (!m_options.compiler .outputs .signatureHashes )
271
281
return ;
@@ -297,7 +307,7 @@ void CommandLineInterface::handleSignatureHashes(string const& _contract)
297
307
298
308
void CommandLineInterface::handleMetadata (string const & _contract)
299
309
{
300
- solAssert (m_options. input . mode == InputMode::Compiler || m_options.input .mode == InputMode::CompilerWithASTImport, " " );
310
+ solAssert (ValidInputModes. count ( m_options.input .mode ) == 1 );
301
311
302
312
if (!m_options.compiler .outputs .metadata )
303
313
return ;
@@ -311,7 +321,7 @@ void CommandLineInterface::handleMetadata(string const& _contract)
311
321
312
322
void CommandLineInterface::handleABI (string const & _contract)
313
323
{
314
- solAssert (m_options. input . mode == InputMode::Compiler || m_options.input .mode == InputMode::CompilerWithASTImport, " " );
324
+ solAssert (ValidInputModes. count ( m_options.input .mode ) == 1 );
315
325
316
326
if (!m_options.compiler .outputs .abi )
317
327
return ;
@@ -325,7 +335,7 @@ void CommandLineInterface::handleABI(string const& _contract)
325
335
326
336
void CommandLineInterface::handleStorageLayout (string const & _contract)
327
337
{
328
- solAssert (m_options. input . mode == InputMode::Compiler || m_options.input .mode == InputMode::CompilerWithASTImport, " " );
338
+ solAssert (ValidInputModes. count ( m_options.input .mode ) == 1 );
329
339
330
340
if (!m_options.compiler .outputs .storageLayout )
331
341
return ;
@@ -339,7 +349,7 @@ void CommandLineInterface::handleStorageLayout(string const& _contract)
339
349
340
350
void CommandLineInterface::handleNatspec (bool _natspecDev, string const & _contract)
341
351
{
342
- solAssert (m_options. input . mode == InputMode::Compiler || m_options.input .mode == InputMode::CompilerWithASTImport, " " );
352
+ solAssert (ValidInputModes. count ( m_options.input .mode ) == 1 );
343
353
344
354
bool enabled = false ;
345
355
std::string suffix;
@@ -382,7 +392,7 @@ void CommandLineInterface::handleNatspec(bool _natspecDev, string const& _contra
382
392
383
393
void CommandLineInterface::handleGasEstimation (string const & _contract)
384
394
{
385
- solAssert (m_options. input . mode == InputMode::Compiler || m_options.input .mode == InputMode::CompilerWithASTImport, " " );
395
+ solAssert (ValidInputModes. count ( m_options.input .mode ) == 1 );
386
396
387
397
Json::Value estimates = m_compiler->gasEstimates (_contract);
388
398
sout () << " Gas estimation:" << endl;
@@ -424,13 +434,9 @@ void CommandLineInterface::handleGasEstimation(string const& _contract)
424
434
425
435
void CommandLineInterface::readInputFiles ()
426
436
{
427
- solAssert (!m_standardJsonInput.has_value (), " " );
437
+ solAssert (!m_standardJsonInput.has_value ());
428
438
429
- if (
430
- m_options.input .mode == InputMode::Help ||
431
- m_options.input .mode == InputMode::License ||
432
- m_options.input .mode == InputMode::Version
433
- )
439
+ if (std::set<InputMode>{InputMode::Help, InputMode::License, InputMode::Version}.count (m_options.input .mode ) == 1 )
434
440
return ;
435
441
436
442
m_fileReader.setBasePath (m_options.input .basePath );
@@ -496,7 +502,7 @@ void CommandLineInterface::readInputFiles()
496
502
string fileContent = readFileAsString (infile);
497
503
if (m_options.input .mode == InputMode::StandardJson)
498
504
{
499
- solAssert (!m_standardJsonInput.has_value (), " " );
505
+ solAssert (!m_standardJsonInput.has_value ());
500
506
m_standardJsonInput = std::move (fileContent);
501
507
}
502
508
else
@@ -510,7 +516,7 @@ void CommandLineInterface::readInputFiles()
510
516
{
511
517
if (m_options.input .mode == InputMode::StandardJson)
512
518
{
513
- solAssert (!m_standardJsonInput.has_value (), " " );
519
+ solAssert (!m_standardJsonInput.has_value ());
514
520
m_standardJsonInput = readUntilEnd (m_sin);
515
521
}
516
522
else
@@ -527,7 +533,7 @@ void CommandLineInterface::readInputFiles()
527
533
528
534
map<string, Json::Value> CommandLineInterface::parseAstFromInput ()
529
535
{
530
- solAssert (m_options.input .mode == InputMode::CompilerWithASTImport, " " );
536
+ solAssert (m_options.input .mode == InputMode::CompilerWithASTImport);
531
537
532
538
map<string, Json::Value> sourceJsons;
533
539
map<string, string> tmpSources;
@@ -559,7 +565,7 @@ void CommandLineInterface::createFile(string const& _fileName, string const& _da
559
565
{
560
566
namespace fs = boost::filesystem;
561
567
562
- solAssert (!m_options.output .dir .empty (), " " );
568
+ solAssert (!m_options.output .dir .empty ());
563
569
564
570
// NOTE: create_directories() raises an exception if the path consists solely of '.' or '..'
565
571
// (or equivalent such as './././.'). Paths like 'a/b/.' and 'a/b/..' are fine though.
@@ -639,7 +645,7 @@ void CommandLineInterface::processInput()
639
645
break ;
640
646
case InputMode::StandardJson:
641
647
{
642
- solAssert (m_standardJsonInput.has_value (), " " );
648
+ solAssert (m_standardJsonInput.has_value ());
643
649
644
650
StandardCompiler compiler (m_fileReader.reader (), m_options.formatting .json );
645
651
sout () << compiler.compile (std::move (m_standardJsonInput.value ())) << endl;
@@ -678,7 +684,7 @@ void CommandLineInterface::printLicense()
678
684
679
685
void CommandLineInterface::compile ()
680
686
{
681
- solAssert (m_options. input . mode == InputMode::Compiler || m_options.input .mode == InputMode::CompilerWithASTImport, " " );
687
+ solAssert (ValidInputModes. count ( m_options.input .mode ) == 1 );
682
688
683
689
m_compiler = make_unique<CompilerStack>(m_fileReader.reader ());
684
690
@@ -788,7 +794,7 @@ void CommandLineInterface::compile()
788
794
789
795
void CommandLineInterface::handleCombinedJSON ()
790
796
{
791
- solAssert (m_options. input . mode == InputMode::Compiler || m_options.input .mode == InputMode::CompilerWithASTImport, " " );
797
+ solAssert (ValidInputModes. count ( m_options.input .mode ) == 1 );
792
798
793
799
if (!m_options.compiler .combinedJsonRequests .has_value ())
794
800
return ;
@@ -880,7 +886,7 @@ void CommandLineInterface::handleCombinedJSON()
880
886
881
887
void CommandLineInterface::handleAst ()
882
888
{
883
- solAssert (m_options. input . mode == InputMode::Compiler || m_options.input .mode == InputMode::CompilerWithASTImport, " " );
889
+ solAssert (ValidInputModes. count ( m_options.input .mode ) == 1 );
884
890
885
891
if (!m_options.compiler .outputs .astCompactJson )
886
892
return ;
@@ -921,7 +927,7 @@ void CommandLineInterface::serveLSP()
921
927
922
928
void CommandLineInterface::link ()
923
929
{
924
- solAssert (m_options.input .mode == InputMode::Linker, " " );
930
+ solAssert (m_options.input .mode == InputMode::Linker);
925
931
926
932
// Map from how the libraries will be named inside the bytecode to their addresses.
927
933
map<string, h160> librariesReplacements;
@@ -984,7 +990,7 @@ void CommandLineInterface::link()
984
990
985
991
void CommandLineInterface::writeLinkedFiles ()
986
992
{
987
- solAssert (m_options.input .mode == InputMode::Linker, " " );
993
+ solAssert (m_options.input .mode == InputMode::Linker);
988
994
989
995
for (auto const & src: m_fileReader.sourceUnits ())
990
996
if (src.first == g_stdinFileName)
@@ -1018,14 +1024,14 @@ string CommandLineInterface::objectWithLinkRefsHex(evmasm::LinkerObject const& _
1018
1024
1019
1025
void CommandLineInterface::assemble (yul::YulStack::Language _language, yul::YulStack::Machine _targetMachine)
1020
1026
{
1021
- solAssert (m_options.input .mode == InputMode::Assembler, " " );
1027
+ solAssert (m_options.input .mode == InputMode::Assembler);
1022
1028
1023
1029
bool successful = true ;
1024
1030
map<string, yul::YulStack> yulStacks;
1025
1031
for (auto const & src: m_fileReader.sourceUnits ())
1026
1032
{
1027
1033
// --no-optimize-yul option is not accepted in assembly mode.
1028
- solAssert (!m_options.optimizer .noOptimizeYul , " " );
1034
+ solAssert (!m_options.optimizer .noOptimizeYul );
1029
1035
1030
1036
auto & stack = yulStacks[src.first ] = yul::YulStack (
1031
1037
m_options.output .evmVersion ,
@@ -1122,7 +1128,7 @@ void CommandLineInterface::assemble(yul::YulStack::Language _language, yul::YulS
1122
1128
1123
1129
void CommandLineInterface::outputCompilationResults ()
1124
1130
{
1125
- solAssert (m_options. input . mode == InputMode::Compiler || m_options.input .mode == InputMode::CompilerWithASTImport, " " );
1131
+ solAssert (ValidInputModes. count ( m_options.input .mode ) == 1 );
1126
1132
1127
1133
handleCombinedJSON ();
1128
1134
0 commit comments