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

Method formatSourceLocation

libyul/AsmPrinter.cpp:260–306  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

258}
259
260std::string AsmPrinter::formatSourceLocation(
261 SourceLocation const& _location,
262 std::map<std::string, unsigned> const& _nameToSourceIndex,
263 DebugInfoSelection const& _debugInfoSelection,
264 CharStreamProvider const* _soliditySourceProvider
265)
266{
267 yulAssert(!_nameToSourceIndex.empty(), "");
268 if (_debugInfoSelection.snippet)
269 yulAssert(_debugInfoSelection.location, "@src tag must always contain the source location");
270
271 if (_debugInfoSelection.none())
272 return "";
273
274 std::string sourceIndex = "-1";
275 std::string solidityCodeSnippet = "";
276 if (_location.sourceName)
277 {
278 sourceIndex = std::to_string(_nameToSourceIndex.at(*_location.sourceName));
279
280 if (
281 _debugInfoSelection.snippet &&
282 _soliditySourceProvider &&
283 !_soliditySourceProvider->charStream(*_location.sourceName).isImportedFromAST()
284 )
285 {
286 solidityCodeSnippet = escapeAndQuoteString(
287 _soliditySourceProvider->charStream(*_location.sourceName).singleLineSnippet(_location)
288 );
289
290 // On top of escaping quotes we also escape the slash inside any `*/` to guard against
291 // it prematurely terminating multi-line comment blocks. We do not escape all slashes
292 // because the ones without `*` are not dangerous and ignoring them reduces visual noise.
293 boost::replace_all(solidityCodeSnippet, "*/", "*\\/");
294 }
295 }
296
297 std::string sourceLocation =
298 "@src " +
299 sourceIndex +
300 ":" +
301 std::to_string(_location.start) +
302 ":" +
303 std::to_string(_location.end);
304
305 return sourceLocation + (solidityCodeSnippet.empty() ? "" : " ") + solidityCodeSnippet;
306}
307
308std::string AsmPrinter::formatDebugData(langutil::DebugData::ConstPtr const& _debugData, bool _statement)
309{

Callers

nothing calls this directly

Calls 6

atMethod · 0.80
isImportedFromASTMethod · 0.80
to_stringFunction · 0.70
emptyMethod · 0.45
noneMethod · 0.45
singleLineSnippetMethod · 0.45

Tested by

no test coverage detected