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

Side by Side Diff: pkg/polymer_expressions/lib/eval.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, 10 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 9
10 @MirrorsUsed(metaTargets: const [Reflectable, ObservableProperty], 10 @MirrorsUsed(metaTargets: const [Reflectable, ObservableProperty],
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 return binary; 363 return binary;
364 } 364 }
365 365
366 visitUnaryOperator(UnaryOperator o) { 366 visitUnaryOperator(UnaryOperator o) {
367 var expr = visit(o.child); 367 var expr = visit(o.child);
368 var unary = new UnaryObserver(o, expr); 368 var unary = new UnaryObserver(o, expr);
369 expr._parent = unary; 369 expr._parent = unary;
370 return unary; 370 return unary;
371 } 371 }
372 372
373 visitTernaryOperator(TernaryOperator o) {
374 var condition = visit(o.condition);
375 var trueExpr = visit(o.trueExpr);
376 var falseExpr = visit(o.falseExpr);
377 var ternary = new TernaryObserver(o, condition, trueExpr, falseExpr);
378 condition._parent = ternary;
379 trueExpr._parent = ternary;
380 falseExpr._parent = ternary;
381 return ternary;
382 }
383
373 visitInExpression(InExpression i) { 384 visitInExpression(InExpression i) {
374 // don't visit the left. It's an identifier, but we don't want to evaluate 385 // don't visit the left. It's an identifier, but we don't want to evaluate
375 // it, we just want to add it to the comprehension object 386 // it, we just want to add it to the comprehension object
376 var left = visit(i.left); 387 var left = visit(i.left);
377 var right = visit(i.right); 388 var right = visit(i.right);
378 var inexpr = new InObserver(i, left, right); 389 var inexpr = new InObserver(i, left, right);
379 right._parent = inexpr; 390 right._parent = inexpr;
380 return inexpr; 391 return inexpr;
381 } 392 }
382 } 393 }
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 .listen((_) => _invalidate(scope)); 529 .listen((_) => _invalidate(scope));
519 } 530 }
520 _value = f(left._value, right._value); 531 _value = f(left._value, right._value);
521 } 532 }
522 } 533 }
523 534
524 accept(Visitor v) => v.visitBinaryOperator(this); 535 accept(Visitor v) => v.visitBinaryOperator(this);
525 536
526 } 537 }
527 538
539 class TernaryObserver extends ExpressionObserver<TernaryOperator>
540 implements TernaryOperator {
541
542 final ExpressionObserver condition;
543 final ExpressionObserver trueExpr;
544 final ExpressionObserver falseExpr;
545
546 TernaryObserver(TernaryOperator expr, this.condition, this.trueExpr,
547 this.falseExpr) : super(expr);
548
549 _updateSelf(Scope scope) {
550 _value = _toBool(condition._value) ? trueExpr._value : falseExpr._value;
551 }
552
553 accept(Visitor v) => v.visitTernaryOperator(this);
554
555 }
556
528 class GetterObserver extends ExpressionObserver<Getter> implements Getter { 557 class GetterObserver extends ExpressionObserver<Getter> implements Getter {
529 final ExpressionObserver receiver; 558 final ExpressionObserver receiver;
530 559
531 GetterObserver(Expression expr, this.receiver) : super(expr); 560 GetterObserver(Expression expr, this.receiver) : super(expr);
532 561
533 String get name => _expr.name; 562 String get name => _expr.name;
534 563
535 _updateSelf(Scope scope) { 564 _updateSelf(Scope scope) {
536 var receiverValue = receiver._value; 565 var receiverValue = receiver._value;
537 if (receiverValue == null) { 566 if (receiverValue == null) {
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
693 * This does not work for calls that need to pass more than one argument. 722 * This does not work for calls that need to pass more than one argument.
694 */ 723 */
695 call(arg0) => mirror.invoke(symbol, [arg0], null).reflectee; 724 call(arg0) => mirror.invoke(symbol, [arg0], null).reflectee;
696 } 725 }
697 726
698 class EvalException implements Exception { 727 class EvalException implements Exception {
699 final String message; 728 final String message;
700 EvalException(this.message); 729 EvalException(this.message);
701 String toString() => "EvalException: $message"; 730 String toString() => "EvalException: $message";
702 } 731 }
OLDNEW
« no previous file with comments | « no previous file | pkg/polymer_expressions/lib/expression.dart » ('j') | pkg/polymer_expressions/test/eval_test.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698