Coverage Report

Created: 2025-06-24 07:59

/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 <libsolutil/JSON.h>
29
#include <boost/variant/static_visitor.hpp>
30
#include <optional>
31
#include <vector>
32
33
namespace solidity::yul
34
{
35
36
class Dialect;
37
38
/**
39
 * Converter of the yul AST into JSON format
40
 */
41
class AsmJsonConverter: public boost::static_visitor<Json>
42
{
43
public:
44
  /// Create a converter to JSON for any block of inline assembly
45
  /// @a _sourceIndex to be used to abbreviate source name in the source locations
46
  AsmJsonConverter(Dialect const& _dialect, std::optional<size_t> _sourceIndex):
47
0
    m_dialect(_dialect), m_sourceIndex(_sourceIndex) {}
48
49
  Json operator()(Block const& _node) const;
50
  Json operator()(NameWithDebugData const& _node) const;
51
  Json operator()(Literal const& _node) const;
52
  Json operator()(Identifier const& _node) const;
53
  Json operator()(BuiltinName const& _node) const;
54
  Json operator()(Assignment const& _node) const;
55
  Json operator()(VariableDeclaration const& _node) const;
56
  Json operator()(FunctionDefinition const& _node) const;
57
  Json operator()(FunctionCall const& _node) const;
58
  Json operator()(If const& _node) const;
59
  Json operator()(Switch const& _node) const;
60
  Json operator()(Case const& _node) const;
61
  Json operator()(ForLoop const& _node) const;
62
  Json operator()(Break const& _node) const;
63
  Json operator()(Continue const& _node) const;
64
  Json operator()(Leave const& _node) const;
65
  Json operator()(ExpressionStatement const& _node) const;
66
  Json operator()(Label const& _node) const;
67
68
private:
69
  Json createAstNode(langutil::SourceLocation const& _originLocation, langutil::SourceLocation const& _nativeLocation, std::string _nodeType) const;
70
  template <class T>
71
  Json vectorOfVariantsToJson(std::vector<T> const& vec) const;
72
73
  Dialect const& m_dialect;
74
  std::optional<size_t> const m_sourceIndex;
75
};
76
77
}