2014-10-13 15:13:48 +00:00
|
|
|
/*
|
2016-11-18 23:13:20 +00:00
|
|
|
This file is part of solidity.
|
2014-10-13 15:13:48 +00:00
|
|
|
|
2016-11-18 23:13:20 +00:00
|
|
|
solidity is free software: you can redistribute it and/or modify
|
2014-10-16 12:08:54 +00:00
|
|
|
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.
|
2014-10-13 15:13:48 +00:00
|
|
|
|
2016-11-18 23:13:20 +00:00
|
|
|
solidity is distributed in the hope that it will be useful,
|
2014-10-16 12:08:54 +00:00
|
|
|
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.
|
2014-10-13 15:13:48 +00:00
|
|
|
|
2014-10-16 12:08:54 +00:00
|
|
|
You should have received a copy of the GNU General Public License
|
2016-11-18 23:13:20 +00:00
|
|
|
along with solidity. If not, see <http://www.gnu.org/licenses/>.
|
2014-10-13 15:13:48 +00:00
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* @author Christian <c@ethdev.com>
|
|
|
|
* @date 2014
|
|
|
|
* Pretty-printer for the abstract syntax tree (the "pretty" is arguable), used for debugging.
|
|
|
|
*/
|
|
|
|
|
2015-10-20 22:21:52 +00:00
|
|
|
#include <libsolidity/ast/ASTPrinter.h>
|
|
|
|
#include <libsolidity/ast/AST.h>
|
2014-10-10 14:37:54 +00:00
|
|
|
|
2017-08-29 14:51:37 +00:00
|
|
|
#include <json/json.h>
|
2017-08-25 10:43:58 +00:00
|
|
|
|
|
|
|
#include <boost/algorithm/string/join.hpp>
|
|
|
|
|
2014-10-24 17:06:30 +00:00
|
|
|
using namespace std;
|
|
|
|
|
2014-10-16 12:08:54 +00:00
|
|
|
namespace dev
|
|
|
|
{
|
|
|
|
namespace solidity
|
|
|
|
{
|
2014-10-10 14:37:54 +00:00
|
|
|
|
2015-05-06 11:56:55 +00:00
|
|
|
ASTPrinter::ASTPrinter(
|
|
|
|
ASTNode const& _ast,
|
2015-05-06 08:43:59 +00:00
|
|
|
string const& _source,
|
2015-05-22 08:48:54 +00:00
|
|
|
GasEstimator::ASTGasConsumption const& _gasCosts
|
2015-05-06 08:43:59 +00:00
|
|
|
): m_indentation(0), m_source(_source), m_ast(&_ast), m_gasCosts(_gasCosts)
|
2014-10-10 14:37:54 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-10-24 17:06:30 +00:00
|
|
|
void ASTPrinter::print(ostream& _stream)
|
2014-10-10 14:37:54 +00:00
|
|
|
{
|
|
|
|
m_ostream = &_stream;
|
|
|
|
m_ast->accept(*this);
|
|
|
|
m_ostream = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-19 17:57:21 +00:00
|
|
|
bool ASTPrinter::visit(PragmaDirective const& _node)
|
|
|
|
{
|
|
|
|
writeLine("PragmaDirective");
|
|
|
|
printSourcePart(_node);
|
|
|
|
return goDeeper();
|
|
|
|
}
|
|
|
|
|
2014-12-05 16:29:20 +00:00
|
|
|
bool ASTPrinter::visit(ImportDirective const& _node)
|
2014-12-03 06:46:55 +00:00
|
|
|
{
|
2015-12-14 17:01:40 +00:00
|
|
|
writeLine("ImportDirective \"" + _node.path() + "\"");
|
2014-12-03 06:46:55 +00:00
|
|
|
printSourcePart(_node);
|
|
|
|
return goDeeper();
|
|
|
|
}
|
|
|
|
|
2014-12-05 16:29:20 +00:00
|
|
|
bool ASTPrinter::visit(ContractDefinition const& _node)
|
2014-10-10 14:37:54 +00:00
|
|
|
{
|
2015-08-31 16:44:29 +00:00
|
|
|
writeLine("ContractDefinition \"" + _node.name() + "\"");
|
2014-10-10 14:37:54 +00:00
|
|
|
printSourcePart(_node);
|
|
|
|
return goDeeper();
|
|
|
|
}
|
|
|
|
|
2015-01-28 10:28:22 +00:00
|
|
|
bool ASTPrinter::visit(InheritanceSpecifier const& _node)
|
|
|
|
{
|
2015-12-21 17:44:21 +00:00
|
|
|
writeLine("InheritanceSpecifier");
|
2015-01-28 10:28:22 +00:00
|
|
|
printSourcePart(_node);
|
|
|
|
return goDeeper();
|
|
|
|
}
|
|
|
|
|
2017-11-13 15:15:56 +00:00
|
|
|
bool ASTPrinter::visit(UsingForDirective const& _node)
|
|
|
|
{
|
|
|
|
writeLine("UsingForDirective");
|
|
|
|
printSourcePart(_node);
|
|
|
|
return goDeeper();
|
|
|
|
}
|
|
|
|
|
2014-12-05 16:29:20 +00:00
|
|
|
bool ASTPrinter::visit(StructDefinition const& _node)
|
2014-10-10 14:37:54 +00:00
|
|
|
{
|
2015-08-31 16:44:29 +00:00
|
|
|
writeLine("StructDefinition \"" + _node.name() + "\"");
|
2014-10-10 14:37:54 +00:00
|
|
|
printSourcePart(_node);
|
|
|
|
return goDeeper();
|
|
|
|
}
|
|
|
|
|
2015-02-09 17:08:56 +00:00
|
|
|
bool ASTPrinter::visit(EnumDefinition const& _node)
|
|
|
|
{
|
2015-08-31 16:44:29 +00:00
|
|
|
writeLine("EnumDefinition \"" + _node.name() + "\"");
|
2015-02-09 17:08:56 +00:00
|
|
|
return goDeeper();
|
|
|
|
}
|
|
|
|
|
2015-02-13 16:34:46 +00:00
|
|
|
bool ASTPrinter::visit(EnumValue const& _node)
|
2015-02-09 17:08:56 +00:00
|
|
|
{
|
2015-08-31 16:44:29 +00:00
|
|
|
writeLine("EnumValue \"" + _node.name() + "\"");
|
2015-02-09 17:08:56 +00:00
|
|
|
return goDeeper();
|
|
|
|
}
|
|
|
|
|
2014-12-05 16:29:20 +00:00
|
|
|
bool ASTPrinter::visit(ParameterList const& _node)
|
2014-10-10 14:37:54 +00:00
|
|
|
{
|
|
|
|
writeLine("ParameterList");
|
|
|
|
printSourcePart(_node);
|
|
|
|
return goDeeper();
|
|
|
|
}
|
|
|
|
|
2014-12-05 16:29:20 +00:00
|
|
|
bool ASTPrinter::visit(FunctionDefinition const& _node)
|
2014-10-10 14:37:54 +00:00
|
|
|
{
|
2015-08-31 16:44:29 +00:00
|
|
|
writeLine("FunctionDefinition \"" + _node.name() + "\"" +
|
2014-10-10 14:37:54 +00:00
|
|
|
(_node.isPublic() ? " - public" : "") +
|
2017-08-16 16:03:06 +00:00
|
|
|
(_node.stateMutability() == StateMutability::View ? " - const" : ""));
|
2014-10-10 14:37:54 +00:00
|
|
|
printSourcePart(_node);
|
|
|
|
return goDeeper();
|
|
|
|
}
|
|
|
|
|
2014-12-05 16:29:20 +00:00
|
|
|
bool ASTPrinter::visit(VariableDeclaration const& _node)
|
2014-10-10 14:37:54 +00:00
|
|
|
{
|
2015-08-31 16:44:29 +00:00
|
|
|
writeLine("VariableDeclaration \"" + _node.name() + "\"");
|
2015-09-24 10:12:31 +00:00
|
|
|
*m_ostream << indentation() << (
|
|
|
|
_node.annotation().type ?
|
|
|
|
string(" Type: ") + _node.annotation().type->toString() :
|
|
|
|
string(" Type unknown.")
|
|
|
|
) << "\n";
|
2014-10-10 14:37:54 +00:00
|
|
|
printSourcePart(_node);
|
|
|
|
return goDeeper();
|
|
|
|
}
|
|
|
|
|
2015-01-21 10:16:18 +00:00
|
|
|
bool ASTPrinter::visit(ModifierDefinition const& _node)
|
|
|
|
{
|
2015-08-31 16:44:29 +00:00
|
|
|
writeLine("ModifierDefinition \"" + _node.name() + "\"");
|
2015-01-21 10:16:18 +00:00
|
|
|
printSourcePart(_node);
|
|
|
|
return goDeeper();
|
|
|
|
}
|
|
|
|
|
2015-01-22 00:02:38 +00:00
|
|
|
bool ASTPrinter::visit(ModifierInvocation const& _node)
|
|
|
|
{
|
2015-08-31 16:44:29 +00:00
|
|
|
writeLine("ModifierInvocation \"" + _node.name()->name() + "\"");
|
2015-01-22 00:02:38 +00:00
|
|
|
printSourcePart(_node);
|
|
|
|
return goDeeper();
|
|
|
|
}
|
|
|
|
|
2015-01-29 13:35:28 +00:00
|
|
|
bool ASTPrinter::visit(EventDefinition const& _node)
|
|
|
|
{
|
2015-08-31 16:44:29 +00:00
|
|
|
writeLine("EventDefinition \"" + _node.name() + "\"");
|
2015-01-29 13:35:28 +00:00
|
|
|
printSourcePart(_node);
|
|
|
|
return goDeeper();
|
|
|
|
}
|
|
|
|
|
2014-12-05 16:29:20 +00:00
|
|
|
bool ASTPrinter::visit(ElementaryTypeName const& _node)
|
2014-10-10 14:37:54 +00:00
|
|
|
{
|
2016-02-08 21:43:22 +00:00
|
|
|
writeLine(string("ElementaryTypeName ") + _node.typeName().toString());
|
2014-10-10 14:37:54 +00:00
|
|
|
printSourcePart(_node);
|
|
|
|
return goDeeper();
|
|
|
|
}
|
|
|
|
|
2014-12-05 16:29:20 +00:00
|
|
|
bool ASTPrinter::visit(UserDefinedTypeName const& _node)
|
2014-10-10 14:37:54 +00:00
|
|
|
{
|
2015-10-06 10:35:10 +00:00
|
|
|
writeLine("UserDefinedTypeName \"" + boost::algorithm::join(_node.namePath(), ".") + "\"");
|
2014-10-10 14:37:54 +00:00
|
|
|
printSourcePart(_node);
|
|
|
|
return goDeeper();
|
|
|
|
}
|
|
|
|
|
2016-09-27 19:37:32 +00:00
|
|
|
bool ASTPrinter::visit(FunctionTypeName const& _node)
|
|
|
|
{
|
|
|
|
writeLine("FunctionTypeName");
|
|
|
|
printSourcePart(_node);
|
|
|
|
return goDeeper();
|
|
|
|
}
|
|
|
|
|
2014-12-05 16:29:20 +00:00
|
|
|
bool ASTPrinter::visit(Mapping const& _node)
|
2014-10-10 14:37:54 +00:00
|
|
|
{
|
|
|
|
writeLine("Mapping");
|
|
|
|
printSourcePart(_node);
|
|
|
|
return goDeeper();
|
|
|
|
}
|
|
|
|
|
2015-02-20 14:52:30 +00:00
|
|
|
bool ASTPrinter::visit(ArrayTypeName const& _node)
|
|
|
|
{
|
|
|
|
writeLine("ArrayTypeName");
|
|
|
|
printSourcePart(_node);
|
|
|
|
return goDeeper();
|
|
|
|
}
|
|
|
|
|
2016-02-22 01:13:41 +00:00
|
|
|
bool ASTPrinter::visit(InlineAssembly const& _node)
|
|
|
|
{
|
|
|
|
writeLine("InlineAssembly");
|
|
|
|
printSourcePart(_node);
|
|
|
|
return goDeeper();
|
|
|
|
}
|
|
|
|
|
2014-12-05 16:29:20 +00:00
|
|
|
bool ASTPrinter::visit(Block const& _node)
|
2014-10-10 14:37:54 +00:00
|
|
|
{
|
|
|
|
writeLine("Block");
|
|
|
|
printSourcePart(_node);
|
|
|
|
return goDeeper();
|
|
|
|
}
|
|
|
|
|
2015-01-21 10:16:18 +00:00
|
|
|
bool ASTPrinter::visit(PlaceholderStatement const& _node)
|
|
|
|
{
|
|
|
|
writeLine("PlaceholderStatement");
|
|
|
|
printSourcePart(_node);
|
|
|
|
return goDeeper();
|
|
|
|
}
|
|
|
|
|
2014-12-05 16:29:20 +00:00
|
|
|
bool ASTPrinter::visit(IfStatement const& _node)
|
2014-10-10 14:37:54 +00:00
|
|
|
{
|
|
|
|
writeLine("IfStatement");
|
|
|
|
printSourcePart(_node);
|
|
|
|
return goDeeper();
|
|
|
|
}
|
|
|
|
|
2014-12-05 16:29:20 +00:00
|
|
|
bool ASTPrinter::visit(WhileStatement const& _node)
|
2014-10-10 14:37:54 +00:00
|
|
|
{
|
2016-07-30 07:13:05 +00:00
|
|
|
writeLine(_node.isDoWhile() ? "DoWhileStatement" : "WhileStatement");
|
2014-10-10 14:37:54 +00:00
|
|
|
printSourcePart(_node);
|
|
|
|
return goDeeper();
|
|
|
|
}
|
|
|
|
|
2014-12-15 16:45:18 +00:00
|
|
|
bool ASTPrinter::visit(ForStatement const& _node)
|
|
|
|
{
|
|
|
|
writeLine("ForStatement");
|
|
|
|
printSourcePart(_node);
|
|
|
|
return goDeeper();
|
|
|
|
}
|
|
|
|
|
2014-12-05 16:29:20 +00:00
|
|
|
bool ASTPrinter::visit(Continue const& _node)
|
2014-10-10 14:37:54 +00:00
|
|
|
{
|
|
|
|
writeLine("Continue");
|
|
|
|
printSourcePart(_node);
|
|
|
|
return goDeeper();
|
|
|
|
}
|
|
|
|
|
2014-12-05 16:29:20 +00:00
|
|
|
bool ASTPrinter::visit(Break const& _node)
|
2014-10-10 14:37:54 +00:00
|
|
|
{
|
|
|
|
writeLine("Break");
|
|
|
|
printSourcePart(_node);
|
|
|
|
return goDeeper();
|
|
|
|
}
|
|
|
|
|
2014-12-05 16:29:20 +00:00
|
|
|
bool ASTPrinter::visit(Return const& _node)
|
2014-10-10 14:37:54 +00:00
|
|
|
{
|
|
|
|
writeLine("Return");
|
|
|
|
printSourcePart(_node);
|
|
|
|
return goDeeper();
|
|
|
|
}
|
|
|
|
|
2015-09-15 14:33:14 +00:00
|
|
|
bool ASTPrinter::visit(Throw const& _node)
|
|
|
|
{
|
|
|
|
writeLine("Throw");
|
|
|
|
printSourcePart(_node);
|
|
|
|
return goDeeper();
|
|
|
|
}
|
|
|
|
|
2018-02-16 15:55:21 +00:00
|
|
|
bool ASTPrinter::visit(EmitStatement const& _node)
|
|
|
|
{
|
|
|
|
writeLine("EmitStatement");
|
|
|
|
printSourcePart(_node);
|
|
|
|
return goDeeper();
|
|
|
|
}
|
|
|
|
|
2015-02-17 15:21:38 +00:00
|
|
|
bool ASTPrinter::visit(VariableDeclarationStatement const& _node)
|
2014-10-10 14:37:54 +00:00
|
|
|
{
|
2015-02-20 11:27:39 +00:00
|
|
|
writeLine("VariableDeclarationStatement");
|
2014-10-10 14:37:54 +00:00
|
|
|
printSourcePart(_node);
|
|
|
|
return goDeeper();
|
|
|
|
}
|
|
|
|
|
2014-12-05 16:29:20 +00:00
|
|
|
bool ASTPrinter::visit(ExpressionStatement const& _node)
|
2014-10-30 00:20:32 +00:00
|
|
|
{
|
|
|
|
writeLine("ExpressionStatement");
|
|
|
|
printSourcePart(_node);
|
|
|
|
return goDeeper();
|
|
|
|
}
|
|
|
|
|
2015-12-22 16:47:00 +00:00
|
|
|
bool ASTPrinter::visit(Conditional const& _node)
|
|
|
|
{
|
|
|
|
writeLine("Conditional");
|
|
|
|
printType(_node);
|
|
|
|
printSourcePart(_node);
|
|
|
|
return goDeeper();
|
|
|
|
}
|
|
|
|
|
2014-12-05 16:29:20 +00:00
|
|
|
bool ASTPrinter::visit(Assignment const& _node)
|
2014-10-10 14:37:54 +00:00
|
|
|
{
|
2015-08-31 16:44:29 +00:00
|
|
|
writeLine(string("Assignment using operator ") + Token::toString(_node.assignmentOperator()));
|
2014-10-16 15:57:27 +00:00
|
|
|
printType(_node);
|
2014-10-10 14:37:54 +00:00
|
|
|
printSourcePart(_node);
|
|
|
|
return goDeeper();
|
|
|
|
}
|
|
|
|
|
2015-10-12 21:02:35 +00:00
|
|
|
bool ASTPrinter::visit(TupleExpression const& _node)
|
|
|
|
{
|
|
|
|
writeLine(string("TupleExpression"));
|
|
|
|
printType(_node);
|
|
|
|
printSourcePart(_node);
|
|
|
|
return goDeeper();
|
|
|
|
}
|
|
|
|
|
2014-12-05 16:29:20 +00:00
|
|
|
bool ASTPrinter::visit(UnaryOperation const& _node)
|
2014-10-10 14:37:54 +00:00
|
|
|
{
|
2014-10-24 17:06:30 +00:00
|
|
|
writeLine(string("UnaryOperation (") + (_node.isPrefixOperation() ? "prefix" : "postfix") +
|
2014-10-16 12:08:54 +00:00
|
|
|
") " + Token::toString(_node.getOperator()));
|
2014-10-16 15:57:27 +00:00
|
|
|
printType(_node);
|
2014-10-10 14:37:54 +00:00
|
|
|
printSourcePart(_node);
|
|
|
|
return goDeeper();
|
|
|
|
}
|
|
|
|
|
2014-12-05 16:29:20 +00:00
|
|
|
bool ASTPrinter::visit(BinaryOperation const& _node)
|
2014-10-10 14:37:54 +00:00
|
|
|
{
|
2014-10-24 17:06:30 +00:00
|
|
|
writeLine(string("BinaryOperation using operator ") + Token::toString(_node.getOperator()));
|
2014-10-16 15:57:27 +00:00
|
|
|
printType(_node);
|
2014-10-10 14:37:54 +00:00
|
|
|
printSourcePart(_node);
|
|
|
|
return goDeeper();
|
|
|
|
}
|
|
|
|
|
2014-12-05 16:29:20 +00:00
|
|
|
bool ASTPrinter::visit(FunctionCall const& _node)
|
2014-10-10 14:37:54 +00:00
|
|
|
{
|
|
|
|
writeLine("FunctionCall");
|
2014-10-16 15:57:27 +00:00
|
|
|
printType(_node);
|
2014-10-10 14:37:54 +00:00
|
|
|
printSourcePart(_node);
|
|
|
|
return goDeeper();
|
|
|
|
}
|
|
|
|
|
2014-12-12 15:49:26 +00:00
|
|
|
bool ASTPrinter::visit(NewExpression const& _node)
|
|
|
|
{
|
|
|
|
writeLine("NewExpression");
|
|
|
|
printType(_node);
|
|
|
|
printSourcePart(_node);
|
|
|
|
return goDeeper();
|
|
|
|
}
|
|
|
|
|
2014-12-05 16:29:20 +00:00
|
|
|
bool ASTPrinter::visit(MemberAccess const& _node)
|
2014-10-10 14:37:54 +00:00
|
|
|
{
|
2015-08-31 16:44:29 +00:00
|
|
|
writeLine("MemberAccess to member " + _node.memberName());
|
2014-10-16 15:57:27 +00:00
|
|
|
printType(_node);
|
2014-10-10 14:37:54 +00:00
|
|
|
printSourcePart(_node);
|
|
|
|
return goDeeper();
|
|
|
|
}
|
|
|
|
|
2014-12-05 16:29:20 +00:00
|
|
|
bool ASTPrinter::visit(IndexAccess const& _node)
|
2014-10-10 14:37:54 +00:00
|
|
|
{
|
|
|
|
writeLine("IndexAccess");
|
2014-10-16 15:57:27 +00:00
|
|
|
printType(_node);
|
2014-10-10 14:37:54 +00:00
|
|
|
printSourcePart(_node);
|
|
|
|
return goDeeper();
|
|
|
|
}
|
|
|
|
|
2014-12-05 16:29:20 +00:00
|
|
|
bool ASTPrinter::visit(Identifier const& _node)
|
2014-10-13 13:07:21 +00:00
|
|
|
{
|
2015-08-31 16:44:29 +00:00
|
|
|
writeLine(string("Identifier ") + _node.name());
|
2014-10-16 15:57:27 +00:00
|
|
|
printType(_node);
|
2014-10-13 13:07:21 +00:00
|
|
|
printSourcePart(_node);
|
|
|
|
return goDeeper();
|
|
|
|
}
|
|
|
|
|
2014-12-05 16:29:20 +00:00
|
|
|
bool ASTPrinter::visit(ElementaryTypeNameExpression const& _node)
|
2014-10-10 14:37:54 +00:00
|
|
|
{
|
2016-02-08 21:43:22 +00:00
|
|
|
writeLine(string("ElementaryTypeNameExpression ") + _node.typeName().toString());
|
2014-10-16 15:57:27 +00:00
|
|
|
printType(_node);
|
2014-10-10 14:37:54 +00:00
|
|
|
printSourcePart(_node);
|
|
|
|
return goDeeper();
|
|
|
|
}
|
|
|
|
|
2014-12-05 16:29:20 +00:00
|
|
|
bool ASTPrinter::visit(Literal const& _node)
|
2014-10-10 14:37:54 +00:00
|
|
|
{
|
2015-08-31 16:44:29 +00:00
|
|
|
char const* tokenString = Token::toString(_node.token());
|
2014-10-24 14:43:11 +00:00
|
|
|
if (!tokenString)
|
2014-10-16 21:49:45 +00:00
|
|
|
tokenString = "[no token]";
|
2015-08-31 16:44:29 +00:00
|
|
|
writeLine(string("Literal, token: ") + tokenString + " value: " + _node.value());
|
2014-10-16 15:57:27 +00:00
|
|
|
printType(_node);
|
2014-10-10 14:37:54 +00:00
|
|
|
printSourcePart(_node);
|
|
|
|
return goDeeper();
|
|
|
|
}
|
|
|
|
|
2016-08-19 17:57:21 +00:00
|
|
|
void ASTPrinter::endVisit(PragmaDirective const&)
|
|
|
|
{
|
|
|
|
m_indentation--;
|
|
|
|
}
|
|
|
|
|
2014-12-05 16:29:20 +00:00
|
|
|
void ASTPrinter::endVisit(ImportDirective const&)
|
2014-10-10 14:37:54 +00:00
|
|
|
{
|
|
|
|
m_indentation--;
|
|
|
|
}
|
|
|
|
|
2014-12-05 16:29:20 +00:00
|
|
|
void ASTPrinter::endVisit(ContractDefinition const&)
|
2014-10-10 14:37:54 +00:00
|
|
|
{
|
|
|
|
m_indentation--;
|
|
|
|
}
|
|
|
|
|
2015-01-28 10:28:22 +00:00
|
|
|
void ASTPrinter::endVisit(InheritanceSpecifier const&)
|
|
|
|
{
|
|
|
|
m_indentation--;
|
|
|
|
}
|
|
|
|
|
2017-11-13 15:15:56 +00:00
|
|
|
void ASTPrinter::endVisit(UsingForDirective const&)
|
|
|
|
{
|
|
|
|
m_indentation--;
|
|
|
|
}
|
|
|
|
|
2014-12-05 16:29:20 +00:00
|
|
|
void ASTPrinter::endVisit(StructDefinition const&)
|
2014-10-10 14:37:54 +00:00
|
|
|
{
|
|
|
|
m_indentation--;
|
|
|
|
}
|
|
|
|
|
2015-02-09 17:08:56 +00:00
|
|
|
void ASTPrinter::endVisit(EnumDefinition const&)
|
|
|
|
{
|
|
|
|
m_indentation--;
|
|
|
|
}
|
|
|
|
|
2015-02-13 16:34:46 +00:00
|
|
|
void ASTPrinter::endVisit(EnumValue const&)
|
2015-02-09 17:08:56 +00:00
|
|
|
{
|
|
|
|
m_indentation--;
|
|
|
|
}
|
|
|
|
|
2014-12-05 16:29:20 +00:00
|
|
|
void ASTPrinter::endVisit(ParameterList const&)
|
2014-10-10 14:37:54 +00:00
|
|
|
{
|
|
|
|
m_indentation--;
|
|
|
|
}
|
|
|
|
|
2014-12-05 16:29:20 +00:00
|
|
|
void ASTPrinter::endVisit(FunctionDefinition const&)
|
2014-10-10 14:37:54 +00:00
|
|
|
{
|
|
|
|
m_indentation--;
|
|
|
|
}
|
|
|
|
|
2014-12-05 16:29:20 +00:00
|
|
|
void ASTPrinter::endVisit(VariableDeclaration const&)
|
2014-10-10 14:37:54 +00:00
|
|
|
{
|
|
|
|
m_indentation--;
|
|
|
|
}
|
|
|
|
|
2015-01-21 10:16:18 +00:00
|
|
|
void ASTPrinter::endVisit(ModifierDefinition const&)
|
|
|
|
{
|
|
|
|
m_indentation--;
|
|
|
|
}
|
|
|
|
|
2015-01-22 00:02:38 +00:00
|
|
|
void ASTPrinter::endVisit(ModifierInvocation const&)
|
|
|
|
{
|
|
|
|
m_indentation--;
|
|
|
|
}
|
|
|
|
|
2015-01-29 13:35:28 +00:00
|
|
|
void ASTPrinter::endVisit(EventDefinition const&)
|
|
|
|
{
|
|
|
|
m_indentation--;
|
|
|
|
}
|
|
|
|
|
2014-12-05 16:29:20 +00:00
|
|
|
void ASTPrinter::endVisit(ElementaryTypeName const&)
|
2014-10-10 14:37:54 +00:00
|
|
|
{
|
|
|
|
m_indentation--;
|
|
|
|
}
|
|
|
|
|
2014-12-05 16:29:20 +00:00
|
|
|
void ASTPrinter::endVisit(UserDefinedTypeName const&)
|
2014-10-10 14:37:54 +00:00
|
|
|
{
|
|
|
|
m_indentation--;
|
|
|
|
}
|
|
|
|
|
2016-09-27 19:37:32 +00:00
|
|
|
void ASTPrinter::endVisit(FunctionTypeName const&)
|
|
|
|
{
|
|
|
|
m_indentation--;
|
|
|
|
}
|
|
|
|
|
2014-12-05 16:29:20 +00:00
|
|
|
void ASTPrinter::endVisit(Mapping const&)
|
2014-10-10 14:37:54 +00:00
|
|
|
{
|
|
|
|
m_indentation--;
|
|
|
|
}
|
|
|
|
|
2015-02-20 14:52:30 +00:00
|
|
|
void ASTPrinter::endVisit(ArrayTypeName const&)
|
|
|
|
{
|
|
|
|
m_indentation--;
|
|
|
|
}
|
|
|
|
|
2016-02-22 01:13:41 +00:00
|
|
|
void ASTPrinter::endVisit(InlineAssembly const&)
|
|
|
|
{
|
|
|
|
m_indentation--;
|
|
|
|
}
|
|
|
|
|
2014-12-05 16:29:20 +00:00
|
|
|
void ASTPrinter::endVisit(Block const&)
|
2014-10-10 14:37:54 +00:00
|
|
|
{
|
|
|
|
m_indentation--;
|
|
|
|
}
|
|
|
|
|
2015-01-21 10:16:18 +00:00
|
|
|
void ASTPrinter::endVisit(PlaceholderStatement const&)
|
|
|
|
{
|
|
|
|
m_indentation--;
|
|
|
|
}
|
|
|
|
|
2014-12-05 16:29:20 +00:00
|
|
|
void ASTPrinter::endVisit(IfStatement const&)
|
2014-10-10 14:37:54 +00:00
|
|
|
{
|
|
|
|
m_indentation--;
|
|
|
|
}
|
|
|
|
|
2014-12-05 16:29:20 +00:00
|
|
|
void ASTPrinter::endVisit(WhileStatement const&)
|
2014-10-10 14:37:54 +00:00
|
|
|
{
|
|
|
|
m_indentation--;
|
|
|
|
}
|
|
|
|
|
2014-12-15 16:45:18 +00:00
|
|
|
void ASTPrinter::endVisit(ForStatement const&)
|
|
|
|
{
|
|
|
|
m_indentation--;
|
|
|
|
}
|
|
|
|
|
2014-12-05 16:29:20 +00:00
|
|
|
void ASTPrinter::endVisit(Continue const&)
|
2014-10-10 14:37:54 +00:00
|
|
|
{
|
|
|
|
m_indentation--;
|
|
|
|
}
|
|
|
|
|
2014-12-05 16:29:20 +00:00
|
|
|
void ASTPrinter::endVisit(Break const&)
|
2014-10-10 14:37:54 +00:00
|
|
|
{
|
|
|
|
m_indentation--;
|
|
|
|
}
|
|
|
|
|
2014-12-05 16:29:20 +00:00
|
|
|
void ASTPrinter::endVisit(Return const&)
|
2014-10-10 14:37:54 +00:00
|
|
|
{
|
|
|
|
m_indentation--;
|
|
|
|
}
|
|
|
|
|
2015-09-15 14:33:14 +00:00
|
|
|
void ASTPrinter::endVisit(Throw const&)
|
|
|
|
{
|
|
|
|
m_indentation--;
|
|
|
|
}
|
|
|
|
|
2018-02-16 15:55:21 +00:00
|
|
|
void ASTPrinter::endVisit(EmitStatement const&)
|
|
|
|
{
|
|
|
|
m_indentation--;
|
|
|
|
}
|
|
|
|
|
2015-02-17 15:21:38 +00:00
|
|
|
void ASTPrinter::endVisit(VariableDeclarationStatement const&)
|
2014-10-10 14:37:54 +00:00
|
|
|
{
|
|
|
|
m_indentation--;
|
|
|
|
}
|
|
|
|
|
2014-12-05 16:29:20 +00:00
|
|
|
void ASTPrinter::endVisit(ExpressionStatement const&)
|
2014-10-30 00:20:32 +00:00
|
|
|
{
|
|
|
|
m_indentation--;
|
|
|
|
}
|
|
|
|
|
2015-12-22 16:47:00 +00:00
|
|
|
void ASTPrinter::endVisit(Conditional const&)
|
|
|
|
{
|
|
|
|
m_indentation--;
|
|
|
|
}
|
|
|
|
|
2014-12-05 16:29:20 +00:00
|
|
|
void ASTPrinter::endVisit(Assignment const&)
|
2014-10-10 14:37:54 +00:00
|
|
|
{
|
|
|
|
m_indentation--;
|
|
|
|
}
|
|
|
|
|
2015-10-12 21:02:35 +00:00
|
|
|
void ASTPrinter::endVisit(TupleExpression const&)
|
|
|
|
{
|
|
|
|
m_indentation--;
|
|
|
|
}
|
|
|
|
|
2014-12-05 16:29:20 +00:00
|
|
|
void ASTPrinter::endVisit(UnaryOperation const&)
|
2014-10-10 14:37:54 +00:00
|
|
|
{
|
|
|
|
m_indentation--;
|
|
|
|
}
|
|
|
|
|
2014-12-05 16:29:20 +00:00
|
|
|
void ASTPrinter::endVisit(BinaryOperation const&)
|
2014-10-10 14:37:54 +00:00
|
|
|
{
|
|
|
|
m_indentation--;
|
|
|
|
}
|
|
|
|
|
2014-12-05 16:29:20 +00:00
|
|
|
void ASTPrinter::endVisit(FunctionCall const&)
|
2014-10-10 14:37:54 +00:00
|
|
|
{
|
|
|
|
m_indentation--;
|
|
|
|
}
|
|
|
|
|
2014-12-12 15:49:26 +00:00
|
|
|
void ASTPrinter::endVisit(NewExpression const&)
|
|
|
|
{
|
|
|
|
m_indentation--;
|
|
|
|
}
|
|
|
|
|
2014-12-05 16:29:20 +00:00
|
|
|
void ASTPrinter::endVisit(MemberAccess const&)
|
2014-10-10 14:37:54 +00:00
|
|
|
{
|
|
|
|
m_indentation--;
|
|
|
|
}
|
|
|
|
|
2014-12-05 16:29:20 +00:00
|
|
|
void ASTPrinter::endVisit(IndexAccess const&)
|
2014-10-10 14:37:54 +00:00
|
|
|
{
|
|
|
|
m_indentation--;
|
|
|
|
}
|
|
|
|
|
2014-12-05 16:29:20 +00:00
|
|
|
void ASTPrinter::endVisit(Identifier const&)
|
2014-10-13 13:07:21 +00:00
|
|
|
{
|
|
|
|
m_indentation--;
|
|
|
|
}
|
|
|
|
|
2014-12-05 16:29:20 +00:00
|
|
|
void ASTPrinter::endVisit(ElementaryTypeNameExpression const&)
|
2014-10-10 14:37:54 +00:00
|
|
|
{
|
|
|
|
m_indentation--;
|
|
|
|
}
|
|
|
|
|
2014-12-05 16:29:20 +00:00
|
|
|
void ASTPrinter::endVisit(Literal const&)
|
2014-10-10 14:37:54 +00:00
|
|
|
{
|
|
|
|
m_indentation--;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ASTPrinter::printSourcePart(ASTNode const& _node)
|
|
|
|
{
|
2015-05-06 08:43:59 +00:00
|
|
|
if (m_gasCosts.count(&_node))
|
2015-09-01 09:19:02 +00:00
|
|
|
*m_ostream << indentation() << " Gas costs: " << m_gasCosts.at(&_node) << endl;
|
2014-10-16 12:08:54 +00:00
|
|
|
if (!m_source.empty())
|
|
|
|
{
|
2015-08-31 16:44:29 +00:00
|
|
|
SourceLocation const& location(_node.location());
|
2017-08-25 10:43:58 +00:00
|
|
|
*m_ostream <<
|
|
|
|
indentation() <<
|
|
|
|
" Source: " <<
|
2017-08-29 14:51:37 +00:00
|
|
|
Json::valueToQuotedString(m_source.substr(location.start, location.end - location.start).c_str()) <<
|
2017-08-25 10:43:58 +00:00
|
|
|
endl;
|
2014-10-10 14:37:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-16 15:57:27 +00:00
|
|
|
void ASTPrinter::printType(Expression const& _expression)
|
|
|
|
{
|
2015-09-16 14:56:30 +00:00
|
|
|
if (_expression.annotation().type)
|
|
|
|
*m_ostream << indentation() << " Type: " << _expression.annotation().type->toString() << "\n";
|
2014-10-16 15:57:27 +00:00
|
|
|
else
|
2015-09-01 09:19:02 +00:00
|
|
|
*m_ostream << indentation() << " Type unknown.\n";
|
2014-10-16 15:57:27 +00:00
|
|
|
}
|
|
|
|
|
2015-09-01 09:19:02 +00:00
|
|
|
string ASTPrinter::indentation() const
|
2014-10-10 14:37:54 +00:00
|
|
|
{
|
2014-10-24 17:06:30 +00:00
|
|
|
return string(m_indentation * 2, ' ');
|
2014-10-10 14:37:54 +00:00
|
|
|
}
|
|
|
|
|
2014-10-24 17:06:30 +00:00
|
|
|
void ASTPrinter::writeLine(string const& _line)
|
2014-10-10 14:37:54 +00:00
|
|
|
{
|
2015-09-01 09:19:02 +00:00
|
|
|
*m_ostream << indentation() << _line << endl;
|
2014-10-10 14:37:54 +00:00
|
|
|
}
|
|
|
|
|
2014-10-16 12:08:54 +00:00
|
|
|
}
|
|
|
|
}
|