Chromium Code Reviews| 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 library unittest.backend.platform_selector.evaluator; | |
| 6 | |
| 7 import 'package:source_span/source_span.dart'; | |
| 8 | |
| 9 import '../operating_system.dart'; | |
| 10 import '../test_platform.dart'; | |
| 11 import 'ast.dart'; | |
| 12 import 'visitor.dart'; | |
| 13 | |
| 14 /// A visitor for evaluating platform selectors against a specific | |
| 15 /// [TestPlatform] and [OperatingSystem]. | |
| 16 class Evaluator implements Visitor<bool> { | |
| 17 /// The platform to test against. | |
| 18 final TestPlatform _platform; | |
| 19 | |
| 20 /// The operating system to test against. | |
| 21 final OperatingSystem _os; | |
| 22 | |
| 23 Evaluator(this._platform, {OperatingSystem os}) | |
| 24 : _os = os == null ? OperatingSystem.none : os; | |
| 25 | |
| 26 bool visitVariable(VariableNode node) { | |
| 27 if (node.name == _platform.identifier) return true; | |
| 28 if (TestPlatform.all.any((platform) => node.name == platform.identifier)) { | |
| 29 return false; | |
| 30 } | |
|
Bob Nystrom
2015/03/16 16:54:26
Are these false cases needed?
nweiz
2015/03/24 01:03:28
Done.
| |
| 31 | |
| 32 if (node.name == _os.name) return true; | |
| 33 if (OperatingSystem.all.any((os) => node.name == os.name)) { | |
| 34 return false; | |
| 35 } | |
| 36 | |
| 37 switch (node.name) { | |
| 38 case "dart-vm": return _platform.isDartVm; | |
| 39 case "browser": return _platform.isBrowser; | |
| 40 case "dart2js": return _platform.isDart2js; | |
| 41 case "blink": return _platform.isBlink; | |
| 42 case "posix": return _os.isPosix; | |
| 43 default: | |
| 44 throw new SourceSpanFormatException( | |
| 45 'Undefined variable "${node.name}".', node.span); | |
|
Bob Nystrom
2015/03/16 16:54:26
If you've already done the check for undefined var
nweiz
2015/03/24 01:03:28
Done.
| |
| 46 } | |
| 47 } | |
| 48 | |
| 49 bool visitNot(NotNode node) => !node.child.accept(this); | |
| 50 | |
| 51 bool visitOr(OrNode node) => | |
| 52 node.left.accept(this) || node.right.accept(this); | |
| 53 | |
| 54 bool visitAnd(AndNode node) => | |
| 55 node.left.accept(this) && node.right.accept(this); | |
| 56 | |
| 57 bool visitConditional(ConditionalNode node) => node.condition.accept(this) | |
| 58 ? node.whenTrue.accept(this) | |
| 59 : node.whenFalse.accept(this); | |
| 60 } | |
| OLD | NEW |