mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Add SourceLocation.length() and use it in AsmJsonConverter
This commit is contained in:
parent
628e37c7a0
commit
a7e5f6b52b
@ -79,6 +79,10 @@ struct SourceLocation
|
|||||||
|
|
||||||
bool hasText() const { return sourceName && 0 <= start && start <= end; }
|
bool hasText() const { return sourceName && 0 <= start && start <= end; }
|
||||||
|
|
||||||
|
/// @returns the length of text covered by the location if both @a start and @a end are defined.
|
||||||
|
/// Otherwise returns -1.
|
||||||
|
int length() const { return (start >= 0 && end >= 0 ? end - start : -1); }
|
||||||
|
|
||||||
/// @returns the smallest SourceLocation that contains both @param _a and @param _b.
|
/// @returns the smallest SourceLocation that contains both @param _a and @param _b.
|
||||||
/// Assumes that @param _a and @param _b refer to the same source (exception: if the source of either one
|
/// Assumes that @param _a and @param _b refer to the same source (exception: if the source of either one
|
||||||
/// is unset, the source of the other will be used for the result, even if that is unset as well).
|
/// is unset, the source of the other will be used for the result, even if that is unset as well).
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
#include <libsolutil/UTF8.h>
|
#include <libsolutil/UTF8.h>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
using namespace solidity::langutil;
|
||||||
|
|
||||||
namespace solidity::yul
|
namespace solidity::yul
|
||||||
{
|
{
|
||||||
@ -183,14 +184,23 @@ Json::Value AsmJsonConverter::operator()(Leave const& _node) const
|
|||||||
return createAstNode(nativeLocationOf(_node), "YulLeave");
|
return createAstNode(nativeLocationOf(_node), "YulLeave");
|
||||||
}
|
}
|
||||||
|
|
||||||
Json::Value AsmJsonConverter::createAstNode(langutil::SourceLocation const& _location, string _nodeType) const
|
string AsmJsonConverter::formatLocation(SourceLocation const& _location, optional<size_t> const& _sourceIndex)
|
||||||
|
{
|
||||||
|
return
|
||||||
|
to_string(_location.start) +
|
||||||
|
":" +
|
||||||
|
to_string(_location.length()) +
|
||||||
|
":" +
|
||||||
|
(_sourceIndex.has_value() ? to_string(_sourceIndex.value()) : "-1");
|
||||||
|
}
|
||||||
|
|
||||||
|
Json::Value AsmJsonConverter::createAstNode(SourceLocation const& _location, string _nodeType) const
|
||||||
{
|
{
|
||||||
Json::Value ret{Json::objectValue};
|
Json::Value ret{Json::objectValue};
|
||||||
ret["nodeType"] = std::move(_nodeType);
|
ret["nodeType"] = std::move(_nodeType);
|
||||||
int length = -1;
|
|
||||||
if (_location.start >= 0 && _location.end >= 0)
|
ret["src"] = formatLocation(_location, m_sourceIndex);
|
||||||
length = _location.end - _location.start;
|
|
||||||
ret["src"] = to_string(_location.start) + ":" + to_string(length) + ":" + (m_sourceIndex.has_value() ? to_string(m_sourceIndex.value()) : "-1");
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,7 +62,10 @@ public:
|
|||||||
Json::Value operator()(Label const& _node) const;
|
Json::Value operator()(Label const& _node) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
static std::string formatLocation(langutil::SourceLocation const& _location, std::optional<size_t> const& m_sourceIndex);
|
||||||
|
|
||||||
Json::Value createAstNode(langutil::SourceLocation const& _location, std::string _nodeType) const;
|
Json::Value createAstNode(langutil::SourceLocation const& _location, std::string _nodeType) const;
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
Json::Value vectorOfVariantsToJson(std::vector<T> const& vec) const;
|
Json::Value vectorOfVariantsToJson(std::vector<T> const& vec) const;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user