mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Deduplicate code for printing source locations
This commit is contained in:
+33
-16
@@ -38,6 +38,7 @@
|
||||
|
||||
using namespace std;
|
||||
using namespace solidity;
|
||||
using namespace solidity::langutil;
|
||||
using namespace solidity::util;
|
||||
using namespace solidity::yul;
|
||||
|
||||
@@ -256,7 +257,33 @@ string AsmPrinter::appendTypeName(YulString _type, bool _isBoolLiteral) const
|
||||
return ":" + _type.str();
|
||||
}
|
||||
|
||||
string AsmPrinter::formatSourceLocationComment(shared_ptr<DebugData const> const& _debugData, bool _statement)
|
||||
string AsmPrinter::formatSourceLocationComment(
|
||||
SourceLocation const& _location,
|
||||
map<string, unsigned> const& _nameToSourceIndex,
|
||||
bool _statement
|
||||
)
|
||||
{
|
||||
yulAssert(!_nameToSourceIndex.empty(), "");
|
||||
|
||||
string sourceIndex = "-1";
|
||||
if (_location.sourceName)
|
||||
sourceIndex = to_string(_nameToSourceIndex.at(*_location.sourceName));
|
||||
|
||||
string sourceLocation =
|
||||
"@src " +
|
||||
sourceIndex +
|
||||
":" +
|
||||
to_string(_location.start) +
|
||||
":" +
|
||||
to_string(_location.end);
|
||||
|
||||
return
|
||||
_statement ?
|
||||
"/// " + sourceLocation :
|
||||
"/** " + sourceLocation + " */ ";
|
||||
}
|
||||
|
||||
string AsmPrinter::formatSourceLocationComment(shared_ptr<DebugData const> const& _debugData, bool _statement)
|
||||
{
|
||||
if (
|
||||
!_debugData ||
|
||||
@@ -267,19 +294,9 @@ string AsmPrinter::formatSourceLocationComment(shared_ptr<DebugData const> const
|
||||
|
||||
m_lastLocation = _debugData->location;
|
||||
|
||||
string sourceIndex = "-1";
|
||||
if (_debugData->location.sourceName)
|
||||
sourceIndex = to_string(m_nameToSourceIndex.at(*_debugData->location.sourceName));
|
||||
|
||||
string sourceLocation =
|
||||
"@src " +
|
||||
sourceIndex +
|
||||
":" +
|
||||
to_string(_debugData->location.start) +
|
||||
":" +
|
||||
to_string(_debugData->location.end);
|
||||
return
|
||||
_statement ?
|
||||
"/// " + sourceLocation + "\n" :
|
||||
"/** " + sourceLocation + " */ ";
|
||||
return formatSourceLocationComment(
|
||||
_debugData->location,
|
||||
m_nameToSourceIndex,
|
||||
_statement
|
||||
) + (_statement ? "\n" : "");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user