diff options
author | chriseth <c@ethdev.com> | 2015-04-21 17:45:33 +0800 |
---|---|---|
committer | chriseth <c@ethdev.com> | 2015-04-21 17:46:11 +0800 |
commit | 02121683f5f43cb3c547521fb4a2642f637f246f (patch) | |
tree | e7bbfb580082eac8b606b29e13444f00f80f0273 /libsolidity | |
parent | e375612a7ecbab9ad33a6a40df1c722a82e07630 (diff) | |
download | dexon-solidity-02121683f5f43cb3c547521fb4a2642f637f246f.tar.gz dexon-solidity-02121683f5f43cb3c547521fb4a2642f637f246f.tar.zst dexon-solidity-02121683f5f43cb3c547521fb4a2642f637f246f.zip |
Removed (and added) some #ifs (but removed more than I added).
Diffstat (limited to 'libsolidity')
-rw-r--r-- | libsolidity/Assembly.cpp | 120 | ||||
-rw-r--r-- | libsolidity/SolidityABIJSON.cpp | 3 | ||||
-rw-r--r-- | libsolidity/SolidityCompiler.cpp | 4 | ||||
-rw-r--r-- | libsolidity/SolidityEndToEndTest.cpp | 4 | ||||
-rw-r--r-- | libsolidity/SolidityExpressionCompiler.cpp | 4 | ||||
-rw-r--r-- | libsolidity/SolidityInterface.cpp | 4 | ||||
-rw-r--r-- | libsolidity/SolidityNameAndTypeResolution.cpp | 4 | ||||
-rw-r--r-- | libsolidity/SolidityNatspecJSON.cpp | 4 | ||||
-rw-r--r-- | libsolidity/SolidityOptimizer.cpp | 4 | ||||
-rw-r--r-- | libsolidity/SolidityParser.cpp | 4 | ||||
-rw-r--r-- | libsolidity/SolidityScanner.cpp | 4 | ||||
-rw-r--r-- | libsolidity/SolidityTypes.cpp | 4 |
12 files changed, 120 insertions, 43 deletions
diff --git a/libsolidity/Assembly.cpp b/libsolidity/Assembly.cpp new file mode 100644 index 00000000..8dcee7fb --- /dev/null +++ b/libsolidity/Assembly.cpp @@ -0,0 +1,120 @@ +/* + This file is part of cpp-ethereum. + + cpp-ethereum 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. + + cpp-ethereum 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 cpp-ethereum. If not, see <http://www.gnu.org/licenses/>. +*/ +/** + * @author Lefteris Karapetsas <lefteris@ethdev.com> + * @date 2015 + * Unit tests for Assembly Items from evmcore/Assembly.h + */ + +#include <string> +#include <iostream> +#include <boost/test/unit_test.hpp> +#include <libdevcore/Log.h> +#include <libevmcore/SourceLocation.h> +#include <libsolidity/Scanner.h> +#include <libsolidity/Parser.h> +#include <libsolidity/NameAndTypeResolver.h> +#include <libsolidity/Compiler.h> +#include <libsolidity/AST.h> +#include <libevmcore/Assembly.h> + +using namespace std; +using namespace dev::eth; + +namespace dev +{ +namespace solidity +{ +namespace test +{ + +namespace +{ + +eth::AssemblyItems compileContract(const string& _sourceCode) +{ + Parser parser; + ASTPointer<SourceUnit> sourceUnit; + BOOST_REQUIRE_NO_THROW(sourceUnit = parser.parse(make_shared<Scanner>(CharStream(_sourceCode)))); + NameAndTypeResolver resolver({}); + resolver.registerDeclarations(*sourceUnit); + for (ASTPointer<ASTNode> const& node: sourceUnit->getNodes()) + if (ContractDefinition* contract = dynamic_cast<ContractDefinition*>(node.get())) + { + BOOST_REQUIRE_NO_THROW(resolver.resolveNamesAndTypes(*contract)); + } + for (ASTPointer<ASTNode> const& node: sourceUnit->getNodes()) + if (ContractDefinition* contract = dynamic_cast<ContractDefinition*>(node.get())) + { + BOOST_REQUIRE_NO_THROW(resolver.checkTypeRequirements(*contract)); + } + for (ASTPointer<ASTNode> const& node: sourceUnit->getNodes()) + if (ContractDefinition* contract = dynamic_cast<ContractDefinition*>(node.get())) + { + Compiler compiler; + compiler.compileContract(*contract, map<ContractDefinition const*, bytes const*>{}); + + return compiler.getRuntimeAssemblyItems(); + } + BOOST_FAIL("No contract found in source."); + return AssemblyItems(); +} + +void checkAssemblyLocations(AssemblyItems const& _items, vector<SourceLocation> const& _locations) +{ + BOOST_CHECK_EQUAL(_items.size(), _locations.size()); + for (size_t i = 0; i < min(_items.size(), _locations.size()); ++i) + { + BOOST_CHECK_MESSAGE( + _items[i].getLocation() == _locations[i], + "Location mismatch for assembly item " + to_string(i) + ". Found: " + + to_string(_items[i].getLocation().start) + "-" + + to_string(_items[i].getLocation().end) + ", expected: " + + to_string(_locations[i].start) + "-" + + to_string(_locations[i].end)); + } +} + +} // end anonymous namespace + +BOOST_AUTO_TEST_SUITE(Assembly) + +BOOST_AUTO_TEST_CASE(location_test) +{ + char const* sourceCode = R"( + contract test { + function f() returns (uint256 a) { + return 16; + } + } + )"; + shared_ptr<string const> n = make_shared<string>("source"); + AssemblyItems items = compileContract(sourceCode); + vector<SourceLocation> locations = + vector<SourceLocation>(11, SourceLocation(2, 75, n)) + + vector<SourceLocation>(12, SourceLocation(20, 72, n)) + + vector<SourceLocation>{SourceLocation(42, 51, n), SourceLocation(65, 67, n)} + + vector<SourceLocation>(4, SourceLocation(58, 67, n)) + + vector<SourceLocation>(3, SourceLocation(20, 72, n)); + checkAssemblyLocations(items, locations); +} + +BOOST_AUTO_TEST_SUITE_END() + +} +} +} // end namespaces diff --git a/libsolidity/SolidityABIJSON.cpp b/libsolidity/SolidityABIJSON.cpp index b0633cca..f0e54a94 100644 --- a/libsolidity/SolidityABIJSON.cpp +++ b/libsolidity/SolidityABIJSON.cpp @@ -19,7 +19,6 @@ * @date 2014 * Unit tests for the solidity compiler JSON Interface output. */ -#if ETH_SOLIDITY #include "../TestHelper.h" #include <libsolidity/CompilerStack.h> @@ -501,5 +500,3 @@ BOOST_AUTO_TEST_SUITE_END() } } } - -#endif diff --git a/libsolidity/SolidityCompiler.cpp b/libsolidity/SolidityCompiler.cpp index bb16c88c..7b0ceedb 100644 --- a/libsolidity/SolidityCompiler.cpp +++ b/libsolidity/SolidityCompiler.cpp @@ -20,8 +20,6 @@ * Unit tests for the solidity compiler. */ -#if ETH_SOLIDITY - #include <string> #include <iostream> #include <boost/test/unit_test.hpp> @@ -193,5 +191,3 @@ BOOST_AUTO_TEST_SUITE_END() } } } // end namespaces - -#endif diff --git a/libsolidity/SolidityEndToEndTest.cpp b/libsolidity/SolidityEndToEndTest.cpp index c345f520..db58c344 100644 --- a/libsolidity/SolidityEndToEndTest.cpp +++ b/libsolidity/SolidityEndToEndTest.cpp @@ -21,8 +21,6 @@ * Unit tests for the solidity expression compiler, testing the behaviour of the code. */ -#if ETH_SOLIDITY - #include <string> #include <tuple> #include <boost/test/unit_test.hpp> @@ -3704,5 +3702,3 @@ BOOST_AUTO_TEST_SUITE_END() } } } // end namespaces - -#endif diff --git a/libsolidity/SolidityExpressionCompiler.cpp b/libsolidity/SolidityExpressionCompiler.cpp index 505cac99..613b0b1f 100644 --- a/libsolidity/SolidityExpressionCompiler.cpp +++ b/libsolidity/SolidityExpressionCompiler.cpp @@ -20,8 +20,6 @@ * Unit tests for the solidity expression compiler. */ -#if ETH_SOLIDITY - #include <string> #include <libdevcore/Log.h> @@ -491,5 +489,3 @@ BOOST_AUTO_TEST_SUITE_END() } } } // end namespaces - -#endif diff --git a/libsolidity/SolidityInterface.cpp b/libsolidity/SolidityInterface.cpp index ab6cb902..c8f74e3a 100644 --- a/libsolidity/SolidityInterface.cpp +++ b/libsolidity/SolidityInterface.cpp @@ -20,8 +20,6 @@ * Unit tests for generating source interfaces for Solidity contracts. */ -#if ETH_SOLIDITY - #include "../TestHelper.h" #include <libsolidity/CompilerStack.h> #include <libsolidity/AST.h> @@ -149,5 +147,3 @@ BOOST_AUTO_TEST_SUITE_END() } } } - -#endif diff --git a/libsolidity/SolidityNameAndTypeResolution.cpp b/libsolidity/SolidityNameAndTypeResolution.cpp index 917ea000..076ea595 100644 --- a/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/libsolidity/SolidityNameAndTypeResolution.cpp @@ -20,8 +20,6 @@ * Unit tests for the name and type resolution of the solidity parser. */ -#if ETH_SOLIDITY - #include <string> #include <libdevcore/Log.h> @@ -1671,5 +1669,3 @@ BOOST_AUTO_TEST_SUITE_END() } } } // end namespaces - -#endif diff --git a/libsolidity/SolidityNatspecJSON.cpp b/libsolidity/SolidityNatspecJSON.cpp index 99adcf19..d2c1ec18 100644 --- a/libsolidity/SolidityNatspecJSON.cpp +++ b/libsolidity/SolidityNatspecJSON.cpp @@ -20,8 +20,6 @@ * Unit tests for the solidity compiler JSON Interface output. */ -#if ETH_SOLIDITY - #include "../TestHelper.h" #include <json/json.h> #include <libsolidity/CompilerStack.h> @@ -539,5 +537,3 @@ BOOST_AUTO_TEST_SUITE_END() } } } - -#endif diff --git a/libsolidity/SolidityOptimizer.cpp b/libsolidity/SolidityOptimizer.cpp index 8ab1de8f..af9b5146 100644 --- a/libsolidity/SolidityOptimizer.cpp +++ b/libsolidity/SolidityOptimizer.cpp @@ -20,8 +20,6 @@ * Tests for the Solidity optimizer. */ -#if ETH_SOLIDITY - #include <string> #include <tuple> #include <boost/test/unit_test.hpp> @@ -816,5 +814,3 @@ BOOST_AUTO_TEST_SUITE_END() } } } // end namespaces - -#endif diff --git a/libsolidity/SolidityParser.cpp b/libsolidity/SolidityParser.cpp index 7baa1292..ad17c40a 100644 --- a/libsolidity/SolidityParser.cpp +++ b/libsolidity/SolidityParser.cpp @@ -20,8 +20,6 @@ * Unit tests for the solidity parser. */ -#if ETH_SOLIDITY - #include <string> #include <memory> #include <libdevcore/Log.h> @@ -855,5 +853,3 @@ BOOST_AUTO_TEST_SUITE_END() } } } // end namespaces - -#endif diff --git a/libsolidity/SolidityScanner.cpp b/libsolidity/SolidityScanner.cpp index 20b946ee..8d3e5392 100644 --- a/libsolidity/SolidityScanner.cpp +++ b/libsolidity/SolidityScanner.cpp @@ -20,8 +20,6 @@ * Unit tests for the solidity scanner. */ -#if ETH_SOLIDITY - #include <libsolidity/Scanner.h> #include <boost/test/unit_test.hpp> @@ -288,5 +286,3 @@ BOOST_AUTO_TEST_SUITE_END() } } } // end namespaces - -#endif diff --git a/libsolidity/SolidityTypes.cpp b/libsolidity/SolidityTypes.cpp index da8b4830..6b630647 100644 --- a/libsolidity/SolidityTypes.cpp +++ b/libsolidity/SolidityTypes.cpp @@ -20,8 +20,6 @@ * Unit tests for the type system of Solidity. */ -#if ETH_SOLIDITY - #include <libsolidity/Types.h> #include <boost/test/unit_test.hpp> @@ -93,5 +91,3 @@ BOOST_AUTO_TEST_SUITE_END() } } } - -#endif |