From a72f4f39939e8f2d474c4fb48c833e948b0ca4bb Mon Sep 17 00:00:00 2001 From: chriseth Date: Mon, 6 Sep 2021 18:52:48 +0200 Subject: [PATCH] Print AST ID. --- libsolidity/codegen/ir/Common.cpp | 3 +- libyul/AsmPrinter.cpp | 46 +++++++++++++++++++------------ libyul/AsmPrinter.h | 3 +- 3 files changed, 30 insertions(+), 22 deletions(-) diff --git a/libsolidity/codegen/ir/Common.cpp b/libsolidity/codegen/ir/Common.cpp index 0a445c119..49a6be5e5 100644 --- a/libsolidity/codegen/ir/Common.cpp +++ b/libsolidity/codegen/ir/Common.cpp @@ -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() ); } diff --git a/libyul/AsmPrinter.cpp b/libyul/AsmPrinter.cpp index 6be9fc33f..6a764ee16 100644 --- a/libyul/AsmPrinter.cpp +++ b/libyul/AsmPrinter.cpp @@ -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 const& _nameToSourceIndex, - bool _statement, CharStreamProvider const* _soliditySourceProvider ) { @@ -294,27 +293,38 @@ string AsmPrinter::formatSourceLocationComment( ":" + to_string(_location.end); - return - _statement ? - "/// " + joinHumanReadable(vector{sourceLocation, solidityCodeSnippet}, " ") : - "/** " + joinHumanReadable(vector{sourceLocation, solidityCodeSnippet}, " ") + " */ "; + return joinHumanReadable(vector{sourceLocation, solidityCodeSnippet}, " "); } string AsmPrinter::formatDebugData(shared_ptr const& _debugData, bool _statement) { - if ( - !_debugData || - m_lastLocation == _debugData->location || - m_nameToSourceIndex.empty() - ) + if (!_debugData) return ""; - m_lastLocation = _debugData->location; + vector 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 + " */ "; } diff --git a/libyul/AsmPrinter.h b/libyul/AsmPrinter.h index 73a878958..3bb683191 100644 --- a/libyul/AsmPrinter.h +++ b/libyul/AsmPrinter.h @@ -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 const& _nameToSourceIndex, - bool _statement, langutil::CharStreamProvider const* m_soliditySourceProvider = nullptr );