@@ -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
+ set<frontend::InputMode> const CompilerInputModes{
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 (CompilerInputModes. 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 (CompilerInputModes. 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 (CompilerInputModes. 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 (CompilerInputModes. 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 (CompilerInputModes. 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 (CompilerInputModes. 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 (CompilerInputModes. 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 (CompilerInputModes. 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 (CompilerInputModes. 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 (CompilerInputModes. 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 (CompilerInputModes. 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 (CompilerInputModes. 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,15 @@ 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
+ static set<frontend::InputMode> const noInputFiles{
440
+ frontend::InputMode::Help,
441
+ frontend::InputMode::License,
442
+ frontend::InputMode::Version
443
+ };
444
+
445
+ if (noInputFiles.count (m_options.input .mode ) == 1 )
434
446
return ;
435
447
436
448
m_fileReader.setBasePath (m_options.input .basePath );
@@ -496,7 +508,7 @@ void CommandLineInterface::readInputFiles()
496
508
string fileContent = readFileAsString (infile);
497
509
if (m_options.input .mode == InputMode::StandardJson)
498
510
{
499
- solAssert (!m_standardJsonInput.has_value (), " " );
511
+ solAssert (!m_standardJsonInput.has_value ());
500
512
m_standardJsonInput = std::move (fileContent);
501
513
}
502
514
else
@@ -510,7 +522,7 @@ void CommandLineInterface::readInputFiles()
510
522
{
511
523
if (m_options.input .mode == InputMode::StandardJson)
512
524
{
513
- solAssert (!m_standardJsonInput.has_value (), " " );
525
+ solAssert (!m_standardJsonInput.has_value ());
514
526
m_standardJsonInput = readUntilEnd (m_sin);
515
527
}
516
528
else
@@ -527,7 +539,7 @@ void CommandLineInterface::readInputFiles()
527
539
528
540
map<string, Json::Value> CommandLineInterface::parseAstFromInput ()
529
541
{
530
- solAssert (m_options.input .mode == InputMode::CompilerWithASTImport, " " );
542
+ solAssert (m_options.input .mode == InputMode::CompilerWithASTImport);
531
543
532
544
map<string, Json::Value> sourceJsons;
533
545
map<string, string> tmpSources;
@@ -559,7 +571,7 @@ void CommandLineInterface::createFile(string const& _fileName, string const& _da
559
571
{
560
572
namespace fs = boost::filesystem;
561
573
562
- solAssert (!m_options.output .dir .empty (), " " );
574
+ solAssert (!m_options.output .dir .empty ());
563
575
564
576
// NOTE: create_directories() raises an exception if the path consists solely of '.' or '..'
565
577
// (or equivalent such as './././.'). Paths like 'a/b/.' and 'a/b/..' are fine though.
@@ -639,7 +651,7 @@ void CommandLineInterface::processInput()
639
651
break ;
640
652
case InputMode::StandardJson:
641
653
{
642
- solAssert (m_standardJsonInput.has_value (), " " );
654
+ solAssert (m_standardJsonInput.has_value ());
643
655
644
656
StandardCompiler compiler (m_fileReader.reader (), m_options.formatting .json );
645
657
sout () << compiler.compile (std::move (m_standardJsonInput.value ())) << endl;
@@ -678,7 +690,7 @@ void CommandLineInterface::printLicense()
678
690
679
691
void CommandLineInterface::compile ()
680
692
{
681
- solAssert (m_options. input . mode == InputMode::Compiler || m_options.input .mode == InputMode::CompilerWithASTImport, " " );
693
+ solAssert (CompilerInputModes. count ( m_options.input .mode ) == 1 );
682
694
683
695
m_compiler = make_unique<CompilerStack>(m_fileReader.reader ());
684
696
@@ -789,7 +801,7 @@ void CommandLineInterface::compile()
789
801
790
802
void CommandLineInterface::handleCombinedJSON ()
791
803
{
792
- solAssert (m_options. input . mode == InputMode::Compiler || m_options.input .mode == InputMode::CompilerWithASTImport, " " );
804
+ solAssert (CompilerInputModes. count ( m_options.input .mode ) == 1 );
793
805
794
806
if (!m_options.compiler .combinedJsonRequests .has_value ())
795
807
return ;
@@ -881,7 +893,7 @@ void CommandLineInterface::handleCombinedJSON()
881
893
882
894
void CommandLineInterface::handleAst ()
883
895
{
884
- solAssert (m_options. input . mode == InputMode::Compiler || m_options.input .mode == InputMode::CompilerWithASTImport, " " );
896
+ solAssert (CompilerInputModes. count ( m_options.input .mode ) == 1 );
885
897
886
898
if (!m_options.compiler .outputs .astCompactJson )
887
899
return ;
@@ -922,7 +934,7 @@ void CommandLineInterface::serveLSP()
922
934
923
935
void CommandLineInterface::link ()
924
936
{
925
- solAssert (m_options.input .mode == InputMode::Linker, " " );
937
+ solAssert (m_options.input .mode == InputMode::Linker);
926
938
927
939
// Map from how the libraries will be named inside the bytecode to their addresses.
928
940
map<string, h160> librariesReplacements;
@@ -985,7 +997,7 @@ void CommandLineInterface::link()
985
997
986
998
void CommandLineInterface::writeLinkedFiles ()
987
999
{
988
- solAssert (m_options.input .mode == InputMode::Linker, " " );
1000
+ solAssert (m_options.input .mode == InputMode::Linker);
989
1001
990
1002
for (auto const & src: m_fileReader.sourceUnits ())
991
1003
if (src.first == g_stdinFileName)
@@ -1019,14 +1031,14 @@ string CommandLineInterface::objectWithLinkRefsHex(evmasm::LinkerObject const& _
1019
1031
1020
1032
void CommandLineInterface::assemble (yul::YulStack::Language _language, yul::YulStack::Machine _targetMachine)
1021
1033
{
1022
- solAssert (m_options.input .mode == InputMode::Assembler, " " );
1034
+ solAssert (m_options.input .mode == InputMode::Assembler);
1023
1035
1024
1036
bool successful = true ;
1025
1037
map<string, yul::YulStack> yulStacks;
1026
1038
for (auto const & src: m_fileReader.sourceUnits ())
1027
1039
{
1028
1040
// --no-optimize-yul option is not accepted in assembly mode.
1029
- solAssert (!m_options.optimizer .noOptimizeYul , " " );
1041
+ solAssert (!m_options.optimizer .noOptimizeYul );
1030
1042
1031
1043
auto & stack = yulStacks[src.first ] = yul::YulStack (
1032
1044
m_options.output .evmVersion ,
@@ -1123,7 +1135,7 @@ void CommandLineInterface::assemble(yul::YulStack::Language _language, yul::YulS
1123
1135
1124
1136
void CommandLineInterface::outputCompilationResults ()
1125
1137
{
1126
- solAssert (m_options. input . mode == InputMode::Compiler || m_options.input .mode == InputMode::CompilerWithASTImport, " " );
1138
+ solAssert (CompilerInputModes. count ( m_options.input .mode ) == 1 );
1127
1139
1128
1140
handleCombinedJSON ();
1129
1141
0 commit comments