aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--AST.cpp209
-rw-r--r--AST.h39
-rw-r--r--ASTPrinter.cpp126
-rw-r--r--ASTPrinter.h128
-rw-r--r--ASTVisitor.h68
5 files changed, 436 insertions, 134 deletions
diff --git a/AST.cpp b/AST.cpp
index 697ffe8e..619d3f5c 100644
--- a/AST.cpp
+++ b/AST.cpp
@@ -57,6 +57,17 @@ void ContractDefinition::accept(ASTVisitor& _visitor)
_visitor.endVisit(*this);
}
+void ContractDefinition::accept(ASTVisitor& _visitor) const
+{
+ if (_visitor.visit(*this))
+ {
+ listAccept(m_definedStructs, _visitor);
+ listAccept(m_stateVariables, _visitor);
+ listAccept(m_definedFunctions, _visitor);
+ }
+ _visitor.endVisit(*this);
+}
+
void StructDefinition::accept(ASTVisitor& _visitor)
{
if (_visitor.visit(*this))
@@ -64,6 +75,13 @@ void StructDefinition::accept(ASTVisitor& _visitor)
_visitor.endVisit(*this);
}
+void StructDefinition::accept(ASTVisitor& _visitor) const
+{
+ if (_visitor.visit(*this))
+ listAccept(m_members, _visitor);
+ _visitor.endVisit(*this);
+}
+
void StructDefinition::checkValidityOfMembers()
{
checkMemberTypes();
@@ -77,6 +95,13 @@ void ParameterList::accept(ASTVisitor& _visitor)
_visitor.endVisit(*this);
}
+void ParameterList::accept(ASTVisitor& _visitor) const
+{
+ if (_visitor.visit(*this))
+ listAccept(m_parameters, _visitor);
+ _visitor.endVisit(*this);
+}
+
void FunctionDefinition::accept(ASTVisitor& _visitor)
{
if (_visitor.visit(*this))
@@ -89,6 +114,18 @@ void FunctionDefinition::accept(ASTVisitor& _visitor)
_visitor.endVisit(*this);
}
+void FunctionDefinition::accept(ASTVisitor& _visitor) const
+{
+ if (_visitor.visit(*this))
+ {
+ m_parameters->accept(_visitor);
+ if (m_returnParameters)
+ m_returnParameters->accept(_visitor);
+ m_body->accept(_visitor);
+ }
+ _visitor.endVisit(*this);
+}
+
void VariableDeclaration::accept(ASTVisitor& _visitor)
{
if (_visitor.visit(*this))
@@ -97,24 +134,50 @@ void VariableDeclaration::accept(ASTVisitor& _visitor)
_visitor.endVisit(*this);
}
+void VariableDeclaration::accept(ASTVisitor& _visitor) const
+{
+ if (_visitor.visit(*this))
+ if (m_typeName)
+ m_typeName->accept(_visitor);
+ _visitor.endVisit(*this);
+}
+
void TypeName::accept(ASTVisitor& _visitor)
{
_visitor.visit(*this);
_visitor.endVisit(*this);
}
+void TypeName::accept(ASTVisitor& _visitor) const
+{
+ _visitor.visit(*this);
+ _visitor.endVisit(*this);
+}
+
void ElementaryTypeName::accept(ASTVisitor& _visitor)
{
_visitor.visit(*this);
_visitor.endVisit(*this);
}
+void ElementaryTypeName::accept(ASTVisitor& _visitor) const
+{
+ _visitor.visit(*this);
+ _visitor.endVisit(*this);
+}
+
void UserDefinedTypeName::accept(ASTVisitor& _visitor)
{
_visitor.visit(*this);
_visitor.endVisit(*this);
}
+void UserDefinedTypeName::accept(ASTVisitor& _visitor) const
+{
+ _visitor.visit(*this);
+ _visitor.endVisit(*this);
+}
+
void Mapping::accept(ASTVisitor& _visitor)
{
if (_visitor.visit(*this))
@@ -125,9 +188,13 @@ void Mapping::accept(ASTVisitor& _visitor)
_visitor.endVisit(*this);
}
-void Statement::accept(ASTVisitor& _visitor)
+void Mapping::accept(ASTVisitor& _visitor) const
{
- _visitor.visit(*this);
+ if (_visitor.visit(*this))
+ {
+ m_keyType->accept(_visitor);
+ m_valueType->accept(_visitor);
+ }
_visitor.endVisit(*this);
}
@@ -138,6 +205,13 @@ void Block::accept(ASTVisitor& _visitor)
_visitor.endVisit(*this);
}
+void Block::accept(ASTVisitor& _visitor) const
+{
+ if (_visitor.visit(*this))
+ listAccept(m_statements, _visitor);
+ _visitor.endVisit(*this);
+}
+
void IfStatement::accept(ASTVisitor& _visitor)
{
if (_visitor.visit(*this))
@@ -150,9 +224,15 @@ void IfStatement::accept(ASTVisitor& _visitor)
_visitor.endVisit(*this);
}
-void BreakableStatement::accept(ASTVisitor& _visitor)
+void IfStatement::accept(ASTVisitor& _visitor) const
{
- _visitor.visit(*this);
+ if (_visitor.visit(*this))
+ {
+ m_condition->accept(_visitor);
+ m_trueBody->accept(_visitor);
+ if (m_falseBody)
+ m_falseBody->accept(_visitor);
+ }
_visitor.endVisit(*this);
}
@@ -166,18 +246,40 @@ void WhileStatement::accept(ASTVisitor& _visitor)
_visitor.endVisit(*this);
}
+void WhileStatement::accept(ASTVisitor& _visitor) const
+{
+ if (_visitor.visit(*this))
+ {
+ m_condition->accept(_visitor);
+ m_body->accept(_visitor);
+ }
+ _visitor.endVisit(*this);
+}
+
void Continue::accept(ASTVisitor& _visitor)
{
_visitor.visit(*this);
_visitor.endVisit(*this);
}
+void Continue::accept(ASTVisitor& _visitor) const
+{
+ _visitor.visit(*this);
+ _visitor.endVisit(*this);
+}
+
void Break::accept(ASTVisitor& _visitor)
{
_visitor.visit(*this);
_visitor.endVisit(*this);
}
+void Break::accept(ASTVisitor& _visitor) const
+{
+ _visitor.visit(*this);
+ _visitor.endVisit(*this);
+}
+
void Return::accept(ASTVisitor& _visitor)
{
if (_visitor.visit(*this))
@@ -186,6 +288,14 @@ void Return::accept(ASTVisitor& _visitor)
_visitor.endVisit(*this);
}
+void Return::accept(ASTVisitor& _visitor) const
+{
+ if (_visitor.visit(*this))
+ if (m_expression)
+ m_expression->accept(_visitor);
+ _visitor.endVisit(*this);
+}
+
void ExpressionStatement::accept(ASTVisitor& _visitor)
{
if (_visitor.visit(*this))
@@ -194,6 +304,14 @@ void ExpressionStatement::accept(ASTVisitor& _visitor)
_visitor.endVisit(*this);
}
+void ExpressionStatement::accept(ASTVisitor& _visitor) const
+{
+ if (_visitor.visit(*this))
+ if (m_expression)
+ m_expression->accept(_visitor);
+ _visitor.endVisit(*this);
+}
+
void VariableDefinition::accept(ASTVisitor& _visitor)
{
if (_visitor.visit(*this))
@@ -205,6 +323,17 @@ void VariableDefinition::accept(ASTVisitor& _visitor)
_visitor.endVisit(*this);
}
+void VariableDefinition::accept(ASTVisitor& _visitor) const
+{
+ if (_visitor.visit(*this))
+ {
+ m_variable->accept(_visitor);
+ if (m_value)
+ m_value->accept(_visitor);
+ }
+ _visitor.endVisit(*this);
+}
+
void Assignment::accept(ASTVisitor& _visitor)
{
if (_visitor.visit(*this))
@@ -215,6 +344,16 @@ void Assignment::accept(ASTVisitor& _visitor)
_visitor.endVisit(*this);
}
+void Assignment::accept(ASTVisitor& _visitor) const
+{
+ if (_visitor.visit(*this))
+ {
+ m_leftHandSide->accept(_visitor);
+ m_rightHandSide->accept(_visitor);
+ }
+ _visitor.endVisit(*this);
+}
+
void UnaryOperation::accept(ASTVisitor& _visitor)
{
if (_visitor.visit(*this))
@@ -222,6 +361,13 @@ void UnaryOperation::accept(ASTVisitor& _visitor)
_visitor.endVisit(*this);
}
+void UnaryOperation::accept(ASTVisitor& _visitor) const
+{
+ if (_visitor.visit(*this))
+ m_subExpression->accept(_visitor);
+ _visitor.endVisit(*this);
+}
+
void BinaryOperation::accept(ASTVisitor& _visitor)
{
if (_visitor.visit(*this))
@@ -232,6 +378,16 @@ void BinaryOperation::accept(ASTVisitor& _visitor)
_visitor.endVisit(*this);
}
+void BinaryOperation::accept(ASTVisitor& _visitor) const
+{
+ if (_visitor.visit(*this))
+ {
+ m_left->accept(_visitor);
+ m_right->accept(_visitor);
+ }
+ _visitor.endVisit(*this);
+}
+
void FunctionCall::accept(ASTVisitor& _visitor)
{
if (_visitor.visit(*this))
@@ -242,6 +398,16 @@ void FunctionCall::accept(ASTVisitor& _visitor)
_visitor.endVisit(*this);
}
+void FunctionCall::accept(ASTVisitor& _visitor) const
+{
+ if (_visitor.visit(*this))
+ {
+ m_expression->accept(_visitor);
+ listAccept(m_arguments, _visitor);
+ }
+ _visitor.endVisit(*this);
+}
+
void MemberAccess::accept(ASTVisitor& _visitor)
{
if (_visitor.visit(*this))
@@ -249,6 +415,13 @@ void MemberAccess::accept(ASTVisitor& _visitor)
_visitor.endVisit(*this);
}
+void MemberAccess::accept(ASTVisitor& _visitor) const
+{
+ if (_visitor.visit(*this))
+ m_expression->accept(_visitor);
+ _visitor.endVisit(*this);
+}
+
void IndexAccess::accept(ASTVisitor& _visitor)
{
if (_visitor.visit(*this))
@@ -259,24 +432,52 @@ void IndexAccess::accept(ASTVisitor& _visitor)
_visitor.endVisit(*this);
}
+void IndexAccess::accept(ASTVisitor& _visitor) const
+{
+ if (_visitor.visit(*this))
+ {
+ m_base->accept(_visitor);
+ m_index->accept(_visitor);
+ }
+ _visitor.endVisit(*this);
+}
+
void Identifier::accept(ASTVisitor& _visitor)
{
_visitor.visit(*this);
_visitor.endVisit(*this);
}
+void Identifier::accept(ASTVisitor& _visitor) const
+{
+ _visitor.visit(*this);
+ _visitor.endVisit(*this);
+}
+
void ElementaryTypeNameExpression::accept(ASTVisitor& _visitor)
{
_visitor.visit(*this);
_visitor.endVisit(*this);
}
+void ElementaryTypeNameExpression::accept(ASTVisitor& _visitor) const
+{
+ _visitor.visit(*this);
+ _visitor.endVisit(*this);
+}
+
void Literal::accept(ASTVisitor& _visitor)
{
_visitor.visit(*this);
_visitor.endVisit(*this);
}
+void Literal::accept(ASTVisitor& _visitor) const
+{
+ _visitor.visit(*this);
+ _visitor.endVisit(*this);
+}
+
TypeError ASTNode::createTypeError(string const& _description) const
{
return TypeError() << errinfo_sourceLocation(getLocation()) << errinfo_comment(_description);
diff --git a/AST.h b/AST.h
index 10616022..e1044618 100644
--- a/AST.h
+++ b/AST.h
@@ -54,12 +54,19 @@ public:
virtual ~ASTNode() {}
virtual void accept(ASTVisitor& _visitor) = 0;
+ virtual void accept(ASTVisitor& _visitor) const = 0;
template <class T>
static void listAccept(std::vector<ASTPointer<T>>& _list, ASTVisitor& _visitor)
{
for (ASTPointer<T>& element: _list)
element->accept(_visitor);
}
+ template <class T>
+ static void listAccept(std::vector<ASTPointer<T>> const& _list, ASTVisitor& _visitor)
+ {
+ for (ASTPointer<T const> const& element: _list)
+ element->accept(_visitor);
+ }
/// Returns the source code location of this node.
Location const& getLocation() const { return m_location; }
@@ -156,6 +163,7 @@ public:
{}
virtual void accept(ASTVisitor& _visitor) override;
+ virtual void accept(ASTVisitor& _visitor) const override;
std::vector<ASTPointer<StructDefinition>> const& getDefinedStructs() const { return m_definedStructs; }
std::vector<ASTPointer<VariableDeclaration>> const& getStateVariables() const { return m_stateVariables; }
@@ -178,6 +186,7 @@ public:
std::vector<ASTPointer<VariableDeclaration>> const& _members):
Declaration(_location, _name), m_members(_members) {}
virtual void accept(ASTVisitor& _visitor) override;
+ virtual void accept(ASTVisitor& _visitor) const override;
std::vector<ASTPointer<VariableDeclaration>> const& getMembers() const { return m_members; }
@@ -204,6 +213,7 @@ public:
std::vector<ASTPointer<VariableDeclaration>> const& _parameters):
ASTNode(_location), m_parameters(_parameters) {}
virtual void accept(ASTVisitor& _visitor) override;
+ virtual void accept(ASTVisitor& _visitor) const override;
std::vector<ASTPointer<VariableDeclaration>> const& getParameters() const { return m_parameters; }
@@ -230,6 +240,7 @@ public:
{}
virtual void accept(ASTVisitor& _visitor) override;
+ virtual void accept(ASTVisitor& _visitor) const override;
bool isPublic() const { return m_isPublic; }
bool isDeclaredConst() const { return m_isDeclaredConst; }
@@ -270,6 +281,7 @@ public:
ASTPointer<ASTString> const& _name):
Declaration(_location, _name), m_typeName(_type) {}
virtual void accept(ASTVisitor& _visitor) override;
+ virtual void accept(ASTVisitor& _visitor) const override;
TypeName* getTypeName() const { return m_typeName.get(); }
@@ -297,6 +309,8 @@ public:
Declaration(Location(), std::make_shared<ASTString>(_name)), m_type(_type) {}
virtual void accept(ASTVisitor&) override { BOOST_THROW_EXCEPTION(InternalCompilerError()
<< errinfo_comment("MagicVariableDeclaration used inside real AST.")); }
+ virtual void accept(ASTVisitor&) const override { BOOST_THROW_EXCEPTION(InternalCompilerError()
+ << errinfo_comment("MagicVariableDeclaration used inside real AST.")); }
std::shared_ptr<Type const> const& getType() const { return m_type; }
@@ -315,6 +329,7 @@ class TypeName: public ASTNode
public:
explicit TypeName(Location const& _location): ASTNode(_location) {}
virtual void accept(ASTVisitor& _visitor) override;
+ virtual void accept(ASTVisitor& _visitor) const override;
/// Retrieve the element of the type hierarchy this node refers to. Can return an empty shared
/// pointer until the types have been resolved using the @ref NameAndTypeResolver.
@@ -335,6 +350,7 @@ public:
if (asserts(Token::isElementaryTypeName(_type))) BOOST_THROW_EXCEPTION(InternalCompilerError());
}
virtual void accept(ASTVisitor& _visitor) override;
+ virtual void accept(ASTVisitor& _visitor) const override;
virtual std::shared_ptr<Type> toType() const override { return Type::fromElementaryTypeName(m_type); }
Token::Value getTypeName() const { return m_type; }
@@ -352,6 +368,7 @@ public:
UserDefinedTypeName(Location const& _location, ASTPointer<ASTString> const& _name):
TypeName(_location), m_name(_name) {}
virtual void accept(ASTVisitor& _visitor) override;
+ virtual void accept(ASTVisitor& _visitor) const override;
virtual std::shared_ptr<Type> toType() const override { return Type::fromUserDefinedTypeName(*this); }
ASTString const& getName() const { return *m_name; }
@@ -374,6 +391,7 @@ public:
ASTPointer<TypeName> const& _valueType):
TypeName(_location), m_keyType(_keyType), m_valueType(_valueType) {}
virtual void accept(ASTVisitor& _visitor) override;
+ virtual void accept(ASTVisitor& _visitor) const override;
virtual std::shared_ptr<Type> toType() const override { return Type::fromMapping(*this); }
ElementaryTypeName const& getKeyType() const { return *m_keyType; }
@@ -397,7 +415,6 @@ class Statement: public ASTNode
{
public:
explicit Statement(Location const& _location): ASTNode(_location) {}
- virtual void accept(ASTVisitor& _visitor) override;
/// Check all type requirements, throws exception if some requirement is not met.
/// This includes checking that operators are applicable to their arguments but also that
@@ -414,6 +431,7 @@ public:
Block(Location const& _location, std::vector<ASTPointer<Statement>> const& _statements):
Statement(_location), m_statements(_statements) {}
virtual void accept(ASTVisitor& _visitor) override;
+ virtual void accept(ASTVisitor& _visitor) const override;
virtual void checkTypeRequirements() override;
@@ -433,6 +451,7 @@ public:
Statement(_location),
m_condition(_condition), m_trueBody(_trueBody), m_falseBody(_falseBody) {}
virtual void accept(ASTVisitor& _visitor) override;
+ virtual void accept(ASTVisitor& _visitor) const override;
virtual void checkTypeRequirements() override;
Expression& getCondition() const { return *m_condition; }
@@ -447,13 +466,12 @@ private:
};
/**
- * Statement in which a break statement is legal.
+ * Statement in which a break statement is legal (abstract class).
*/
class BreakableStatement: public Statement
{
public:
BreakableStatement(Location const& _location): Statement(_location) {}
- virtual void accept(ASTVisitor& _visitor) override;
};
class WhileStatement: public BreakableStatement
@@ -463,6 +481,7 @@ public:
ASTPointer<Statement> const& _body):
BreakableStatement(_location), m_condition(_condition), m_body(_body) {}
virtual void accept(ASTVisitor& _visitor) override;
+ virtual void accept(ASTVisitor& _visitor) const override;
virtual void checkTypeRequirements() override;
Expression& getCondition() const { return *m_condition; }
@@ -478,6 +497,7 @@ class Continue: public Statement
public:
Continue(Location const& _location): Statement(_location) {}
virtual void accept(ASTVisitor& _visitor) override;
+ virtual void accept(ASTVisitor& _visitor) const override;
virtual void checkTypeRequirements() override {}
};
@@ -486,6 +506,7 @@ class Break: public Statement
public:
Break(Location const& _location): Statement(_location) {}
virtual void accept(ASTVisitor& _visitor) override;
+ virtual void accept(ASTVisitor& _visitor) const override;
virtual void checkTypeRequirements() override {}
};
@@ -495,6 +516,7 @@ public:
Return(Location const& _location, ASTPointer<Expression> _expression):
Statement(_location), m_expression(_expression) {}
virtual void accept(ASTVisitor& _visitor) override;
+ virtual void accept(ASTVisitor& _visitor) const override;
virtual void checkTypeRequirements() override;
void setFunctionReturnParameters(ParameterList& _parameters) { m_returnParameters = &_parameters; }
@@ -525,6 +547,7 @@ public:
ASTPointer<Expression> _value):
Statement(_location), m_variable(_variable), m_value(_value) {}
virtual void accept(ASTVisitor& _visitor) override;
+ virtual void accept(ASTVisitor& _visitor) const override;
virtual void checkTypeRequirements() override;
VariableDeclaration const& getDeclaration() const { return *m_variable; }
@@ -544,6 +567,7 @@ public:
ExpressionStatement(Location const& _location, ASTPointer<Expression> _expression):
Statement(_location), m_expression(_expression) {}
virtual void accept(ASTVisitor& _visitor) override;
+ virtual void accept(ASTVisitor& _visitor) const override;
virtual void checkTypeRequirements() override;
Expression& getExpression() const { return *m_expression; }
@@ -608,6 +632,7 @@ public:
if (asserts(Token::isAssignmentOp(_assignmentOperator))) BOOST_THROW_EXCEPTION(InternalCompilerError());
}
virtual void accept(ASTVisitor& _visitor) override;
+ virtual void accept(ASTVisitor& _visitor) const override;
virtual void checkTypeRequirements() override;
Expression& getLeftHandSide() const { return *m_leftHandSide; }
@@ -635,6 +660,7 @@ public:
if (asserts(Token::isUnaryOp(_operator))) BOOST_THROW_EXCEPTION(InternalCompilerError());
}
virtual void accept(ASTVisitor& _visitor) override;
+ virtual void accept(ASTVisitor& _visitor) const override;
virtual void checkTypeRequirements() override;
Token::Value getOperator() const { return m_operator; }
@@ -661,6 +687,7 @@ public:
if (asserts(Token::isBinaryOp(_operator) || Token::isCompareOp(_operator))) BOOST_THROW_EXCEPTION(InternalCompilerError());
}
virtual void accept(ASTVisitor& _visitor) override;
+ virtual void accept(ASTVisitor& _visitor) const override;
virtual void checkTypeRequirements() override;
Expression& getLeftExpression() const { return *m_left; }
@@ -688,6 +715,7 @@ public:
std::vector<ASTPointer<Expression>> const& _arguments):
Expression(_location), m_expression(_expression), m_arguments(_arguments) {}
virtual void accept(ASTVisitor& _visitor) override;
+ virtual void accept(ASTVisitor& _visitor) const override;
virtual void checkTypeRequirements() override;
Expression& getExpression() const { return *m_expression; }
@@ -712,6 +740,7 @@ public:
ASTPointer<ASTString> const& _memberName):
Expression(_location), m_expression(_expression), m_memberName(_memberName) {}
virtual void accept(ASTVisitor& _visitor) override;
+ virtual void accept(ASTVisitor& _visitor) const override;
Expression& getExpression() const { return *m_expression; }
ASTString const& getMemberName() const { return *m_memberName; }
virtual void checkTypeRequirements() override;
@@ -731,6 +760,7 @@ public:
ASTPointer<Expression> const& _index):
Expression(_location), m_base(_base), m_index(_index) {}
virtual void accept(ASTVisitor& _visitor) override;
+ virtual void accept(ASTVisitor& _visitor) const override;
virtual void checkTypeRequirements() override;
Expression& getBaseExpression() const { return *m_base; }
@@ -760,6 +790,7 @@ public:
Identifier(Location const& _location, ASTPointer<ASTString> const& _name):
PrimaryExpression(_location), m_name(_name) {}
virtual void accept(ASTVisitor& _visitor) override;
+ virtual void accept(ASTVisitor& _visitor) const override;
virtual void checkTypeRequirements() override;
ASTString const& getName() const { return *m_name; }
@@ -788,6 +819,7 @@ public:
if (asserts(Token::isElementaryTypeName(_typeToken))) BOOST_THROW_EXCEPTION(InternalCompilerError());
}
virtual void accept(ASTVisitor& _visitor) override;
+ virtual void accept(ASTVisitor& _visitor) const override;
virtual void checkTypeRequirements() override;
Token::Value getTypeToken() const { return m_typeToken; }
@@ -805,6 +837,7 @@ public:
Literal(Location const& _location, Token::Value _token, ASTPointer<ASTString> const& _value):
PrimaryExpression(_location), m_token(_token), m_value(_value) {}
virtual void accept(ASTVisitor& _visitor) override;
+ virtual void accept(ASTVisitor& _visitor) const override;
virtual void checkTypeRequirements() override;
Token::Value getToken() const { return m_token; }
diff --git a/ASTPrinter.cpp b/ASTPrinter.cpp
index 3d09fd9a..eddb5134 100644
--- a/ASTPrinter.cpp
+++ b/ASTPrinter.cpp
@@ -30,7 +30,7 @@ namespace dev
namespace solidity
{
-ASTPrinter::ASTPrinter(ASTNode& _ast, string const& _source):
+ASTPrinter::ASTPrinter(ASTNode const& _ast, string const& _source):
m_indentation(0), m_source(_source), m_ast(&_ast)
{
}
@@ -43,35 +43,35 @@ void ASTPrinter::print(ostream& _stream)
}
-bool ASTPrinter::visit(ImportDirective& _node)
+bool ASTPrinter::visit(ImportDirective const& _node)
{
writeLine("ImportDirective \"" + _node.getIdentifier() + "\"");
printSourcePart(_node);
return goDeeper();
}
-bool ASTPrinter::visit(ContractDefinition& _node)
+bool ASTPrinter::visit(ContractDefinition const& _node)
{
writeLine("ContractDefinition \"" + _node.getName() + "\"");
printSourcePart(_node);
return goDeeper();
}
-bool ASTPrinter::visit(StructDefinition& _node)
+bool ASTPrinter::visit(StructDefinition const& _node)
{
writeLine("StructDefinition \"" + _node.getName() + "\"");
printSourcePart(_node);
return goDeeper();
}
-bool ASTPrinter::visit(ParameterList& _node)
+bool ASTPrinter::visit(ParameterList const& _node)
{
writeLine("ParameterList");
printSourcePart(_node);
return goDeeper();
}
-bool ASTPrinter::visit(FunctionDefinition& _node)
+bool ASTPrinter::visit(FunctionDefinition const& _node)
{
writeLine("FunctionDefinition \"" + _node.getName() + "\"" +
(_node.isPublic() ? " - public" : "") +
@@ -80,112 +80,112 @@ bool ASTPrinter::visit(FunctionDefinition& _node)
return goDeeper();
}
-bool ASTPrinter::visit(VariableDeclaration& _node)
+bool ASTPrinter::visit(VariableDeclaration const& _node)
{
writeLine("VariableDeclaration \"" + _node.getName() + "\"");
printSourcePart(_node);
return goDeeper();
}
-bool ASTPrinter::visit(TypeName& _node)
+bool ASTPrinter::visit(TypeName const& _node)
{
writeLine("TypeName");
printSourcePart(_node);
return goDeeper();
}
-bool ASTPrinter::visit(ElementaryTypeName& _node)
+bool ASTPrinter::visit(ElementaryTypeName const& _node)
{
writeLine(string("ElementaryTypeName ") + Token::toString(_node.getTypeName()));
printSourcePart(_node);
return goDeeper();
}
-bool ASTPrinter::visit(UserDefinedTypeName& _node)
+bool ASTPrinter::visit(UserDefinedTypeName const& _node)
{
writeLine("UserDefinedTypeName \"" + _node.getName() + "\"");
printSourcePart(_node);
return goDeeper();
}
-bool ASTPrinter::visit(Mapping& _node)
+bool ASTPrinter::visit(Mapping const& _node)
{
writeLine("Mapping");
printSourcePart(_node);
return goDeeper();
}
-bool ASTPrinter::visit(Statement& _node)
+bool ASTPrinter::visit(Statement const& _node)
{
writeLine("Statement");
printSourcePart(_node);
return goDeeper();
}
-bool ASTPrinter::visit(Block& _node)
+bool ASTPrinter::visit(Block const& _node)
{
writeLine("Block");
printSourcePart(_node);
return goDeeper();
}
-bool ASTPrinter::visit(IfStatement& _node)
+bool ASTPrinter::visit(IfStatement const& _node)
{
writeLine("IfStatement");
printSourcePart(_node);
return goDeeper();
}
-bool ASTPrinter::visit(BreakableStatement& _node)
+bool ASTPrinter::visit(BreakableStatement const& _node)
{
writeLine("BreakableStatement");
printSourcePart(_node);
return goDeeper();
}
-bool ASTPrinter::visit(WhileStatement& _node)
+bool ASTPrinter::visit(WhileStatement const& _node)
{
writeLine("WhileStatement");
printSourcePart(_node);
return goDeeper();
}
-bool ASTPrinter::visit(Continue& _node)
+bool ASTPrinter::visit(Continue const& _node)
{
writeLine("Continue");
printSourcePart(_node);
return goDeeper();
}
-bool ASTPrinter::visit(Break& _node)
+bool ASTPrinter::visit(Break const& _node)
{
writeLine("Break");
printSourcePart(_node);
return goDeeper();
}
-bool ASTPrinter::visit(Return& _node)
+bool ASTPrinter::visit(Return const& _node)
{
writeLine("Return");
printSourcePart(_node);
return goDeeper();
}
-bool ASTPrinter::visit(VariableDefinition& _node)
+bool ASTPrinter::visit(VariableDefinition const& _node)
{
writeLine("VariableDefinition");
printSourcePart(_node);
return goDeeper();
}
-bool ASTPrinter::visit(ExpressionStatement& _node)
+bool ASTPrinter::visit(ExpressionStatement const& _node)
{
writeLine("ExpressionStatement");
printSourcePart(_node);
return goDeeper();
}
-bool ASTPrinter::visit(Expression& _node)
+bool ASTPrinter::visit(Expression const& _node)
{
writeLine("Expression");
printType(_node);
@@ -193,7 +193,7 @@ bool ASTPrinter::visit(Expression& _node)
return goDeeper();
}
-bool ASTPrinter::visit(Assignment& _node)
+bool ASTPrinter::visit(Assignment const& _node)
{
writeLine(string("Assignment using operator ") + Token::toString(_node.getAssignmentOperator()));
printType(_node);
@@ -201,7 +201,7 @@ bool ASTPrinter::visit(Assignment& _node)
return goDeeper();
}
-bool ASTPrinter::visit(UnaryOperation& _node)
+bool ASTPrinter::visit(UnaryOperation const& _node)
{
writeLine(string("UnaryOperation (") + (_node.isPrefixOperation() ? "prefix" : "postfix") +
") " + Token::toString(_node.getOperator()));
@@ -210,7 +210,7 @@ bool ASTPrinter::visit(UnaryOperation& _node)
return goDeeper();
}
-bool ASTPrinter::visit(BinaryOperation& _node)
+bool ASTPrinter::visit(BinaryOperation const& _node)
{
writeLine(string("BinaryOperation using operator ") + Token::toString(_node.getOperator()));
printType(_node);
@@ -218,7 +218,7 @@ bool ASTPrinter::visit(BinaryOperation& _node)
return goDeeper();
}
-bool ASTPrinter::visit(FunctionCall& _node)
+bool ASTPrinter::visit(FunctionCall const& _node)
{
writeLine("FunctionCall");
printType(_node);
@@ -226,7 +226,7 @@ bool ASTPrinter::visit(FunctionCall& _node)
return goDeeper();
}
-bool ASTPrinter::visit(MemberAccess& _node)
+bool ASTPrinter::visit(MemberAccess const& _node)
{
writeLine("MemberAccess to member " + _node.getMemberName());
printType(_node);
@@ -234,7 +234,7 @@ bool ASTPrinter::visit(MemberAccess& _node)
return goDeeper();
}
-bool ASTPrinter::visit(IndexAccess& _node)
+bool ASTPrinter::visit(IndexAccess const& _node)
{
writeLine("IndexAccess");
printType(_node);
@@ -242,7 +242,7 @@ bool ASTPrinter::visit(IndexAccess& _node)
return goDeeper();
}
-bool ASTPrinter::visit(PrimaryExpression& _node)
+bool ASTPrinter::visit(PrimaryExpression const& _node)
{
writeLine("PrimaryExpression");
printType(_node);
@@ -250,7 +250,7 @@ bool ASTPrinter::visit(PrimaryExpression& _node)
return goDeeper();
}
-bool ASTPrinter::visit(Identifier& _node)
+bool ASTPrinter::visit(Identifier const& _node)
{
writeLine(string("Identifier ") + _node.getName());
printType(_node);
@@ -258,7 +258,7 @@ bool ASTPrinter::visit(Identifier& _node)
return goDeeper();
}
-bool ASTPrinter::visit(ElementaryTypeNameExpression& _node)
+bool ASTPrinter::visit(ElementaryTypeNameExpression const& _node)
{
writeLine(string("ElementaryTypeNameExpression ") + Token::toString(_node.getTypeToken()));
printType(_node);
@@ -266,7 +266,7 @@ bool ASTPrinter::visit(ElementaryTypeNameExpression& _node)
return goDeeper();
}
-bool ASTPrinter::visit(Literal& _node)
+bool ASTPrinter::visit(Literal const& _node)
{
char const* tokenString = Token::toString(_node.getToken());
if (!tokenString)
@@ -277,157 +277,157 @@ bool ASTPrinter::visit(Literal& _node)
return goDeeper();
}
-void ASTPrinter::endVisit(ImportDirective&)
+void ASTPrinter::endVisit(ImportDirective const&)
{
m_indentation--;
}
-void ASTPrinter::endVisit(ContractDefinition&)
+void ASTPrinter::endVisit(ContractDefinition const&)
{
m_indentation--;
}
-void ASTPrinter::endVisit(StructDefinition&)
+void ASTPrinter::endVisit(StructDefinition const&)
{
m_indentation--;
}
-void ASTPrinter::endVisit(ParameterList&)
+void ASTPrinter::endVisit(ParameterList const&)
{
m_indentation--;
}
-void ASTPrinter::endVisit(FunctionDefinition&)
+void ASTPrinter::endVisit(FunctionDefinition const&)
{
m_indentation--;
}
-void ASTPrinter::endVisit(VariableDeclaration&)
+void ASTPrinter::endVisit(VariableDeclaration const&)
{
m_indentation--;
}
-void ASTPrinter::endVisit(TypeName&)
+void ASTPrinter::endVisit(TypeName const&)
{
m_indentation--;
}
-void ASTPrinter::endVisit(ElementaryTypeName&)
+void ASTPrinter::endVisit(ElementaryTypeName const&)
{
m_indentation--;
}
-void ASTPrinter::endVisit(UserDefinedTypeName&)
+void ASTPrinter::endVisit(UserDefinedTypeName const&)
{
m_indentation--;
}
-void ASTPrinter::endVisit(Mapping&)
+void ASTPrinter::endVisit(Mapping const&)
{
m_indentation--;
}
-void ASTPrinter::endVisit(Statement&)
+void ASTPrinter::endVisit(Statement const&)
{
m_indentation--;
}
-void ASTPrinter::endVisit(Block&)
+void ASTPrinter::endVisit(Block const&)
{
m_indentation--;
}
-void ASTPrinter::endVisit(IfStatement&)
+void ASTPrinter::endVisit(IfStatement const&)
{
m_indentation--;
}
-void ASTPrinter::endVisit(BreakableStatement&)
+void ASTPrinter::endVisit(BreakableStatement const&)
{
m_indentation--;
}
-void ASTPrinter::endVisit(WhileStatement&)
+void ASTPrinter::endVisit(WhileStatement const&)
{
m_indentation--;
}
-void ASTPrinter::endVisit(Continue&)
+void ASTPrinter::endVisit(Continue const&)
{
m_indentation--;
}
-void ASTPrinter::endVisit(Break&)
+void ASTPrinter::endVisit(Break const&)
{
m_indentation--;
}
-void ASTPrinter::endVisit(Return&)
+void ASTPrinter::endVisit(Return const&)
{
m_indentation--;
}
-void ASTPrinter::endVisit(VariableDefinition&)
+void ASTPrinter::endVisit(VariableDefinition const&)
{
m_indentation--;
}
-void ASTPrinter::endVisit(ExpressionStatement&)
+void ASTPrinter::endVisit(ExpressionStatement const&)
{
m_indentation--;
}
-void ASTPrinter::endVisit(Expression&)
+void ASTPrinter::endVisit(Expression const&)
{
m_indentation--;
}
-void ASTPrinter::endVisit(Assignment&)
+void ASTPrinter::endVisit(Assignment const&)
{
m_indentation--;
}
-void ASTPrinter::endVisit(UnaryOperation&)
+void ASTPrinter::endVisit(UnaryOperation const&)
{
m_indentation--;
}
-void ASTPrinter::endVisit(BinaryOperation&)
+void ASTPrinter::endVisit(BinaryOperation const&)
{
m_indentation--;
}
-void ASTPrinter::endVisit(FunctionCall&)
+void ASTPrinter::endVisit(FunctionCall const&)
{
m_indentation--;
}
-void ASTPrinter::endVisit(MemberAccess&)
+void ASTPrinter::endVisit(MemberAccess const&)
{
m_indentation--;
}
-void ASTPrinter::endVisit(IndexAccess&)
+void ASTPrinter::endVisit(IndexAccess const&)
{
m_indentation--;
}
-void ASTPrinter::endVisit(PrimaryExpression&)
+void ASTPrinter::endVisit(PrimaryExpression const&)
{
m_indentation--;
}
-void ASTPrinter::endVisit(Identifier&)
+void ASTPrinter::endVisit(Identifier const&)
{
m_indentation--;
}
-void ASTPrinter::endVisit(ElementaryTypeNameExpression&)
+void ASTPrinter::endVisit(ElementaryTypeNameExpression const&)
{
m_indentation--;
}
-void ASTPrinter::endVisit(Literal&)
+void ASTPrinter::endVisit(Literal const&)
{
m_indentation--;
}
diff --git a/ASTPrinter.h b/ASTPrinter.h
index 1a18fc4a..8092dbd5 100644
--- a/ASTPrinter.h
+++ b/ASTPrinter.h
@@ -38,73 +38,73 @@ class ASTPrinter: public ASTVisitor
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.
- ASTPrinter(ASTNode& _ast, std::string const& _source = std::string());
+ ASTPrinter(ASTNode const& _ast, std::string const& _source = std::string());
/// Output the string representation of the AST to _stream.
void print(std::ostream& _stream);
- bool visit(ImportDirective& _node) override;
- bool visit(ContractDefinition& _node) override;
- bool visit(StructDefinition& _node) override;
- bool visit(ParameterList& _node) override;
- bool visit(FunctionDefinition& _node) override;
- bool visit(VariableDeclaration& _node) override;
- bool visit(TypeName& _node) override;
- bool visit(ElementaryTypeName& _node) override;
- bool visit(UserDefinedTypeName& _node) override;
- bool visit(Mapping& _node) override;
- bool visit(Statement& _node) override;
- bool visit(Block& _node) override;
- bool visit(IfStatement& _node) override;
- bool visit(BreakableStatement& _node) override;
- bool visit(WhileStatement& _node) override;
- bool visit(Continue& _node) override;
- bool visit(Break& _node) override;
- bool visit(Return& _node) override;
- bool visit(VariableDefinition& _node) override;
- bool visit(ExpressionStatement& _node) override;
- bool visit(Expression& _node) override;
- bool visit(Assignment& _node) override;
- bool visit(UnaryOperation& _node) override;
- bool visit(BinaryOperation& _node) override;
- bool visit(FunctionCall& _node) override;
- bool visit(MemberAccess& _node) override;
- bool visit(IndexAccess& _node) override;
- bool visit(PrimaryExpression& _node) override;
- bool visit(Identifier& _node) override;
- bool visit(ElementaryTypeNameExpression& _node) override;
- bool visit(Literal& _node) override;
+ bool visit(ImportDirective const& _node) override;
+ bool visit(ContractDefinition const& _node) override;
+ bool visit(StructDefinition const& _node) override;
+ bool visit(ParameterList const& _node) override;
+ bool visit(FunctionDefinition const& _node) override;
+ bool visit(VariableDeclaration const& _node) override;
+ bool visit(TypeName const& _node) override;
+ bool visit(ElementaryTypeName const& _node) override;
+ bool visit(UserDefinedTypeName const& _node) override;
+ bool visit(Mapping const& _node) override;
+ bool visit(Statement const& _node) override;
+ bool visit(Block const& _node) override;
+ bool visit(IfStatement const& _node) override;
+ bool visit(BreakableStatement const& _node) override;
+ bool visit(WhileStatement const& _node) override;
+ bool visit(Continue const& _node) override;
+ bool visit(Break const& _node) override;
+ bool visit(Return const& _node) override;
+ bool visit(VariableDefinition const& _node) override;
+ bool visit(ExpressionStatement const& _node) override;
+ bool visit(Expression 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;
+ bool visit(MemberAccess const& _node) override;
+ bool visit(IndexAccess const& _node) override;
+ bool visit(PrimaryExpression const& _node) override;
+ bool visit(Identifier const& _node) override;
+ bool visit(ElementaryTypeNameExpression const& _node) override;
+ bool visit(Literal const& _node) override;
- void endVisit(ImportDirective&) override;
- void endVisit(ContractDefinition&) override;
- void endVisit(StructDefinition&) override;
- void endVisit(ParameterList&) override;
- void endVisit(FunctionDefinition&) override;
- void endVisit(VariableDeclaration&) override;
- void endVisit(TypeName&) override;
- void endVisit(ElementaryTypeName&) override;
- void endVisit(UserDefinedTypeName&) override;
- void endVisit(Mapping&) override;
- void endVisit(Statement&) override;
- void endVisit(Block&) override;
- void endVisit(IfStatement&) override;
- void endVisit(BreakableStatement&) override;
- void endVisit(WhileStatement&) override;
- void endVisit(Continue&) override;
- void endVisit(Break&) override;
- void endVisit(Return&) override;
- void endVisit(VariableDefinition&) override;
- void endVisit(ExpressionStatement&) override;
- void endVisit(Expression&) override;
- void endVisit(Assignment&) override;
- void endVisit(UnaryOperation&) override;
- void endVisit(BinaryOperation&) override;
- void endVisit(FunctionCall&) override;
- void endVisit(MemberAccess&) override;
- void endVisit(IndexAccess&) override;
- void endVisit(PrimaryExpression&) override;
- void endVisit(Identifier&) override;
- void endVisit(ElementaryTypeNameExpression&) override;
- void endVisit(Literal&) override;
+ void endVisit(ImportDirective const&) override;
+ void endVisit(ContractDefinition const&) override;
+ void endVisit(StructDefinition const&) override;
+ void endVisit(ParameterList const&) override;
+ void endVisit(FunctionDefinition const&) override;
+ void endVisit(VariableDeclaration const&) override;
+ void endVisit(TypeName const&) override;
+ void endVisit(ElementaryTypeName const&) override;
+ void endVisit(UserDefinedTypeName const&) override;
+ void endVisit(Mapping const&) override;
+ void endVisit(Statement const&) override;
+ void endVisit(Block const&) override;
+ void endVisit(IfStatement const&) override;
+ void endVisit(BreakableStatement const&) override;
+ void endVisit(WhileStatement const&) override;
+ void endVisit(Continue const&) override;
+ void endVisit(Break const&) override;
+ void endVisit(Return const&) override;
+ void endVisit(VariableDefinition const&) override;
+ void endVisit(ExpressionStatement const&) override;
+ void endVisit(Expression const&) override;
+ void endVisit(Assignment const&) override;
+ void endVisit(UnaryOperation const&) override;
+ void endVisit(BinaryOperation const&) override;
+ void endVisit(FunctionCall const&) override;
+ void endVisit(MemberAccess const&) override;
+ void endVisit(IndexAccess const&) override;
+ void endVisit(PrimaryExpression const&) override;
+ void endVisit(Identifier const&) override;
+ void endVisit(ElementaryTypeNameExpression const&) override;
+ void endVisit(Literal const&) override;
private:
void printSourcePart(ASTNode const& _node);
@@ -115,7 +115,7 @@ private:
int m_indentation;
std::string m_source;
- ASTNode* m_ast;
+ ASTNode const* m_ast;
std::ostream* m_ostream;
};
diff --git a/ASTVisitor.h b/ASTVisitor.h
index bf1ccc41..c731588d 100644
--- a/ASTVisitor.h
+++ b/ASTVisitor.h
@@ -75,6 +75,40 @@ public:
virtual bool visit(ElementaryTypeNameExpression&) { return true; }
virtual bool visit(Literal&) { return true; }
+ 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; }
+ virtual bool visit(StructDefinition const&) { return true; }
+ virtual bool visit(ParameterList const&) { return true; }
+ virtual bool visit(FunctionDefinition const&) { return true; }
+ virtual bool visit(VariableDeclaration const&) { return true; }
+ 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; }
+ virtual bool visit(IfStatement const&) { return true; }
+ virtual bool visit(BreakableStatement const&) { return true; }
+ virtual bool visit(WhileStatement const&) { return true; }
+ 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; }
+ 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; }
+
virtual void endVisit(ASTNode&) { }
virtual void endVisit(SourceUnit&) { }
virtual void endVisit(ImportDirective&) { }
@@ -108,6 +142,40 @@ public:
virtual void endVisit(Identifier&) { }
virtual void endVisit(ElementaryTypeNameExpression&) { }
virtual void endVisit(Literal&) { }
+
+ virtual void endVisit(ASTNode const&) { }
+ virtual void endVisit(SourceUnit const&) { }
+ virtual void endVisit(ImportDirective const&) { }
+ virtual void endVisit(ContractDefinition const&) { }
+ virtual void endVisit(StructDefinition const&) { }
+ virtual void endVisit(ParameterList const&) { }
+ virtual void endVisit(FunctionDefinition const&) { }
+ virtual void endVisit(VariableDeclaration const&) { }
+ 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&) { }
+ virtual void endVisit(IfStatement const&) { }
+ virtual void endVisit(BreakableStatement const&) { }
+ virtual void endVisit(WhileStatement const&) { }
+ 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&) { }
+ 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&) { }
};
}