From a269adb549994e1c411eec023862a817e00cdb44 Mon Sep 17 00:00:00 2001 From: Lefteris Karapetsas Date: Mon, 23 Feb 2015 17:14:59 +0100 Subject: Moving Source Location libdevcore - Big plus is we now remove the useless header libsolibity/BaseTypes.h --- SolidityInterface.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SolidityInterface.cpp b/SolidityInterface.cpp index a73c118b..35471518 100644 --- a/SolidityInterface.cpp +++ b/SolidityInterface.cpp @@ -50,7 +50,7 @@ public: string getSourcePart(ASTNode const& _node) const { - Location location = _node.getLocation(); + SourceLocation location = _node.getLocation(); BOOST_REQUIRE(!location.isEmpty()); return m_interface.substr(location.start, location.end - location.start); } -- cgit v1.2.3 From 5d204e97293821541dba74702aeb0cbbba24a80f Mon Sep 17 00:00:00 2001 From: Lefteris Karapetsas Date: Tue, 24 Feb 2015 12:08:51 +0100 Subject: Reset CompilerContext's visited nodes at compile start --- SolidityExpressionCompiler.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/SolidityExpressionCompiler.cpp b/SolidityExpressionCompiler.cpp index 9cd13dcf..c7d83cef 100644 --- a/SolidityExpressionCompiler.cpp +++ b/SolidityExpressionCompiler.cpp @@ -127,6 +127,7 @@ bytes compileFirstExpression(const string& _sourceCode, vector> _ BOOST_REQUIRE(extractor.getExpression() != nullptr); CompilerContext context; + context.resetVisitedNodes(contract); context.setInheritanceHierarchy(inheritanceHierarchy); unsigned parametersSize = _localVariables.size(); // assume they are all one slot on the stack context.adjustStackOffset(parametersSize); -- cgit v1.2.3 From 8aabe7082e5d1c6fe7722dc7d67f505d267b06a6 Mon Sep 17 00:00:00 2001 From: Lefteris Karapetsas Date: Tue, 24 Feb 2015 17:08:27 +0100 Subject: Simple Assembly Locations test - Also adding some helper functions to SourceLocation --- Assembly.cpp | 128 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100644 Assembly.cpp diff --git a/Assembly.cpp b/Assembly.cpp new file mode 100644 index 00000000..0ccc174c --- /dev/null +++ b/Assembly.cpp @@ -0,0 +1,128 @@ +/* + 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 . +*/ +/** + * @author Lefteris Karapetsas + * @date 2015 + * Unit tests for Assembly Items from evmcore/Assembly.h + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace std; +using namespace dev::eth; + +namespace dev +{ +namespace solidity +{ +namespace test +{ + +namespace +{ + +eth::AssemblyItems compileContract(const string& _sourceCode) +{ + Parser parser; + ASTPointer sourceUnit; + BOOST_REQUIRE_NO_THROW(sourceUnit = parser.parse(make_shared(CharStream(_sourceCode)))); + NameAndTypeResolver resolver({}); + resolver.registerDeclarations(*sourceUnit); + for (ASTPointer const& node: sourceUnit->getNodes()) + if (ContractDefinition* contract = dynamic_cast(node.get())) + { + BOOST_REQUIRE_NO_THROW(resolver.resolveNamesAndTypes(*contract)); + } + for (ASTPointer const& node: sourceUnit->getNodes()) + if (ContractDefinition* contract = dynamic_cast(node.get())) + { + BOOST_REQUIRE_NO_THROW(resolver.checkTypeRequirements(*contract)); + } + for (ASTPointer const& node: sourceUnit->getNodes()) + if (ContractDefinition* contract = dynamic_cast(node.get())) + { + Compiler compiler; + compiler.compileContract(*contract, map{}); + + return compiler.getRuntimeContext().getAssembly().getItems(); + } + BOOST_FAIL("No contract found in source."); + return AssemblyItems(); +} + +void checkAssemblyLocations(AssemblyItems const& _items, std::vector _locations) +{ + size_t i = 0; + BOOST_CHECK_EQUAL(_items.size(), _locations.size()); + for (auto const& it: _items) + { + BOOST_CHECK_MESSAGE(it.getLocation() == _locations[i], std::string("Location mismatch for item" + i)); + ++ i; + } + +} + +} // end anonymous namespace + +BOOST_AUTO_TEST_SUITE(Assembly) + +BOOST_AUTO_TEST_CASE(location_test) +{ + char const* sourceCode = "contract test {\n" + " function f() returns (uint256 a)\n" + " {\n" + " return 16;\n" + " }\n" + "}\n"; + std::shared_ptr n = make_shared("source"); + AssemblyItems items = compileContract(sourceCode); + std::vector locations { + SourceLocation(0, 77, n), SourceLocation(0, 77, n), + SourceLocation(0, 77, n), SourceLocation(0, 77, n), + SourceLocation(0, 77, n), SourceLocation(0, 77, n), + SourceLocation(0, 77, n), SourceLocation(0, 77, n), + SourceLocation(), SourceLocation(), + SourceLocation(0, 77, n), SourceLocation(0, 77, n), + SourceLocation(), SourceLocation(), SourceLocation(), + SourceLocation(0, 77, n), SourceLocation(0, 77, n), + SourceLocation(0, 77, n), SourceLocation(0, 77, n), + SourceLocation(0, 77, n), SourceLocation(0, 77, n), + SourceLocation(0, 77, n), + SourceLocation(18, 75, n), SourceLocation(18, 75, n), + SourceLocation(61, 70, n), SourceLocation(61, 70, n), SourceLocation(61, 70, n), + SourceLocation(), SourceLocation(), + SourceLocation(61, 70, n), SourceLocation(61, 70, n), SourceLocation(61, 70, n) + }; + checkAssemblyLocations(items, locations); +} + +BOOST_AUTO_TEST_SUITE_END() + +} +} +} // end namespaces + -- cgit v1.2.3 From 689750e1146a4551426db0a48e87a891ede15417 Mon Sep 17 00:00:00 2001 From: Lefteris Karapetsas Date: Wed, 25 Feb 2015 09:53:28 +0100 Subject: Styling changes for SourceLocation and friends --- Assembly.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/Assembly.cpp b/Assembly.cpp index 0ccc174c..021463e4 100644 --- a/Assembly.cpp +++ b/Assembly.cpp @@ -54,14 +54,10 @@ eth::AssemblyItems compileContract(const string& _sourceCode) resolver.registerDeclarations(*sourceUnit); for (ASTPointer const& node: sourceUnit->getNodes()) if (ContractDefinition* contract = dynamic_cast(node.get())) - { BOOST_REQUIRE_NO_THROW(resolver.resolveNamesAndTypes(*contract)); - } for (ASTPointer const& node: sourceUnit->getNodes()) if (ContractDefinition* contract = dynamic_cast(node.get())) - { BOOST_REQUIRE_NO_THROW(resolver.checkTypeRequirements(*contract)); - } for (ASTPointer const& node: sourceUnit->getNodes()) if (ContractDefinition* contract = dynamic_cast(node.get())) { @@ -81,7 +77,7 @@ void checkAssemblyLocations(AssemblyItems const& _items, std::vector Date: Wed, 25 Feb 2015 10:40:14 +0100 Subject: LocationSetter in some extra places during Compiling - Also adjusted the test, and fixed its error reporting --- Assembly.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Assembly.cpp b/Assembly.cpp index 021463e4..60f10d08 100644 --- a/Assembly.cpp +++ b/Assembly.cpp @@ -76,7 +76,8 @@ void checkAssemblyLocations(AssemblyItems const& _items, std::vector Date: Wed, 25 Feb 2015 12:02:58 +0100 Subject: Tighter coupling for Assembly items retrieval - Exposing only assembly items, not the entire compiler context --- Assembly.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Assembly.cpp b/Assembly.cpp index 60f10d08..1837feac 100644 --- a/Assembly.cpp +++ b/Assembly.cpp @@ -64,7 +64,7 @@ eth::AssemblyItems compileContract(const string& _sourceCode) Compiler compiler; compiler.compileContract(*contract, map{}); - return compiler.getRuntimeContext().getAssembly().getItems(); + return compiler.getRuntimeAssemblyItems(); } BOOST_FAIL("No contract found in source."); return AssemblyItems(); -- cgit v1.2.3 From 396075717f6f9e691af69b39a03c770a48ffdf91 Mon Sep 17 00:00:00 2001 From: Lefteris Karapetsas Date: Wed, 25 Feb 2015 12:19:02 +0100 Subject: Move SourceLocation to evmcore --- Assembly.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Assembly.cpp b/Assembly.cpp index 1837feac..bad8233d 100644 --- a/Assembly.cpp +++ b/Assembly.cpp @@ -24,7 +24,7 @@ #include #include #include -#include +#include #include #include #include -- cgit v1.2.3 From c930068c77be57007cb79b36ae69c820fbaf5c57 Mon Sep 17 00:00:00 2001 From: Lefteris Karapetsas Date: Wed, 25 Feb 2015 12:37:13 +0100 Subject: Re-adding braces to if in test/Assembly.cpp --- Assembly.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Assembly.cpp b/Assembly.cpp index bad8233d..3869919e 100644 --- a/Assembly.cpp +++ b/Assembly.cpp @@ -54,10 +54,14 @@ eth::AssemblyItems compileContract(const string& _sourceCode) resolver.registerDeclarations(*sourceUnit); for (ASTPointer const& node: sourceUnit->getNodes()) if (ContractDefinition* contract = dynamic_cast(node.get())) + { BOOST_REQUIRE_NO_THROW(resolver.resolveNamesAndTypes(*contract)); + } for (ASTPointer const& node: sourceUnit->getNodes()) if (ContractDefinition* contract = dynamic_cast(node.get())) + { BOOST_REQUIRE_NO_THROW(resolver.checkTypeRequirements(*contract)); + } for (ASTPointer const& node: sourceUnit->getNodes()) if (ContractDefinition* contract = dynamic_cast(node.get())) { -- cgit v1.2.3 From 60ade5b33f004d64b4f55b5efc2f7083724d9682 Mon Sep 17 00:00:00 2001 From: Christian Date: Wed, 25 Feb 2015 15:14:22 +0100 Subject: LValue refactoring. --- SolidityExpressionCompiler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SolidityExpressionCompiler.cpp b/SolidityExpressionCompiler.cpp index c7d83cef..3340334f 100644 --- a/SolidityExpressionCompiler.cpp +++ b/SolidityExpressionCompiler.cpp @@ -135,7 +135,7 @@ bytes compileFirstExpression(const string& _sourceCode, vector> _ context.addVariable(dynamic_cast(resolveDeclaration(variable, resolver)), parametersSize--); - ExpressionCompiler::compileExpression(context, *extractor.getExpression()); + ExpressionCompiler(context).compile(*extractor.getExpression()); for (vector const& function: _functions) context << context.getFunctionEntryLabel(dynamic_cast(resolveDeclaration(function, resolver))); -- cgit v1.2.3