From 7bab242f5fd598a8e30fc1cef78917d615834c51 Mon Sep 17 00:00:00 2001 From: Christian Date: Fri, 24 Oct 2014 12:42:44 +0200 Subject: [PATCH] Use createTypeError everywhere and stream out Location. --- libsolidity/AST.cpp | 5 +---- libsolidity/AST.h | 3 +-- libsolidity/BaseTypes.h | 7 +++++++ libsolidity/Exceptions.h | 6 +++--- libsolidity/NameAndTypeResolver.cpp | 3 +-- 5 files changed, 13 insertions(+), 11 deletions(-) diff --git a/libsolidity/AST.cpp b/libsolidity/AST.cpp index 50c53bf37..357b9bd94 100644 --- a/libsolidity/AST.cpp +++ b/libsolidity/AST.cpp @@ -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() diff --git a/libsolidity/AST.h b/libsolidity/AST.h index 5679ed831..e94137a84 100644 --- a/libsolidity/AST.h +++ b/libsolidity/AST.h @@ -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/libsolidity/BaseTypes.h b/libsolidity/BaseTypes.h index fdf3f7b53..cfc14c7e9 100644 --- a/libsolidity/BaseTypes.h +++ b/libsolidity/BaseTypes.h @@ -22,6 +22,7 @@ #pragma once +#include 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/libsolidity/Exceptions.h b/libsolidity/Exceptions.h index 330c37788..5a48c47dd 100644 --- a/libsolidity/Exceptions.h +++ b/libsolidity/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 errinfo_sourcePosition; typedef boost::error_info errinfo_sourceLocation; diff --git a/libsolidity/NameAndTypeResolver.cpp b/libsolidity/NameAndTypeResolver.cpp index a56502727..c0467b036 100644 --- a/libsolidity/NameAndTypeResolver.cpp +++ b/libsolidity/NameAndTypeResolver.cpp @@ -182,8 +182,7 @@ bool ReferencesResolver::visit(UserDefinedTypeName& _typeName) StructDefinition* referencedStruct = dynamic_cast(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; }