Browse Source

Merge pull request #2114 from LianaHus/sol_byte0_in_storage

Sol removed bytes0
cl-refactor
chriseth 10 years ago
parent
commit
5dbcf57046
  1. 3
      libsolidity/Token.h
  2. 4
      libsolidity/Types.cpp
  3. 42
      test/libsolidity/SolidityEndToEndTest.cpp
  4. 11
      test/libsolidity/SolidityNameAndTypeResolution.cpp

3
libsolidity/Token.h

@ -253,7 +253,6 @@ namespace solidity
K(UInt240, "uint240", 0) \ K(UInt240, "uint240", 0) \
K(UInt248, "uint248", 0) \ K(UInt248, "uint248", 0) \
K(UInt256, "uint256", 0) \ K(UInt256, "uint256", 0) \
K(Bytes0, "bytes0", 0) \
K(Bytes1, "bytes1", 0) \ K(Bytes1, "bytes1", 0) \
K(Bytes2, "bytes2", 0) \ K(Bytes2, "bytes2", 0) \
K(Bytes3, "bytes3", 0) \ K(Bytes3, "bytes3", 0) \
@ -306,7 +305,7 @@ namespace solidity
/* Identifiers (not keywords or future reserved words). */ \ /* Identifiers (not keywords or future reserved words). */ \
T(Identifier, NULL, 0) \ T(Identifier, NULL, 0) \
\ \
/* Keywords reserved for future. use*/ \ /* Keywords reserved for future. use. */ \
K(As, "as", 0) \ K(As, "as", 0) \
K(Case, "case", 0) \ K(Case, "case", 0) \
K(Catch, "catch", 0) \ K(Catch, "catch", 0) \

4
libsolidity/Types.cpp

@ -121,7 +121,7 @@ TypePointer Type::fromElementaryTypeName(Token::Value _typeToken)
{ {
int offset = _typeToken - Token::Int; int offset = _typeToken - Token::Int;
int bytes = offset % 33; int bytes = offset % 33;
if (bytes == 0 && _typeToken != Token::Bytes0) if (bytes == 0 && _typeToken != Token::Bytes1)
bytes = 32; bytes = 32;
int modifier = offset / 33; int modifier = offset / 33;
switch(modifier) switch(modifier)
@ -131,7 +131,7 @@ TypePointer Type::fromElementaryTypeName(Token::Value _typeToken)
case 1: case 1:
return make_shared<IntegerType>(bytes * 8, IntegerType::Modifier::Unsigned); return make_shared<IntegerType>(bytes * 8, IntegerType::Modifier::Unsigned);
case 2: case 2:
return make_shared<FixedBytesType>(bytes); return make_shared<FixedBytesType>(bytes + 1);
default: default:
solAssert(false, "Unexpected modifier value. Should never happen"); solAssert(false, "Unexpected modifier value. Should never happen");
return TypePointer(); return TypePointer();

42
test/libsolidity/SolidityEndToEndTest.cpp

@ -566,16 +566,16 @@ BOOST_AUTO_TEST_CASE(strings)
BOOST_AUTO_TEST_CASE(empty_string_on_stack) BOOST_AUTO_TEST_CASE(empty_string_on_stack)
{ {
char const* sourceCode = "contract test {\n" char const* sourceCode = R"(
" function run(bytes0 empty, uint8 inp) returns(uint16 a, bytes0 b, bytes4 c) {\n" contract test {
" var x = \"abc\";\n" function run() external returns(bytes2 ret) {
" var y = \"\";\n" var y = "";
" var z = inp;\n" ret = y;
" a = z; b = y; c = x;" }
" }\n" }
"}\n"; )";
compileAndRun(sourceCode); compileAndRun(sourceCode);
BOOST_CHECK(callContractFunction("run(bytes0,uint8)", string(), byte(0x02)) == encodeArgs(0x2, string(""), string("abc\0"))); BOOST_CHECK(callContractFunction("run()") == encodeArgs(byte(0x00)));
} }
BOOST_AUTO_TEST_CASE(inc_dec_operators) BOOST_AUTO_TEST_CASE(inc_dec_operators)
@ -3786,30 +3786,6 @@ BOOST_AUTO_TEST_CASE(packed_storage_structs_delete)
BOOST_CHECK(m_state.storage(m_contractAddress).empty()); BOOST_CHECK(m_state.storage(m_contractAddress).empty());
} }
BOOST_AUTO_TEST_CASE(packed_storage_structs_with_bytes0)
{
char const* sourceCode = R"(
contract C {
struct str { uint8 a; bytes0 b; uint8 c; }
uint8 a;
bytes0 x;
uint8 b;
str data;
function test() returns (bool) {
a = 2;
b = 3;
data.a = 4;
data.c = 5;
delete x;
delete data.b;
return a == 2 && b == 3 && data.a == 4 && data.c == 5;
}
}
)";
compileAndRun(sourceCode);
BOOST_CHECK(callContractFunction("test()") == encodeArgs(true));
}
BOOST_AUTO_TEST_CASE(overloaded_function_call_resolve_to_first) BOOST_AUTO_TEST_CASE(overloaded_function_call_resolve_to_first)
{ {
char const* sourceCode = R"( char const* sourceCode = R"(

11
test/libsolidity/SolidityNameAndTypeResolution.cpp

@ -1579,7 +1579,6 @@ BOOST_AUTO_TEST_CASE(test_fromElementaryTypeName)
BOOST_CHECK(*Type::fromElementaryTypeName(Token::UInt256) == *make_shared<IntegerType>(256, IntegerType::Modifier::Unsigned)); BOOST_CHECK(*Type::fromElementaryTypeName(Token::UInt256) == *make_shared<IntegerType>(256, IntegerType::Modifier::Unsigned));
BOOST_CHECK(*Type::fromElementaryTypeName(Token::Byte) == *make_shared<FixedBytesType>(1)); BOOST_CHECK(*Type::fromElementaryTypeName(Token::Byte) == *make_shared<FixedBytesType>(1));
BOOST_CHECK(*Type::fromElementaryTypeName(Token::Bytes0) == *make_shared<FixedBytesType>(0));
BOOST_CHECK(*Type::fromElementaryTypeName(Token::Bytes1) == *make_shared<FixedBytesType>(1)); BOOST_CHECK(*Type::fromElementaryTypeName(Token::Bytes1) == *make_shared<FixedBytesType>(1));
BOOST_CHECK(*Type::fromElementaryTypeName(Token::Bytes2) == *make_shared<FixedBytesType>(2)); BOOST_CHECK(*Type::fromElementaryTypeName(Token::Bytes2) == *make_shared<FixedBytesType>(2));
BOOST_CHECK(*Type::fromElementaryTypeName(Token::Bytes3) == *make_shared<FixedBytesType>(3)); BOOST_CHECK(*Type::fromElementaryTypeName(Token::Bytes3) == *make_shared<FixedBytesType>(3));
@ -1666,16 +1665,6 @@ BOOST_AUTO_TEST_CASE(local_const_variable)
BOOST_CHECK_THROW(parseTextAndResolveNames(text), ParserError); BOOST_CHECK_THROW(parseTextAndResolveNames(text), ParserError);
} }
BOOST_AUTO_TEST_CASE(bytes0_array)
{
char const* text = R"(
contract Foo {
bytes0[] illegalArray;
}
)";
BOOST_CHECK_THROW(parseTextAndResolveNames(text), TypeError);
}
BOOST_AUTO_TEST_CASE(overloaded_function_cannot_resolve) BOOST_AUTO_TEST_CASE(overloaded_function_cannot_resolve)
{ {
char const* sourceCode = R"( char const* sourceCode = R"(

Loading…
Cancel
Save