mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
[test] AnalysisFramework's instance of CompilerStack to be lazily instanciated.
This commit is contained in:
parent
94053c9a52
commit
862d798047
@ -47,21 +47,21 @@ AnalysisFramework::parseAnalyseAndReturnError(
|
|||||||
bool _allowMultipleErrors
|
bool _allowMultipleErrors
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
m_compiler.reset();
|
compiler().reset();
|
||||||
m_compiler.setSources({{"", _insertVersionPragma ? "pragma solidity >=0.0;\n" + _source : _source}});
|
compiler().setSources({{"", _insertVersionPragma ? "pragma solidity >=0.0;\n" + _source : _source}});
|
||||||
m_compiler.setEVMVersion(dev::test::Options::get().evmVersion());
|
compiler().setEVMVersion(dev::test::Options::get().evmVersion());
|
||||||
if (!m_compiler.parse())
|
if (!compiler().parse())
|
||||||
{
|
{
|
||||||
BOOST_FAIL("Parsing contract failed in analysis test suite:" + formatErrors());
|
BOOST_FAIL("Parsing contract failed in analysis test suite:" + formatErrors());
|
||||||
}
|
}
|
||||||
|
|
||||||
m_compiler.analyze();
|
compiler().analyze();
|
||||||
|
|
||||||
ErrorList errors = filterErrors(m_compiler.errors(), _reportWarnings);
|
ErrorList errors = filterErrors(compiler().errors(), _reportWarnings);
|
||||||
if (errors.size() > 1 && !_allowMultipleErrors)
|
if (errors.size() > 1 && !_allowMultipleErrors)
|
||||||
BOOST_FAIL("Multiple errors found: " + formatErrors());
|
BOOST_FAIL("Multiple errors found: " + formatErrors());
|
||||||
|
|
||||||
return make_pair(&m_compiler.ast(""), std::move(errors));
|
return make_pair(&compiler().ast(""), std::move(errors));
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorList AnalysisFramework::filterErrors(ErrorList const& _errorList, bool _includeWarnings) const
|
ErrorList AnalysisFramework::filterErrors(ErrorList const& _errorList, bool _includeWarnings) const
|
||||||
@ -118,7 +118,7 @@ ErrorList AnalysisFramework::expectError(std::string const& _source, bool _warni
|
|||||||
string AnalysisFramework::formatErrors() const
|
string AnalysisFramework::formatErrors() const
|
||||||
{
|
{
|
||||||
string message;
|
string message;
|
||||||
for (auto const& error: m_compiler.errors())
|
for (auto const& error: compiler().errors())
|
||||||
message += formatError(*error);
|
message += formatError(*error);
|
||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
|
@ -71,7 +71,25 @@ protected:
|
|||||||
langutil::ErrorList filterErrors(langutil::ErrorList const& _errorList, bool _includeWarnings) const;
|
langutil::ErrorList filterErrors(langutil::ErrorList const& _errorList, bool _includeWarnings) const;
|
||||||
|
|
||||||
std::vector<std::string> m_warningsToFilter = {"This is a pre-release compiler version"};
|
std::vector<std::string> m_warningsToFilter = {"This is a pre-release compiler version"};
|
||||||
dev::solidity::CompilerStack m_compiler;
|
|
||||||
|
/// @returns reference to lazy-instanciated CompilerStack.
|
||||||
|
dev::solidity::CompilerStack& compiler()
|
||||||
|
{
|
||||||
|
if (!m_compiler)
|
||||||
|
m_compiler = std::make_unique<dev::solidity::CompilerStack>();
|
||||||
|
return *m_compiler;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// @returns reference to lazy-instanciated CompilerStack.
|
||||||
|
dev::solidity::CompilerStack const& compiler() const
|
||||||
|
{
|
||||||
|
if (!m_compiler)
|
||||||
|
m_compiler = std::make_unique<dev::solidity::CompilerStack>();
|
||||||
|
return *m_compiler;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
mutable std::unique_ptr<dev::solidity::CompilerStack> m_compiler;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Asserts that the compilation down to typechecking
|
// Asserts that the compilation down to typechecking
|
||||||
|
@ -42,11 +42,11 @@ BOOST_AUTO_TEST_CASE(does_not_include_creation_time_only_internal_functions)
|
|||||||
function f() internal { for (uint i = 0; i < 10; ++i) x += 3 + i; }
|
function f() internal { for (uint i = 0; i < 10; ++i) x += 3 + i; }
|
||||||
}
|
}
|
||||||
)";
|
)";
|
||||||
m_compiler.setOptimiserSettings(dev::test::Options::get().optimize);
|
compiler().setOptimiserSettings(dev::test::Options::get().optimize);
|
||||||
BOOST_REQUIRE(success(sourceCode));
|
BOOST_REQUIRE(success(sourceCode));
|
||||||
BOOST_REQUIRE_MESSAGE(m_compiler.compile(), "Compiling contract failed");
|
BOOST_REQUIRE_MESSAGE(compiler().compile(), "Compiling contract failed");
|
||||||
bytes const& creationBytecode = dev::test::bytecodeSansMetadata(m_compiler.object("C").bytecode);
|
bytes const& creationBytecode = dev::test::bytecodeSansMetadata(compiler().object("C").bytecode);
|
||||||
bytes const& runtimeBytecode = dev::test::bytecodeSansMetadata(m_compiler.runtimeObject("C").bytecode);
|
bytes const& runtimeBytecode = dev::test::bytecodeSansMetadata(compiler().runtimeObject("C").bytecode);
|
||||||
BOOST_CHECK(creationBytecode.size() >= 90);
|
BOOST_CHECK(creationBytecode.size() >= 90);
|
||||||
BOOST_CHECK(creationBytecode.size() <= 120);
|
BOOST_CHECK(creationBytecode.size() <= 120);
|
||||||
BOOST_CHECK(runtimeBytecode.size() >= 10);
|
BOOST_CHECK(runtimeBytecode.size() >= 10);
|
||||||
|
@ -436,7 +436,7 @@ BOOST_AUTO_TEST_CASE(getter_is_memory_type)
|
|||||||
)";
|
)";
|
||||||
CHECK_SUCCESS_NO_WARNINGS(text);
|
CHECK_SUCCESS_NO_WARNINGS(text);
|
||||||
// Check that the getters return a memory strings, not a storage strings.
|
// Check that the getters return a memory strings, not a storage strings.
|
||||||
ContractDefinition const& c = dynamic_cast<ContractDefinition const&>(*m_compiler.ast("").nodes().at(1));
|
ContractDefinition const& c = dynamic_cast<ContractDefinition const&>(*compiler().ast("").nodes().at(1));
|
||||||
BOOST_CHECK(c.interfaceFunctions().size() == 2);
|
BOOST_CHECK(c.interfaceFunctions().size() == 2);
|
||||||
for (auto const& f: c.interfaceFunctions())
|
for (auto const& f: c.interfaceFunctions())
|
||||||
{
|
{
|
||||||
|
@ -66,14 +66,14 @@ SyntaxTest::SyntaxTest(string const& _filename, langutil::EVMVersion _evmVersion
|
|||||||
bool SyntaxTest::run(ostream& _stream, string const& _linePrefix, bool _formatted)
|
bool SyntaxTest::run(ostream& _stream, string const& _linePrefix, bool _formatted)
|
||||||
{
|
{
|
||||||
string const versionPragma = "pragma solidity >=0.0;\n";
|
string const versionPragma = "pragma solidity >=0.0;\n";
|
||||||
m_compiler.reset();
|
compiler().reset();
|
||||||
m_compiler.setSources({{"", versionPragma + m_source}});
|
compiler().setSources({{"", versionPragma + m_source}});
|
||||||
m_compiler.setEVMVersion(m_evmVersion);
|
compiler().setEVMVersion(m_evmVersion);
|
||||||
|
|
||||||
if (m_compiler.parse())
|
if (compiler().parse())
|
||||||
m_compiler.analyze();
|
compiler().analyze();
|
||||||
|
|
||||||
for (auto const& currentError: filterErrors(m_compiler.errors(), true))
|
for (auto const& currentError: filterErrors(compiler().errors(), true))
|
||||||
{
|
{
|
||||||
int locationStart = -1, locationEnd = -1;
|
int locationStart = -1, locationEnd = -1;
|
||||||
if (auto location = boost::get_error_info<errinfo_sourceLocation>(*currentError))
|
if (auto location = boost::get_error_info<errinfo_sourceLocation>(*currentError))
|
||||||
|
Loading…
Reference in New Issue
Block a user