Chromium Code Reviews| 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.eval; | 5 library polymer_expressions.eval; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:collection'; | 8 import 'dart:collection'; |
| 9 import 'dart:mirrors'; | 9 import 'dart:mirrors'; |
| 10 | 10 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 67 void assign(Expression expr, Object value, Scope scope) { | 67 void assign(Expression expr, Object value, Scope scope) { |
| 68 | 68 |
| 69 notAssignable() => | 69 notAssignable() => |
| 70 throw new EvalException("Expression is not assignable: $expr"); | 70 throw new EvalException("Expression is not assignable: $expr"); |
| 71 | 71 |
| 72 Expression expression; | 72 Expression expression; |
| 73 var property; | 73 var property; |
| 74 bool isIndex = false; | 74 bool isIndex = false; |
| 75 var filters = <Expression>[]; // reversed order for assignment | 75 var filters = <Expression>[]; // reversed order for assignment |
| 76 | 76 |
| 77 while (expr is BinaryOperator && expr.operator == '|') { | 77 while (expr is BinaryOperator && (expr as BinaryOperator).operator == '|') { |
| 78 filters.add(expr.right); | 78 filters.add((expr as BinaryOperator).right); |
|
justinfagnani
2013/08/29 18:31:49
I'd prefer not use casts when they can be avoided.
blois
2013/08/29 19:43:22
Done.
| |
| 79 expr = expr.left; | 79 expr = (expr as BinaryOperator).left; |
| 80 } | 80 } |
| 81 | 81 |
| 82 if (expr is Identifier) { | 82 if (expr is Identifier) { |
| 83 expression = empty(); | 83 expression = empty(); |
| 84 property = expr.value; | 84 property = (expr as Identifier).value; |
|
justinfagnani
2013/08/29 18:31:49
Identifier ident = expr;
property = ident.value;
blois
2013/08/29 19:43:22
Done.
| |
| 85 } else if (expr is Invoke) { | 85 } else if (expr is Invoke) { |
| 86 expression = expr.receiver; | 86 Invoke invoke = expr; |
| 87 if (expr.method == '[]') { | 87 expression = invoke.receiver; |
| 88 if (expr.arguments[0] is! Literal) notAssignable(); | 88 if (invoke.method == '[]') { |
| 89 Literal l = expr.arguments[0]; | 89 if (invoke.arguments[0] is! Literal) notAssignable(); |
| 90 Literal l = invoke.arguments[0]; | |
| 90 property = l.value; | 91 property = l.value; |
| 91 isIndex = true; | 92 isIndex = true; |
| 92 } else if (expr.method != null) { | 93 } else if (invoke.method != null) { |
| 93 if (expr.arguments != null) notAssignable(); | 94 if (invoke.arguments != null) notAssignable(); |
| 94 property = expr.method; | 95 property = invoke.method; |
| 95 } else { | 96 } else { |
| 96 notAssignable(); | 97 notAssignable(); |
| 97 } | 98 } |
| 98 } else { | 99 } else { |
| 99 notAssignable(); | 100 notAssignable(); |
| 100 } | 101 } |
| 101 | 102 |
| 102 // transform the values backwards through the filters | 103 // transform the values backwards through the filters |
| 103 for (var filterExpr in filters) { | 104 for (var filterExpr in filters) { |
| 104 var filter = eval(filterExpr, scope); | 105 var filter = eval(filterExpr, scope); |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 411 } | 412 } |
| 412 } | 413 } |
| 413 | 414 |
| 414 accept(Visitor v) => v.visitIdentifier(this); | 415 accept(Visitor v) => v.visitIdentifier(this); |
| 415 } | 416 } |
| 416 | 417 |
| 417 class ParenthesizedObserver extends ExpressionObserver<ParenthesizedExpression> | 418 class ParenthesizedObserver extends ExpressionObserver<ParenthesizedExpression> |
| 418 implements ParenthesizedExpression { | 419 implements ParenthesizedExpression { |
| 419 final ExpressionObserver child; | 420 final ExpressionObserver child; |
| 420 | 421 |
| 421 ParenthesizedObserver(ExpressionObserver expr, this.child) : super(expr); | 422 ParenthesizedObserver(ParenthesizedExpression expr, this.child) : super(expr); |
| 422 | 423 |
| 423 | 424 |
| 424 _updateSelf(Scope scope) { | 425 _updateSelf(Scope scope) { |
| 425 _value = child._value; | 426 _value = child._value; |
| 426 } | 427 } |
| 427 | 428 |
| 428 accept(Visitor v) => v.visitParenthesizedExpression(this); | 429 accept(Visitor v) => v.visitParenthesizedExpression(this); |
| 429 } | 430 } |
| 430 | 431 |
| 431 class UnaryObserver extends ExpressionObserver<UnaryOperator> | 432 class UnaryObserver extends ExpressionObserver<UnaryOperator> |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 604 Method(this.mirror, this.symbol); | 605 Method(this.mirror, this.symbol); |
| 605 | 606 |
| 606 dynamic call(List args) => mirror.invoke(symbol, args, null).reflectee; | 607 dynamic call(List args) => mirror.invoke(symbol, args, null).reflectee; |
| 607 } | 608 } |
| 608 | 609 |
| 609 class EvalException implements Exception { | 610 class EvalException implements Exception { |
| 610 final String message; | 611 final String message; |
| 611 EvalException(this.message); | 612 EvalException(this.message); |
| 612 String toString() => "EvalException: $message"; | 613 String toString() => "EvalException: $message"; |
| 613 } | 614 } |
| OLD | NEW |