aboutsummaryrefslogtreecommitdiffstats
path: root/test/libjulia/Common.cpp
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2017-11-23 22:35:14 +0800
committerchriseth <chris@ethereum.org>2017-12-05 19:09:55 +0800
commitcba58629d24404ed7553d16bb2ad064f95f9fe37 (patch)
tree8e6f258bf2956b668084261b4e3d01ed502eab87 /test/libjulia/Common.cpp
parent861210f543cea615d7779fb7b1bc133349ae971a (diff)
downloaddexon-solidity-cba58629d24404ed7553d16bb2ad064f95f9fe37.tar.gz
dexon-solidity-cba58629d24404ed7553d16bb2ad064f95f9fe37.tar.zst
dexon-solidity-cba58629d24404ed7553d16bb2ad064f95f9fe37.zip
Refactor iulia tests.
Diffstat (limited to 'test/libjulia/Common.cpp')
-rw-r--r--test/libjulia/Common.cpp87
1 files changed, 87 insertions, 0 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);
+}