aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity
diff options
context:
space:
mode:
authorchriseth <c@ethdev.com>2015-06-05 17:07:50 +0800
committerchriseth <c@ethdev.com>2015-06-05 20:44:05 +0800
commit7aff1fb942c7a9b5a5fa04e886336db737337d0d (patch)
tree7807f91a31962268caaac99b7508f605acbe8ed6 /libsolidity
parent8ba801ec0e885ebca5babadef007f20bcdde1f0b (diff)
downloaddexon-solidity-7aff1fb942c7a9b5a5fa04e886336db737337d0d.tar.gz
dexon-solidity-7aff1fb942c7a9b5a5fa04e886336db737337d0d.tar.zst
dexon-solidity-7aff1fb942c7a9b5a5fa04e886336db737337d0d.zip
Ability to specify the storage location of a reference type.
Diffstat (limited to 'libsolidity')
-rw-r--r--libsolidity/SolidityNameAndTypeResolution.cpp34
-rw-r--r--libsolidity/SolidityParser.cpp41
-rw-r--r--libsolidity/SolidityTypes.cpp14
3 files changed, 82 insertions, 7 deletions
diff --git a/libsolidity/SolidityNameAndTypeResolution.cpp b/libsolidity/SolidityNameAndTypeResolution.cpp
index 3691868c..73bbcb16 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 cad0e1f2..438e650b 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 6b630647..718798a5 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<FixedBytesType>(1), 32).getStorageSize() == 1);
- BOOST_CHECK(ArrayType(ArrayType::Location::Storage, make_shared<FixedBytesType>(1), 33).getStorageSize() == 2);
- BOOST_CHECK(ArrayType(ArrayType::Location::Storage, make_shared<FixedBytesType>(2), 31).getStorageSize() == 2);
- BOOST_CHECK(ArrayType(ArrayType::Location::Storage, make_shared<FixedBytesType>(7), 8).getStorageSize() == 2);
- BOOST_CHECK(ArrayType(ArrayType::Location::Storage, make_shared<FixedBytesType>(7), 9).getStorageSize() == 3);
- BOOST_CHECK(ArrayType(ArrayType::Location::Storage, make_shared<FixedBytesType>(31), 9).getStorageSize() == 9);
- BOOST_CHECK(ArrayType(ArrayType::Location::Storage, make_shared<FixedBytesType>(32), 9).getStorageSize() == 9);
+ BOOST_CHECK(ArrayType(ReferenceType::Location::Storage, make_shared<FixedBytesType>(1), 32).getStorageSize() == 1);
+ BOOST_CHECK(ArrayType(ReferenceType::Location::Storage, make_shared<FixedBytesType>(1), 33).getStorageSize() == 2);
+ BOOST_CHECK(ArrayType(ReferenceType::Location::Storage, make_shared<FixedBytesType>(2), 31).getStorageSize() == 2);
+ BOOST_CHECK(ArrayType(ReferenceType::Location::Storage, make_shared<FixedBytesType>(7), 8).getStorageSize() == 2);
+ BOOST_CHECK(ArrayType(ReferenceType::Location::Storage, make_shared<FixedBytesType>(7), 9).getStorageSize() == 3);
+ BOOST_CHECK(ArrayType(ReferenceType::Location::Storage, make_shared<FixedBytesType>(31), 9).getStorageSize() == 9);
+ BOOST_CHECK(ArrayType(ReferenceType::Location::Storage, make_shared<FixedBytesType>(32), 9).getStorageSize() == 9);
}
BOOST_AUTO_TEST_SUITE_END()