aboutsummaryrefslogtreecommitdiffstats
path: root/ExpressionCompiler.cpp
diff options
context:
space:
mode:
authorChristian <c@ethdev.com>2014-12-10 01:46:18 +0800
committerChristian <c@ethdev.com>2014-12-10 23:30:20 +0800
commit130ff85e85de3ea8a9666f84843428a3a09b1aab (patch)
treeafff06eddf204678b099dc9fae187a697e8debcc /ExpressionCompiler.cpp
parente8b7d266641175039d40c344449409a60527156e (diff)
downloaddexon-solidity-130ff85e85de3ea8a9666f84843428a3a09b1aab.tar.gz
dexon-solidity-130ff85e85de3ea8a9666f84843428a3a09b1aab.tar.zst
dexon-solidity-130ff85e85de3ea8a9666f84843428a3a09b1aab.zip
String types.
Diffstat (limited to 'ExpressionCompiler.cpp')
-rw-r--r--ExpressionCompiler.cpp22
1 files changed, 18 insertions, 4 deletions
diff --git a/ExpressionCompiler.cpp b/ExpressionCompiler.cpp
index f1086c14..5e688f6b 100644
--- a/ExpressionCompiler.cpp
+++ b/ExpressionCompiler.cpp
@@ -226,7 +226,8 @@ bool ExpressionCompiler::visit(FunctionCall& _functionCall)
<< errinfo_sourceLocation(arguments[i]->getLocation())
<< errinfo_comment("Type " + type.toString() + " not yet supported."));
if (numBytes != 32)
- m_context << (u256(1) << ((32 - numBytes) * 8)) << eth::Instruction::MUL;
+ if (type.getCategory() != Type::Category::STRING)
+ m_context << (u256(1) << ((32 - numBytes) * 8)) << eth::Instruction::MUL;
m_context << u256(dataOffset) << eth::Instruction::MSTORE;
dataOffset += numBytes;
}
@@ -243,8 +244,15 @@ bool ExpressionCompiler::visit(FunctionCall& _functionCall)
if (retSize == 32)
m_context << u256(0) << eth::Instruction::MLOAD;
else if (retSize > 0)
- m_context << (u256(1) << ((32 - retSize) * 8))
- << u256(0) << eth::Instruction::MLOAD << eth::Instruction::DIV;
+ {
+ if (function.getReturnParameterTypes().front()->getCategory() == Type::Category::STRING)
+ m_context << (u256(1) << ((32 - retSize) * 8)) << eth::Instruction::DUP1
+ << u256(0) << eth::Instruction::MLOAD
+ << eth::Instruction::DIV << eth::Instruction::MUL;
+ else
+ m_context << (u256(1) << ((32 - retSize) * 8))
+ << u256(0) << eth::Instruction::MLOAD << eth::Instruction::DIV;
+ }
break;
}
case Location::SEND:
@@ -411,10 +419,11 @@ void ExpressionCompiler::endVisit(Literal& _literal)
{
case Type::Category::INTEGER:
case Type::Category::BOOL:
+ case Type::Category::STRING:
m_context << _literal.getType()->literalValue(_literal);
break;
default:
- BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Only integer and boolean literals implemented for now."));
+ BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Only integer, boolean and string literals implemented for now."));
}
}
@@ -550,6 +559,11 @@ void ExpressionCompiler::appendTypeConversion(Type const& _typeOnStack, Type con
return;
if (_typeOnStack.getCategory() == Type::Category::INTEGER)
appendHighBitsCleanup(dynamic_cast<IntegerType const&>(_typeOnStack));
+ else if (_typeOnStack.getCategory() == Type::Category::STRING)
+ {
+ // nothing to do, strings are high-order-bit-aligned
+ //@todo clear lower-order bytes if we allow explicit conversion to shorter strings
+ }
else if (_typeOnStack != _targetType)
// All other types should not be convertible to non-equal types.
BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Invalid type conversion requested."));