Browse Source

Merge pull request #887 from chriseth/sol_excludeStd

Exclude standard contracts by default.
cl-refactor
chriseth 10 years ago
parent
commit
da414f8d82
  1. 2
      libsolidity/CompilerStack.h
  2. 41
      solc/CommandLineInterface.cpp
  3. 6
      solc/CommandLineInterface.h
  4. 1
      test/SolidityEndToEndTest.cpp
  5. 4
      test/solidityExecutionFramework.h

2
libsolidity/CompilerStack.h

@ -60,7 +60,7 @@ class CompilerStack: boost::noncopyable
{
public:
/// Creates a new compiler stack. Adds standard sources if @a _addStandardSources.
explicit CompilerStack(bool _addStandardSources = true);
explicit CompilerStack(bool _addStandardSources = false);
/// Adds a source object (e.g. file) to the parser. After this, parse has to be called again.
/// @returns true if a source object by the name already existed and was replaced.

41
solc/CommandLineInterface.cpp

@ -61,6 +61,7 @@ static string const g_argBinaryStr = "binary";
static string const g_argOpcodesStr = "opcodes";
static string const g_argNatspecDevStr = "natspec-dev";
static string const g_argNatspecUserStr = "natspec-user";
static string const g_argAddStandard = "add-std";
static void version()
{
@ -116,13 +117,13 @@ void CommandLineInterface::handleBinary(string const& _contract)
if (outputToStdout(choice))
{
cout << "Binary: " << endl;
cout << toHex(m_compiler.getBytecode(_contract)) << endl;
cout << toHex(m_compiler->getBytecode(_contract)) << endl;
}
if (outputToFile(choice))
{
ofstream outFile(_contract + ".binary");
outFile << toHex(m_compiler.getBytecode(_contract));
outFile << toHex(m_compiler->getBytecode(_contract));
outFile.close();
}
}
@ -133,14 +134,14 @@ void CommandLineInterface::handleOpcode(string const& _contract)
if (outputToStdout(choice))
{
cout << "Opcodes: " << endl;
cout << eth::disassemble(m_compiler.getBytecode(_contract));
cout << eth::disassemble(m_compiler->getBytecode(_contract));
cout << endl;
}
if (outputToFile(choice))
{
ofstream outFile(_contract + ".opcode");
outFile << eth::disassemble(m_compiler.getBytecode(_contract));
outFile << eth::disassemble(m_compiler->getBytecode(_contract));
outFile.close();
}
}
@ -191,13 +192,13 @@ void CommandLineInterface::handleMeta(DocumentationType _type, string const& _co
if (outputToStdout(choice))
{
cout << title << endl;
cout << m_compiler.getMetadata(_contract, _type) << endl;
cout << m_compiler->getMetadata(_contract, _type) << endl;
}
if (outputToFile(choice))
{
ofstream outFile(_contract + suffix);
outFile << m_compiler.getMetadata(_contract, _type);
outFile << m_compiler->getMetadata(_contract, _type);
outFile.close();
}
}
@ -211,6 +212,7 @@ bool CommandLineInterface::parseArguments(int argc, char** argv)
("help", "Show help message and exit")
("version", "Show version and exit")
("optimize", po::value<bool>()->default_value(false), "Optimize bytecode for size")
("add-std", po::value<bool>()->default_value(false), "Add standard contracts")
("input-file", po::value<vector<string>>(), "input file")
(g_argAstStr.c_str(), po::value<OutputType>()->value_name("stdout|file|both"),
"Request to output the AST of the contract.")
@ -292,31 +294,32 @@ bool CommandLineInterface::processInput()
m_sourceCodes[infile] = asString(dev::contents(infile));
}
m_compiler.reset(new CompilerStack(m_args["add-std"].as<bool>()));
try
{
for (auto const& sourceCode: m_sourceCodes)
m_compiler.addSource(sourceCode.first, sourceCode.second);
m_compiler->addSource(sourceCode.first, sourceCode.second);
// TODO: Perhaps we should not compile unless requested
m_compiler.compile(m_args["optimize"].as<bool>());
m_compiler->compile(m_args["optimize"].as<bool>());
}
catch (ParserError const& _exception)
{
SourceReferenceFormatter::printExceptionInformation(cerr, _exception, "Parser error", m_compiler);
SourceReferenceFormatter::printExceptionInformation(cerr, _exception, "Parser error", *m_compiler);
return false;
}
catch (DeclarationError const& _exception)
{
SourceReferenceFormatter::printExceptionInformation(cerr, _exception, "Declaration error", m_compiler);
SourceReferenceFormatter::printExceptionInformation(cerr, _exception, "Declaration error", *m_compiler);
return false;
}
catch (TypeError const& _exception)
{
SourceReferenceFormatter::printExceptionInformation(cerr, _exception, "Type error", m_compiler);
SourceReferenceFormatter::printExceptionInformation(cerr, _exception, "Type error", *m_compiler);
return false;
}
catch (CompilerError const& _exception)
{
SourceReferenceFormatter::printExceptionInformation(cerr, _exception, "Compiler error", m_compiler);
SourceReferenceFormatter::printExceptionInformation(cerr, _exception, "Compiler error", *m_compiler);
return false;
}
catch (InternalCompilerError const& _exception)
@ -369,12 +372,12 @@ void CommandLineInterface::handleAst(string const& _argStr)
cout << endl << "======= " << sourceCode.first << " =======" << endl;
if (_argStr == g_argAstStr)
{
ASTPrinter printer(m_compiler.getAST(sourceCode.first), sourceCode.second);
ASTPrinter printer(m_compiler->getAST(sourceCode.first), sourceCode.second);
printer.print(cout);
}
else
{
ASTJsonConverter converter(m_compiler.getAST(sourceCode.first));
ASTJsonConverter converter(m_compiler->getAST(sourceCode.first));
converter.print(cout);
}
}
@ -388,12 +391,12 @@ void CommandLineInterface::handleAst(string const& _argStr)
ofstream outFile(p.stem().string() + ".ast");
if (_argStr == g_argAstStr)
{
ASTPrinter printer(m_compiler.getAST(sourceCode.first), sourceCode.second);
ASTPrinter printer(m_compiler->getAST(sourceCode.first), sourceCode.second);
printer.print(outFile);
}
else
{
ASTJsonConverter converter(m_compiler.getAST(sourceCode.first));
ASTJsonConverter converter(m_compiler->getAST(sourceCode.first));
converter.print(outFile);
}
outFile.close();
@ -408,7 +411,7 @@ void CommandLineInterface::actOnInput()
handleAst(g_argAstStr);
handleAst(g_argAstJson);
vector<string> contracts = m_compiler.getContractNames();
vector<string> contracts = m_compiler->getContractNames();
for (string const& contract: contracts)
{
if (needStdout(m_args))
@ -421,13 +424,13 @@ void CommandLineInterface::actOnInput()
if (outputToStdout(choice))
{
cout << "EVM assembly:" << endl;
m_compiler.streamAssembly(cout, contract);
m_compiler->streamAssembly(cout, contract);
}
if (outputToFile(choice))
{
ofstream outFile(contract + ".evm");
m_compiler.streamAssembly(outFile, contract);
m_compiler->streamAssembly(outFile, contract);
outFile.close();
}
}

6
solc/CommandLineInterface.h

@ -21,9 +21,9 @@
*/
#pragma once
#include <boost/program_options.hpp>
#include <libsolidity/CompilerStack.h>
#include <memory>
#include <boost/program_options.hpp>
namespace dev
{
@ -65,7 +65,7 @@ private:
/// map of input files to source code strings
std::map<std::string, std::string> m_sourceCodes;
/// Solidity compiler stack
dev::solidity::CompilerStack m_compiler;
std::unique_ptr<dev::solidity::CompilerStack> m_compiler;
};
}

1
test/SolidityEndToEndTest.cpp

@ -1905,6 +1905,7 @@ BOOST_AUTO_TEST_CASE(use_std_lib)
import "mortal";
contract Icarus is mortal { }
)";
m_addStandardSources = true;
u256 amount(130);
u160 address(23);
compileAndRun(sourceCode, amount, "Icarus");

4
test/solidityExecutionFramework.h

@ -45,8 +45,7 @@ public:
bytes const& compileAndRun(std::string const& _sourceCode, u256 const& _value = 0, std::string const& _contractName = "")
{
// add standard sources only if contract name is given
dev::solidity::CompilerStack compiler(!_contractName.empty());
dev::solidity::CompilerStack compiler(m_addStandardSources);
try
{
compiler.addSource("", _sourceCode);
@ -175,6 +174,7 @@ private:
protected:
bool m_optimize = false;
bool m_addStandardSources = false;
Address m_sender;
Address m_contractAddress;
eth::State m_state;

Loading…
Cancel
Save