diff options
author | Christian <c@ethdev.com> | 2014-10-24 18:42:44 +0800 |
---|---|---|
committer | Christian <c@ethdev.com> | 2014-10-24 18:42:44 +0800 |
commit | 1ae1fc66e2d02fc17d4148a553a59ead402b9f54 (patch) | |
tree | 4c7378c2d1568a1f4bbffc95ea41bc3529d46be9 | |
parent | 094ee44f721054518ff384aef7cde1afe649636d (diff) | |
download | dexon-solidity-1ae1fc66e2d02fc17d4148a553a59ead402b9f54.tar dexon-solidity-1ae1fc66e2d02fc17d4148a553a59ead402b9f54.tar.gz dexon-solidity-1ae1fc66e2d02fc17d4148a553a59ead402b9f54.tar.bz2 dexon-solidity-1ae1fc66e2d02fc17d4148a553a59ead402b9f54.tar.lz dexon-solidity-1ae1fc66e2d02fc17d4148a553a59ead402b9f54.tar.xz dexon-solidity-1ae1fc66e2d02fc17d4148a553a59ead402b9f54.tar.zst dexon-solidity-1ae1fc66e2d02fc17d4148a553a59ead402b9f54.zip |
Use createTypeError everywhere and stream out Location.
-rw-r--r-- | AST.cpp | 5 | ||||
-rw-r--r-- | AST.h | 3 | ||||
-rw-r--r-- | BaseTypes.h | 7 | ||||
-rw-r--r-- | Exceptions.h | 6 | ||||
-rw-r--r-- | NameAndTypeResolver.cpp | 3 |
5 files changed, 13 insertions, 11 deletions
@@ -257,8 +257,7 @@ void Statement::expectType(Expression& _expression, const Type& _expectedType) { _expression.checkTypeRequirements(); if (!_expression.getType()->isImplicitlyConvertibleTo(_expectedType)) - BOOST_THROW_EXCEPTION(TypeError() << errinfo_sourceLocation(_expression.getLocation()) - << errinfo_comment("Type not implicitly convertible to expected type.")); + BOOST_THROW_EXCEPTION(_expression.createTypeError("Type not implicitly convertible to expected type.")); //@todo provide more information to the exception } @@ -407,9 +406,7 @@ void FunctionCall::checkTypeRequirements() m_type = fun.getReturnParameterList()->getParameters().front()->getType(); } else - { BOOST_THROW_EXCEPTION(createTypeError("Type does not support invocation.")); - } } void MemberAccess::checkTypeRequirements() @@ -57,8 +57,7 @@ public: Location const& getLocation() const { return m_location; } -protected: - /// Creates a @ref TypeError exception and decorates it with the current location and + /// Creates a @ref TypeError exception and decorates it with the location of the node and /// the given description TypeError createTypeError(std::string const& _description); diff --git a/BaseTypes.h b/BaseTypes.h index fdf3f7b5..cfc14c7e 100644 --- a/BaseTypes.h +++ b/BaseTypes.h @@ -22,6 +22,7 @@ #pragma once +#include <ostream> namespace dev { @@ -41,5 +42,11 @@ struct Location int end; }; +/// Stream output for Location (used e.g. in boost exceptions). +inline std::ostream& operator<<(std::ostream& _out, Location const& _location) +{ + return _out << "[" << _location.start << "," << _location.end << ")"; +} + } } diff --git a/Exceptions.h b/Exceptions.h index 330c3778..5a48c47d 100644 --- a/Exceptions.h +++ b/Exceptions.h @@ -31,9 +31,9 @@ namespace dev namespace solidity { -struct ParserError: public virtual Exception {}; -struct TypeError: public virtual Exception {}; -struct DeclarationError: public virtual Exception {}; +struct ParserError: virtual Exception {}; +struct TypeError: virtual Exception {}; +struct DeclarationError: virtual Exception {}; typedef boost::error_info<struct tag_sourcePosition, int> errinfo_sourcePosition; typedef boost::error_info<struct tag_sourceLocation, Location> errinfo_sourceLocation; diff --git a/NameAndTypeResolver.cpp b/NameAndTypeResolver.cpp index a5650272..c0467b03 100644 --- a/NameAndTypeResolver.cpp +++ b/NameAndTypeResolver.cpp @@ -182,8 +182,7 @@ bool ReferencesResolver::visit(UserDefinedTypeName& _typeName) StructDefinition* referencedStruct = dynamic_cast<StructDefinition*>(declaration); //@todo later, contracts are also valid types if (referencedStruct == nullptr) - BOOST_THROW_EXCEPTION(TypeError() << errinfo_sourceLocation(_typeName.getLocation()) - << errinfo_comment("Identifier does not name a type name.")); + BOOST_THROW_EXCEPTION(_typeName.createTypeError("Identifier does not name a type name.")); _typeName.setReferencedStruct(*referencedStruct); return false; } |