|
|
@ -32,9 +32,11 @@ namespace dev |
|
|
|
namespace solidity |
|
|
|
{ |
|
|
|
|
|
|
|
void SourceReferenceFormatter::printSourceLocation(ostream& _stream, |
|
|
|
SourceLocation const& _location, |
|
|
|
Scanner const& _scanner) |
|
|
|
void SourceReferenceFormatter::printSourceLocation( |
|
|
|
ostream& _stream, |
|
|
|
SourceLocation const& _location, |
|
|
|
Scanner const& _scanner |
|
|
|
) |
|
|
|
{ |
|
|
|
int startLine; |
|
|
|
int startColumn; |
|
|
@ -46,11 +48,11 @@ void SourceReferenceFormatter::printSourceLocation(ostream& _stream, |
|
|
|
{ |
|
|
|
string line = _scanner.getLineAtPosition(_location.start); |
|
|
|
_stream << line << endl; |
|
|
|
std::for_each(line.cbegin(), line.cbegin() + startColumn, |
|
|
|
[&_stream](char const& ch) |
|
|
|
{ |
|
|
|
_stream << (ch == '\t' ? '\t' : ' '); |
|
|
|
}); |
|
|
|
for_each( |
|
|
|
line.cbegin(), |
|
|
|
line.cbegin() + startColumn, |
|
|
|
[&_stream](char const& ch) { _stream << (ch == '\t' ? '\t' : ' '); } |
|
|
|
); |
|
|
|
_stream << "^"; |
|
|
|
if (endColumn > startColumn + 2) |
|
|
|
_stream << string(endColumn - startColumn - 2, '-'); |
|
|
@ -59,33 +61,65 @@ void SourceReferenceFormatter::printSourceLocation(ostream& _stream, |
|
|
|
_stream << endl; |
|
|
|
} |
|
|
|
else |
|
|
|
_stream << _scanner.getLineAtPosition(_location.start) << endl |
|
|
|
<< string(startColumn, ' ') << "^\n" |
|
|
|
<< "Spanning multiple lines.\n"; |
|
|
|
_stream << |
|
|
|
_scanner.getLineAtPosition(_location.start) << |
|
|
|
endl << |
|
|
|
string(startColumn, ' ') << |
|
|
|
"^\n" << |
|
|
|
"Spanning multiple lines.\n"; |
|
|
|
} |
|
|
|
|
|
|
|
void SourceReferenceFormatter::printExceptionInformation(ostream& _stream, |
|
|
|
Exception const& _exception, |
|
|
|
string const& _name, |
|
|
|
CompilerStack const& _compiler) |
|
|
|
void SourceReferenceFormatter::printSourceName( |
|
|
|
ostream& _stream, |
|
|
|
SourceLocation const& _location, |
|
|
|
Scanner const& _scanner |
|
|
|
) |
|
|
|
{ |
|
|
|
int startLine; |
|
|
|
int startColumn; |
|
|
|
tie(startLine, startColumn) = _scanner.translatePositionToLineColumn(_location.start); |
|
|
|
_stream << *_location.sourceName << ":" << (startLine + 1) << ":" << (startColumn + 1) << ": "; |
|
|
|
} |
|
|
|
|
|
|
|
void SourceReferenceFormatter::printExceptionInformation( |
|
|
|
ostream& _stream, |
|
|
|
Exception const& _exception, |
|
|
|
string const& _name, |
|
|
|
CompilerStack const& _compiler |
|
|
|
) |
|
|
|
{ |
|
|
|
SourceLocation const* location = boost::get_error_info<errinfo_sourceLocation>(_exception); |
|
|
|
Scanner const* scanner; |
|
|
|
auto secondarylocation = boost::get_error_info<errinfo_secondarySourceLocation>(_exception); |
|
|
|
Scanner const* scanner = nullptr; |
|
|
|
|
|
|
|
if (location) |
|
|
|
{ |
|
|
|
scanner = &_compiler.getScanner(*location->sourceName); |
|
|
|
int startLine; |
|
|
|
int startColumn; |
|
|
|
tie(startLine, startColumn) = scanner->translatePositionToLineColumn(location->start); |
|
|
|
_stream << *location->sourceName << ":" << (startLine + 1) << ":" << (startColumn + 1) << ": "; |
|
|
|
printSourceName(_stream, *location, *scanner); |
|
|
|
} |
|
|
|
|
|
|
|
_stream << _name; |
|
|
|
if (string const* description = boost::get_error_info<errinfo_comment>(_exception)) |
|
|
|
_stream << ": " << *description << endl; |
|
|
|
|
|
|
|
if (location) |
|
|
|
{ |
|
|
|
scanner = &_compiler.getScanner(*location->sourceName); |
|
|
|
printSourceLocation(_stream, *location, *scanner); |
|
|
|
} |
|
|
|
|
|
|
|
if (secondarylocation && !secondarylocation->infos.empty()) |
|
|
|
{ |
|
|
|
for (auto info: secondarylocation->infos) |
|
|
|
{ |
|
|
|
scanner = &_compiler.getScanner(*info.second.sourceName); |
|
|
|
_stream << info.first << " "; |
|
|
|
printSourceName(_stream, info.second, *scanner); |
|
|
|
_stream << endl; |
|
|
|
printSourceLocation(_stream, info.second, *scanner); |
|
|
|
} |
|
|
|
_stream << endl; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|