Skip to content

Commit

Permalink
CommandLineInterface: Accept the standard input stream as a parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
cameel committed Jul 1, 2021
1 parent a5ea5f0 commit a7cb9a5
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
5 changes: 3 additions & 2 deletions solc/CommandLineInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ ostream& CommandLineInterface::serr(bool _markAsUsed)
return m_serr;
}

#define cin
#define cout
#define cerr

Expand Down Expand Up @@ -414,7 +415,7 @@ bool CommandLineInterface::readInputFilesAndConfigureFileReader()
}

if (m_options.input.addStdin)
m_fileReader.setSource(g_stdinFileName, readUntilEnd(cin));
m_fileReader.setSource(g_stdinFileName, readUntilEnd(m_sin));

if (m_fileReader.sourceCodes().size() == 0)
{
Expand Down Expand Up @@ -512,7 +513,7 @@ bool CommandLineInterface::processInput()
{
string input;
if (m_options.input.standardJsonFile.empty())
input = readUntilEnd(cin);
input = readUntilEnd(m_sin);
else
{
try
Expand Down
3 changes: 3 additions & 0 deletions solc/CommandLineInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,12 @@ class CommandLineInterface
{
public:
explicit CommandLineInterface(
std::istream& _sin,
std::ostream& _sout,
std::ostream& _serr,
CommandLineOptions const& _options = CommandLineOptions{}
):
m_sin(_sin),
m_sout(_sout),
m_serr(_serr),
m_options(_options)
Expand Down Expand Up @@ -121,6 +123,7 @@ class CommandLineInterface
/// stream has ever been used unless @arg _markAsUsed is set to false.
std::ostream& serr(bool _markAsUsed = true);

std::istream& m_sin;
std::ostream& m_sout;
std::ostream& m_serr;
bool m_hasOutput = false;
Expand Down
2 changes: 1 addition & 1 deletion solc/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ static void setDefaultOrCLocale()
int main(int argc, char** argv)
{
setDefaultOrCLocale();
solidity::frontend::CommandLineInterface cli(cout, cerr);
solidity::frontend::CommandLineInterface cli(cin, cout, cerr);
if (!cli.parseArguments(argc, argv))
return 1;
if (!cli.processInput())
Expand Down

0 comments on commit a7cb9a5

Please sign in to comment.