CommandLineInterface: Merge processInput() and actOnInput()

- The distinction between them is not as clear-cut as it should be. For example processInput() prints output in assembly mode.
This commit is contained in:
Kamil Śliwak 2021-10-11 13:17:01 +02:00
parent 93c1fe6878
commit a1c9c1e2b5
4 changed files with 21 additions and 40 deletions

View File

@ -610,10 +610,10 @@ bool CommandLineInterface::processInput()
return false;
case InputMode::License:
printLicense();
return true;
break;
case InputMode::Version:
printVersion();
return true;
break;
case InputMode::StandardJson:
{
solAssert(m_standardJsonInput.has_value(), "");
@ -621,21 +621,25 @@ bool CommandLineInterface::processInput()
StandardCompiler compiler(m_fileReader.reader(), m_options.formatting.json);
sout() << compiler.compile(move(m_standardJsonInput.value())) << endl;
m_standardJsonInput.reset();
return true;
break;
}
case InputMode::Assembler:
{
return assemble(m_options.assembly.inputLanguage, m_options.assembly.targetMachine);
}
if (!assemble(m_options.assembly.inputLanguage, m_options.assembly.targetMachine))
return false;
break;
case InputMode::Linker:
return link();
if (!link())
return false;
writeLinkedFiles();
break;
case InputMode::Compiler:
case InputMode::CompilerWithASTImport:
return compile();
if (!compile())
return false;
outputCompilationResults();
}
solAssert(false, "");
return false;
return !m_outputFailed;
}
void CommandLineInterface::printVersion()
@ -883,29 +887,6 @@ void CommandLineInterface::handleAst()
}
}
bool CommandLineInterface::actOnInput()
{
switch (m_options.input.mode)
{
case InputMode::Help:
case InputMode::License:
case InputMode::Version:
case InputMode::StandardJson:
case InputMode::Assembler:
// Already done in "processInput" phase.
break;
case InputMode::Linker:
writeLinkedFiles();
break;
case InputMode::Compiler:
case InputMode::CompilerWithASTImport:
outputCompilationResults();
break;
}
return !m_outputFailed;
}
bool CommandLineInterface::link()
{
solAssert(m_options.input.mode == InputMode::Linker, "");

View File

@ -55,11 +55,8 @@ public:
bool parseArguments(int _argc, char const* const* _argv);
/// Read the content of all input files and initialize the file reader.
bool readInputFiles();
/// Parse the files and create source code objects
/// Parse the files, create source code objects, print the output.
bool processInput();
/// Perform actions on the input depending on provided compiler arguments
/// @returns true on success.
bool actOnInput();
CommandLineOptions const& options() const { return m_options; }
FileReader const& fileReader() const { return m_fileReader; }

View File

@ -65,8 +65,7 @@ int main(int argc, char** argv)
bool success =
cli.parseArguments(argc, argv) &&
cli.readInputFiles() &&
cli.processInput() &&
cli.actOnInput();
cli.processInput();
return success ? 0 : 1;
}

View File

@ -70,6 +70,10 @@ string test::stripPreReleaseWarning(string const& _stderrContent)
R"(Warning( \(3805\))?: This is a pre-release compiler version, please do not use it in production\.\n)"
R"((\n)?)"
};
static regex const noOutputRegex{
R"(Compiler run successful, no output requested\.\n)"
};
return regex_replace(_stderrContent, preReleaseWarningRegex, "");
string output = regex_replace(_stderrContent, preReleaseWarningRegex, "");
return regex_replace(move(output), noOutputRegex, "");
}