Skip to content

Commit

Permalink
turned common code to lambda func
Browse files Browse the repository at this point in the history
  • Loading branch information
GiokaMarkella committed May 15, 2023
1 parent a7578e5 commit 6d8a149
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
17 changes: 8 additions & 9 deletions libyul/AsmJsonConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,18 +183,17 @@ Json::Value AsmJsonConverter::operator()(Leave const& _node) const
return createAstNode(originLocationOf(_node), nativeLocationOf(_node), "YulLeave");
}

Json::Value AsmJsonConverter::createAstNode(langutil::SourceLocation const& _location, langutil::SourceLocation const& _nativeLocation, string _nodeType) const
Json::Value AsmJsonConverter::createAstNode(langutil::SourceLocation const& _originLocation, langutil::SourceLocation const& _nativeLocation, string _nodeType) const
{
Json::Value ret{Json::objectValue};
ret["nodeType"] = std::move(_nodeType);
int length = -1;
if (_location.start >= 0 && _location.end >= 0)
length = _location.end - _location.start;
ret["src"] = to_string(_location.start) + ":" + to_string(length) + ":" + (m_sourceIndex.has_value() ? to_string(m_sourceIndex.value()) : "-1");
length = -1;
if (_nativeLocation.start >= 0 && _nativeLocation.end >= 0)
length = _nativeLocation.end - _nativeLocation.start;
ret["nativeSrc"] = to_string(_nativeLocation.start) + ":" + to_string(length) + ":" + (m_sourceIndex.has_value() ? to_string(m_sourceIndex.value()) : "-1");
auto srcLocation = [&](int start, int end) -> string
{
int length = (start >= 0 && end >= 0) ? end - start : -1;
return to_string(start) + ":" + to_string(length) + ":" + (m_sourceIndex.has_value() ? to_string(m_sourceIndex.value()) : "-1");
};
ret["src"] = srcLocation(_originLocation.start, _originLocation.end);
ret["nativeSrc"] = srcLocation(_nativeLocation.start, _nativeLocation.end);
return ret;
}

Expand Down
2 changes: 1 addition & 1 deletion libyul/AsmJsonConverter.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class AsmJsonConverter: public boost::static_visitor<Json::Value>
Json::Value operator()(Label const& _node) const;

private:
Json::Value createAstNode(langutil::SourceLocation const& _location, langutil::SourceLocation const& _nativeLocation, std::string _nodeType) const;
Json::Value createAstNode(langutil::SourceLocation const& _originLocation, langutil::SourceLocation const& _nativeLocation, std::string _nodeType) const;
template <class T>
Json::Value vectorOfVariantsToJson(std::vector<T> const& vec) const;

Expand Down

0 comments on commit 6d8a149

Please sign in to comment.