aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity/interface/SourceReferenceFormatter.h
diff options
context:
space:
mode:
Diffstat (limited to 'libsolidity/interface/SourceReferenceFormatter.h')
-rw-r--r--libsolidity/interface/SourceReferenceFormatter.h38
1 files changed, 20 insertions, 18 deletions
diff --git a/libsolidity/interface/SourceReferenceFormatter.h b/libsolidity/interface/SourceReferenceFormatter.h
index e8676d60..a32babdc 100644
--- a/libsolidity/interface/SourceReferenceFormatter.h
+++ b/libsolidity/interface/SourceReferenceFormatter.h
@@ -38,22 +38,23 @@ namespace solidity
class Scanner; // forward
class CompilerStack; // forward
-struct SourceReferenceFormatter
+class SourceReferenceFormatter
{
public:
using ScannerFromSourceNameFun = std::function<Scanner const&(std::string const&)>;
- /// Prints source location if it is given.
- static void printSourceLocation(
- std::ostream& _stream,
- SourceLocation const* _location,
- ScannerFromSourceNameFun const& _scannerFromSourceName
- );
- static void printExceptionInformation(
+
+ explicit SourceReferenceFormatter(
std::ostream& _stream,
- Exception const& _exception,
- std::string const& _name,
- ScannerFromSourceNameFun const& _scannerFromSourceName
- );
+ ScannerFromSourceNameFun _scannerFromSourceName
+ ):
+ m_stream(_stream),
+ m_scannerFromSourceName(std::move(_scannerFromSourceName))
+ {}
+
+ /// Prints source location if it is given.
+ void printSourceLocation(SourceLocation const* _location);
+ void printExceptionInformation(Exception const& _exception, std::string const& _name);
+
static std::string formatExceptionInformation(
Exception const& _exception,
std::string const& _name,
@@ -61,16 +62,17 @@ public:
)
{
std::ostringstream errorOutput;
- printExceptionInformation(errorOutput, _exception, _name, _scannerFromSourceName);
+
+ SourceReferenceFormatter formatter(errorOutput, _scannerFromSourceName);
+ formatter.printExceptionInformation(_exception, _name);
return errorOutput.str();
}
private:
/// Prints source name if location is given.
- static void printSourceName(
- std::ostream& _stream,
- SourceLocation const* _location,
- ScannerFromSourceNameFun const& _scannerFromSourceName
- );
+ void printSourceName(SourceLocation const* _location);
+
+ std::ostream& m_stream;
+ ScannerFromSourceNameFun m_scannerFromSourceName;
};
}