From cba58629d24404ed7553d16bb2ad064f95f9fe37 Mon Sep 17 00:00:00 2001 From: chriseth Date: Thu, 23 Nov 2017 15:35:14 +0100 Subject: Refactor iulia tests. --- test/libjulia/Common.cpp | 87 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 test/libjulia/Common.cpp (limited to 'test/libjulia/Common.cpp') diff --git a/test/libjulia/Common.cpp b/test/libjulia/Common.cpp new file mode 100644 index 00000000..30bb22ea --- /dev/null +++ b/test/libjulia/Common.cpp @@ -0,0 +1,87 @@ +/* + This file is part of solidity. + + solidity is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + solidity is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with solidity. If not, see . +*/ +/** + * @date 2017 + * Common functions the iulia tests. + */ + +#include + +#include + +#include + +#include +#include +#include + +#include +#include + +#include + +using namespace std; +using namespace dev::julia; +using namespace dev::solidity; + +void dev::julia::test::printErrors(ErrorList const& _errors, Scanner const& _scanner) +{ + for (auto const& error: _errors) + SourceReferenceFormatter::printExceptionInformation( + cout, + *error, + (error->type() == Error::Type::Warning) ? "Warning" : "Error", + [&](std::string const&) -> Scanner const& { return _scanner; } + ); +} + + +pair, shared_ptr> dev::julia::test::parse(string const& _source, bool _julia) +{ + ErrorList errors; + ErrorReporter errorReporter(errors); + auto scanner = make_shared(CharStream(_source), ""); + auto parserResult = assembly::Parser(errorReporter, true).parse(scanner); + if (parserResult) + { + BOOST_REQUIRE(errorReporter.errors().empty()); + auto analysisInfo = make_shared(); + assembly::AsmAnalyzer analyzer(*analysisInfo, errorReporter, true); + if (analyzer.analyze(*parserResult)) + { + BOOST_REQUIRE(errorReporter.errors().empty()); + return make_pair(parserResult, analysisInfo); + } + } + printErrors(errors, *scanner); + BOOST_FAIL("Invalid source."); + + // Unreachable. + return {}; +} + +shared_ptr dev::julia::test::disambiguate(string const& _source) +{ + auto result = parse(_source); + Disambiguator disambiguator(*result.first, *result.second); + return disambiguator.run(); +} + +string dev::julia::test::format(string const& _source) +{ + return assembly::AsmPrinter(_julia)(*parse(_source, _julia).first); +} -- cgit v1.2.3 From 30d7afc2e3fd27333e463a9127011ec1f7470d3e Mon Sep 17 00:00:00 2001 From: chriseth Date: Tue, 28 Nov 2017 15:00:23 +0100 Subject: Simplify disambiguator. --- test/libjulia/Common.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'test/libjulia/Common.cpp') diff --git a/test/libjulia/Common.cpp b/test/libjulia/Common.cpp index 30bb22ea..da1538f3 100644 --- a/test/libjulia/Common.cpp +++ b/test/libjulia/Common.cpp @@ -55,12 +55,12 @@ pair, shared_ptr> dev::julia::test: ErrorList errors; ErrorReporter errorReporter(errors); auto scanner = make_shared(CharStream(_source), ""); - auto parserResult = assembly::Parser(errorReporter, true).parse(scanner); + auto parserResult = assembly::Parser(errorReporter, _julia).parse(scanner); if (parserResult) { BOOST_REQUIRE(errorReporter.errors().empty()); auto analysisInfo = make_shared(); - assembly::AsmAnalyzer analyzer(*analysisInfo, errorReporter, true); + assembly::AsmAnalyzer analyzer(*analysisInfo, errorReporter, _julia); if (analyzer.analyze(*parserResult)) { BOOST_REQUIRE(errorReporter.errors().empty()); @@ -74,14 +74,13 @@ pair, shared_ptr> dev::julia::test: return {}; } -shared_ptr dev::julia::test::disambiguate(string const& _source) +assembly::Block dev::julia::test::disambiguate(string const& _source, bool _julia) { - auto result = parse(_source); - Disambiguator disambiguator(*result.first, *result.second); - return disambiguator.run(); + auto result = parse(_source, _julia); + return boost::get(Disambiguator(*result.second)(*result.first)); } -string dev::julia::test::format(string const& _source) +string dev::julia::test::format(string const& _source, bool _julia) { return assembly::AsmPrinter(_julia)(*parse(_source, _julia).first); } -- cgit v1.2.3 From 124190336b0a70ea32d5f8ca0c4b364f1fc774d0 Mon Sep 17 00:00:00 2001 From: chriseth Date: Wed, 13 Dec 2017 14:40:54 +0100 Subject: Split inline assembly into loose and strict flavours. --- test/libjulia/Common.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'test/libjulia/Common.cpp') diff --git a/test/libjulia/Common.cpp b/test/libjulia/Common.cpp index da1538f3..e1ab8215 100644 --- a/test/libjulia/Common.cpp +++ b/test/libjulia/Common.cpp @@ -52,15 +52,16 @@ void dev::julia::test::printErrors(ErrorList const& _errors, Scanner const& _sca pair, shared_ptr> dev::julia::test::parse(string const& _source, bool _julia) { + auto flavour = _julia ? assembly::AsmFlavour::IULIA : assembly::AsmFlavour::Strict; ErrorList errors; ErrorReporter errorReporter(errors); auto scanner = make_shared(CharStream(_source), ""); - auto parserResult = assembly::Parser(errorReporter, _julia).parse(scanner); + auto parserResult = assembly::Parser(errorReporter, flavour).parse(scanner); if (parserResult) { BOOST_REQUIRE(errorReporter.errors().empty()); auto analysisInfo = make_shared(); - assembly::AsmAnalyzer analyzer(*analysisInfo, errorReporter, _julia); + assembly::AsmAnalyzer analyzer(*analysisInfo, errorReporter, flavour); if (analyzer.analyze(*parserResult)) { BOOST_REQUIRE(errorReporter.errors().empty()); -- cgit v1.2.3