aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity/ast
diff options
context:
space:
mode:
authorLu Guanqun <guanqun.lu@gmail.com>2015-12-23 00:44:51 +0800
committerLu Guanqun <guanqun.lu@gmail.com>2016-01-23 01:14:00 +0800
commit4fa0326813b4fc9d3c85cb9235f42cf22beead72 (patch)
tree33e92344628ec38e89a6de665e4a3b2e5404381e /libsolidity/ast
parent67c855c583042ddee6261a9921239a3afd086c14 (diff)
downloaddexon-solidity-4fa0326813b4fc9d3c85cb9235f42cf22beead72.tar.gz
dexon-solidity-4fa0326813b4fc9d3c85cb9235f42cf22beead72.tar.zst
dexon-solidity-4fa0326813b4fc9d3c85cb9235f42cf22beead72.zip
[cond-expr] add an AST node
Diffstat (limited to 'libsolidity/ast')
-rw-r--r--libsolidity/ast/AST.h27
-rw-r--r--libsolidity/ast/ASTForward.h1
-rw-r--r--libsolidity/ast/AST_accept.h22
3 files changed, 50 insertions, 0 deletions
diff --git a/libsolidity/ast/AST.h b/libsolidity/ast/AST.h
index 4baf95d3..e1063467 100644
--- a/libsolidity/ast/AST.h
+++ b/libsolidity/ast/AST.h
@@ -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
diff --git a/libsolidity/ast/ASTForward.h b/libsolidity/ast/ASTForward.h
index 6aaa77ce..dad2b2e2 100644
--- a/libsolidity/ast/ASTForward.h
+++ b/libsolidity/ast/ASTForward.h
@@ -69,6 +69,7 @@ class Throw;
class VariableDeclarationStatement;
class ExpressionStatement;
class Expression;
+class Conditional;
class Assignment;
class TupleExpression;
class UnaryOperation;
diff --git a/libsolidity/ast/AST_accept.h b/libsolidity/ast/AST_accept.h
index 61370c55..dee9d5b1 100644
--- a/libsolidity/ast/AST_accept.h
+++ b/libsolidity/ast/AST_accept.h
@@ -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))