Print AST ID.

This commit is contained in:
chriseth 2021-09-06 18:52:48 +02:00
parent dafa6f552b
commit a72f4f3993
3 changed files with 30 additions and 22 deletions

View File

@ -135,10 +135,9 @@ string dispenseLocationComment(langutil::SourceLocation const& _location, IRGene
{
solAssert(_location.sourceName, "");
_context.markSourceUsed(*_location.sourceName);
return AsmPrinter::formatSourceLocationComment(
return "/// " + AsmPrinter::formatSourceLocation(
_location,
_context.sourceIndices(),
true /* _statement */,
_context.soliditySourceProvider()
);
}

View File

@ -258,10 +258,9 @@ string AsmPrinter::appendTypeName(YulString _type, bool _isBoolLiteral) const
return ":" + _type.str();
}
string AsmPrinter::formatSourceLocationComment(
string AsmPrinter::formatSourceLocation(
SourceLocation const& _location,
map<string, unsigned> const& _nameToSourceIndex,
bool _statement,
CharStreamProvider const* _soliditySourceProvider
)
{
@ -294,27 +293,38 @@ string AsmPrinter::formatSourceLocationComment(
":" +
to_string(_location.end);
return
_statement ?
"/// " + joinHumanReadable(vector<string>{sourceLocation, solidityCodeSnippet}, " ") :
"/** " + joinHumanReadable(vector<string>{sourceLocation, solidityCodeSnippet}, " ") + " */ ";
return joinHumanReadable(vector<string>{sourceLocation, solidityCodeSnippet}, " ");
}
string AsmPrinter::formatDebugData(shared_ptr<DebugData const> const& _debugData, bool _statement)
{
if (
!_debugData ||
m_lastLocation == _debugData->location ||
m_nameToSourceIndex.empty()
)
if (!_debugData)
return "";
m_lastLocation = _debugData->location;
vector<string> items;
if (auto id = _debugData->astID)
items.emplace_back("@ast-id " + to_string(*id));
return formatSourceLocationComment(
_debugData->location,
m_nameToSourceIndex,
_statement,
m_soliditySourceProvider
) + (_statement ? "\n" : "");
if (
m_lastLocation != _debugData->location &&
!m_nameToSourceIndex.empty()
)
{
m_lastLocation = _debugData->location;
items.emplace_back(formatSourceLocation(
_debugData->location,
m_nameToSourceIndex,
m_soliditySourceProvider
));
}
string commentBody = joinHumanReadable(items, " ");
if (commentBody.empty())
return "";
else
return
_statement ?
"/// " + commentBody + "\n" :
"/** " + commentBody + " */ ";
}

View File

@ -80,10 +80,9 @@ public:
std::string operator()(Leave const& _continue);
std::string operator()(Block const& _block);
static std::string formatSourceLocationComment(
static std::string formatSourceLocation(
langutil::SourceLocation const& _location,
std::map<std::string, unsigned> const& _nameToSourceIndex,
bool _statement,
langutil::CharStreamProvider const* m_soliditySourceProvider = nullptr
);