From 89b60ffbd4c2dde26fa5e9f1d750729b5c89373e Mon Sep 17 00:00:00 2001 From: Rhett Aultman Date: Thu, 11 May 2017 06:26:35 -0700 Subject: Refactor error reporting This commit introduces ErrorReporter, a utility class which consolidates all of the error logging functionality into a common set of functions. It also replaces all direct interactions with an ErrorList with calls to an ErrorReporter. This commit resolves issue #2209 --- libsolidity/parsing/DocStringParser.cpp | 9 ++++----- libsolidity/parsing/DocStringParser.h | 7 ++++--- libsolidity/parsing/Parser.cpp | 6 +++--- libsolidity/parsing/Parser.h | 2 +- libsolidity/parsing/ParserBase.cpp | 11 +++-------- libsolidity/parsing/ParserBase.h | 6 +++--- 6 files changed, 18 insertions(+), 23 deletions(-) (limited to 'libsolidity/parsing') diff --git a/libsolidity/parsing/DocStringParser.cpp b/libsolidity/parsing/DocStringParser.cpp index 8e912126..cd6c1d8a 100644 --- a/libsolidity/parsing/DocStringParser.cpp +++ b/libsolidity/parsing/DocStringParser.cpp @@ -1,5 +1,6 @@ #include +#include #include #include @@ -51,9 +52,9 @@ string::const_iterator skipWhitespace( } -bool DocStringParser::parse(string const& _docString, ErrorList& _errors) +bool DocStringParser::parse(string const& _docString, ErrorReporter& _errorReporter) { - m_errors = &_errors; + m_errorReporter = &_errorReporter; m_errorsOccurred = false; m_lastTag = nullptr; @@ -172,8 +173,6 @@ void DocStringParser::newTag(string const& _tagName) void DocStringParser::appendError(string const& _description) { - auto err = make_shared(Error::Type::DocstringParsingError); - *err << errinfo_comment(_description); - m_errors->push_back(err); m_errorsOccurred = true; + m_errorReporter->docstringParsingError(_description); } diff --git a/libsolidity/parsing/DocStringParser.h b/libsolidity/parsing/DocStringParser.h index c7f81c55..5f2819cc 100644 --- a/libsolidity/parsing/DocStringParser.h +++ b/libsolidity/parsing/DocStringParser.h @@ -23,7 +23,6 @@ #pragma once #include -#include #include namespace dev @@ -31,12 +30,14 @@ namespace dev namespace solidity { +class ErrorReporter; + class DocStringParser { public: /// Parse the given @a _docString and stores the parsed components internally. /// @returns false on error and appends the error to @a _errors. - bool parse(std::string const& _docString, ErrorList& _errors); + bool parse(std::string const& _docString, ErrorReporter& _errorReporter); std::multimap const& tags() const { return m_docTags; } @@ -62,7 +63,7 @@ private: /// Mapping tag name -> content. std::multimap m_docTags; DocTag* m_lastTag = nullptr; - ErrorList* m_errors = nullptr; + ErrorReporter* m_errorReporter = nullptr; bool m_errorsOccurred = false; }; diff --git a/libsolidity/parsing/Parser.cpp b/libsolidity/parsing/Parser.cpp index 5b318b2b..ec27f89b 100644 --- a/libsolidity/parsing/Parser.cpp +++ b/libsolidity/parsing/Parser.cpp @@ -26,7 +26,7 @@ #include #include #include -#include +#include using namespace std; @@ -94,7 +94,7 @@ ASTPointer Parser::parse(shared_ptr const& _scanner) } catch (FatalError const&) { - if (m_errors.empty()) + if (m_errorReporter.errors().empty()) throw; // Something is weird here, rather throw again. return nullptr; } @@ -865,7 +865,7 @@ ASTPointer Parser::parseInlineAssembly(ASTPointer con m_scanner->next(); } - assembly::Parser asmParser(m_errors); + assembly::Parser asmParser(m_errorReporter); shared_ptr block = asmParser.parse(m_scanner); nodeFactory.markEndPosition(); return nodeFactory.createNode(_docString, block); diff --git a/libsolidity/parsing/Parser.h b/libsolidity/parsing/Parser.h index 5ec3dbed..19631c58 100644 --- a/libsolidity/parsing/Parser.h +++ b/libsolidity/parsing/Parser.h @@ -35,7 +35,7 @@ class Scanner; class Parser: public ParserBase { public: - Parser(ErrorList& _errors): ParserBase(_errors) {} + Parser(ErrorReporter& _errorReporter): ParserBase(_errorReporter) {} ASTPointer parse(std::shared_ptr const& _scanner); diff --git a/libsolidity/parsing/ParserBase.cpp b/libsolidity/parsing/ParserBase.cpp index ac103bda..9987b82c 100644 --- a/libsolidity/parsing/ParserBase.cpp +++ b/libsolidity/parsing/ParserBase.cpp @@ -22,6 +22,7 @@ #include #include +#include using namespace std; using namespace dev; @@ -82,16 +83,10 @@ void ParserBase::expectToken(Token::Value _value) void ParserBase::parserError(string const& _description) { - auto err = make_shared(Error::Type::ParserError); - *err << - errinfo_sourceLocation(SourceLocation(position(), position(), sourceName())) << - errinfo_comment(_description); - - m_errors.push_back(err); + m_errorReporter.parserError(SourceLocation(position(), position(), sourceName()), _description); } void ParserBase::fatalParserError(string const& _description) { - parserError(_description); - BOOST_THROW_EXCEPTION(FatalError()); + m_errorReporter.fatalParserError(SourceLocation(position(), position(), sourceName()), _description); } diff --git a/libsolidity/parsing/ParserBase.h b/libsolidity/parsing/ParserBase.h index 18b39a5e..ae56cead 100644 --- a/libsolidity/parsing/ParserBase.h +++ b/libsolidity/parsing/ParserBase.h @@ -23,7 +23,6 @@ #pragma once #include -#include #include #include @@ -32,12 +31,13 @@ namespace dev namespace solidity { +class ErrorReporter; class Scanner; class ParserBase { public: - ParserBase(ErrorList& errors): m_errors(errors) {} + ParserBase(ErrorReporter& errorReporter): m_errorReporter(errorReporter) {} std::shared_ptr const& sourceName() const; @@ -67,7 +67,7 @@ protected: std::shared_ptr m_scanner; /// The reference to the list of errors and warning to add errors/warnings during parsing - ErrorList& m_errors; + ErrorReporter& m_errorReporter; }; } -- cgit v1.2.3