@@ -30,100 +30,63 @@ using namespace langutil;
30
30
31
31
void SourceReferenceFormatter::printSourceLocation (SourceLocation const * _location)
32
32
{
33
- if (!_location || !_location->source )
34
- return ; // Nothing we can print here
35
- auto const & scanner = m_scannerFromSourceName (_location->source ->name ());
36
- int startLine;
37
- int startColumn;
38
- tie (startLine, startColumn) = scanner.translatePositionToLineColumn (_location->start );
39
- int endLine;
40
- int endColumn;
41
- tie (endLine, endColumn) = scanner.translatePositionToLineColumn (_location->end );
42
- if (startLine == endLine)
43
- {
44
- string line = scanner.lineAtPosition (_location->start );
33
+ printSourceLocation (SourceReferenceExtractor::extract (_location));
34
+ }
45
35
46
- int locationLength = endColumn - startColumn;
47
- if (locationLength > 150 )
48
- {
49
- line = line.substr (0 , startColumn + 35 ) + " ... " + line.substr (endColumn - 35 );
50
- endColumn = startColumn + 75 ;
51
- locationLength = 75 ;
52
- }
53
- if (line.length () > 150 )
54
- {
55
- int len = line.length ();
56
- line = line.substr (max (0 , startColumn - 35 ), min (startColumn, 35 ) + min (locationLength + 35 , len - startColumn));
57
- if (startColumn + locationLength + 35 < len)
58
- line += " ..." ;
59
- if (startColumn > 35 )
60
- {
61
- line = " ... " + line;
62
- startColumn = 40 ;
63
- }
64
- endColumn = startColumn + locationLength;
65
- }
36
+ void SourceReferenceFormatter::printSourceLocation (SourceReference const & _ref)
37
+ {
38
+ if (_ref.position .line < 0 )
39
+ return ; // Nothing we can print here
66
40
67
- m_stream << line << endl;
41
+ if (!_ref.multiline )
42
+ {
43
+ m_stream << _ref.text << endl;
68
44
45
+ // mark the text-range like this: ^-----^
69
46
for_each (
70
- line .cbegin (),
71
- line. cbegin () + startColumn,
72
- [this ](char const & ch) { m_stream << (ch == ' \t ' ? ' \t ' : ' ' ); }
47
+ _ref. text .cbegin (),
48
+ _ref. text . cbegin () + _ref. startColumn ,
49
+ [this ](char ch) { m_stream << (ch == ' \t ' ? ' \t ' : ' ' ); }
73
50
);
74
51
m_stream << " ^" ;
75
- if (endColumn > startColumn + 2 )
76
- m_stream << string (endColumn - startColumn - 2 , ' -' );
77
- if (endColumn > startColumn + 1 )
52
+ if (_ref. endColumn > _ref. startColumn + 2 )
53
+ m_stream << string (_ref. endColumn - _ref. startColumn - 2 , ' -' );
54
+ if (_ref. endColumn > _ref. startColumn + 1 )
78
55
m_stream << " ^" ;
79
56
m_stream << endl;
80
57
}
81
58
else
82
59
m_stream <<
83
- scanner. lineAtPosition (_location-> start ) <<
60
+ _ref. text <<
84
61
endl <<
85
- string (startColumn, ' ' ) <<
62
+ string (_ref. startColumn , ' ' ) <<
86
63
" ^ (Relevant source part starts here and spans across multiple lines)." <<
87
64
endl;
88
65
}
89
66
90
- void SourceReferenceFormatter::printSourceName (SourceLocation const * _location )
67
+ void SourceReferenceFormatter::printSourceName (SourceReference const & _ref )
91
68
{
92
- if (!_location || !_location->source )
93
- return ; // Nothing we can print here
94
- auto const & scanner = m_scannerFromSourceName (_location->source ->name ());
95
- int startLine;
96
- int startColumn;
97
- tie (startLine, startColumn) = scanner.translatePositionToLineColumn (_location->start );
98
- m_stream << _location->source ->name () << " :" << (startLine + 1 ) << " :" << (startColumn + 1 ) << " : " ;
69
+ if (_ref.position .line != -1 )
70
+ m_stream << _ref.sourceName << " :" << (_ref.position .line + 1 ) << " :" << (_ref.position .column + 1 ) << " : " ;
99
71
}
100
72
101
- void SourceReferenceFormatter::printExceptionInformation (
102
- dev::Exception const & _exception,
103
- string const & _name
104
- )
73
+ void SourceReferenceFormatter::printExceptionInformation (dev::Exception const & _error, std::string const & _category)
105
74
{
106
- SourceLocation const * location = boost::get_error_info<errinfo_sourceLocation>(_exception );
107
- auto secondarylocation = boost::get_error_info<errinfo_secondarySourceLocation>(_exception);
75
+ printExceptionInformation ( SourceReferenceExtractor::extract (_error, _category) );
76
+ }
108
77
109
- printSourceName (location);
78
+ void SourceReferenceFormatter::printExceptionInformation (SourceReferenceExtractor::Message const & _msg)
79
+ {
80
+ printSourceName (_msg.primary );
110
81
111
- m_stream << _name;
112
- if (string const * description = boost::get_error_info<errinfo_comment>(_exception))
113
- m_stream << " : " << *description << endl;
114
- else
115
- m_stream << endl;
82
+ m_stream << _msg.category << " : " << _msg.primary .message << endl;
116
83
117
- printSourceLocation (location );
84
+ printSourceLocation (_msg. primary );
118
85
119
- if (secondarylocation && !secondarylocation-> infos . empty () )
86
+ for ( auto const & ref: _msg. secondary )
120
87
{
121
- for (auto info: secondarylocation->infos )
122
- {
123
- printSourceName (&info.second );
124
- m_stream << info.first << endl;
125
- printSourceLocation (&info.second );
126
- }
127
- m_stream << endl;
88
+ printSourceName (ref);
89
+ m_stream << ref.message << endl;
90
+ printSourceLocation (ref);
128
91
}
129
92
}
0 commit comments