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
|
|
|
#include <libsolidity/ASTPrinter.h>
|
|
|
|
#include <libsolidity/AST.h>
|
|
|
|
|
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
|
|
|
|
2014-12-05 16:29:20 +00:00
|
|
|
ASTPrinter::ASTPrinter(ASTNode const& _ast, string const& _source):
|
2014-11-11 16:41:48 +00:00
|
|
|
m_indentation(0), m_source(_source), m_ast(&_ast)
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-12-05 16:29:20 +00:00
|
|
|
bool ASTPrinter::visit(ImportDirective const& _node)
|
2014-12-03 06:46:55 +00:00
|
|
|
{
|
2014-12-05 14:35:05 +00:00
|
|
|
writeLine("ImportDirective \"" + _node.getIdentifier() + "\"");
|
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
|
|
|
{
|
|
|
|
writeLine("ContractDefinition \"" + _node.getName() + "\"");
|
|
|
|
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
|
|
|
{
|
|
|
|
writeLine("StructDefinition \"" + _node.getName() + "\"");
|
|
|
|
printSourcePart(_node);
|
|
|
|
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
|
|
|
{
|
|
|
|
writeLine("FunctionDefinition \"" + _node.getName() + "\"" +
|
|
|
|
(_node.isPublic() ? " - public" : "") +
|
|
|
|
(_node.isDeclaredConst() ? " - const" : ""));
|
|
|
|
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
|
|
|
{
|
|
|
|
writeLine("VariableDeclaration \"" + _node.getName() + "\"");
|
|
|
|
printSourcePart(_node);
|
|
|
|
return goDeeper();
|
|
|
|
}
|
|
|
|
|
2014-12-05 16:29:20 +00:00
|
|
|
bool ASTPrinter::visit(TypeName const& _node)
|
2014-10-10 14:37:54 +00:00
|
|
|
{
|
|
|
|
writeLine("TypeName");
|
|
|
|
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
|
|
|
{
|
2014-10-24 17:06:30 +00:00
|
|
|
writeLine(string("ElementaryTypeName ") + Token::toString(_node.getTypeName()));
|
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
|
|
|
{
|
|
|
|
writeLine("UserDefinedTypeName \"" + _node.getName() + "\"");
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2014-12-05 16:29:20 +00:00
|
|
|
bool ASTPrinter::visit(Statement const& _node)
|
2014-10-10 14:37:54 +00:00
|
|
|
{
|
|
|
|
writeLine("Statement");
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
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(BreakableStatement const& _node)
|
2014-10-10 14:37:54 +00:00
|
|
|
{
|
|
|
|
writeLine("BreakableStatement");
|
|
|
|
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
|
|
|
{
|
|
|
|
writeLine("WhileStatement");
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2014-12-05 16:29:20 +00:00
|
|
|
bool ASTPrinter::visit(VariableDefinition const& _node)
|
2014-10-10 14:37:54 +00:00
|
|
|
{
|
|
|
|
writeLine("VariableDefinition");
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2014-12-05 16:29:20 +00:00
|
|
|
bool ASTPrinter::visit(Expression const& _node)
|
2014-10-10 14:37:54 +00:00
|
|
|
{
|
|
|
|
writeLine("Expression");
|
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(Assignment const& _node)
|
2014-10-10 14:37:54 +00:00
|
|
|
{
|
2014-10-24 17:06:30 +00:00
|
|
|
writeLine(string("Assignment using operator ") + Token::toString(_node.getAssignmentOperator()));
|
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(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
|
|
|
{
|
|
|
|
writeLine("MemberAccess to member " + _node.getMemberName());
|
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(PrimaryExpression const& _node)
|
2014-10-10 14:37:54 +00:00
|
|
|
{
|
|
|
|
writeLine("PrimaryExpression");
|
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
|
|
|
{
|
2014-10-24 17:06:30 +00:00
|
|
|
writeLine(string("Identifier ") + _node.getName());
|
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
|
|
|
{
|
2014-10-24 17:06:30 +00:00
|
|
|
writeLine(string("ElementaryTypeNameExpression ") + Token::toString(_node.getTypeToken()));
|
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
|
|
|
{
|
2014-10-20 11:02:06 +00:00
|
|
|
char const* tokenString = Token::toString(_node.getToken());
|
2014-10-24 14:43:11 +00:00
|
|
|
if (!tokenString)
|
2014-10-16 21:49:45 +00:00
|
|
|
tokenString = "[no token]";
|
2014-10-24 17:06:30 +00:00
|
|
|
writeLine(string("Literal, token: ") + tokenString + " value: " + _node.getValue());
|
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
|
|
|
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--;
|
|
|
|
}
|
|
|
|
|
2014-12-05 16:29:20 +00:00
|
|
|
void ASTPrinter::endVisit(StructDefinition const&)
|
2014-10-10 14:37:54 +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--;
|
|
|
|
}
|
|
|
|
|
2014-12-05 16:29:20 +00:00
|
|
|
void ASTPrinter::endVisit(TypeName const&)
|
2014-10-10 14:37:54 +00:00
|
|
|
{
|
|
|
|
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--;
|
|
|
|
}
|
|
|
|
|
2014-12-05 16:29:20 +00:00
|
|
|
void ASTPrinter::endVisit(Mapping const&)
|
2014-10-10 14:37:54 +00:00
|
|
|
{
|
|
|
|
m_indentation--;
|
|
|
|
}
|
|
|
|
|
2014-12-05 16:29:20 +00:00
|
|
|
void ASTPrinter::endVisit(Statement const&)
|
2014-10-10 14:37:54 +00:00
|
|
|
{
|
|
|
|
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--;
|
|
|
|
}
|
|
|
|
|
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(BreakableStatement 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--;
|
|
|
|
}
|
|
|
|
|
2014-12-05 16:29:20 +00:00
|
|
|
void ASTPrinter::endVisit(VariableDefinition 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--;
|
|
|
|
}
|
|
|
|
|
2014-12-05 16:29:20 +00:00
|
|
|
void ASTPrinter::endVisit(Expression const&)
|
2014-10-10 14:37:54 +00:00
|
|
|
{
|
|
|
|
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--;
|
|
|
|
}
|
|
|
|
|
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(PrimaryExpression 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)
|
|
|
|
{
|
2014-10-16 12:08:54 +00:00
|
|
|
if (!m_source.empty())
|
|
|
|
{
|
2014-10-10 14:37:54 +00:00
|
|
|
Location const& location(_node.getLocation());
|
2014-11-11 16:41:48 +00:00
|
|
|
*m_ostream << getIndentation() << " Source: "
|
|
|
|
<< escaped(m_source.substr(location.start, location.end - location.start), false) << endl;
|
2014-10-10 14:37:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-16 15:57:27 +00:00
|
|
|
void ASTPrinter::printType(Expression const& _expression)
|
|
|
|
{
|
|
|
|
if (_expression.getType())
|
|
|
|
*m_ostream << getIndentation() << " Type: " << _expression.getType()->toString() << "\n";
|
|
|
|
else
|
|
|
|
*m_ostream << getIndentation() << " Type unknown.\n";
|
|
|
|
}
|
|
|
|
|
2014-10-24 17:06:30 +00:00
|
|
|
string ASTPrinter::getIndentation() 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
|
|
|
{
|
2014-10-24 17:06:30 +00:00
|
|
|
*m_ostream << getIndentation() << _line << endl;
|
2014-10-10 14:37:54 +00:00
|
|
|
}
|
|
|
|
|
2014-10-16 12:08:54 +00:00
|
|
|
}
|
|
|
|
}
|