| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | |
| 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. | |
| 4 | |
| 5 import '../operating_system.dart'; | |
| 6 import '../test_platform.dart'; | |
| 7 import 'ast.dart'; | |
| 8 import 'visitor.dart'; | |
| 9 | |
| 10 /// A visitor for evaluating platform selectors against a specific | |
| 11 /// [TestPlatform] and [OperatingSystem]. | |
| 12 class Evaluator implements Visitor<bool> { | |
| 13 /// The platform to test against. | |
| 14 final TestPlatform _platform; | |
| 15 | |
| 16 /// The operating system to test against. | |
| 17 final OperatingSystem _os; | |
| 18 | |
| 19 Evaluator(this._platform, {OperatingSystem os}) | |
| 20 : _os = os == null ? OperatingSystem.none : os; | |
| 21 | |
| 22 bool visitVariable(VariableNode node) { | |
| 23 if (node.name == _platform.identifier) return true; | |
| 24 if (node.name == _os.name) return true; | |
| 25 | |
| 26 switch (node.name) { | |
| 27 case "dart-vm": return _platform.isDartVM; | |
| 28 case "browser": return _platform.isBrowser; | |
| 29 case "js": return _platform.isJS; | |
| 30 case "blink": return _platform.isBlink; | |
| 31 case "posix": return _os.isPosix; | |
| 32 default: return false; | |
| 33 } | |
| 34 } | |
| 35 | |
| 36 bool visitNot(NotNode node) => !node.child.accept(this); | |
| 37 | |
| 38 bool visitOr(OrNode node) => | |
| 39 node.left.accept(this) || node.right.accept(this); | |
| 40 | |
| 41 bool visitAnd(AndNode node) => | |
| 42 node.left.accept(this) && node.right.accept(this); | |
| 43 | |
| 44 bool visitConditional(ConditionalNode node) => node.condition.accept(this) | |
| 45 ? node.whenTrue.accept(this) | |
| 46 : node.whenFalse.accept(this); | |
| 47 } | |
| OLD | NEW |