diff options
author | chriseth <c@ethdev.com> | 2015-06-05 17:07:50 +0800 |
---|---|---|
committer | chriseth <c@ethdev.com> | 2015-06-05 20:44:05 +0800 |
commit | f4d1acc563a972ee4f5a44c690cd3fdd1783ae97 (patch) | |
tree | b2814613dff69ffe8f1e14ef6160dcc0902eb3c4 /Types.cpp | |
parent | 4987eec3d1e87868e091850d31af58e054ab5ee5 (diff) | |
download | dexon-solidity-f4d1acc563a972ee4f5a44c690cd3fdd1783ae97.tar.gz dexon-solidity-f4d1acc563a972ee4f5a44c690cd3fdd1783ae97.tar.zst dexon-solidity-f4d1acc563a972ee4f5a44c690cd3fdd1783ae97.zip |
Ability to specify the storage location of a reference type.
Diffstat (limited to 'Types.cpp')
-rw-r--r-- | Types.cpp | 25 |
1 files changed, 16 insertions, 9 deletions
@@ -144,9 +144,9 @@ TypePointer Type::fromElementaryTypeName(Token::Value _typeToken) else if (_typeToken == Token::Bool) return make_shared<BoolType>(); else if (_typeToken == Token::Bytes) - return make_shared<ArrayType>(ArrayType::Location::Storage); + return make_shared<ArrayType>(ReferenceType::Location::Storage); else if (_typeToken == Token::String) - return make_shared<ArrayType>(ArrayType::Location::Storage, true); + return make_shared<ArrayType>(ReferenceType::Location::Storage, true); else BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Unable to convert elementary typename " + std::string(Token::toString(_typeToken)) + " to type.")); @@ -196,10 +196,10 @@ TypePointer Type::fromArrayTypeName(TypeName& _baseTypeName, Expression* _length auto const* length = dynamic_cast<IntegerConstantType const*>(_length->getType().get()); if (!length) BOOST_THROW_EXCEPTION(_length->createTypeError("Invalid array length.")); - return make_shared<ArrayType>(ArrayType::Location::Storage, baseType, length->literalValue(nullptr)); + return make_shared<ArrayType>(ReferenceType::Location::Storage, baseType, length->literalValue(nullptr)); } else - return make_shared<ArrayType>(ArrayType::Location::Storage, baseType); + return make_shared<ArrayType>(ReferenceType::Location::Storage, baseType); } TypePointer Type::forLiteral(Literal const& _literal) @@ -674,7 +674,7 @@ bool ArrayType::isImplicitlyConvertibleTo(const Type& _convertTo) const return false; auto& convertTo = dynamic_cast<ArrayType const&>(_convertTo); // let us not allow assignment to memory arrays for now - if (convertTo.getLocation() != Location::Storage) + if (convertTo.location() != Location::Storage) return false; if (convertTo.isByteArray() != isByteArray() || convertTo.isString() != isString()) return false; @@ -778,12 +778,12 @@ TypePointer ArrayType::externalType() const return std::make_shared<ArrayType>(Location::CallData, m_baseType->externalType(), m_length); } -shared_ptr<ArrayType> ArrayType::copyForLocation(ArrayType::Location _location) const +TypePointer ArrayType::copyForLocation(ReferenceType::Location _location) const { auto copy = make_shared<ArrayType>(_location); copy->m_arrayKind = m_arrayKind; - if (m_baseType->getCategory() == Type::Category::Array) - copy->m_baseType = dynamic_cast<ArrayType const&>(*m_baseType).copyForLocation(_location); + if (auto ref = dynamic_cast<ReferenceType const*>(m_baseType.get())) + copy->m_baseType = ref->copyForLocation(_location); else copy->m_baseType = m_baseType; copy->m_hasDynamicLength = m_hasDynamicLength; @@ -934,6 +934,13 @@ MemberList const& StructType::getMembers() const return *m_members; } +TypePointer StructType::copyForLocation(ReferenceType::Location _location) const +{ + auto copy = make_shared<StructType>(m_struct); + copy->m_location = _location; + return copy; +} + pair<u256, unsigned> const& StructType::getStorageOffsetsOfMember(string const& _name) const { auto const* offsets = getMembers().getMemberStorageOffset(_name); @@ -1466,7 +1473,7 @@ MagicType::MagicType(MagicType::Kind _kind): {"sender", make_shared<IntegerType>(0, IntegerType::Modifier::Address)}, {"gas", make_shared<IntegerType>(256)}, {"value", make_shared<IntegerType>(256)}, - {"data", make_shared<ArrayType>(ArrayType::Location::CallData)}, + {"data", make_shared<ArrayType>(ReferenceType::Location::CallData)}, {"sig", make_shared<FixedBytesType>(4)} })); break; |