2014-10-13 15:13:48 +00:00
|
|
|
/*
|
2014-10-16 12:08:54 +00:00
|
|
|
This file is part of cpp-ethereum.
|
2014-10-13 15:13:48 +00:00
|
|
|
|
2014-10-16 12:08:54 +00:00
|
|
|
cpp-ethereum 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.
|
2014-10-13 15:13:48 +00:00
|
|
|
|
2014-10-16 12:08:54 +00:00
|
|
|
cpp-ethereum 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.
|
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
|
|
|
|
along with cpp-ethereum. 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.
|
|
|
|
*/
|
|
|
|
|
2014-10-10 14:37:54 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <ostream>
|
|
|
|
#include <libsolidity/ASTVisitor.h>
|
2015-05-06 08:43:59 +00:00
|
|
|
#include <libsolidity/StructuralGasEstimator.h>
|
2014-10-10 14:37:54 +00:00
|
|
|
|
2014-10-16 12:08:54 +00:00
|
|
|
namespace dev
|
|
|
|
{
|
|
|
|
namespace solidity
|
|
|
|
{
|
2014-10-10 14:37:54 +00:00
|
|
|
|
2014-10-28 15:51:26 +00:00
|
|
|
/**
|
|
|
|
* Pretty-printer for the abstract syntax tree (the "pretty" is arguable) for debugging purposes.
|
|
|
|
*/
|
2014-12-06 01:19:10 +00:00
|
|
|
class ASTPrinter: public ASTConstVisitor
|
2014-10-10 14:37:54 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
/// Create a printer for the given abstract syntax tree. If the source is specified,
|
|
|
|
/// the corresponding parts of the source are printed with each node.
|
2015-05-06 08:43:59 +00:00
|
|
|
ASTPrinter(
|
|
|
|
ASTNode const& _ast,
|
|
|
|
std::string const& _source = std::string(),
|
2015-05-10 10:45:36 +00:00
|
|
|
StructuralGasEstimator::ASTGasConsumption const& _gasCosts = StructuralGasEstimator::ASTGasConsumption()
|
2015-05-06 08:43:59 +00:00
|
|
|
);
|
2014-10-10 14:37:54 +00:00
|
|
|
/// Output the string representation of the AST to _stream.
|
|
|
|
void print(std::ostream& _stream);
|
|
|
|
|
2014-12-05 16:29:20 +00:00
|
|
|
bool visit(ImportDirective const& _node) override;
|
|
|
|
bool visit(ContractDefinition const& _node) override;
|
2015-01-28 10:28:22 +00:00
|
|
|
bool visit(InheritanceSpecifier const& _node) override;
|
2014-12-05 16:29:20 +00:00
|
|
|
bool visit(StructDefinition const& _node) override;
|
2015-02-09 17:08:56 +00:00
|
|
|
bool visit(EnumDefinition const& _node) override;
|
2015-02-13 16:34:46 +00:00
|
|
|
bool visit(EnumValue const& _node) override;
|
2014-12-05 16:29:20 +00:00
|
|
|
bool visit(ParameterList const& _node) override;
|
|
|
|
bool visit(FunctionDefinition const& _node) override;
|
|
|
|
bool visit(VariableDeclaration const& _node) override;
|
2015-01-21 10:16:18 +00:00
|
|
|
bool visit(ModifierDefinition const& _node) override;
|
2015-01-22 00:02:38 +00:00
|
|
|
bool visit(ModifierInvocation const& _node) override;
|
2015-01-29 13:35:28 +00:00
|
|
|
bool visit(EventDefinition const& _node) override;
|
2014-12-05 16:29:20 +00:00
|
|
|
bool visit(TypeName const& _node) override;
|
|
|
|
bool visit(ElementaryTypeName const& _node) override;
|
|
|
|
bool visit(UserDefinedTypeName const& _node) override;
|
|
|
|
bool visit(Mapping const& _node) override;
|
2015-02-20 14:52:30 +00:00
|
|
|
bool visit(ArrayTypeName const& _node) override;
|
2014-12-05 16:29:20 +00:00
|
|
|
bool visit(Block const& _node) override;
|
2015-01-21 10:16:18 +00:00
|
|
|
bool visit(PlaceholderStatement const& _node) override;
|
2014-12-05 16:29:20 +00:00
|
|
|
bool visit(IfStatement const& _node) override;
|
|
|
|
bool visit(WhileStatement const& _node) override;
|
2014-12-15 16:45:18 +00:00
|
|
|
bool visit(ForStatement const& _node) override;
|
2014-12-05 16:29:20 +00:00
|
|
|
bool visit(Continue const& _node) override;
|
|
|
|
bool visit(Break const& _node) override;
|
|
|
|
bool visit(Return const& _node) override;
|
2015-02-17 15:21:38 +00:00
|
|
|
bool visit(VariableDeclarationStatement const& _node) override;
|
2014-12-05 16:29:20 +00:00
|
|
|
bool visit(ExpressionStatement const& _node) override;
|
|
|
|
bool visit(Assignment const& _node) override;
|
|
|
|
bool visit(UnaryOperation const& _node) override;
|
|
|
|
bool visit(BinaryOperation const& _node) override;
|
|
|
|
bool visit(FunctionCall const& _node) override;
|
2014-12-12 15:49:26 +00:00
|
|
|
bool visit(NewExpression const& _node) override;
|
2014-12-05 16:29:20 +00:00
|
|
|
bool visit(MemberAccess const& _node) override;
|
|
|
|
bool visit(IndexAccess const& _node) override;
|
|
|
|
bool visit(Identifier const& _node) override;
|
|
|
|
bool visit(ElementaryTypeNameExpression const& _node) override;
|
|
|
|
bool visit(Literal const& _node) override;
|
2014-10-10 14:37:54 +00:00
|
|
|
|
2014-12-05 16:29:20 +00:00
|
|
|
void endVisit(ImportDirective const&) override;
|
|
|
|
void endVisit(ContractDefinition const&) override;
|
2015-01-28 10:28:22 +00:00
|
|
|
void endVisit(InheritanceSpecifier const&) override;
|
2014-12-05 16:29:20 +00:00
|
|
|
void endVisit(StructDefinition const&) override;
|
2015-02-09 17:08:56 +00:00
|
|
|
void endVisit(EnumDefinition const&) override;
|
2015-02-13 16:34:46 +00:00
|
|
|
void endVisit(EnumValue const&) override;
|
2014-12-05 16:29:20 +00:00
|
|
|
void endVisit(ParameterList const&) override;
|
|
|
|
void endVisit(FunctionDefinition const&) override;
|
|
|
|
void endVisit(VariableDeclaration const&) override;
|
2015-01-21 10:16:18 +00:00
|
|
|
void endVisit(ModifierDefinition const&) override;
|
2015-01-22 00:02:38 +00:00
|
|
|
void endVisit(ModifierInvocation const&) override;
|
2015-01-29 13:35:28 +00:00
|
|
|
void endVisit(EventDefinition const&) override;
|
2014-12-05 16:29:20 +00:00
|
|
|
void endVisit(TypeName const&) override;
|
|
|
|
void endVisit(ElementaryTypeName const&) override;
|
|
|
|
void endVisit(UserDefinedTypeName const&) override;
|
|
|
|
void endVisit(Mapping const&) override;
|
2015-02-20 14:52:30 +00:00
|
|
|
void endVisit(ArrayTypeName const&) override;
|
2014-12-05 16:29:20 +00:00
|
|
|
void endVisit(Block const&) override;
|
2015-01-21 10:16:18 +00:00
|
|
|
void endVisit(PlaceholderStatement const&) override;
|
2014-12-05 16:29:20 +00:00
|
|
|
void endVisit(IfStatement const&) override;
|
|
|
|
void endVisit(WhileStatement const&) override;
|
2014-12-15 16:45:18 +00:00
|
|
|
void endVisit(ForStatement const&) override;
|
2014-12-05 16:29:20 +00:00
|
|
|
void endVisit(Continue const&) override;
|
|
|
|
void endVisit(Break const&) override;
|
|
|
|
void endVisit(Return const&) override;
|
2015-02-17 15:21:38 +00:00
|
|
|
void endVisit(VariableDeclarationStatement const&) override;
|
2014-12-05 16:29:20 +00:00
|
|
|
void endVisit(ExpressionStatement const&) override;
|
|
|
|
void endVisit(Assignment const&) override;
|
|
|
|
void endVisit(UnaryOperation const&) override;
|
|
|
|
void endVisit(BinaryOperation const&) override;
|
|
|
|
void endVisit(FunctionCall const&) override;
|
2014-12-12 15:49:26 +00:00
|
|
|
void endVisit(NewExpression const&) override;
|
2014-12-05 16:29:20 +00:00
|
|
|
void endVisit(MemberAccess const&) override;
|
|
|
|
void endVisit(IndexAccess const&) override;
|
|
|
|
void endVisit(Identifier const&) override;
|
|
|
|
void endVisit(ElementaryTypeNameExpression const&) override;
|
|
|
|
void endVisit(Literal const&) override;
|
2014-10-10 14:37:54 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
void printSourcePart(ASTNode const& _node);
|
2014-10-16 15:57:27 +00:00
|
|
|
void printType(Expression const& _expression);
|
2014-10-10 14:37:54 +00:00
|
|
|
std::string getIndentation() const;
|
|
|
|
void writeLine(std::string const& _line);
|
|
|
|
bool goDeeper() { m_indentation++; return true; }
|
2014-10-16 12:08:54 +00:00
|
|
|
|
2014-10-10 14:37:54 +00:00
|
|
|
int m_indentation;
|
|
|
|
std::string m_source;
|
2014-12-05 16:29:20 +00:00
|
|
|
ASTNode const* m_ast;
|
2015-05-06 08:43:59 +00:00
|
|
|
StructuralGasEstimator::ASTGasConsumption m_gasCosts;
|
2014-10-10 14:37:54 +00:00
|
|
|
std::ostream* m_ostream;
|
|
|
|
};
|
|
|
|
|
2014-10-16 12:08:54 +00:00
|
|
|
}
|
|
|
|
}
|