libyul: Adds Comment as new AST node type, to be used for pretty printing (and preserving) comments in yul-format.

This commit is contained in:
Christian Parpart
2019-06-19 12:48:12 +02:00
parent cfbbb194d1
commit ee572ee138
16 changed files with 50 additions and 2 deletions
+5
View File
@@ -153,6 +153,11 @@ Statement ASTCopier::operator ()(Block const& _block)
return translate(_block);
}
Statement ASTCopier::operator()(Comment const& _comment)
{
return Comment{_comment.location, _comment.text};
}
Expression ASTCopier::translate(Expression const& _expression)
{
return _expression.apply_visitor(static_cast<ExpressionCopier&>(*this));
+2
View File
@@ -61,6 +61,7 @@ public:
virtual Statement operator()(Break const&) = 0;
virtual Statement operator()(Continue const&) = 0;
virtual Statement operator()(Block const& _block) = 0;
virtual Statement operator()(Comment const& _comment) = 0;
};
/**
@@ -88,6 +89,7 @@ public:
Statement operator()(Break const&) override;
Statement operator()(Continue const&) override;
Statement operator()(Block const& _block) override;
Statement operator()(Comment const& _comment) override;
virtual Expression translate(Expression const& _expression);
virtual Statement translate(Statement const& _statement);
+2
View File
@@ -59,6 +59,7 @@ public:
virtual void operator()(Break const&) {}
virtual void operator()(Continue const&) {}
virtual void operator()(Block const& _block);
virtual void operator()(Comment const&) {}
virtual void visit(Statement const& _st);
virtual void visit(Expression const& _e);
@@ -96,6 +97,7 @@ public:
virtual void operator()(Break&);
virtual void operator()(Continue&);
virtual void operator()(Block& _block);
virtual void operator()(Comment&) {}
virtual void visit(Statement& _st);
virtual void visit(Expression& _e);
+5
View File
@@ -181,6 +181,11 @@ bool SyntacticallyEqual::statementEqual(Block const& _lhs, Block const& _rhs)
});
}
bool SyntacticallyEqual::statementEqual(Comment const& _lhs, Comment const& _rhs)
{
return _lhs.text == _rhs.text;
}
bool SyntacticallyEqual::visitDeclaration(TypedName const& _lhs, TypedName const& _rhs)
{
if (_lhs.type != _rhs.type)
+1
View File
@@ -58,6 +58,7 @@ public:
bool statementEqual(Break const&, Break const&) { return true; }
bool statementEqual(Continue const&, Continue const&) { return true; }
bool statementEqual(Block const& _lhs, Block const& _rhs);
bool statementEqual(Comment const& _lhs, Comment const& _rhs);
private:
bool statementEqual(Instruction const& _lhs, Instruction const& _rhs);
bool statementEqual(Label const& _lhs, Label const& _rhs);