aboutsummaryrefslogtreecommitdiffstats
path: root/AST.cpp
diff options
context:
space:
mode:
authorChristian <c@ethdev.com>2015-02-22 01:25:08 +0800
committerChristian <c@ethdev.com>2015-02-22 01:25:08 +0800
commit261786d909262e6cb4e9602cced76a3a22b7cb88 (patch)
treef4003a11a769bd9c15758b23fe24ec7f38482f57 /AST.cpp
parentbe15e0b424d9a7bd181c8525dbb2eb0a26806c13 (diff)
downloaddexon-solidity-261786d909262e6cb4e9602cced76a3a22b7cb88.tar.gz
dexon-solidity-261786d909262e6cb4e9602cced76a3a22b7cb88.tar.zst
dexon-solidity-261786d909262e6cb4e9602cced76a3a22b7cb88.zip
Allow conversion to dynamic arrays and update grammar.
Diffstat (limited to 'AST.cpp')
-rw-r--r--AST.cpp22
1 files changed, 21 insertions, 1 deletions
diff --git a/AST.cpp b/AST.cpp
index 4e4fe7d5..17946115 100644
--- a/AST.cpp
+++ b/AST.cpp
@@ -614,6 +614,8 @@ void IndexAccess::checkTypeRequirements()
case Type::Category::Array:
{
ArrayType const& type = dynamic_cast<ArrayType const&>(*m_base->getType());
+ if (!m_index)
+ BOOST_THROW_EXCEPTION(createTypeError("Index expression cannot be omitted."));
m_index->expectType(IntegerType(256));
m_type = type.getBaseType();
m_isLValue = true;
@@ -622,14 +624,32 @@ void IndexAccess::checkTypeRequirements()
case Type::Category::Mapping:
{
MappingType const& type = dynamic_cast<MappingType const&>(*m_base->getType());
+ if (!m_index)
+ BOOST_THROW_EXCEPTION(createTypeError("Index expression cannot be omitted."));
m_index->expectType(*type.getKeyType());
m_type = type.getValueType();
m_isLValue = true;
break;
}
+ case Type::Category::TypeType:
+ {
+ TypeType const& type = dynamic_cast<TypeType const&>(*m_base->getType());
+ if (!m_index)
+ m_type = make_shared<TypeType>(make_shared<ArrayType>(ArrayType::Location::Memory, type.getActualType()));
+ else
+ {
+ m_index->checkTypeRequirements();
+ auto length = dynamic_cast<IntegerConstantType const*>(m_index->getType().get());
+ if (!length)
+ BOOST_THROW_EXCEPTION(m_index->createTypeError("Integer constant expected."));
+ m_type = make_shared<TypeType>(make_shared<ArrayType>(
+ ArrayType::Location::Memory, type.getActualType(), length->literalValue(nullptr)));
+ }
+ break;
+ }
default:
BOOST_THROW_EXCEPTION(m_base->createTypeError(
- "Indexed expression has to be a mapping or array (is " + m_base->getType()->toString() + ")"));
+ "Indexed expression has to be a type, mapping or array (is " + m_base->getType()->toString() + ")"));
}
}