diff options
author | Rhett Aultman <roadriverrail@gmail.com> | 2017-05-11 21:26:35 +0800 |
---|---|---|
committer | Rhett Aultman <roadriverrail@gmail.com> | 2017-05-30 22:28:31 +0800 |
commit | 89b60ffbd4c2dde26fa5e9f1d750729b5c89373e (patch) | |
tree | a4c464d4d40baaa260f071c1028f347bd287e44d /libsolidity/analysis/SyntaxChecker.cpp | |
parent | 0066a08aa8f6c469cde7947ec50ca662a32123a0 (diff) | |
download | dexon-solidity-89b60ffbd4c2dde26fa5e9f1d750729b5c89373e.tar dexon-solidity-89b60ffbd4c2dde26fa5e9f1d750729b5c89373e.tar.gz dexon-solidity-89b60ffbd4c2dde26fa5e9f1d750729b5c89373e.tar.bz2 dexon-solidity-89b60ffbd4c2dde26fa5e9f1d750729b5c89373e.tar.lz dexon-solidity-89b60ffbd4c2dde26fa5e9f1d750729b5c89373e.tar.xz dexon-solidity-89b60ffbd4c2dde26fa5e9f1d750729b5c89373e.tar.zst dexon-solidity-89b60ffbd4c2dde26fa5e9f1d750729b5c89373e.zip |
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
Diffstat (limited to 'libsolidity/analysis/SyntaxChecker.cpp')
-rw-r--r-- | libsolidity/analysis/SyntaxChecker.cpp | 41 |
1 files changed, 9 insertions, 32 deletions
diff --git a/libsolidity/analysis/SyntaxChecker.cpp b/libsolidity/analysis/SyntaxChecker.cpp index 94e82a87..35d71d85 100644 --- a/libsolidity/analysis/SyntaxChecker.cpp +++ b/libsolidity/analysis/SyntaxChecker.cpp @@ -19,6 +19,7 @@ #include <memory> #include <libsolidity/ast/AST.h> #include <libsolidity/analysis/SemVerHandler.h> +#include <libsolidity/interface/ErrorReporter.h> #include <libsolidity/interface/Version.h> using namespace std; @@ -29,27 +30,7 @@ using namespace dev::solidity; bool SyntaxChecker::checkSyntax(ASTNode const& _astRoot) { _astRoot.accept(*this); - return Error::containsOnlyWarnings(m_errors); -} - -void SyntaxChecker::warning(SourceLocation const& _location, string const& _description) -{ - auto err = make_shared<Error>(Error::Type::Warning); - *err << - errinfo_sourceLocation(_location) << - errinfo_comment(_description); - - m_errors.push_back(err); -} - -void SyntaxChecker::syntaxError(SourceLocation const& _location, std::string const& _description) -{ - auto err = make_shared<Error>(Error::Type::SyntaxError); - *err << - errinfo_sourceLocation(_location) << - errinfo_comment(_description); - - m_errors.push_back(err); + return Error::containsOnlyWarnings(m_errorReporter.errors()); } bool SyntaxChecker::visit(SourceUnit const&) @@ -74,11 +55,7 @@ void SyntaxChecker::endVisit(SourceUnit const& _sourceUnit) to_string(recommendedVersion.patch()); string(";\""); - auto err = make_shared<Error>(Error::Type::Warning); - *err << - errinfo_sourceLocation(_sourceUnit.location()) << - errinfo_comment(errorString); - m_errors.push_back(err); + m_errorReporter.warning(_sourceUnit.location(), errorString); } } @@ -87,7 +64,7 @@ bool SyntaxChecker::visit(PragmaDirective const& _pragma) solAssert(!_pragma.tokens().empty(), ""); solAssert(_pragma.tokens().size() == _pragma.literals().size(), ""); if (_pragma.tokens()[0] != Token::Identifier || _pragma.literals()[0] != "solidity") - syntaxError(_pragma.location(), "Unknown pragma \"" + _pragma.literals()[0] + "\""); + m_errorReporter.syntaxError(_pragma.location(), "Unknown pragma \"" + _pragma.literals()[0] + "\""); else { vector<Token::Value> tokens(_pragma.tokens().begin() + 1, _pragma.tokens().end()); @@ -96,7 +73,7 @@ bool SyntaxChecker::visit(PragmaDirective const& _pragma) auto matchExpression = parser.parse(); SemVerVersion currentVersion{string(VersionString)}; if (!matchExpression.matches(currentVersion)) - syntaxError( + m_errorReporter.syntaxError( _pragma.location(), "Source file requires different compiler version (current compiler is " + string(VersionString) + " - note that nightly builds are considered to be " @@ -116,7 +93,7 @@ bool SyntaxChecker::visit(ModifierDefinition const&) void SyntaxChecker::endVisit(ModifierDefinition const& _modifier) { if (!m_placeholderFound) - syntaxError(_modifier.body().location(), "Modifier body does not contain '_'."); + m_errorReporter.syntaxError(_modifier.body().location(), "Modifier body does not contain '_'."); m_placeholderFound = false; } @@ -146,7 +123,7 @@ bool SyntaxChecker::visit(Continue const& _continueStatement) { if (m_inLoopDepth <= 0) // we're not in a for/while loop, report syntax error - syntaxError(_continueStatement.location(), "\"continue\" has to be in a \"for\" or \"while\" loop."); + m_errorReporter.syntaxError(_continueStatement.location(), "\"continue\" has to be in a \"for\" or \"while\" loop."); return true; } @@ -154,14 +131,14 @@ bool SyntaxChecker::visit(Break const& _breakStatement) { if (m_inLoopDepth <= 0) // we're not in a for/while loop, report syntax error - syntaxError(_breakStatement.location(), "\"break\" has to be in a \"for\" or \"while\" loop."); + m_errorReporter.syntaxError(_breakStatement.location(), "\"break\" has to be in a \"for\" or \"while\" loop."); return true; } bool SyntaxChecker::visit(UnaryOperation const& _operation) { if (_operation.getOperator() == Token::Add) - warning(_operation.location(), "Use of unary + is deprecated."); + m_errorReporter.warning(_operation.location(), "Use of unary + is deprecated."); return true; } |