mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
[cond-expr] add an AST node
This commit is contained in:
parent
67c855c583
commit
4fa0326813
@ -1119,6 +1119,33 @@ public:
|
||||
ExpressionAnnotation& annotation() const override;
|
||||
};
|
||||
|
||||
class Conditional: public Expression
|
||||
{
|
||||
public:
|
||||
Conditional(
|
||||
SourceLocation const& _location,
|
||||
ASTPointer<Expression> const& _condition,
|
||||
ASTPointer<Expression> const& _trueExpression,
|
||||
ASTPointer<Expression> const& _falseExpression
|
||||
):
|
||||
Expression(_location),
|
||||
m_condition(_condition),
|
||||
m_trueExpression(_trueExpression),
|
||||
m_falseExpression(_falseExpression)
|
||||
{}
|
||||
virtual void accept(ASTVisitor& _visitor) override;
|
||||
virtual void accept(ASTConstVisitor& _visitor) const override;
|
||||
|
||||
Expression const& condition() const { return *m_condition; }
|
||||
Expression const& trueExpression() const { return *m_trueExpression; }
|
||||
Expression const& falseExpression() const { return *m_falseExpression; }
|
||||
|
||||
private:
|
||||
ASTPointer<Expression> m_condition;
|
||||
ASTPointer<Expression> m_trueExpression;
|
||||
ASTPointer<Expression> m_falseExpression;
|
||||
};
|
||||
|
||||
/// Assignment, can also be a compound assignment.
|
||||
/// Examples: (a = 7 + 8) or (a *= 2)
|
||||
class Assignment: public Expression
|
||||
|
@ -69,6 +69,7 @@ class Throw;
|
||||
class VariableDeclarationStatement;
|
||||
class ExpressionStatement;
|
||||
class Expression;
|
||||
class Conditional;
|
||||
class Assignment;
|
||||
class TupleExpression;
|
||||
class UnaryOperation;
|
||||
|
@ -551,6 +551,28 @@ void VariableDeclarationStatement::accept(ASTConstVisitor& _visitor) const
|
||||
_visitor.endVisit(*this);
|
||||
}
|
||||
|
||||
void Conditional::accept(ASTVisitor& _visitor)
|
||||
{
|
||||
if (_visitor.visit(*this))
|
||||
{
|
||||
m_condition->accept(_visitor);
|
||||
m_trueExpression->accept(_visitor);
|
||||
m_falseExpression->accept(_visitor);
|
||||
}
|
||||
_visitor.endVisit(*this);
|
||||
}
|
||||
|
||||
void Conditional::accept(ASTConstVisitor& _visitor) const
|
||||
{
|
||||
if (_visitor.visit(*this))
|
||||
{
|
||||
m_condition->accept(_visitor);
|
||||
m_trueExpression->accept(_visitor);
|
||||
m_falseExpression->accept(_visitor);
|
||||
}
|
||||
_visitor.endVisit(*this);
|
||||
}
|
||||
|
||||
void Assignment::accept(ASTVisitor& _visitor)
|
||||
{
|
||||
if (_visitor.visit(*this))
|
||||
|
Loading…
Reference in New Issue
Block a user