mirror of
				https://github.com/ethereum/solidity
				synced 2023-10-03 13:03:40 +00:00 
			
		
		
		
	Merge pull request #14474 from ethereum/refactor-analysis-framework-error-filtering
Sane error filtering in `AnalysisFramework`
This commit is contained in:
		
						commit
						e357b8bc42
					
				| @ -63,14 +63,14 @@ AnalysisFramework::parseAnalyseAndReturnError( | |||||||
| 	_allowMultipleErrors = _allowMultipleErrors || _allowRecoveryErrors; | 	_allowMultipleErrors = _allowMultipleErrors || _allowRecoveryErrors; | ||||||
| 	if (!compiler().parse()) | 	if (!compiler().parse()) | ||||||
| 	{ | 	{ | ||||||
| 		BOOST_FAIL("Parsing contract failed in analysis test suite:" + formatErrors()); | 		BOOST_FAIL("Parsing contract failed in analysis test suite:" + formatErrors(compiler().errors())); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	compiler().analyze(); | 	compiler().analyze(); | ||||||
| 
 | 
 | ||||||
| 	ErrorList errors = filterErrors(compiler().errors(), _reportWarnings); | 	ErrorList errors = filteredErrors(_reportWarnings); | ||||||
| 	if (errors.size() > 1 && !_allowMultipleErrors) | 	if (errors.size() > 1 && !_allowMultipleErrors) | ||||||
| 		BOOST_FAIL("Multiple errors found: " + formatErrors()); | 		BOOST_FAIL("Multiple errors found: " + formatErrors(errors)); | ||||||
| 
 | 
 | ||||||
| 	return make_pair(&compiler().ast(""), std::move(errors)); | 	return make_pair(&compiler().ast(""), std::move(errors)); | ||||||
| } | } | ||||||
| @ -128,7 +128,7 @@ SourceUnit const* AnalysisFramework::parseAndAnalyse(string const& _source) | |||||||
| 	BOOST_REQUIRE(!!sourceAndError.first); | 	BOOST_REQUIRE(!!sourceAndError.first); | ||||||
| 	string message; | 	string message; | ||||||
| 	if (!sourceAndError.second.empty()) | 	if (!sourceAndError.second.empty()) | ||||||
| 		message = "Unexpected error: " + formatErrors(); | 		message = "Unexpected error: " + formatErrors(compiler().errors()); | ||||||
| 	BOOST_REQUIRE_MESSAGE(sourceAndError.second.empty(), message); | 	BOOST_REQUIRE_MESSAGE(sourceAndError.second.empty(), message); | ||||||
| 	return sourceAndError.first; | 	return sourceAndError.first; | ||||||
| } | } | ||||||
| @ -146,17 +146,31 @@ ErrorList AnalysisFramework::expectError(std::string const& _source, bool _warni | |||||||
| 	return sourceAndErrors.second; | 	return sourceAndErrors.second; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| string AnalysisFramework::formatErrors() const | string AnalysisFramework::formatErrors( | ||||||
|  | 	langutil::ErrorList _errors, | ||||||
|  | 	bool _colored, | ||||||
|  | 	bool _withErrorIds | ||||||
|  | ) const | ||||||
| { | { | ||||||
| 	string message; | 	string message; | ||||||
| 	for (auto const& error: compiler().errors()) | 	for (auto const& error: _errors) | ||||||
| 		message += formatError(*error); | 		message += formatError(*error, _colored, _withErrorIds); | ||||||
| 	return message; | 	return message; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| string AnalysisFramework::formatError(Error const& _error) const | string AnalysisFramework::formatError( | ||||||
|  | 	Error const& _error, | ||||||
|  | 	bool _colored, | ||||||
|  | 	bool _withErrorIds | ||||||
|  | ) const | ||||||
| { | { | ||||||
| 	return SourceReferenceFormatter::formatErrorInformation(_error, *m_compiler); | 	return SourceReferenceFormatter::formatExceptionInformation( | ||||||
|  | 		_error, | ||||||
|  | 		_error.type(), | ||||||
|  | 		*m_compiler, | ||||||
|  | 		_colored, | ||||||
|  | 		_withErrorIds | ||||||
|  | 	); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| ContractDefinition const* AnalysisFramework::retrieveContractByName(SourceUnit const& _source, string const& _name) | ContractDefinition const* AnalysisFramework::retrieveContractByName(SourceUnit const& _source, string const& _name) | ||||||
|  | |||||||
| @ -57,8 +57,16 @@ protected: | |||||||
| 	bool success(std::string const& _source); | 	bool success(std::string const& _source); | ||||||
| 	langutil::ErrorList expectError(std::string const& _source, bool _warning = false, bool _allowMultiple = false); | 	langutil::ErrorList expectError(std::string const& _source, bool _warning = false, bool _allowMultiple = false); | ||||||
| 
 | 
 | ||||||
| 	std::string formatErrors() const; | 	std::string formatErrors( | ||||||
| 	std::string formatError(langutil::Error const& _error) const; | 		langutil::ErrorList _errors, | ||||||
|  | 		bool _colored = false, | ||||||
|  | 		bool _withErrorIds = false | ||||||
|  | 	) const; | ||||||
|  | 	std::string formatError( | ||||||
|  | 		langutil::Error const& _error, | ||||||
|  | 		bool _colored = false, | ||||||
|  | 		bool _withErrorIds = false | ||||||
|  | 	) const; | ||||||
| 
 | 
 | ||||||
| 	static ContractDefinition const* retrieveContractByName(SourceUnit const& _source, std::string const& _name); | 	static ContractDefinition const* retrieveContractByName(SourceUnit const& _source, std::string const& _name); | ||||||
| 	static FunctionTypePointer retrieveFunctionBySignature( | 	static FunctionTypePointer retrieveFunctionBySignature( | ||||||
| @ -66,8 +74,12 @@ protected: | |||||||
| 		std::string const& _signature | 		std::string const& _signature | ||||||
| 	); | 	); | ||||||
| 
 | 
 | ||||||
| 	// filter out the warnings in m_warningsToFilter or all warnings and infos if _includeWarningsAndInfos is false
 | 	/// filter out the warnings in m_warningsToFilter or all warnings and infos if _includeWarningsAndInfos is false
 | ||||||
| 	langutil::ErrorList filterErrors(langutil::ErrorList const& _errorList, bool _includeWarningsAndInfos) const; | 	langutil::ErrorList filterErrors(langutil::ErrorList const& _errorList, bool _includeWarningsAndInfos = true) const; | ||||||
|  | 	langutil::ErrorList filteredErrors(bool _includeWarningsAndInfos = true) const | ||||||
|  | 	{ | ||||||
|  | 		return filterErrors(compiler().errors(), _includeWarningsAndInfos); | ||||||
|  | 	} | ||||||
| 
 | 
 | ||||||
| 	std::vector<std::string> m_warningsToFilter = {"This is a pre-release compiler version"}; | 	std::vector<std::string> m_warningsToFilter = {"This is a pre-release compiler version"}; | ||||||
| 	std::vector<std::string> m_messagesToCut = {"Source file requires different compiler version (current compiler is"}; | 	std::vector<std::string> m_messagesToCut = {"Source file requires different compiler version (current compiler is"}; | ||||||
| @ -151,7 +163,7 @@ do \ | |||||||
| 	auto sourceAndError = parseAnalyseAndReturnError((text), true); \ | 	auto sourceAndError = parseAnalyseAndReturnError((text), true); \ | ||||||
| 	std::string message; \ | 	std::string message; \ | ||||||
| 	if (!sourceAndError.second.empty()) \ | 	if (!sourceAndError.second.empty()) \ | ||||||
| 		message = formatErrors();\ | 		message = formatErrors(compiler().errors());\ | ||||||
| 	BOOST_CHECK_MESSAGE(sourceAndError.second.empty(), message); \ | 	BOOST_CHECK_MESSAGE(sourceAndError.second.empty(), message); \ | ||||||
| } \ | } \ | ||||||
| while(0) | while(0) | ||||||
|  | |||||||
| @ -118,8 +118,7 @@ TestCase::TestResult GasTest::run(ostream& _stream, string const& _linePrefix, b | |||||||
| 
 | 
 | ||||||
| 	if (!compiler().parseAndAnalyze() || !compiler().compile()) | 	if (!compiler().parseAndAnalyze() || !compiler().compile()) | ||||||
| 	{ | 	{ | ||||||
| 		SourceReferenceFormatter{_stream, compiler(), _formatted, false} | 		_stream << formatErrors(filteredErrors(), _formatted); | ||||||
| 			.printErrorInformation(compiler().errors()); |  | ||||||
| 		return TestResult::FatalError; | 		return TestResult::FatalError; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -44,7 +44,10 @@ TestCase::TestResult MemoryGuardTest::run(ostream& _stream, string const& _lineP | |||||||
| 	compiler().setViaIR(true); | 	compiler().setViaIR(true); | ||||||
| 	compiler().setOptimiserSettings(OptimiserSettings::none()); | 	compiler().setOptimiserSettings(OptimiserSettings::none()); | ||||||
| 	if (!compiler().compile()) | 	if (!compiler().compile()) | ||||||
|  | 	{ | ||||||
|  | 		_stream << formatErrors(filteredErrors(), _formatted); | ||||||
| 		return TestResult::FatalError; | 		return TestResult::FatalError; | ||||||
|  | 	} | ||||||
| 
 | 
 | ||||||
| 	m_obtainedResult.clear(); | 	m_obtainedResult.clear(); | ||||||
| 	for (string contractName: compiler().contractNames()) | 	for (string contractName: compiler().contractNames()) | ||||||
|  | |||||||
| @ -42,7 +42,10 @@ BOOST_AUTO_TEST_CASE(does_not_include_creation_time_only_internal_functions) | |||||||
| 	)"; | 	)"; | ||||||
| 	compiler().setOptimiserSettings(solidity::test::CommonOptions::get().optimize); | 	compiler().setOptimiserSettings(solidity::test::CommonOptions::get().optimize); | ||||||
| 	BOOST_REQUIRE(success(sourceCode)); | 	BOOST_REQUIRE(success(sourceCode)); | ||||||
| 	BOOST_REQUIRE_MESSAGE(compiler().compile(), "Compiling contract failed"); | 	BOOST_REQUIRE_MESSAGE( | ||||||
|  | 		compiler().compile(), | ||||||
|  | 		"Contract compilation failed:\n" + formatErrors(filteredErrors(), true /* _colored */) | ||||||
|  | 	); | ||||||
| 	bytes const& creationBytecode = solidity::test::bytecodeSansMetadata(compiler().object("C").bytecode); | 	bytes const& creationBytecode = solidity::test::bytecodeSansMetadata(compiler().object("C").bytecode); | ||||||
| 	bytes const& runtimeBytecode = solidity::test::bytecodeSansMetadata(compiler().runtimeObject("C").bytecode); | 	bytes const& runtimeBytecode = solidity::test::bytecodeSansMetadata(compiler().runtimeObject("C").bytecode); | ||||||
| 	BOOST_CHECK(creationBytecode.size() >= 90); | 	BOOST_CHECK(creationBytecode.size() >= 90); | ||||||
|  | |||||||
| @ -111,7 +111,7 @@ void SyntaxTest::parseAndAnalyze() | |||||||
| 
 | 
 | ||||||
| void SyntaxTest::filterObtainedErrors() | void SyntaxTest::filterObtainedErrors() | ||||||
| { | { | ||||||
| 	for (auto const& currentError: filterErrors(compiler().errors(), true)) | 	for (auto const& currentError: filteredErrors()) | ||||||
| 	{ | 	{ | ||||||
| 		int locationStart = -1; | 		int locationStart = -1; | ||||||
| 		int locationEnd = -1; | 		int locationEnd = -1; | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user