Chromium Code Reviews| 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 1313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1324 // classes and preserve the Dart initialization order. | 1324 // classes and preserve the Dart initialization order. |
| 1325 // | 1325 // |
| 1326 // Instead we use the same trick as named constructors, and do them as | 1326 // Instead we use the same trick as named constructors, and do them as |
| 1327 // instance methods that perform initialization. | 1327 // instance methods that perform initialization. |
| 1328 // | 1328 // |
| 1329 // Therefore, dart:core Object gets the one real `constructor` and | 1329 // Therefore, dart:core Object gets the one real `constructor` and |
| 1330 // immediately bounces to the `new() { ... }` initializer, letting us | 1330 // immediately bounces to the `new() { ... }` initializer, letting us |
| 1331 // bypass the ES6 restrictions. | 1331 // bypass the ES6 restrictions. |
| 1332 // | 1332 // |
| 1333 // TODO(jmesserly): we'll need to rethink this. | 1333 // TODO(jmesserly): we'll need to rethink this. |
| 1334 // See <https://github.com/dart-lang/dev_compiler/issues/51>. | 1334 // See #28322. |
|
Jennifer Messerly
2017/01/10 19:01:18
nit: I try and use full bug links because they're
vsm
2017/01/10 20:55:27
Good point. Done here and elsewhere. Also makes
| |
| 1335 // This level of indirection will hurt performance. | 1335 // This level of indirection will hurt performance. |
| 1336 jsMethods.add(new JS.Method( | 1336 jsMethods.add(new JS.Method( |
| 1337 _propertyName('constructor'), | 1337 _propertyName('constructor'), |
| 1338 js.call('function(...args) { return this.new.apply(this, args); }') | 1338 js.call('function(...args) { return this.new.apply(this, args); }') |
| 1339 as JS.Fun)); | 1339 as JS.Fun)); |
| 1340 } else if (ctors.isEmpty) { | 1340 } else if (ctors.isEmpty) { |
| 1341 jsMethods.add(_emitImplicitConstructor(node, fields, virtualFields)); | 1341 jsMethods.add(_emitImplicitConstructor(node, fields, virtualFields)); |
| 1342 } | 1342 } |
| 1343 | 1343 |
| 1344 bool hasJsPeer = findAnnotation(element, isJsPeerInterface) != null; | 1344 bool hasJsPeer = findAnnotation(element, isJsPeerInterface) != null; |
| (...skipping 940 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2285 namedArgumentTemp, | 2285 namedArgumentTemp, |
| 2286 paramName, | 2286 paramName, |
| 2287 _defaultParamValue(param), | 2287 _defaultParamValue(param), |
| 2288 ])); | 2288 ])); |
| 2289 } else if (param.kind == ParameterKind.POSITIONAL) { | 2289 } else if (param.kind == ParameterKind.POSITIONAL) { |
| 2290 body.add(js.statement('if (# === void 0) # = #;', | 2290 body.add(js.statement('if (# === void 0) # = #;', |
| 2291 [jsParam, jsParam, _defaultParamValue(param)])); | 2291 [jsParam, jsParam, _defaultParamValue(param)])); |
| 2292 } | 2292 } |
| 2293 } | 2293 } |
| 2294 | 2294 |
| 2295 // TODO(jmesserly): various problems here, see: | 2295 // TODO(jmesserly): various problems here, see: #27259 |
| 2296 // https://github.com/dart-lang/dev_compiler/issues/116 | |
| 2297 var paramType = | 2296 var paramType = |
| 2298 resolutionMap.elementDeclaredByFormalParameter(param).type; | 2297 resolutionMap.elementDeclaredByFormalParameter(param).type; |
| 2299 if (node is MethodDeclaration && | 2298 if (node is MethodDeclaration && |
| 2300 (resolutionMap.elementDeclaredByFormalParameter(param).isCovariant || | 2299 (resolutionMap.elementDeclaredByFormalParameter(param).isCovariant || |
| 2301 _unsoundCovariant(paramType, true)) && | 2300 _unsoundCovariant(paramType, true)) && |
| 2302 !_inWhitelistCode(node)) { | 2301 !_inWhitelistCode(node)) { |
| 2303 var castType = _emitType(paramType, | 2302 var castType = _emitType(paramType, |
| 2304 nameType: options.nameTypeTests || options.hoistTypeTests, | 2303 nameType: options.nameTypeTests || options.hoistTypeTests, |
| 2305 hoistType: options.hoistTypeTests); | 2304 hoistType: options.hoistTypeTests); |
| 2306 body.add(js.statement('#._check(#);', [castType, jsParam])); | 2305 body.add(js.statement('#._check(#);', [castType, jsParam])); |
| (...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2641 // }, T, <args>).bind(this); | 2640 // }, T, <args>).bind(this); |
| 2642 // } | 2641 // } |
| 2643 // | 2642 // |
| 2644 // We need to include <args> in case any are mutated, so each `.iterator` | 2643 // We need to include <args> in case any are mutated, so each `.iterator` |
| 2645 // gets the same initial values. | 2644 // gets the same initial values. |
| 2646 // | 2645 // |
| 2647 // TODO(jmesserly): we could omit the args for the common case where args | 2646 // TODO(jmesserly): we could omit the args for the common case where args |
| 2648 // are not mutated inside the generator. | 2647 // are not mutated inside the generator. |
| 2649 // | 2648 // |
| 2650 // In the future, we might be able to simplify this, see: | 2649 // In the future, we might be able to simplify this, see: |
| 2651 // https://github.com/dart-lang/dev_compiler/issues/247. | 2650 // https://github.com/dart-lang/sdk#28320 |
|
Jennifer Messerly
2017/01/10 19:01:18
this link is broken, it should be
https://github
vsm
2017/01/10 20:55:27
Done.
| |
| 2652 // | |
| 2653 // `async` works the same, but uses the `dart.async` helper. | 2651 // `async` works the same, but uses the `dart.async` helper. |
| 2654 // | 2652 // |
| 2655 // In the body of a `sync*` and `async`, `yield`/`await` are both generated | 2653 // In the body of a `sync*` and `async`, `yield`/`await` are both generated |
| 2656 // simply as `yield`. | 2654 // simply as `yield`. |
| 2657 // | 2655 // |
| 2658 // `async*` uses the `dart.asyncStar` helper, and also has an extra `stream` | 2656 // `async*` uses the `dart.asyncStar` helper, and also has an extra `stream` |
| 2659 // argument to the generator, which is used for passing values to the | 2657 // argument to the generator, which is used for passing values to the |
| 2660 // _AsyncStarStreamController implementation type. | 2658 // _AsyncStarStreamController implementation type. |
| 2661 // `yield` is specially generated inside `async*`, see visitYieldStatement. | 2659 // `yield` is specially generated inside `async*`, see visitYieldStatement. |
| 2662 // `await` is generated as `yield`. | 2660 // `await` is generated as `yield`. |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2949 optionalTypes, parameters?.sublist(parameterTypes.length), | 2947 optionalTypes, parameters?.sublist(parameterTypes.length), |
| 2950 nameType: nameType, hoistType: hoistType); | 2948 nameType: nameType, hoistType: hoistType); |
| 2951 typeParts = [rt, ra, oa]; | 2949 typeParts = [rt, ra, oa]; |
| 2952 } else { | 2950 } else { |
| 2953 typeParts = [rt, ra]; | 2951 typeParts = [rt, ra]; |
| 2954 } | 2952 } |
| 2955 | 2953 |
| 2956 var typeFormals = type.typeFormals; | 2954 var typeFormals = type.typeFormals; |
| 2957 if (typeFormals.isNotEmpty && !lowerTypedef) { | 2955 if (typeFormals.isNotEmpty && !lowerTypedef) { |
| 2958 // TODO(jmesserly): this is a suboptimal representation for universal | 2956 // TODO(jmesserly): this is a suboptimal representation for universal |
| 2959 // function types (as callable functions). See discussion at: | 2957 // function types (as callable functions). See discussion at #27333 |
| 2960 // https://github.com/dart-lang/dev_compiler/issues/526 | |
| 2961 var tf = _emitTypeFormals(typeFormals); | 2958 var tf = _emitTypeFormals(typeFormals); |
| 2962 var names = _typeTable.discharge(typeFormals); | 2959 var names = _typeTable.discharge(typeFormals); |
| 2963 var parts = new JS.ArrayInitializer(typeParts); | 2960 var parts = new JS.ArrayInitializer(typeParts); |
| 2964 if (names.isEmpty) { | 2961 if (names.isEmpty) { |
| 2965 typeParts = [ | 2962 typeParts = [ |
| 2966 js.call('(#) => #', [tf, parts]) | 2963 js.call('(#) => #', [tf, parts]) |
| 2967 ]; | 2964 ]; |
| 2968 } else { | 2965 } else { |
| 2969 typeParts = [ | 2966 typeParts = [ |
| 2970 js.call('(#) => {#; return #;}', [tf, names, parts]) | 2967 js.call('(#) => {#; return #;}', [tf, names, parts]) |
| (...skipping 2665 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5636 } | 5633 } |
| 5637 var type = functionType.returnType; | 5634 var type = functionType.returnType; |
| 5638 | 5635 |
| 5639 InterfaceType expectedType = null; | 5636 InterfaceType expectedType = null; |
| 5640 if (element.isAsynchronous) { | 5637 if (element.isAsynchronous) { |
| 5641 if (element.isGenerator) { | 5638 if (element.isGenerator) { |
| 5642 // Stream<T> -> T | 5639 // Stream<T> -> T |
| 5643 expectedType = types.streamType; | 5640 expectedType = types.streamType; |
| 5644 } else { | 5641 } else { |
| 5645 // Future<T> -> T | 5642 // Future<T> -> T |
| 5646 // TODO(vsm): Revisit with issue #228. | |
| 5647 expectedType = types.futureType; | 5643 expectedType = types.futureType; |
| 5648 } | 5644 } |
| 5649 } else { | 5645 } else { |
| 5650 if (element.isGenerator) { | 5646 if (element.isGenerator) { |
| 5651 // Iterable<T> -> T | 5647 // Iterable<T> -> T |
| 5652 expectedType = types.iterableType; | 5648 expectedType = types.iterableType; |
| 5653 } else { | 5649 } else { |
| 5654 // T -> T | 5650 // T -> T |
| 5655 return type; | 5651 return type; |
| 5656 } | 5652 } |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5815 if (targetIdentifier.staticElement is! PrefixElement) return false; | 5811 if (targetIdentifier.staticElement is! PrefixElement) return false; |
| 5816 var prefix = targetIdentifier.staticElement as PrefixElement; | 5812 var prefix = targetIdentifier.staticElement as PrefixElement; |
| 5817 | 5813 |
| 5818 // The library the prefix is referring to must come from a deferred import. | 5814 // The library the prefix is referring to must come from a deferred import. |
| 5819 var containingLibrary = resolutionMap | 5815 var containingLibrary = resolutionMap |
| 5820 .elementDeclaredByCompilationUnit(target.root as CompilationUnit) | 5816 .elementDeclaredByCompilationUnit(target.root as CompilationUnit) |
| 5821 .library; | 5817 .library; |
| 5822 var imports = containingLibrary.getImportsWithPrefix(prefix); | 5818 var imports = containingLibrary.getImportsWithPrefix(prefix); |
| 5823 return imports.length == 1 && imports[0].isDeferred; | 5819 return imports.length == 1 && imports[0].isDeferred; |
| 5824 } | 5820 } |
| OLD | NEW |