OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
2 | 2 |
3 // for details. All rights reserved. Use of this source code is governed by a | 3 // for details. All rights reserved. Use of this source code is governed by a |
4 // BSD-style license that can be found in the LICENSE file. | 4 // BSD-style license that can be found in the LICENSE file. |
5 | 5 |
6 import 'dart:collection' show HashMap, HashSet; | 6 import 'dart:collection' show HashMap, HashSet; |
7 import 'dart:math' show min, max; | 7 import 'dart:math' show min, max; |
8 | 8 |
9 import 'package:analyzer/analyzer.dart' hide ConstantEvaluator; | 9 import 'package:analyzer/analyzer.dart' hide ConstantEvaluator; |
10 import 'package:analyzer/dart/ast/ast.dart'; | 10 import 'package:analyzer/dart/ast/ast.dart'; |
(...skipping 3935 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3946 JS.Statement visitExpressionStatement(ExpressionStatement node) => | 3946 JS.Statement visitExpressionStatement(ExpressionStatement node) => |
3947 _visit(node.expression).toStatement(); | 3947 _visit(node.expression).toStatement(); |
3948 | 3948 |
3949 @override | 3949 @override |
3950 JS.EmptyStatement visitEmptyStatement(EmptyStatement node) => | 3950 JS.EmptyStatement visitEmptyStatement(EmptyStatement node) => |
3951 new JS.EmptyStatement(); | 3951 new JS.EmptyStatement(); |
3952 | 3952 |
3953 @override | 3953 @override |
3954 JS.Statement visitAssertStatement(AssertStatement node) { | 3954 JS.Statement visitAssertStatement(AssertStatement node) { |
3955 // TODO(jmesserly): only emit in checked mode. | 3955 // TODO(jmesserly): only emit in checked mode. |
| 3956 var condition = node.condition; |
| 3957 var conditionType = condition.staticType; |
| 3958 JS.Expression jsCondition = _visit(condition); |
| 3959 if (conditionType is FunctionType && |
| 3960 conditionType.parameters.isEmpty && |
| 3961 conditionType.returnType == types.boolType) { |
| 3962 jsCondition = new JS.Call(jsCondition, []); |
| 3963 } |
| 3964 var args = [jsCondition]; |
3956 if (node.message != null) { | 3965 if (node.message != null) { |
3957 return _callHelperStatement('assert(#, () => #);', | 3966 args.add(js.call('() => #', [_visit(node.message)])); |
3958 [_visit(node.condition), _visit(node.message)]); | |
3959 } | 3967 } |
3960 | 3968 return _callHelperStatement('assert(#);', [args]); |
3961 return _callHelperStatement('assert(#);', _visit(node.condition)); | |
3962 } | 3969 } |
3963 | 3970 |
3964 @override | 3971 @override |
3965 JS.Statement visitReturnStatement(ReturnStatement node) { | 3972 JS.Statement visitReturnStatement(ReturnStatement node) { |
3966 var e = node.expression; | 3973 var e = node.expression; |
3967 if (e == null) return new JS.Return(); | 3974 if (e == null) return new JS.Return(); |
3968 return (_visit(e) as JS.Expression).toReturn(); | 3975 return _visit<JS.Expression>(e).toReturn(); |
3969 } | 3976 } |
3970 | 3977 |
3971 @override | 3978 @override |
3972 JS.Statement visitYieldStatement(YieldStatement node) { | 3979 JS.Statement visitYieldStatement(YieldStatement node) { |
3973 JS.Expression jsExpr = _visit(node.expression); | 3980 JS.Expression jsExpr = _visit(node.expression); |
3974 var star = node.star != null; | 3981 var star = node.star != null; |
3975 if (_asyncStarController != null) { | 3982 if (_asyncStarController != null) { |
3976 // async* yields are generated differently from sync* yields. `yield e` | 3983 // async* yields are generated differently from sync* yields. `yield e` |
3977 // becomes: | 3984 // becomes: |
3978 // | 3985 // |
(...skipping 991 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4970 /// `obj.name(args)` because that could be a getter followed by a call. | 4977 /// `obj.name(args)` because that could be a getter followed by a call. |
4971 /// See [visitMethodInvocation]. | 4978 /// See [visitMethodInvocation]. |
4972 JS.Expression _emitSend( | 4979 JS.Expression _emitSend( |
4973 Expression target, String name, List<Expression> args) { | 4980 Expression target, String name, List<Expression> args) { |
4974 var type = getStaticType(target); | 4981 var type = getStaticType(target); |
4975 var memberName = _emitMemberName(name, type: type); | 4982 var memberName = _emitMemberName(name, type: type); |
4976 if (isDynamicInvoke(target)) { | 4983 if (isDynamicInvoke(target)) { |
4977 // dynamic dispatch | 4984 // dynamic dispatch |
4978 var dynamicHelper = const {'[]': 'dindex', '[]=': 'dsetindex'}[name]; | 4985 var dynamicHelper = const {'[]': 'dindex', '[]=': 'dsetindex'}[name]; |
4979 if (dynamicHelper != null) { | 4986 if (dynamicHelper != null) { |
4980 return _callHelper('$dynamicHelper(#, #)', | 4987 return _callHelper( |
4981 [_visit(target) as JS.Expression, _visitList(args)]); | 4988 '$dynamicHelper(#, #)', [_visit(target), _visitList(args)]); |
4982 } else { | 4989 } else { |
4983 return _callHelper( | 4990 return _callHelper( |
4984 'dsend(#, #, #)', [_visit(target), memberName, _visitList(args)]); | 4991 'dsend(#, #, #)', [_visit(target), memberName, _visitList(args)]); |
4985 } | 4992 } |
4986 } | 4993 } |
4987 | 4994 |
4988 // Generic dispatch to a statically known method. | 4995 // Generic dispatch to a statically known method. |
4989 return js.call('#.#(#)', [_visit(target), memberName, _visitList(args)]); | 4996 return js.call('#.#(#)', [_visit(target), memberName, _visitList(args)]); |
4990 } | 4997 } |
4991 | 4998 |
(...skipping 972 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5964 if (targetIdentifier.staticElement is! PrefixElement) return false; | 5971 if (targetIdentifier.staticElement is! PrefixElement) return false; |
5965 var prefix = targetIdentifier.staticElement as PrefixElement; | 5972 var prefix = targetIdentifier.staticElement as PrefixElement; |
5966 | 5973 |
5967 // The library the prefix is referring to must come from a deferred import. | 5974 // The library the prefix is referring to must come from a deferred import. |
5968 var containingLibrary = resolutionMap | 5975 var containingLibrary = resolutionMap |
5969 .elementDeclaredByCompilationUnit(target.root as CompilationUnit) | 5976 .elementDeclaredByCompilationUnit(target.root as CompilationUnit) |
5970 .library; | 5977 .library; |
5971 var imports = containingLibrary.getImportsWithPrefix(prefix); | 5978 var imports = containingLibrary.getImportsWithPrefix(prefix); |
5972 return imports.length == 1 && imports[0].isDeferred; | 5979 return imports.length == 1 && imports[0].isDeferred; |
5973 } | 5980 } |
OLD | NEW |