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, ""); solAssert(_location.sourceName, "");
_context.markSourceUsed(*_location.sourceName); _context.markSourceUsed(*_location.sourceName);
return AsmPrinter::formatSourceLocationComment( return "/// " + AsmPrinter::formatSourceLocation(
_location, _location,
_context.sourceIndices(), _context.sourceIndices(),
true /* _statement */,
_context.soliditySourceProvider() _context.soliditySourceProvider()
); );
} }

View File

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