Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(518)

Unified Diff: pkg/polymer_expressions/lib/expression.dart

Issue 131623004: Ternary operator support for polymer_expressions (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: pkg/polymer_expressions/lib/expression.dart
diff --git a/pkg/polymer_expressions/lib/expression.dart b/pkg/polymer_expressions/lib/expression.dart
index c89724fe8232828b3ff828bcdb1783ac7263fba6..5a69ab05891db0e655869bcf7e0295d76520746c 100644
--- a/pkg/polymer_expressions/lib/expression.dart
+++ b/pkg/polymer_expressions/lib/expression.dart
@@ -23,7 +23,8 @@ Index index(Expression e, Expression a) => new Index(e, a);
Invoke invoke(Expression e, String m, List<Expression> a) =>
new Invoke(e, m, a);
InExpression inExpr(Expression l, Expression r) => new InExpression(l, r);
-
+TernaryOperator ternary(Expression c, Expression t, Expression f) =>
+ new TernaryOperator(c, t, f);
class AstFactory {
EmptyExpression empty() => const EmptyExpression();
@@ -46,6 +47,9 @@ class AstFactory {
BinaryOperator binary(Expression l, String op, Expression r) =>
new BinaryOperator(l, op, r);
+ TernaryOperator ternary(Expression c, Expression t, Expression f) =>
+ new TernaryOperator(c, t, f);
+
Getter getter(Expression g, String n) => new Getter(g, n);
Index index(Expression e, Expression a) => new Index(e, a);
@@ -173,6 +177,26 @@ class BinaryOperator extends Expression {
right.hashCode);
}
+class TernaryOperator extends Expression {
+ final Expression condition;
+ final Expression trueExpr;
+ final Expression falseExpr;
+
+ TernaryOperator(this.condition, this.trueExpr, this.falseExpr);
+
+ accept(Visitor v) => v.visitTernaryOperator(this);
+
+ String toString() => '($condition ? $trueExpr : $falseExpr)';
+
+ bool operator ==(o) => o is TernaryOperator
+ && o.condition == condition
+ && o.trueExpr == trueExpr
+ && o.falseExpr == falseExpr;
+
+ int get hashCode => _JenkinsSmiHash.hash3(condition.hashCode,
+ trueExpr.hashCode, falseExpr.hashCode);
+}
+
class InExpression extends Expression {
final Expression left;
final Expression right;

Powered by Google App Engine
This is Rietveld 408576698