From 7aff1fb942c7a9b5a5fa04e886336db737337d0d Mon Sep 17 00:00:00 2001 From: chriseth Date: Fri, 5 Jun 2015 11:07:50 +0200 Subject: [PATCH] Ability to specify the storage location of a reference type. --- libsolidity/SolidityNameAndTypeResolution.cpp | 34 +++++++++++++++ libsolidity/SolidityParser.cpp | 41 +++++++++++++++++++ libsolidity/SolidityTypes.cpp | 14 +++---- 3 files changed, 82 insertions(+), 7 deletions(-) diff --git a/libsolidity/SolidityNameAndTypeResolution.cpp b/libsolidity/SolidityNameAndTypeResolution.cpp index 3691868cc..73bbcb162 100644 --- a/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/libsolidity/SolidityNameAndTypeResolution.cpp @@ -1876,6 +1876,40 @@ BOOST_AUTO_TEST_CASE(positive_integers_to_unsigned_out_of_bound) BOOST_CHECK_THROW(parseTextAndResolveNames(sourceCode), TypeError); } +BOOST_AUTO_TEST_CASE(overwrite_memory_location_external) +{ + char const* sourceCode = R"( + contract C { + function f(uint[] memory a) external {} + } + )"; + BOOST_CHECK_THROW(parseTextAndResolveNames(sourceCode), TypeError); +} + +BOOST_AUTO_TEST_CASE(overwrite_storage_location_external) +{ + char const* sourceCode = R"( + contract C { + function f(uint[] storage a) external {} + } + )"; + BOOST_CHECK_THROW(parseTextAndResolveNames(sourceCode), TypeError); +} + +BOOST_AUTO_TEST_CASE(storage_location_local_variables) +{ + char const* sourceCode = R"( + contract C { + function f() { + uint[] storage x; + uint[] memory y; + uint[] memory z; + } + } + )"; + BOOST_CHECK_NO_THROW(parseTextAndResolveNames(sourceCode)); +} + BOOST_AUTO_TEST_SUITE_END() } diff --git a/libsolidity/SolidityParser.cpp b/libsolidity/SolidityParser.cpp index cad0e1f2c..438e650bf 100644 --- a/libsolidity/SolidityParser.cpp +++ b/libsolidity/SolidityParser.cpp @@ -873,6 +873,47 @@ BOOST_AUTO_TEST_CASE(var_array) BOOST_CHECK_THROW(parseText(text), ParserError); } +BOOST_AUTO_TEST_CASE(location_specifiers_for_params) +{ + char const* text = R"( + contract Foo { + function f(uint[] storage constant x, uint[] memory y) { } + } + )"; + BOOST_CHECK_NO_THROW(parseText(text)); +} + +BOOST_AUTO_TEST_CASE(location_specifiers_for_locals) +{ + char const* text = R"( + contract Foo { + function f() { + uint[] storage x; + uint[] memory y; + } + } + )"; + BOOST_CHECK_NO_THROW(parseText(text)); +} + +BOOST_AUTO_TEST_CASE(location_specifiers_for_state) +{ + char const* text = R"( + contract Foo { + uint[] memory x; + })"; + BOOST_CHECK_THROW(parseText(text), ParserError); +} + +BOOST_AUTO_TEST_CASE(location_specifiers_with_var) +{ + char const* text = R"( + contract Foo { + function f() { var memory x; } + })"; + BOOST_CHECK_THROW(parseText(text), ParserError); +} + BOOST_AUTO_TEST_SUITE_END() } diff --git a/libsolidity/SolidityTypes.cpp b/libsolidity/SolidityTypes.cpp index 6b6306479..718798a5a 100644 --- a/libsolidity/SolidityTypes.cpp +++ b/libsolidity/SolidityTypes.cpp @@ -77,13 +77,13 @@ BOOST_AUTO_TEST_CASE(storage_layout_mapping) BOOST_AUTO_TEST_CASE(storage_layout_arrays) { - BOOST_CHECK(ArrayType(ArrayType::Location::Storage, make_shared(1), 32).getStorageSize() == 1); - BOOST_CHECK(ArrayType(ArrayType::Location::Storage, make_shared(1), 33).getStorageSize() == 2); - BOOST_CHECK(ArrayType(ArrayType::Location::Storage, make_shared(2), 31).getStorageSize() == 2); - BOOST_CHECK(ArrayType(ArrayType::Location::Storage, make_shared(7), 8).getStorageSize() == 2); - BOOST_CHECK(ArrayType(ArrayType::Location::Storage, make_shared(7), 9).getStorageSize() == 3); - BOOST_CHECK(ArrayType(ArrayType::Location::Storage, make_shared(31), 9).getStorageSize() == 9); - BOOST_CHECK(ArrayType(ArrayType::Location::Storage, make_shared(32), 9).getStorageSize() == 9); + BOOST_CHECK(ArrayType(ReferenceType::Location::Storage, make_shared(1), 32).getStorageSize() == 1); + BOOST_CHECK(ArrayType(ReferenceType::Location::Storage, make_shared(1), 33).getStorageSize() == 2); + BOOST_CHECK(ArrayType(ReferenceType::Location::Storage, make_shared(2), 31).getStorageSize() == 2); + BOOST_CHECK(ArrayType(ReferenceType::Location::Storage, make_shared(7), 8).getStorageSize() == 2); + BOOST_CHECK(ArrayType(ReferenceType::Location::Storage, make_shared(7), 9).getStorageSize() == 3); + BOOST_CHECK(ArrayType(ReferenceType::Location::Storage, make_shared(31), 9).getStorageSize() == 9); + BOOST_CHECK(ArrayType(ReferenceType::Location::Storage, make_shared(32), 9).getStorageSize() == 9); } BOOST_AUTO_TEST_SUITE_END()