diff options
author | Christian <c@ethdev.com> | 2015-02-22 01:25:08 +0800 |
---|---|---|
committer | Christian <c@ethdev.com> | 2015-02-22 01:25:08 +0800 |
commit | 261786d909262e6cb4e9602cced76a3a22b7cb88 (patch) | |
tree | f4003a11a769bd9c15758b23fe24ec7f38482f57 /AST.cpp | |
parent | be15e0b424d9a7bd181c8525dbb2eb0a26806c13 (diff) | |
download | dexon-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.cpp | 22 |
1 files changed, 21 insertions, 1 deletions
@@ -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() + ")")); } } |