diff options
author | Christian <c@ethdev.com> | 2014-11-21 01:33:23 +0800 |
---|---|---|
committer | Christian <c@ethdev.com> | 2014-11-24 04:28:44 +0800 |
commit | c50cd646ce3b8b6c20da747efee89f9420526cae (patch) | |
tree | a6ebf3a1fe6088d9b8c5e3d4f36caa09bfd3fdd7 /Types.cpp | |
parent | fa987e0a206bba35cfe6e311f8bad1470d9b5d4f (diff) | |
download | dexon-solidity-c50cd646ce3b8b6c20da747efee89f9420526cae.tar.gz dexon-solidity-c50cd646ce3b8b6c20da747efee89f9420526cae.tar.zst dexon-solidity-c50cd646ce3b8b6c20da747efee89f9420526cae.zip |
Contracts as types and framework for special global variables.
Diffstat (limited to 'Types.cpp')
-rw-r--r-- | Types.cpp | 30 |
1 files changed, 27 insertions, 3 deletions
@@ -60,13 +60,24 @@ shared_ptr<Type> Type::fromElementaryTypeName(Token::Value _typeToken) shared_ptr<Type> Type::fromUserDefinedTypeName(UserDefinedTypeName const& _typeName) { - return make_shared<StructType>(*_typeName.getReferencedStruct()); + Declaration const* declaration = _typeName.getReferencedDeclaration(); + if (StructDefinition const* structDef = dynamic_cast<StructDefinition const*>(declaration)) + return make_shared<StructType>(*structDef); + else if (FunctionDefinition const* function = dynamic_cast<FunctionDefinition const*>(declaration)) + return make_shared<FunctionType>(*function); + else if (ContractDefinition const* contract = dynamic_cast<ContractDefinition const*>(declaration)) + return make_shared<ContractType>(*contract); + return shared_ptr<Type>(); } shared_ptr<Type> Type::fromMapping(Mapping const& _typeName) { shared_ptr<Type const> keyType = _typeName.getKeyType().toType(); + if (!keyType) + BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Error resolving type name.")); shared_ptr<Type const> valueType = _typeName.getValueType().toType(); + if (!valueType) + BOOST_THROW_EXCEPTION(_typeName.getValueType().createTypeError("Invalid type name")); return make_shared<MappingType>(keyType, valueType); } @@ -201,6 +212,15 @@ u256 BoolType::literalValue(Literal const& _literal) const BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Bool type constructed from non-boolean literal.")); } +bool ContractType::isExplicitlyConvertibleTo(Type const& _convertTo) const +{ + if (isImplicitlyConvertibleTo(_convertTo)) + return true; + if (_convertTo.getCategory() == Category::INTEGER) + return dynamic_cast<IntegerType const&>(_convertTo).isAddress(); + return false; +} + bool ContractType::operator==(Type const& _other) const { if (_other.getCategory() != getCategory()) @@ -217,6 +237,11 @@ u256 ContractType::getStorageSize() const return max<u256>(1, size); } +string ContractType::toString() const +{ + return "contract " + m_contract.getName(); +} + bool StructType::operator==(Type const& _other) const { if (_other.getCategory() != getCategory()) @@ -282,8 +307,7 @@ bool FunctionType::operator==(Type const& _other) const string FunctionType::toString() const { - //@todo nice string for function types - return "function(...)returns(...)"; + return "function " + m_function.getName(); } bool MappingType::operator==(Type const& _other) const |