From b1db6eac8b298967b73e3f09c75f12f566b3074c Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Wed, 29 Mar 2017 22:40:10 +0100 Subject: Introduce formatExceptionInformation --- libsolidity/interface/SourceReferenceFormatter.h | 11 +++++++++++ solc/jsonCompiler.cpp | 4 +--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/libsolidity/interface/SourceReferenceFormatter.h b/libsolidity/interface/SourceReferenceFormatter.h index 7034f4ab..e8676d60 100644 --- a/libsolidity/interface/SourceReferenceFormatter.h +++ b/libsolidity/interface/SourceReferenceFormatter.h @@ -23,6 +23,7 @@ #pragma once #include +#include #include #include @@ -53,6 +54,16 @@ public: std::string const& _name, ScannerFromSourceNameFun const& _scannerFromSourceName ); + static std::string formatExceptionInformation( + Exception const& _exception, + std::string const& _name, + ScannerFromSourceNameFun const& _scannerFromSourceName + ) + { + std::ostringstream errorOutput; + printExceptionInformation(errorOutput, _exception, _name, _scannerFromSourceName); + return errorOutput.str(); + } private: /// Prints source name if location is given. static void printSourceName( diff --git a/solc/jsonCompiler.cpp b/solc/jsonCompiler.cpp index 45322117..f55d0c8d 100644 --- a/solc/jsonCompiler.cpp +++ b/solc/jsonCompiler.cpp @@ -56,9 +56,7 @@ string formatError( function const& _scannerFromSourceName ) { - ostringstream errorOutput; - SourceReferenceFormatter::printExceptionInformation(errorOutput, _exception, _name, _scannerFromSourceName); - return errorOutput.str(); + return SourceReferenceFormatter::formatExceptionInformation(_exception, _name, _scannerFromSourceName); } Json::Value functionHashes(ContractDefinition const& _contract) -- cgit From a182dfe26695b24704047265cbe1cac80d0f8a83 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Mon, 10 Apr 2017 13:05:50 +0100 Subject: Remove empty wrapper formatError from jsonCompiler --- solc/jsonCompiler.cpp | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/solc/jsonCompiler.cpp b/solc/jsonCompiler.cpp index f55d0c8d..0bf890af 100644 --- a/solc/jsonCompiler.cpp +++ b/solc/jsonCompiler.cpp @@ -50,15 +50,6 @@ extern "C" { typedef void (*CStyleReadFileCallback)(char const* _path, char** o_contents, char** o_error); } -string formatError( - Exception const& _exception, - string const& _name, - function const& _scannerFromSourceName -) -{ - return SourceReferenceFormatter::formatExceptionInformation(_exception, _name, _scannerFromSourceName); -} - Json::Value functionHashes(ContractDefinition const& _contract) { Json::Value functionHashes(Json::objectValue); @@ -168,7 +159,7 @@ string compile(StringMap const& _sources, bool _optimize, CStyleReadFileCallback for (auto const& error: compiler.errors()) { auto err = dynamic_pointer_cast(error); - errors.append(formatError( + errors.append(SourceReferenceFormatter::formatExceptionInformation( *error, (err->type() == Error::Type::Warning) ? "Warning" : "Error", scannerFromSourceName @@ -178,19 +169,19 @@ string compile(StringMap const& _sources, bool _optimize, CStyleReadFileCallback } catch (Error const& error) { - errors.append(formatError(error, error.typeName(), scannerFromSourceName)); + errors.append(SourceReferenceFormatter::formatExceptionInformation(error, error.typeName(), scannerFromSourceName)); } catch (CompilerError const& exception) { - errors.append(formatError(exception, "Compiler error (" + exception.lineInfo() + ")", scannerFromSourceName)); + errors.append(SourceReferenceFormatter::formatExceptionInformation(exception, "Compiler error (" + exception.lineInfo() + ")", scannerFromSourceName)); } catch (InternalCompilerError const& exception) { - errors.append(formatError(exception, "Internal compiler error (" + exception.lineInfo() + ")", scannerFromSourceName)); + errors.append(SourceReferenceFormatter::formatExceptionInformation(exception, "Internal compiler error (" + exception.lineInfo() + ")", scannerFromSourceName)); } catch (UnimplementedFeatureError const& exception) { - errors.append(formatError(exception, "Unimplemented feature (" + exception.lineInfo() + ")", scannerFromSourceName)); + errors.append(SourceReferenceFormatter::formatExceptionInformation(exception, "Unimplemented feature (" + exception.lineInfo() + ")", scannerFromSourceName)); } catch (Exception const& exception) { @@ -243,7 +234,7 @@ string compile(StringMap const& _sources, bool _optimize, CStyleReadFileCallback { Json::Value errors(Json::arrayValue); for (auto const& error: formalErrors) - errors.append(formatError( + errors.append(SourceReferenceFormatter::formatExceptionInformation( *error, (error->type() == Error::Type::Warning) ? "Warning" : "Error", scannerFromSourceName -- cgit