From cfb8e74a75acac98042a0aef2d26ccfaf6749647 Mon Sep 17 00:00:00 2001 From: Lefteris Karapetsas Date: Fri, 5 Dec 2014 12:08:26 +0100 Subject: [PATCH] Introducing Docstring parsing error exception and style fixes --- libsolidity/Exceptions.h | 1 + libsolidity/InterfaceHandler.cpp | 22 ++++++++++------------ 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/libsolidity/Exceptions.h b/libsolidity/Exceptions.h index 1903c1dc2..8298c9810 100644 --- a/libsolidity/Exceptions.h +++ b/libsolidity/Exceptions.h @@ -36,6 +36,7 @@ struct TypeError: virtual Exception {}; struct DeclarationError: virtual Exception {}; struct CompilerError: virtual Exception {}; struct InternalCompilerError: virtual Exception {}; +struct DocstringParsingError: virtual Exception {}; typedef boost::error_info errinfo_sourcePosition; typedef boost::error_info errinfo_sourceLocation; diff --git a/libsolidity/InterfaceHandler.cpp b/libsolidity/InterfaceHandler.cpp index 1450d8fc3..ca02cc37d 100644 --- a/libsolidity/InterfaceHandler.cpp +++ b/libsolidity/InterfaceHandler.cpp @@ -28,7 +28,7 @@ std::unique_ptr InterfaceHandler::getDocumentation(std::shared_ptr< return getABIInterface(_contractDef); } - BOOST_THROW_EXCEPTION(CompilerError() << errinfo_comment("Internal error")); + BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Unknown documentation type")); return nullptr; } @@ -160,7 +160,7 @@ std::string::const_iterator InterfaceHandler::parseDocTagParam(std::string::cons // find param name auto currPos = std::find(_pos, _end, ' '); if (currPos == _end) - BOOST_THROW_EXCEPTION(CompilerError() << errinfo_comment("End of param name not found")); + BOOST_THROW_EXCEPTION(DocstringParsingError() << errinfo_comment("End of param name not found" + std::string(_pos, _end))); auto paramName = std::string(_pos, currPos); @@ -179,7 +179,7 @@ std::string::const_iterator InterfaceHandler::appendDocTagParam(std::string::con { // Should never be called with an empty vector if (asserts(!m_params.empty())) - BOOST_THROW_EXCEPTION(CompilerError() << errinfo_comment("Internal: Tried to append to empty parameter")); + BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Internal: Tried to append to empty parameter")); auto pair = m_params.back(); pair.second += " "; @@ -210,7 +210,7 @@ std::string::const_iterator InterfaceHandler::parseDocTag(std::string::const_ite else { // LTODO: Unknown tag, throw some form of warning and not just an exception - BOOST_THROW_EXCEPTION(CompilerError() << errinfo_comment("Unknown tag encountered")); + BOOST_THROW_EXCEPTION(DocstringParsingError() << errinfo_comment("Unknown tag " + _tag + " encountered")); } } else @@ -234,7 +234,7 @@ std::string::const_iterator InterfaceHandler::appendDocTag(std::string::const_it case DOCTAG_PARAM: return appendDocTagParam(_pos, _end); default: - BOOST_THROW_EXCEPTION(CompilerError() << errinfo_comment("Internal: Illegal documentation tag")); + BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Internal: Illegal documentation tag type")); break; } } @@ -254,17 +254,15 @@ void InterfaceHandler::parseDocString(std::string const& _string) // we found a tag auto tagNameEndPos = std::find(tagPos, end, ' '); if (tagNameEndPos == end) - BOOST_THROW_EXCEPTION(CompilerError() << errinfo_comment("End of tag not found")); + BOOST_THROW_EXCEPTION(DocstringParsingError() << + errinfo_comment("End of tag " + std::string(tagPos, tagNameEndPos) + "not found")); - currPos = parseDocTag(tagNameEndPos + 1, end, std::string(tagPos +1, tagNameEndPos)); + currPos = parseDocTag(tagNameEndPos + 1, end, std::string(tagPos + 1, tagNameEndPos)); } else if (m_lastTag != DOCTAG_NONE) // continuation of the previous tag currPos = appendDocTag(currPos + 1, end); - else // skip the line if a newline was found - { - if (currPos != end) - currPos = nlPos + 1; - } + else if (currPos != end) // skip the line if a newline was found + currPos = nlPos + 1; } }