@@ -33,19 +33,22 @@ namespace solidity
3333
3434void SourceReferenceFormatter::printSourceLocation (
3535 ostream& _stream,
36- SourceLocation const & _location,
37- Scanner const & _scanner
36+ SourceLocation const * _location,
37+ function< Scanner const &(string const &)> const & _scannerFromSourceName
3838)
3939{
40+ if (!_location || !_location->sourceName )
41+ return ; // Nothing we can print here
42+ auto const & scanner = _scannerFromSourceName (*_location->sourceName );
4043 int startLine;
4144 int startColumn;
42- tie (startLine, startColumn) = _scanner .translatePositionToLineColumn (_location. start );
45+ tie (startLine, startColumn) = scanner .translatePositionToLineColumn (_location-> start );
4346 int endLine;
4447 int endColumn;
45- tie (endLine, endColumn) = _scanner .translatePositionToLineColumn (_location. end );
48+ tie (endLine, endColumn) = scanner .translatePositionToLineColumn (_location-> end );
4649 if (startLine == endLine)
4750 {
48- string line = _scanner .lineAtPosition (_location. start );
51+ string line = scanner .lineAtPosition (_location-> start );
4952 _stream << line << endl;
5053 for_each (
5154 line.cbegin (),
@@ -61,7 +64,7 @@ void SourceReferenceFormatter::printSourceLocation(
6164 }
6265 else
6366 _stream <<
64- _scanner .lineAtPosition (_location. start ) <<
67+ scanner .lineAtPosition (_location-> start ) <<
6568 endl <<
6669 string (startColumn, ' ' ) <<
6770 " ^\n " <<
@@ -70,14 +73,17 @@ void SourceReferenceFormatter::printSourceLocation(
7073
7174void SourceReferenceFormatter::printSourceName (
7275 ostream& _stream,
73- SourceLocation const & _location,
74- Scanner const & _scanner
76+ SourceLocation const * _location,
77+ function< Scanner const &(string const &)> const & _scannerFromSourceName
7578)
7679{
80+ if (!_location || !_location->sourceName )
81+ return ; // Nothing we can print here
82+ auto const & scanner = _scannerFromSourceName (*_location->sourceName );
7783 int startLine;
7884 int startColumn;
79- tie (startLine, startColumn) = _scanner .translatePositionToLineColumn (_location. start );
80- _stream << *_location. sourceName << " :" << (startLine + 1 ) << " :" << (startColumn + 1 ) << " : " ;
85+ tie (startLine, startColumn) = scanner .translatePositionToLineColumn (_location-> start );
86+ _stream << *_location-> sourceName << " :" << (startLine + 1 ) << " :" << (startColumn + 1 ) << " : " ;
8187}
8288
8389void SourceReferenceFormatter::printExceptionInformation (
@@ -89,38 +95,23 @@ void SourceReferenceFormatter::printExceptionInformation(
8995{
9096 SourceLocation const * location = boost::get_error_info<errinfo_sourceLocation>(_exception);
9197 auto secondarylocation = boost::get_error_info<errinfo_secondarySourceLocation>(_exception);
92- Scanner const * scannerPtr = nullptr ;
9398
94- if (location && location->sourceName )
95- {
96- scannerPtr = &_scannerFromSourceName (*location->sourceName );
97- printSourceName (_stream, *location, *scannerPtr);
98- }
99+ printSourceName (_stream, location, _scannerFromSourceName);
99100
100101 _stream << _name;
101102 if (string const * description = boost::get_error_info<errinfo_comment>(_exception))
102103 _stream << " : " << *description << endl;
103104
104- if (location && location->sourceName )
105- {
106- scannerPtr = &_scannerFromSourceName (*location->sourceName );
107- printSourceLocation (_stream, *location, *scannerPtr);
108- }
105+ printSourceLocation (_stream, location, _scannerFromSourceName);
109106
110107 if (secondarylocation && !secondarylocation->infos .empty ())
111108 {
112109 for (auto info: secondarylocation->infos )
113110 {
114111 _stream << info.first << " " ;
115- if (!info.second .sourceName )
116- {
117- _stream << endl;
118- continue ;
119- }
120- scannerPtr = &_scannerFromSourceName (*info.second .sourceName );
121- printSourceName (_stream, info.second , *scannerPtr);
112+ printSourceName (_stream, &info.second , _scannerFromSourceName);
122113 _stream << endl;
123- printSourceLocation (_stream, info.second , *scannerPtr );
114+ printSourceLocation (_stream, & info.second , _scannerFromSourceName );
124115 }
125116 _stream << endl;
126117 }
0 commit comments