solidity/libyul/AsmJsonConverter.h

73 lines
2.6 KiB
C
Raw Normal View History

2019-10-15 10:38:12 +00:00
/*
This file is part of solidity.
solidity is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
solidity is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/
// SPDX-License-Identifier: GPL-3.0
2019-10-15 10:38:12 +00:00
/**
* @date 2019
* @author julius <djudju@protonmail.com>
* Converts inline assembly AST to JSON format
*/
2020-05-11 09:44:20 +00:00
#pragma once
#include <libyul/ASTForward.h>
2019-10-15 10:38:12 +00:00
#include <liblangutil/SourceLocation.h>
#include <json/json.h>
2022-09-27 01:14:10 +00:00
#include <boost/variant/static_visitor.hpp>
#include <optional>
2019-10-15 10:38:12 +00:00
#include <vector>
2019-12-11 16:31:36 +00:00
namespace solidity::yul
2019-10-15 10:38:12 +00:00
{
/**
* Converter of the yul AST into JSON format
*/
class AsmJsonConverter: public boost::static_visitor<Json::Value>
{
public:
/// Create a converter to JSON for any block of inline assembly
/// @a _sourceIndex to be used to abbreviate source name in the source locations
explicit AsmJsonConverter(std::optional<size_t> _sourceIndex): m_sourceIndex(_sourceIndex) {}
2019-10-15 10:38:12 +00:00
Json::Value operator()(Block const& _node) const;
Json::Value operator()(TypedName const& _node) const;
Json::Value operator()(Literal const& _node) const;
Json::Value operator()(Identifier const& _node) const;
Json::Value operator()(Assignment const& _node) const;
Json::Value operator()(VariableDeclaration const& _node) const;
Json::Value operator()(FunctionDefinition const& _node) const;
Json::Value operator()(FunctionCall const& _node) const;
Json::Value operator()(If const& _node) const;
Json::Value operator()(Switch const& _node) const;
Json::Value operator()(Case const& _node) const;
Json::Value operator()(ForLoop const& _node) const;
Json::Value operator()(Break const& _node) const;
Json::Value operator()(Continue const& _node) const;
Json::Value operator()(Leave const& _node) const;
Json::Value operator()(ExpressionStatement const& _node) const;
Json::Value operator()(Label const& _node) const;
private:
Json::Value createAstNode(langutil::SourceLocation const& _originLocation, langutil::SourceLocation const& _nativeLocation, std::string _nodeType) const;
2019-10-15 10:38:12 +00:00
template <class T>
Json::Value vectorOfVariantsToJson(std::vector<T> const& vec) const;
std::optional<size_t> const m_sourceIndex;
2019-10-15 10:38:12 +00:00
};
}