MCPcopy Create free account
hub / github.com/argotorg/solidity / printSourceLocation

Method printSourceLocation

liblangutil/SourceReferenceFormatter.cpp:115–187  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

113}
114
115void SourceReferenceFormatter::printSourceLocation(SourceReference const& _ref)
116{
117 if (_ref.position.line < 0)
118 {
119 if (_ref.sourceName.empty())
120 return; // Nothing we can print here
121
122 frameColored() << "-->";
123 m_stream << ' ' << _ref.sourceName << '\n';
124 return; // No line available, nothing else to print
125 }
126
127 std::string line = std::to_string(_ref.position.line + 1); // one-based line number as string
128 std::string leftpad = std::string(line.size(), ' ');
129
130 // line 0: source name
131 m_stream << leftpad;
132 frameColored() << "-->";
133 m_stream << ' ' << _ref.sourceName << ':' << line << ':' << (_ref.position.column + 1) << ":\n";
134
135 std::string_view text = _ref.text;
136
137 if (m_charStreamProvider.charStream(_ref.sourceName).isImportedFromAST())
138 return;
139
140 if (!_ref.multiline)
141 {
142 size_t const locationLength = static_cast<size_t>(_ref.endColumn - _ref.startColumn);
143
144 // line 1:
145 m_stream << leftpad << ' ';
146 frameColored() << '|';
147 m_stream << '\n';
148
149 // line 2:
150 frameColored() << line << " |";
151
152 m_stream << ' ' << text.substr(0, static_cast<size_t>(_ref.startColumn));
153 highlightColored() << text.substr(static_cast<size_t>(_ref.startColumn), locationLength);
154 m_stream << text.substr(static_cast<size_t>(_ref.endColumn)) << '\n';
155
156 // line 3:
157 m_stream << leftpad << ' ';
158 frameColored() << '|';
159
160 m_stream << ' ' << replaceNonTabs(text.substr(0, static_cast<size_t>(_ref.startColumn)), ' ');
161 diagColored() << (
162 locationLength == 0 ?
163 "^" :
164 replaceNonTabs(text.substr(static_cast<size_t>(_ref.startColumn), locationLength), '^')
165 );
166 m_stream << '\n';
167 }
168 else
169 {
170 // line 1:
171 m_stream << leftpad << ' ';
172 frameColored() << '|';

Callers

nothing calls this directly

Calls 5

replaceNonTabsFunction · 0.85
isImportedFromASTMethod · 0.80
to_stringFunction · 0.70
emptyMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected