aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2017-05-30 22:45:36 +0800
committerGitHub <noreply@github.com>2017-05-30 22:45:36 +0800
commit254b55728f66ea164e9085700a294ac4837f2029 (patch)
treea4c464d4d40baaa260f071c1028f347bd287e44d /test
parent0066a08aa8f6c469cde7947ec50ca662a32123a0 (diff)
parent89b60ffbd4c2dde26fa5e9f1d750729b5c89373e (diff)
downloaddexon-solidity-254b55728f66ea164e9085700a294ac4837f2029.tar.gz
dexon-solidity-254b55728f66ea164e9085700a294ac4837f2029.tar.zst
dexon-solidity-254b55728f66ea164e9085700a294ac4837f2029.zip
Merge pull request #2264 from roadriverrail/refactor_error_log
Refactor error reporting
Diffstat (limited to 'test')
-rw-r--r--test/libjulia/Parser.cpp9
-rw-r--r--test/libsolidity/Assembly.cpp14
-rw-r--r--test/libsolidity/SolidityExpressionCompiler.cpp10
-rw-r--r--test/libsolidity/SolidityNameAndTypeResolution.cpp25
-rw-r--r--test/libsolidity/SolidityParser.cpp5
5 files changed, 36 insertions, 27 deletions
diff --git a/test/libjulia/Parser.cpp b/test/libjulia/Parser.cpp
index b82c446a..afeb95f8 100644
--- a/test/libjulia/Parser.cpp
+++ b/test/libjulia/Parser.cpp
@@ -45,16 +45,16 @@ namespace test
namespace
{
-bool parse(string const& _source, ErrorList& errors)
+bool parse(string const& _source, ErrorReporter& errorReporter)
{
try
{
auto scanner = make_shared<Scanner>(CharStream(_source));
- auto parserResult = assembly::Parser(errors, true).parse(scanner);
+ auto parserResult = assembly::Parser(errorReporter, true).parse(scanner);
if (parserResult)
{
assembly::AsmAnalysisInfo analysisInfo;
- return (assembly::AsmAnalyzer(analysisInfo, errors, true)).analyze(*parserResult);
+ return (assembly::AsmAnalyzer(analysisInfo, errorReporter, true)).analyze(*parserResult);
}
}
catch (FatalError const&)
@@ -67,7 +67,8 @@ bool parse(string const& _source, ErrorList& errors)
boost::optional<Error> parseAndReturnFirstError(string const& _source, bool _allowWarnings = true)
{
ErrorList errors;
- if (!parse(_source, errors))
+ ErrorReporter errorReporter(errors);
+ if (!parse(_source, errorReporter))
{
BOOST_REQUIRE_EQUAL(errors.size(), 1);
return *errors.front();
diff --git a/test/libsolidity/Assembly.cpp b/test/libsolidity/Assembly.cpp
index c4ec0d20..e52f4d50 100644
--- a/test/libsolidity/Assembly.cpp
+++ b/test/libsolidity/Assembly.cpp
@@ -31,6 +31,7 @@
#include <libsolidity/codegen/Compiler.h>
#include <libsolidity/ast/AST.h>
#include <libsolidity/analysis/TypeChecker.h>
+#include <libsolidity/interface/ErrorReporter.h>
using namespace std;
using namespace dev::eth;
@@ -48,28 +49,29 @@ namespace
eth::AssemblyItems compileContract(const string& _sourceCode)
{
ErrorList errors;
- Parser parser(errors);
+ ErrorReporter errorReporter(errors);
+ Parser parser(errorReporter);
ASTPointer<SourceUnit> sourceUnit;
BOOST_REQUIRE_NO_THROW(sourceUnit = parser.parse(make_shared<Scanner>(CharStream(_sourceCode))));
BOOST_CHECK(!!sourceUnit);
map<ASTNode const*, shared_ptr<DeclarationContainer>> scopes;
- NameAndTypeResolver resolver({}, scopes, errors);
- solAssert(Error::containsOnlyWarnings(errors), "");
+ NameAndTypeResolver resolver({}, scopes, errorReporter);
+ solAssert(Error::containsOnlyWarnings(errorReporter.errors()), "");
resolver.registerDeclarations(*sourceUnit);
for (ASTPointer<ASTNode> const& node: sourceUnit->nodes())
if (ContractDefinition* contract = dynamic_cast<ContractDefinition*>(node.get()))
{
BOOST_REQUIRE_NO_THROW(resolver.resolveNamesAndTypes(*contract));
- if (!Error::containsOnlyWarnings(errors))
+ if (!Error::containsOnlyWarnings(errorReporter.errors()))
return AssemblyItems();
}
for (ASTPointer<ASTNode> const& node: sourceUnit->nodes())
if (ContractDefinition* contract = dynamic_cast<ContractDefinition*>(node.get()))
{
- TypeChecker checker(errors);
+ TypeChecker checker(errorReporter);
BOOST_REQUIRE_NO_THROW(checker.checkTypeRequirements(*contract));
- if (!Error::containsOnlyWarnings(errors))
+ if (!Error::containsOnlyWarnings(errorReporter.errors()))
return AssemblyItems();
}
for (ASTPointer<ASTNode> const& node: sourceUnit->nodes())
diff --git a/test/libsolidity/SolidityExpressionCompiler.cpp b/test/libsolidity/SolidityExpressionCompiler.cpp
index 3116aea8..58efa0a2 100644
--- a/test/libsolidity/SolidityExpressionCompiler.cpp
+++ b/test/libsolidity/SolidityExpressionCompiler.cpp
@@ -29,6 +29,7 @@
#include <libsolidity/codegen/ExpressionCompiler.h>
#include <libsolidity/ast/AST.h>
#include <libsolidity/analysis/TypeChecker.h>
+#include <libsolidity/interface/ErrorReporter.h>
#include "../TestHelper.h"
using namespace std;
@@ -98,7 +99,8 @@ bytes compileFirstExpression(
try
{
ErrorList errors;
- sourceUnit = Parser(errors).parse(make_shared<Scanner>(CharStream(_sourceCode)));
+ ErrorReporter errorReporter(errors);
+ sourceUnit = Parser(errorReporter).parse(make_shared<Scanner>(CharStream(_sourceCode)));
if (!sourceUnit)
return bytes();
}
@@ -114,8 +116,9 @@ bytes compileFirstExpression(
declarations.push_back(variable.get());
ErrorList errors;
+ ErrorReporter errorReporter(errors);
map<ASTNode const*, shared_ptr<DeclarationContainer>> scopes;
- NameAndTypeResolver resolver(declarations, scopes, errors);
+ NameAndTypeResolver resolver(declarations, scopes, errorReporter);
resolver.registerDeclarations(*sourceUnit);
vector<ContractDefinition const*> inheritanceHierarchy;
@@ -128,7 +131,8 @@ bytes compileFirstExpression(
for (ASTPointer<ASTNode> const& node: sourceUnit->nodes())
if (ContractDefinition* contract = dynamic_cast<ContractDefinition*>(node.get()))
{
- TypeChecker typeChecker(errors);
+ ErrorReporter errorReporter(errors);
+ TypeChecker typeChecker(errorReporter);
BOOST_REQUIRE(typeChecker.checkTypeRequirements(*contract));
}
for (ASTPointer<ASTNode> const& node: sourceUnit->nodes())
diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp
index 97c4303f..0553c691 100644
--- a/test/libsolidity/SolidityNameAndTypeResolution.cpp
+++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp
@@ -30,7 +30,7 @@
#include <libsolidity/analysis/StaticAnalyzer.h>
#include <libsolidity/analysis/PostTypeChecker.h>
#include <libsolidity/analysis/SyntaxChecker.h>
-#include <libsolidity/interface/Exceptions.h>
+#include <libsolidity/interface/ErrorReporter.h>
#include <libsolidity/analysis/GlobalContext.h>
#include <libsolidity/analysis/TypeChecker.h>
@@ -56,7 +56,8 @@ parseAnalyseAndReturnError(string const& _source, bool _reportWarnings = false,
// Silence compiler version warning
string source = _insertVersionPragma ? "pragma solidity >=0.0;\n" + _source : _source;
ErrorList errors;
- Parser parser(errors);
+ ErrorReporter errorReporter(errors);
+ Parser parser(errorReporter);
ASTPointer<SourceUnit> sourceUnit;
// catch exceptions for a transition period
try
@@ -65,14 +66,14 @@ parseAnalyseAndReturnError(string const& _source, bool _reportWarnings = false,
if(!sourceUnit)
BOOST_FAIL("Parsing failed in type checker test.");
- SyntaxChecker syntaxChecker(errors);
+ SyntaxChecker syntaxChecker(errorReporter);
if (!syntaxChecker.checkSyntax(*sourceUnit))
- return make_pair(sourceUnit, errors.at(0));
+ return make_pair(sourceUnit, errorReporter.errors().at(0));
std::shared_ptr<GlobalContext> globalContext = make_shared<GlobalContext>();
map<ASTNode const*, shared_ptr<DeclarationContainer>> scopes;
- NameAndTypeResolver resolver(globalContext->declarations(), scopes, errors);
- solAssert(Error::containsOnlyWarnings(errors), "");
+ NameAndTypeResolver resolver(globalContext->declarations(), scopes, errorReporter);
+ solAssert(Error::containsOnlyWarnings(errorReporter.errors()), "");
resolver.registerDeclarations(*sourceUnit);
bool success = true;
@@ -92,19 +93,19 @@ parseAnalyseAndReturnError(string const& _source, bool _reportWarnings = false,
globalContext->setCurrentContract(*contract);
resolver.updateDeclaration(*globalContext->currentThis());
- TypeChecker typeChecker(errors);
+ TypeChecker typeChecker(errorReporter);
bool success = typeChecker.checkTypeRequirements(*contract);
- BOOST_CHECK(success || !errors.empty());
+ BOOST_CHECK(success || !errorReporter.errors().empty());
}
if (success)
- if (!PostTypeChecker(errors).check(*sourceUnit))
+ if (!PostTypeChecker(errorReporter).check(*sourceUnit))
success = false;
if (success)
- if (!StaticAnalyzer(errors).analyze(*sourceUnit))
+ if (!StaticAnalyzer(errorReporter).analyze(*sourceUnit))
success = false;
- if (errors.size() > 1 && !_allowMultipleErrors)
+ if (errorReporter.errors().size() > 1 && !_allowMultipleErrors)
BOOST_FAIL("Multiple errors found");
- for (auto const& currentError: errors)
+ for (auto const& currentError: errorReporter.errors())
{
if (
(_reportWarnings && currentError->type() == Error::Type::Warning) ||
diff --git a/test/libsolidity/SolidityParser.cpp b/test/libsolidity/SolidityParser.cpp
index 6e33aba5..31dfada9 100644
--- a/test/libsolidity/SolidityParser.cpp
+++ b/test/libsolidity/SolidityParser.cpp
@@ -24,7 +24,7 @@
#include <memory>
#include <libsolidity/parsing/Scanner.h>
#include <libsolidity/parsing/Parser.h>
-#include <libsolidity/interface/Exceptions.h>
+#include <libsolidity/interface/ErrorReporter.h>
#include "../TestHelper.h"
#include "ErrorCheck.h"
@@ -41,7 +41,8 @@ namespace
{
ASTPointer<ContractDefinition> parseText(std::string const& _source, ErrorList& _errors)
{
- ASTPointer<SourceUnit> sourceUnit = Parser(_errors).parse(std::make_shared<Scanner>(CharStream(_source)));
+ ErrorReporter errorReporter(_errors);
+ ASTPointer<SourceUnit> sourceUnit = Parser(errorReporter).parse(std::make_shared<Scanner>(CharStream(_source)));
if (!sourceUnit)
return ASTPointer<ContractDefinition>();
for (ASTPointer<ASTNode> const& node: sourceUnit->nodes())