Coverage Report

Created: 2022-08-24 06:28

/src/solidity/libyul/AsmJsonConverter.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
  This file is part of solidity.
3
4
  solidity is free software: you can redistribute it and/or modify
5
  it under the terms of the GNU General Public License as published by
6
  the Free Software Foundation, either version 3 of the License, or
7
  (at your option) any later version.
8
9
  solidity is distributed in the hope that it will be useful,
10
  but WITHOUT ANY WARRANTY; without even the implied warranty of
11
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
  GNU General Public License for more details.
13
14
  You should have received a copy of the GNU General Public License
15
  along with solidity.  If not, see <http://www.gnu.org/licenses/>.
16
*/
17
// SPDX-License-Identifier: GPL-3.0
18
/**
19
 * @date 2019
20
 * @author julius <djudju@protonmail.com>
21
 * Converts inline assembly AST to JSON format
22
 */
23
24
#pragma once
25
26
#include <libyul/ASTForward.h>
27
#include <liblangutil/SourceLocation.h>
28
#include <json/json.h>
29
#include <boost/variant.hpp>
30
#include <optional>
31
#include <vector>
32
33
namespace solidity::yul
34
{
35
36
/**
37
 * Converter of the yul AST into JSON format
38
 */
39
class AsmJsonConverter: public boost::static_visitor<Json::Value>
40
{
41
public:
42
  /// Create a converter to JSON for any block of inline assembly
43
  /// @a _sourceIndex to be used to abbreviate source name in the source locations
44
0
  explicit AsmJsonConverter(std::optional<size_t> _sourceIndex): m_sourceIndex(_sourceIndex) {}
45
46
  Json::Value operator()(Block const& _node) const;
47
  Json::Value operator()(TypedName const& _node) const;
48
  Json::Value operator()(Literal const& _node) const;
49
  Json::Value operator()(Identifier const& _node) const;
50
  Json::Value operator()(Assignment const& _node) const;
51
  Json::Value operator()(VariableDeclaration const& _node) const;
52
  Json::Value operator()(FunctionDefinition const& _node) const;
53
  Json::Value operator()(FunctionCall const& _node) const;
54
  Json::Value operator()(If const& _node) const;
55
  Json::Value operator()(Switch const& _node) const;
56
  Json::Value operator()(Case const& _node) const;
57
  Json::Value operator()(ForLoop const& _node) const;
58
  Json::Value operator()(Break const& _node) const;
59
  Json::Value operator()(Continue const& _node) const;
60
  Json::Value operator()(Leave const& _node) const;
61
  Json::Value operator()(ExpressionStatement const& _node) const;
62
  Json::Value operator()(Label const& _node) const;
63
64
private:
65
  Json::Value createAstNode(langutil::SourceLocation const& _location, std::string _nodeType) const;
66
  template <class T>
67
  Json::Value vectorOfVariantsToJson(std::vector<T> const& vec) const;
68
69
  std::optional<size_t> const m_sourceIndex;
70
};
71
72
}