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 | 9 |
| 10 @MirrorsUsed(metaTargets: const [Reflectable, ObservableProperty], | 10 @MirrorsUsed(metaTargets: const [Reflectable, ObservableProperty], |
| (...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 329 ? null | 329 ? null |
| 330 : i.arguments.map(visit).toList(growable: false); | 330 : i.arguments.map(visit).toList(growable: false); |
| 331 var invoke = new InvokeObserver(i, receiver, args); | 331 var invoke = new InvokeObserver(i, receiver, args); |
| 332 receiver._parent = invoke; | 332 receiver._parent = invoke; |
| 333 if (args != null) args.forEach((a) => a._parent = invoke); | 333 if (args != null) args.forEach((a) => a._parent = invoke); |
| 334 return invoke; | 334 return invoke; |
| 335 } | 335 } |
| 336 | 336 |
| 337 visitLiteral(Literal l) => new LiteralObserver(l); | 337 visitLiteral(Literal l) => new LiteralObserver(l); |
| 338 | 338 |
| 339 visitListLiteral(ListLiteral l) { | |
| 340 var items = l.items.map(visit).toList(growable: false); | |
| 341 var list = new ListLiteralObserver(l, items); | |
| 342 items.forEach((e) => e._parent = list); | |
|
Jennifer Messerly
2014/01/28 00:07:04
thought for future refactoring ... it might be mor
justinfagnani
2014/01/28 02:16:21
Agreed. I actually want to get rid of the observer
| |
| 343 return list; | |
| 344 } | |
| 345 | |
| 339 visitMapLiteral(MapLiteral l) { | 346 visitMapLiteral(MapLiteral l) { |
| 340 var entries = l.entries.map(visit).toList(growable: false); | 347 var entries = l.entries.map(visit).toList(growable: false); |
| 341 var map = new MapLiteralObserver(l, entries); | 348 var map = new MapLiteralObserver(l, entries); |
| 342 entries.forEach((e) => e._parent = map); | 349 entries.forEach((e) => e._parent = map); |
| 343 return map; | 350 return map; |
| 344 } | 351 } |
| 345 | 352 |
| 346 visitMapLiteralEntry(MapLiteralEntry e) { | 353 visitMapLiteralEntry(MapLiteralEntry e) { |
| 347 var key = visit(e.key); | 354 var key = visit(e.key); |
| 348 var value = visit(e.entryValue); | 355 var value = visit(e.entryValue); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 411 | 418 |
| 412 dynamic get value => _expr.value; | 419 dynamic get value => _expr.value; |
| 413 | 420 |
| 414 _updateSelf(Scope scope) { | 421 _updateSelf(Scope scope) { |
| 415 _value = _expr.value; | 422 _value = _expr.value; |
| 416 } | 423 } |
| 417 | 424 |
| 418 accept(Visitor v) => v.visitLiteral(this); | 425 accept(Visitor v) => v.visitLiteral(this); |
| 419 } | 426 } |
| 420 | 427 |
| 428 class ListLiteralObserver extends ExpressionObserver<ListLiteral> | |
| 429 implements ListLiteral { | |
| 430 | |
| 431 final List<ExpressionObserver> items; | |
| 432 | |
| 433 ListLiteralObserver(ListLiteral value, this.items) : super(value); | |
| 434 | |
| 435 _updateSelf(Scope scope) { | |
| 436 _value = items.map((i) => i._value).toList(growable: false); | |
| 437 } | |
| 438 | |
| 439 accept(Visitor v) => v.visitListLiteral(this); | |
| 440 } | |
| 441 | |
| 421 class MapLiteralObserver extends ExpressionObserver<MapLiteral> | 442 class MapLiteralObserver extends ExpressionObserver<MapLiteral> |
| 422 implements MapLiteral { | 443 implements MapLiteral { |
| 423 | 444 |
| 424 final List<MapLiteralEntryObserver> entries; | 445 final List<MapLiteralEntryObserver> entries; |
| 425 | 446 |
| 426 MapLiteralObserver(MapLiteral value, this.entries) : super(value); | 447 MapLiteralObserver(MapLiteral value, this.entries) : super(value); |
| 427 | 448 |
| 428 _updateSelf(Scope scope) { | 449 _updateSelf(Scope scope) { |
| 429 _value = entries.fold(new Map(), | 450 _value = entries.fold(new Map(), |
| 430 (m, e) => m..[e.key._value] = e.entryValue._value); | 451 (m, e) => m..[e.key._value] = e.entryValue._value); |
| (...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 722 * This does not work for calls that need to pass more than one argument. | 743 * This does not work for calls that need to pass more than one argument. |
| 723 */ | 744 */ |
| 724 call(arg0) => mirror.invoke(symbol, [arg0], null).reflectee; | 745 call(arg0) => mirror.invoke(symbol, [arg0], null).reflectee; |
| 725 } | 746 } |
| 726 | 747 |
| 727 class EvalException implements Exception { | 748 class EvalException implements Exception { |
| 728 final String message; | 749 final String message; |
| 729 EvalException(this.message); | 750 EvalException(this.message); |
| 730 String toString() => "EvalException: $message"; | 751 String toString() => "EvalException: $message"; |
| 731 } | 752 } |
| OLD | NEW |