| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library polymer_expressions.expression; | 5 library polymer_expressions.expression; |
| 6 | 6 |
| 7 import 'visitor.dart'; | 7 import 'visitor.dart'; |
| 8 | 8 |
| 9 // Helper functions for building expression trees programmatically | 9 // Helper functions for building expression trees programmatically |
| 10 | 10 |
| 11 EmptyExpression empty() => const EmptyExpression(); | 11 EmptyExpression empty() => const EmptyExpression(); |
| 12 Literal literal(v) => new Literal(v); | 12 Literal literal(v) => new Literal(v); |
| 13 MapLiteral mapLiteral(List<MapLiteralEntry> entries) => new MapLiteral(entries); | 13 MapLiteral mapLiteral(List<MapLiteralEntry> entries) => new MapLiteral(entries); |
| 14 MapLiteralEntry mapLiteralEntry(Literal key, Expression value) => | 14 MapLiteralEntry mapLiteralEntry(Literal key, Expression value) => |
| 15 new MapLiteralEntry(key, value); | 15 new MapLiteralEntry(key, value); |
| 16 Identifier ident(String v) => new Identifier(v); | 16 Identifier ident(String v) => new Identifier(v); |
| 17 ParenthesizedExpression paren(Expression e) => new ParenthesizedExpression(e); | 17 ParenthesizedExpression paren(Expression e) => new ParenthesizedExpression(e); |
| 18 UnaryOperator unary(String op, Expression e) => new UnaryOperator(op, e); | 18 UnaryOperator unary(String op, Expression e) => new UnaryOperator(op, e); |
| 19 BinaryOperator binary(Expression l, String op, Expression r) => | 19 BinaryOperator binary(Expression l, String op, Expression r) => |
| 20 new BinaryOperator(l, op, r); | 20 new BinaryOperator(l, op, r); |
| 21 Getter getter(Expression e, String m) => new Getter(e, m); | 21 Getter getter(Expression e, String m) => new Getter(e, m); |
| 22 Index index(Expression e, Expression a) => new Index(e, a); | 22 Index index(Expression e, Expression a) => new Index(e, a); |
| 23 Invoke invoke(Expression e, String m, List<Expression> a) => | 23 Invoke invoke(Expression e, String m, List<Expression> a) => |
| 24 new Invoke(e, m, a); | 24 new Invoke(e, m, a); |
| 25 InExpression inExpr(Expression l, Expression r) => new InExpression(l, r); | 25 InExpression inExpr(Expression l, Expression r) => new InExpression(l, r); |
| 26 | 26 TernaryOperator ternary(Expression c, Expression t, Expression f) => |
| 27 new TernaryOperator(c, t, f); |
| 27 | 28 |
| 28 class AstFactory { | 29 class AstFactory { |
| 29 EmptyExpression empty() => const EmptyExpression(); | 30 EmptyExpression empty() => const EmptyExpression(); |
| 30 | 31 |
| 31 Literal literal(v) => new Literal(v); | 32 Literal literal(v) => new Literal(v); |
| 32 | 33 |
| 33 MapLiteral mapLiteral(List<MapLiteralEntry> entries) => | 34 MapLiteral mapLiteral(List<MapLiteralEntry> entries) => |
| 34 new MapLiteral(entries); | 35 new MapLiteral(entries); |
| 35 | 36 |
| 36 MapLiteralEntry mapLiteralEntry(Literal key, Expression value) => | 37 MapLiteralEntry mapLiteralEntry(Literal key, Expression value) => |
| 37 new MapLiteralEntry(key, value); | 38 new MapLiteralEntry(key, value); |
| 38 | 39 |
| 39 Identifier identifier(String v) => new Identifier(v); | 40 Identifier identifier(String v) => new Identifier(v); |
| 40 | 41 |
| 41 ParenthesizedExpression parenthesized(Expression e) => | 42 ParenthesizedExpression parenthesized(Expression e) => |
| 42 new ParenthesizedExpression(e); | 43 new ParenthesizedExpression(e); |
| 43 | 44 |
| 44 UnaryOperator unary(String op, Expression e) => new UnaryOperator(op, e); | 45 UnaryOperator unary(String op, Expression e) => new UnaryOperator(op, e); |
| 45 | 46 |
| 46 BinaryOperator binary(Expression l, String op, Expression r) => | 47 BinaryOperator binary(Expression l, String op, Expression r) => |
| 47 new BinaryOperator(l, op, r); | 48 new BinaryOperator(l, op, r); |
| 48 | 49 |
| 50 TernaryOperator ternary(Expression c, Expression t, Expression f) => |
| 51 new TernaryOperator(c, t, f); |
| 52 |
| 49 Getter getter(Expression g, String n) => new Getter(g, n); | 53 Getter getter(Expression g, String n) => new Getter(g, n); |
| 50 | 54 |
| 51 Index index(Expression e, Expression a) => new Index(e, a); | 55 Index index(Expression e, Expression a) => new Index(e, a); |
| 52 | 56 |
| 53 Invoke invoke(Expression e, String m, List<Expression> a) => | 57 Invoke invoke(Expression e, String m, List<Expression> a) => |
| 54 new Invoke(e, m, a); | 58 new Invoke(e, m, a); |
| 55 | 59 |
| 56 InExpression inExpr(Expression l, Expression r) => new InExpression(l, r); | 60 InExpression inExpr(Expression l, Expression r) => new InExpression(l, r); |
| 57 } | 61 } |
| 58 | 62 |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 | 170 |
| 167 String toString() => '($left $operator $right)'; | 171 String toString() => '($left $operator $right)'; |
| 168 | 172 |
| 169 bool operator ==(o) => o is BinaryOperator && o.operator == operator | 173 bool operator ==(o) => o is BinaryOperator && o.operator == operator |
| 170 && o.left == left && o.right == right; | 174 && o.left == left && o.right == right; |
| 171 | 175 |
| 172 int get hashCode => _JenkinsSmiHash.hash3(operator.hashCode, left.hashCode, | 176 int get hashCode => _JenkinsSmiHash.hash3(operator.hashCode, left.hashCode, |
| 173 right.hashCode); | 177 right.hashCode); |
| 174 } | 178 } |
| 175 | 179 |
| 180 class TernaryOperator extends Expression { |
| 181 final Expression condition; |
| 182 final Expression trueExpr; |
| 183 final Expression falseExpr; |
| 184 |
| 185 TernaryOperator(this.condition, this.trueExpr, this.falseExpr); |
| 186 |
| 187 accept(Visitor v) => v.visitTernaryOperator(this); |
| 188 |
| 189 String toString() => '($condition ? $trueExpr : $falseExpr)'; |
| 190 |
| 191 bool operator ==(o) => o is TernaryOperator |
| 192 && o.condition == condition |
| 193 && o.trueExpr == trueExpr |
| 194 && o.falseExpr == falseExpr; |
| 195 |
| 196 int get hashCode => _JenkinsSmiHash.hash3(condition.hashCode, |
| 197 trueExpr.hashCode, falseExpr.hashCode); |
| 198 } |
| 199 |
| 176 class InExpression extends Expression { | 200 class InExpression extends Expression { |
| 177 final Expression left; | 201 final Expression left; |
| 178 final Expression right; | 202 final Expression right; |
| 179 | 203 |
| 180 InExpression(this.left, this.right); | 204 InExpression(this.left, this.right); |
| 181 | 205 |
| 182 accept(Visitor v) => v.visitInExpression(this); | 206 accept(Visitor v) => v.visitInExpression(this); |
| 183 | 207 |
| 184 String toString() => '($left in $right)'; | 208 String toString() => '($left in $right)'; |
| 185 | 209 |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 } | 312 } |
| 289 | 313 |
| 290 static int hash2(int a, int b) => finish(combine(combine(0, a), b)); | 314 static int hash2(int a, int b) => finish(combine(combine(0, a), b)); |
| 291 | 315 |
| 292 static int hash3(int a, int b, int c) => | 316 static int hash3(int a, int b, int c) => |
| 293 finish(combine(combine(combine(0, a), b), c)); | 317 finish(combine(combine(combine(0, a), b), c)); |
| 294 | 318 |
| 295 static int hash4(int a, int b, int c, int d) => | 319 static int hash4(int a, int b, int c, int d) => |
| 296 finish(combine(combine(combine(combine(0, a), b), c), d)); | 320 finish(combine(combine(combine(combine(0, a), b), c), d)); |
| 297 } | 321 } |
| OLD | NEW |