aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian <c@ethdev.com>2014-12-11 21:19:11 +0800
committerChristian <c@ethdev.com>2014-12-11 21:19:11 +0800
commita7352280790f1b88048b4879c46748d2082b1325 (patch)
treeaaf4f0a40e18abbd8264305e714a1bd50ac3e9d7
parent8b54d1afb2b3ad897330258367b2ce67c8a56940 (diff)
downloaddexon-solidity-a7352280790f1b88048b4879c46748d2082b1325.tar
dexon-solidity-a7352280790f1b88048b4879c46748d2082b1325.tar.gz
dexon-solidity-a7352280790f1b88048b4879c46748d2082b1325.tar.bz2
dexon-solidity-a7352280790f1b88048b4879c46748d2082b1325.tar.lz
dexon-solidity-a7352280790f1b88048b4879c46748d2082b1325.tar.xz
dexon-solidity-a7352280790f1b88048b4879c46748d2082b1325.tar.zst
dexon-solidity-a7352280790f1b88048b4879c46748d2082b1325.zip
Support empty strings.
-rw-r--r--AST.cpp2
-rw-r--r--Compiler.cpp4
-rw-r--r--CompilerUtils.cpp18
-rw-r--r--Token.h1
-rw-r--r--Types.cpp8
5 files changed, 22 insertions, 11 deletions
diff --git a/AST.cpp b/AST.cpp
index 593e0960..8174d138 100644
--- a/AST.cpp
+++ b/AST.cpp
@@ -339,7 +339,7 @@ void Literal::checkTypeRequirements()
{
m_type = Type::forLiteral(*this);
if (!m_type)
- BOOST_THROW_EXCEPTION(createTypeError("Literal value too large or too small."));
+ BOOST_THROW_EXCEPTION(createTypeError("Literal value too large."));
}
}
diff --git a/Compiler.cpp b/Compiler.cpp
index 940a5e70..92d574fb 100644
--- a/Compiler.cpp
+++ b/Compiler.cpp
@@ -135,7 +135,7 @@ unsigned Compiler::appendCalldataUnpacker(FunctionDefinition const& _function, b
for (ASTPointer<VariableDeclaration> const& var: _function.getParameters())
{
unsigned const numBytes = var->getType()->getCalldataEncodedSize();
- if (numBytes == 0 || numBytes > 32)
+ if (numBytes > 32)
BOOST_THROW_EXCEPTION(CompilerError()
<< errinfo_sourceLocation(var->getLocation())
<< errinfo_comment("Type " + var->getType()->toString() + " not yet supported."));
@@ -156,7 +156,7 @@ void Compiler::appendReturnValuePacker(FunctionDefinition const& _function)
{
Type const& paramType = *parameters[i]->getType();
unsigned numBytes = paramType.getCalldataEncodedSize();
- if (numBytes == 0 || numBytes > 32)
+ if (numBytes > 32)
BOOST_THROW_EXCEPTION(CompilerError()
<< errinfo_sourceLocation(parameters[i]->getLocation())
<< errinfo_comment("Type " + paramType.toString() + " not yet supported."));
diff --git a/CompilerUtils.cpp b/CompilerUtils.cpp
index 0ee4a53c..9f474896 100644
--- a/CompilerUtils.cpp
+++ b/CompilerUtils.cpp
@@ -33,9 +33,14 @@ namespace solidity
void CompilerUtils::loadFromMemory(unsigned _offset, unsigned _bytes, bool _leftAligned, bool _fromCalldata)
{
+ if (_bytes == 0)
+ {
+ m_context << u256(0);
+ return;
+ }
eth::Instruction load = _fromCalldata ? eth::Instruction::CALLDATALOAD : eth::Instruction::MLOAD;
- if (asserts(0 < _bytes && _bytes <= 32))
- BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Memory load of 0 or more than 32 bytes requested."));
+ if (asserts(_bytes <= 32))
+ BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Memory load of more than 32 bytes requested."));
if (_bytes == 32)
m_context << u256(_offset) << load;
else
@@ -53,8 +58,13 @@ void CompilerUtils::loadFromMemory(unsigned _offset, unsigned _bytes, bool _left
void CompilerUtils::storeInMemory(unsigned _offset, unsigned _bytes, bool _leftAligned)
{
- if (asserts(0 < _bytes && _bytes <= 32))
- BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Memory store of 0 or more than 32 bytes requested."));
+ if (_bytes == 0)
+ {
+ m_context << eth::Instruction::POP;
+ return;
+ }
+ if (asserts(_bytes <= 32))
+ BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Memory store of more than 32 bytes requested."));
if (_bytes != 32 && !_leftAligned)
// shift the value accordingly before storing
m_context << (u256(1) << ((32 - _bytes) * 8)) << eth::Instruction::MUL;
diff --git a/Token.h b/Token.h
index f9ded311..21b74ece 100644
--- a/Token.h
+++ b/Token.h
@@ -269,6 +269,7 @@ namespace solidity
K(ADDRESS, "address", 0) \
K(BOOL, "bool", 0) \
K(STRING_TYPE, "string", 0) \
+ K(STRING0, "string0", 0) \
K(STRING1, "string1", 0) \
K(STRING2, "string2", 0) \
K(STRING3, "string3", 0) \
diff --git a/Types.cpp b/Types.cpp
index 543c27c2..00e530c3 100644
--- a/Types.cpp
+++ b/Types.cpp
@@ -53,8 +53,8 @@ shared_ptr<Type const> Type::fromElementaryTypeName(Token::Value _typeToken)
return make_shared<IntegerType const>(0, IntegerType::Modifier::ADDRESS);
else if (_typeToken == Token::BOOL)
return make_shared<BoolType const>();
- else if (Token::STRING1 <= _typeToken && _typeToken <= Token::STRING32)
- return make_shared<StaticStringType const>(int(_typeToken) - int(Token::STRING1) + 1);
+ else if (Token::STRING0 <= _typeToken && _typeToken <= Token::STRING32)
+ return make_shared<StaticStringType const>(int(_typeToken) - int(Token::STRING0));
else
BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Unable to convert elementary typename " +
std::string(Token::toString(_typeToken)) + " to type."));
@@ -199,14 +199,14 @@ const MemberList IntegerType::AddressMemberList =
shared_ptr<StaticStringType> StaticStringType::smallestTypeForLiteral(string const& _literal)
{
- if (0 < _literal.length() && _literal.length() <= 32)
+ if (_literal.length() <= 32)
return make_shared<StaticStringType>(_literal.length());
return shared_ptr<StaticStringType>();
}
StaticStringType::StaticStringType(int _bytes): m_bytes(_bytes)
{
- if (asserts(m_bytes > 0 && m_bytes <= 32))
+ if (asserts(m_bytes >= 0 && m_bytes <= 32))
BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Invalid byte number for static string type: " +
dev::toString(m_bytes)));
}