diff options
-rw-r--r-- | test/libjulia/Common.cpp | 87 | ||||
-rw-r--r-- | test/libjulia/Common.h | 54 | ||||
-rw-r--r-- | test/libjulia/Disambiguator.cpp | 86 |
3 files changed, 148 insertions, 79 deletions
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 <http://www.gnu.org/licenses/>. +*/ +/** + * @date 2017 + * Common functions the iulia tests. + */ + +#include <test/libjulia/Common.h> + +#include <libjulia/optimiser/Disambiguator.h> + +#include <libsolidity/parsing/Scanner.h> + +#include <libsolidity/inlineasm/AsmParser.h> +#include <libsolidity/inlineasm/AsmAnalysis.h> +#include <libsolidity/inlineasm/AsmPrinter.h> + +#include <libsolidity/interface/SourceReferenceFormatter.h> +#include <libsolidity/interface/ErrorReporter.h> + +#include <boost/test/unit_test.hpp> + +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<Block>, shared_ptr<assembly::AsmAnalysisInfo>> dev::julia::test::parse(string const& _source, bool _julia) +{ + ErrorList errors; + ErrorReporter errorReporter(errors); + auto scanner = make_shared<Scanner>(CharStream(_source), ""); + auto parserResult = assembly::Parser(errorReporter, true).parse(scanner); + if (parserResult) + { + BOOST_REQUIRE(errorReporter.errors().empty()); + auto analysisInfo = make_shared<assembly::AsmAnalysisInfo>(); + 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<assembly::Block> 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); +} diff --git a/test/libjulia/Common.h b/test/libjulia/Common.h new file mode 100644 index 00000000..55fa03da --- /dev/null +++ b/test/libjulia/Common.h @@ -0,0 +1,54 @@ +/* + 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 <http://www.gnu.org/licenses/>. +*/ +/** + * @date 2017 + * Common functions the iulia tests. + */ + +#pragma once + +#include <libsolidity/inlineasm/AsmData.h> + +#include <string> +#include <vector> +#include <memory> + +namespace dev +{ +namespace solidity +{ +class Scanner; +class Error; +using ErrorList = std::vector<std::shared_ptr<Error const>>; +namespace assembly +{ +struct AsmAnalysisInfo; +} +} +namespace julia +{ +namespace test +{ + +void printErrors(solidity::ErrorList const& _errors, solidity::Scanner const& _scanner); +std::pair<std::shared_ptr<solidity::assembly::Block>, std::shared_ptr<solidity::assembly::AsmAnalysisInfo>> parse(std::string const& _source); +std::shared_ptr<solidity::assembly::Block> disambiguate(std::string const& _source); +std::string format(std::string const& _source); + +} +} +} diff --git a/test/libjulia/Disambiguator.cpp b/test/libjulia/Disambiguator.cpp index baee4641..f5f883ba 100644 --- a/test/libjulia/Disambiguator.cpp +++ b/test/libjulia/Disambiguator.cpp @@ -19,90 +19,23 @@ * Unit tests for the iulia name disambiguator. */ -#include <libsolidity/parsing/Scanner.h> +#include <test/libjulia/Common.h> -#include <libsolidity/inlineasm/AsmParser.h> -#include <libsolidity/inlineasm/AsmAnalysis.h> #include <libsolidity/inlineasm/AsmPrinter.h> -#include <libsolidity/interface/ErrorReporter.h> -#include <libsolidity/interface/SourceReferenceFormatter.h> - -#include <libjulia/optimiser/Disambiguator.h> - #include <boost/test/unit_test.hpp> -#include <string> -#include <memory> - using namespace std; -using namespace dev::solidity::assembly; - -namespace dev -{ -namespace solidity -{ -namespace test -{ - -namespace -{ - -void 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<Block>, shared_ptr<AsmAnalysisInfo>> parse(string const& _source) -{ - ErrorList errors; - ErrorReporter errorReporter(errors); - auto scanner = make_shared<Scanner>(CharStream(_source), ""); - auto parserResult = assembly::Parser(errorReporter, true).parse(scanner); - if (parserResult) - { - BOOST_REQUIRE(errorReporter.errors().empty()); - auto analysisInfo = make_shared<assembly::AsmAnalysisInfo>(); - 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 {}; -} - -string disambiguate(string const& _source) -{ - auto result = parse(_source); - julia::Disambiguator disambiguator(*result.first, *result.second); - return assembly::AsmPrinter(true)(*disambiguator.run()); -} - -string format(string const& _source) -{ - return assembly::AsmPrinter(true)(*parse(_source).first); -} - -} +using namespace dev::julia::test; +using namespace dev::solidity; #define CHECK(_original, _expectation)\ do\ {\ - BOOST_CHECK_EQUAL(disambiguate(_original), format(_expectation));\ - BOOST_CHECK_EQUAL(disambiguate(_original), disambiguate(disambiguate(_original)));\ + assembly::AsmPrinter p(true);\ + string result = p(*disambiguate(_original));\ + BOOST_CHECK_EQUAL(result, format(_expectation));\ + BOOST_CHECK_EQUAL(result, p(*disambiguate(result)));\ }\ while(false) @@ -170,8 +103,3 @@ BOOST_AUTO_TEST_CASE(if_statement) } BOOST_AUTO_TEST_SUITE_END() - - -} -} -} // end namespaces |