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
|
|
|
|
* AST visitor base class.
|
|
|
|
*/
|
|
|
|
|
2014-10-10 14:37:54 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <libsolidity/ASTForward.h>
|
|
|
|
#include <string>
|
|
|
|
|
2014-10-16 12:08:54 +00:00
|
|
|
namespace dev
|
|
|
|
{
|
|
|
|
namespace solidity
|
|
|
|
{
|
2014-10-10 14:37:54 +00:00
|
|
|
|
2014-10-28 15:57:20 +00:00
|
|
|
/**
|
|
|
|
* Visitor interface for the abstract syntax tree. This class is tightly bound to the
|
|
|
|
* implementation of @ref ASTNode::accept and its overrides. After a call to
|
|
|
|
* @ref ASTNode::accept, the function visit for the appropriate parameter is called and then
|
|
|
|
* (if it returns true) this continues recursively for all child nodes in document order
|
|
|
|
* (there is an exception for contracts). After all child nodes have been visited, endVisit is
|
|
|
|
* called for the node.
|
|
|
|
*/
|
2014-10-16 12:08:54 +00:00
|
|
|
class ASTVisitor
|
|
|
|
{
|
2014-10-10 14:37:54 +00:00
|
|
|
public:
|
|
|
|
virtual bool visit(ASTNode&) { return true; }
|
2014-12-03 06:46:55 +00:00
|
|
|
virtual bool visit(SourceUnit&) { return true; }
|
|
|
|
virtual bool visit(ImportDirective&) { return true; }
|
2014-10-10 14:37:54 +00:00
|
|
|
virtual bool visit(ContractDefinition&) { return true; }
|
2015-01-28 10:28:22 +00:00
|
|
|
virtual bool visit(InheritanceSpecifier&) { return true; }
|
2014-10-10 14:37:54 +00:00
|
|
|
virtual bool visit(StructDefinition&) { return true; }
|
2015-02-09 17:08:56 +00:00
|
|
|
virtual bool visit(EnumDefinition&) { return true; }
|
2015-02-13 16:34:46 +00:00
|
|
|
virtual bool visit(EnumValue&) { return true; }
|
2014-10-10 14:37:54 +00:00
|
|
|
virtual bool visit(ParameterList&) { return true; }
|
|
|
|
virtual bool visit(FunctionDefinition&) { return true; }
|
|
|
|
virtual bool visit(VariableDeclaration&) { return true; }
|
2015-01-21 10:16:18 +00:00
|
|
|
virtual bool visit(ModifierDefinition&) { return true; }
|
2015-01-22 00:02:38 +00:00
|
|
|
virtual bool visit(ModifierInvocation&) { return true; }
|
2015-01-29 13:35:28 +00:00
|
|
|
virtual bool visit(EventDefinition&) { return true; }
|
2014-10-10 14:37:54 +00:00
|
|
|
virtual bool visit(TypeName&) { return true; }
|
|
|
|
virtual bool visit(ElementaryTypeName&) { return true; }
|
|
|
|
virtual bool visit(UserDefinedTypeName&) { return true; }
|
|
|
|
virtual bool visit(Mapping&) { return true; }
|
|
|
|
virtual bool visit(Statement&) { return true; }
|
|
|
|
virtual bool visit(Block&) { return true; }
|
2015-01-21 10:16:18 +00:00
|
|
|
virtual bool visit(PlaceholderStatement&) { return true; }
|
2014-10-10 14:37:54 +00:00
|
|
|
virtual bool visit(IfStatement&) { return true; }
|
|
|
|
virtual bool visit(BreakableStatement&) { return true; }
|
|
|
|
virtual bool visit(WhileStatement&) { return true; }
|
2014-12-15 16:45:18 +00:00
|
|
|
virtual bool visit(ForStatement&) { return true; }
|
2014-10-10 14:37:54 +00:00
|
|
|
virtual bool visit(Continue&) { return true; }
|
|
|
|
virtual bool visit(Break&) { return true; }
|
|
|
|
virtual bool visit(Return&) { return true; }
|
|
|
|
virtual bool visit(VariableDefinition&) { return true; }
|
2014-10-30 00:20:32 +00:00
|
|
|
virtual bool visit(ExpressionStatement&) { return true; }
|
2014-10-10 14:37:54 +00:00
|
|
|
virtual bool visit(Expression&) { return true; }
|
|
|
|
virtual bool visit(Assignment&) { return true; }
|
|
|
|
virtual bool visit(UnaryOperation&) { return true; }
|
|
|
|
virtual bool visit(BinaryOperation&) { return true; }
|
|
|
|
virtual bool visit(FunctionCall&) { return true; }
|
2014-12-12 15:49:26 +00:00
|
|
|
virtual bool visit(NewExpression&) { return true; }
|
2014-10-10 14:37:54 +00:00
|
|
|
virtual bool visit(MemberAccess&) { return true; }
|
|
|
|
virtual bool visit(IndexAccess&) { return true; }
|
|
|
|
virtual bool visit(PrimaryExpression&) { return true; }
|
2014-10-13 13:07:21 +00:00
|
|
|
virtual bool visit(Identifier&) { return true; }
|
2014-10-10 14:37:54 +00:00
|
|
|
virtual bool visit(ElementaryTypeNameExpression&) { return true; }
|
|
|
|
virtual bool visit(Literal&) { return true; }
|
|
|
|
|
|
|
|
virtual void endVisit(ASTNode&) { }
|
2014-12-03 06:46:55 +00:00
|
|
|
virtual void endVisit(SourceUnit&) { }
|
|
|
|
virtual void endVisit(ImportDirective&) { }
|
2014-10-10 14:37:54 +00:00
|
|
|
virtual void endVisit(ContractDefinition&) { }
|
2015-01-28 10:28:22 +00:00
|
|
|
virtual void endVisit(InheritanceSpecifier&) { }
|
2014-10-10 14:37:54 +00:00
|
|
|
virtual void endVisit(StructDefinition&) { }
|
2015-02-09 17:08:56 +00:00
|
|
|
virtual void endVisit(EnumDefinition&) { }
|
2015-02-13 16:34:46 +00:00
|
|
|
virtual void endVisit(EnumValue&) { }
|
2014-10-10 14:37:54 +00:00
|
|
|
virtual void endVisit(ParameterList&) { }
|
|
|
|
virtual void endVisit(FunctionDefinition&) { }
|
|
|
|
virtual void endVisit(VariableDeclaration&) { }
|
2015-01-21 10:16:18 +00:00
|
|
|
virtual void endVisit(ModifierDefinition&) { }
|
2015-01-22 00:02:38 +00:00
|
|
|
virtual void endVisit(ModifierInvocation&) { }
|
2015-01-29 13:35:28 +00:00
|
|
|
virtual void endVisit(EventDefinition&) { }
|
2014-10-10 14:37:54 +00:00
|
|
|
virtual void endVisit(TypeName&) { }
|
|
|
|
virtual void endVisit(ElementaryTypeName&) { }
|
|
|
|
virtual void endVisit(UserDefinedTypeName&) { }
|
|
|
|
virtual void endVisit(Mapping&) { }
|
|
|
|
virtual void endVisit(Statement&) { }
|
|
|
|
virtual void endVisit(Block&) { }
|
2015-01-21 10:16:18 +00:00
|
|
|
virtual void endVisit(PlaceholderStatement&) { }
|
2014-10-10 14:37:54 +00:00
|
|
|
virtual void endVisit(IfStatement&) { }
|
|
|
|
virtual void endVisit(BreakableStatement&) { }
|
|
|
|
virtual void endVisit(WhileStatement&) { }
|
2014-12-15 16:45:18 +00:00
|
|
|
virtual void endVisit(ForStatement&) { }
|
2014-10-10 14:37:54 +00:00
|
|
|
virtual void endVisit(Continue&) { }
|
|
|
|
virtual void endVisit(Break&) { }
|
|
|
|
virtual void endVisit(Return&) { }
|
|
|
|
virtual void endVisit(VariableDefinition&) { }
|
2014-10-30 00:20:32 +00:00
|
|
|
virtual void endVisit(ExpressionStatement&) { }
|
2014-10-10 14:37:54 +00:00
|
|
|
virtual void endVisit(Expression&) { }
|
|
|
|
virtual void endVisit(Assignment&) { }
|
|
|
|
virtual void endVisit(UnaryOperation&) { }
|
|
|
|
virtual void endVisit(BinaryOperation&) { }
|
|
|
|
virtual void endVisit(FunctionCall&) { }
|
2014-12-12 15:49:26 +00:00
|
|
|
virtual void endVisit(NewExpression&) { }
|
2014-10-10 14:37:54 +00:00
|
|
|
virtual void endVisit(MemberAccess&) { }
|
|
|
|
virtual void endVisit(IndexAccess&) { }
|
|
|
|
virtual void endVisit(PrimaryExpression&) { }
|
2014-10-13 13:07:21 +00:00
|
|
|
virtual void endVisit(Identifier&) { }
|
2014-10-10 14:37:54 +00:00
|
|
|
virtual void endVisit(ElementaryTypeNameExpression&) { }
|
|
|
|
virtual void endVisit(Literal&) { }
|
2014-12-06 01:19:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class ASTConstVisitor
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual bool visit(ASTNode const&) { return true; }
|
|
|
|
virtual bool visit(SourceUnit const&) { return true; }
|
|
|
|
virtual bool visit(ImportDirective const&) { return true; }
|
|
|
|
virtual bool visit(ContractDefinition const&) { return true; }
|
2015-01-28 10:28:22 +00:00
|
|
|
virtual bool visit(InheritanceSpecifier const&) { return true; }
|
2014-12-06 01:19:10 +00:00
|
|
|
virtual bool visit(StructDefinition const&) { return true; }
|
2015-02-09 17:08:56 +00:00
|
|
|
virtual bool visit(EnumDefinition const&) { return true; }
|
2015-02-13 16:34:46 +00:00
|
|
|
virtual bool visit(EnumValue const&) { return true; }
|
2014-12-06 01:19:10 +00:00
|
|
|
virtual bool visit(ParameterList const&) { return true; }
|
|
|
|
virtual bool visit(FunctionDefinition const&) { return true; }
|
|
|
|
virtual bool visit(VariableDeclaration const&) { return true; }
|
2015-01-21 10:16:18 +00:00
|
|
|
virtual bool visit(ModifierDefinition const&) { return true; }
|
2015-01-22 00:02:38 +00:00
|
|
|
virtual bool visit(ModifierInvocation const&) { return true; }
|
2015-01-29 13:35:28 +00:00
|
|
|
virtual bool visit(EventDefinition const&) { return true; }
|
2014-12-06 01:19:10 +00:00
|
|
|
virtual bool visit(TypeName const&) { return true; }
|
|
|
|
virtual bool visit(ElementaryTypeName const&) { return true; }
|
|
|
|
virtual bool visit(UserDefinedTypeName const&) { return true; }
|
|
|
|
virtual bool visit(Mapping const&) { return true; }
|
|
|
|
virtual bool visit(Statement const&) { return true; }
|
|
|
|
virtual bool visit(Block const&) { return true; }
|
2015-01-21 10:16:18 +00:00
|
|
|
virtual bool visit(PlaceholderStatement const&) { return true; }
|
2014-12-06 01:19:10 +00:00
|
|
|
virtual bool visit(IfStatement const&) { return true; }
|
|
|
|
virtual bool visit(BreakableStatement const&) { return true; }
|
|
|
|
virtual bool visit(WhileStatement const&) { return true; }
|
2014-12-15 16:45:18 +00:00
|
|
|
virtual bool visit(ForStatement const&) { return true; }
|
2014-12-06 01:19:10 +00:00
|
|
|
virtual bool visit(Continue const&) { return true; }
|
|
|
|
virtual bool visit(Break const&) { return true; }
|
|
|
|
virtual bool visit(Return const&) { return true; }
|
|
|
|
virtual bool visit(VariableDefinition const&) { return true; }
|
|
|
|
virtual bool visit(ExpressionStatement const&) { return true; }
|
|
|
|
virtual bool visit(Expression const&) { return true; }
|
|
|
|
virtual bool visit(Assignment const&) { return true; }
|
|
|
|
virtual bool visit(UnaryOperation const&) { return true; }
|
|
|
|
virtual bool visit(BinaryOperation const&) { return true; }
|
|
|
|
virtual bool visit(FunctionCall const&) { return true; }
|
2014-12-12 15:49:26 +00:00
|
|
|
virtual bool visit(NewExpression const&) { return true; }
|
2014-12-06 01:19:10 +00:00
|
|
|
virtual bool visit(MemberAccess const&) { return true; }
|
|
|
|
virtual bool visit(IndexAccess const&) { return true; }
|
|
|
|
virtual bool visit(PrimaryExpression const&) { return true; }
|
|
|
|
virtual bool visit(Identifier const&) { return true; }
|
|
|
|
virtual bool visit(ElementaryTypeNameExpression const&) { return true; }
|
|
|
|
virtual bool visit(Literal const&) { return true; }
|
2014-12-05 16:29:20 +00:00
|
|
|
|
|
|
|
virtual void endVisit(ASTNode const&) { }
|
|
|
|
virtual void endVisit(SourceUnit const&) { }
|
|
|
|
virtual void endVisit(ImportDirective const&) { }
|
|
|
|
virtual void endVisit(ContractDefinition const&) { }
|
2015-01-28 10:28:22 +00:00
|
|
|
virtual void endVisit(InheritanceSpecifier const&) { }
|
2014-12-05 16:29:20 +00:00
|
|
|
virtual void endVisit(StructDefinition const&) { }
|
2015-02-09 17:08:56 +00:00
|
|
|
virtual void endVisit(EnumDefinition const&) { }
|
2015-02-13 16:34:46 +00:00
|
|
|
virtual void endVisit(EnumValue const&) { }
|
2014-12-05 16:29:20 +00:00
|
|
|
virtual void endVisit(ParameterList const&) { }
|
|
|
|
virtual void endVisit(FunctionDefinition const&) { }
|
|
|
|
virtual void endVisit(VariableDeclaration const&) { }
|
2015-01-21 10:16:18 +00:00
|
|
|
virtual void endVisit(ModifierDefinition const&) { }
|
2015-01-22 00:02:38 +00:00
|
|
|
virtual void endVisit(ModifierInvocation const&) { }
|
2015-01-29 13:35:28 +00:00
|
|
|
virtual void endVisit(EventDefinition const&) { }
|
2014-12-05 16:29:20 +00:00
|
|
|
virtual void endVisit(TypeName const&) { }
|
|
|
|
virtual void endVisit(ElementaryTypeName const&) { }
|
|
|
|
virtual void endVisit(UserDefinedTypeName const&) { }
|
|
|
|
virtual void endVisit(Mapping const&) { }
|
|
|
|
virtual void endVisit(Statement const&) { }
|
|
|
|
virtual void endVisit(Block const&) { }
|
2015-01-21 10:16:18 +00:00
|
|
|
virtual void endVisit(PlaceholderStatement const&) { }
|
2014-12-05 16:29:20 +00:00
|
|
|
virtual void endVisit(IfStatement const&) { }
|
|
|
|
virtual void endVisit(BreakableStatement const&) { }
|
|
|
|
virtual void endVisit(WhileStatement const&) { }
|
2014-12-15 16:45:18 +00:00
|
|
|
virtual void endVisit(ForStatement const&) { }
|
2014-12-05 16:29:20 +00:00
|
|
|
virtual void endVisit(Continue const&) { }
|
|
|
|
virtual void endVisit(Break const&) { }
|
|
|
|
virtual void endVisit(Return const&) { }
|
|
|
|
virtual void endVisit(VariableDefinition const&) { }
|
|
|
|
virtual void endVisit(ExpressionStatement const&) { }
|
|
|
|
virtual void endVisit(Expression const&) { }
|
|
|
|
virtual void endVisit(Assignment const&) { }
|
|
|
|
virtual void endVisit(UnaryOperation const&) { }
|
|
|
|
virtual void endVisit(BinaryOperation const&) { }
|
|
|
|
virtual void endVisit(FunctionCall const&) { }
|
2014-12-12 15:49:26 +00:00
|
|
|
virtual void endVisit(NewExpression const&) { }
|
2014-12-05 16:29:20 +00:00
|
|
|
virtual void endVisit(MemberAccess const&) { }
|
|
|
|
virtual void endVisit(IndexAccess const&) { }
|
|
|
|
virtual void endVisit(PrimaryExpression const&) { }
|
|
|
|
virtual void endVisit(Identifier const&) { }
|
|
|
|
virtual void endVisit(ElementaryTypeNameExpression const&) { }
|
|
|
|
virtual void endVisit(Literal const&) { }
|
2014-10-10 14:37:54 +00:00
|
|
|
};
|
|
|
|
|
2014-10-16 12:08:54 +00:00
|
|
|
}
|
|
|
|
}
|