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 // 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 import 'dart:collection' show HashMap, HashSet; | 5 import 'dart:collection' show HashMap, HashSet; |
| 6 import 'dart:math' show min, max; | 6 import 'dart:math' show min, max; |
| 7 | 7 |
| 8 import 'package:analyzer/analyzer.dart' hide ConstantEvaluator; | 8 import 'package:analyzer/analyzer.dart' hide ConstantEvaluator; |
| 9 import 'package:analyzer/dart/ast/ast.dart'; | 9 import 'package:analyzer/dart/ast/ast.dart'; |
| 10 import 'package:analyzer/dart/ast/token.dart' show Token, TokenType; | 10 import 'package:analyzer/dart/ast/token.dart' show Token, TokenType; |
| (...skipping 2485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2496 // normal function (sync), vs (sync*, async, async*) | 2496 // normal function (sync), vs (sync*, async, async*) |
| 2497 var stdFn = !(element.isAsynchronous || element.isGenerator); | 2497 var stdFn = !(element.isAsynchronous || element.isGenerator); |
| 2498 var formals = visitFormalParameterList(parameters, destructure: stdFn); | 2498 var formals = visitFormalParameterList(parameters, destructure: stdFn); |
| 2499 var code = (stdFn) | 2499 var code = (stdFn) |
| 2500 ? _visit(body) | 2500 ? _visit(body) |
| 2501 : new JS.Block( | 2501 : new JS.Block( |
| 2502 [_emitGeneratorFunctionBody(element, parameters, body).toReturn()]); | 2502 [_emitGeneratorFunctionBody(element, parameters, body).toReturn()]); |
| 2503 var typeFormals = _emitTypeFormals(type.typeFormals); | 2503 var typeFormals = _emitTypeFormals(type.typeFormals); |
| 2504 var returnType = emitTypeRef(type.returnType); | 2504 var returnType = emitTypeRef(type.returnType); |
| 2505 if (type.typeFormals.isNotEmpty) { | 2505 if (type.typeFormals.isNotEmpty) { |
| 2506 code = new JS.Block( | 2506 code = new JS.Block(<JS.Statement>[ |
|
Jennifer Messerly
2016/09/15 17:54:04
btw this cast could probably go on "_visit(body) a
| |
| 2507 [new JS.Block(_typeTable.discharge(type.typeFormals)), code]); | 2507 new JS.Block(_typeTable.discharge(type.typeFormals)), |
| 2508 code | |
| 2509 ]); | |
| 2508 } | 2510 } |
| 2509 return new JS.Fun(formals, code, | 2511 return new JS.Fun(formals, code, |
| 2510 typeParams: typeFormals, returnType: returnType); | 2512 typeParams: typeFormals, returnType: returnType); |
| 2511 } | 2513 } |
| 2512 | 2514 |
| 2513 JS.Expression _emitGeneratorFunctionBody(ExecutableElement element, | 2515 JS.Expression _emitGeneratorFunctionBody(ExecutableElement element, |
| 2514 FormalParameterList parameters, FunctionBody body) { | 2516 FormalParameterList parameters, FunctionBody body) { |
| 2515 var kind = element.isSynchronous ? 'sync' : 'async'; | 2517 var kind = element.isSynchronous ? 'sync' : 'async'; |
| 2516 if (element.isGenerator) kind += 'Star'; | 2518 if (element.isGenerator) kind += 'Star'; |
| 2517 | 2519 |
| (...skipping 1976 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4494 if (op != null && op.lexeme == '?.') { | 4496 if (op != null && op.lexeme == '?.') { |
| 4495 var nodeTarget = _getTarget(node); | 4497 var nodeTarget = _getTarget(node); |
| 4496 if (!isNullable(nodeTarget)) { | 4498 if (!isNullable(nodeTarget)) { |
| 4497 node = _stripNullAwareOp(node, nodeTarget); | 4499 node = _stripNullAwareOp(node, nodeTarget); |
| 4498 break; | 4500 break; |
| 4499 } | 4501 } |
| 4500 | 4502 |
| 4501 var param = | 4503 var param = |
| 4502 _createTemporary('_', nodeTarget.staticType, nullable: false); | 4504 _createTemporary('_', nodeTarget.staticType, nullable: false); |
| 4503 var baseNode = _stripNullAwareOp(node, param); | 4505 var baseNode = _stripNullAwareOp(node, param); |
| 4504 tail.add(new JS.ArrowFun([_visit(param)], _visit(baseNode))); | 4506 tail.add( |
| 4507 new JS.ArrowFun(<JS.Parameter>[_visit(param)], _visit(baseNode))); | |
| 4505 node = nodeTarget; | 4508 node = nodeTarget; |
| 4506 } else { | 4509 } else { |
| 4507 break; | 4510 break; |
| 4508 } | 4511 } |
| 4509 } | 4512 } |
| 4510 if (tail.isEmpty) return _visit(node); | 4513 if (tail.isEmpty) return _visit(node); |
| 4511 return js.call('dart.nullSafe(#, #)', [_visit(node), tail.reversed]); | 4514 return js.call('dart.nullSafe(#, #)', [_visit(node), tail.reversed]); |
| 4512 } | 4515 } |
| 4513 | 4516 |
| 4514 static Token _getOperator(Expression node) { | 4517 static Token _getOperator(Expression node) { |
| (...skipping 936 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5451 } | 5454 } |
| 5452 | 5455 |
| 5453 bool isLibraryPrefix(Expression node) => | 5456 bool isLibraryPrefix(Expression node) => |
| 5454 node is SimpleIdentifier && node.staticElement is PrefixElement; | 5457 node is SimpleIdentifier && node.staticElement is PrefixElement; |
| 5455 | 5458 |
| 5456 LibraryElement _getLibrary(AnalysisContext c, String uri) => | 5459 LibraryElement _getLibrary(AnalysisContext c, String uri) => |
| 5457 c.computeLibraryElement(c.sourceFactory.forUri(uri)); | 5460 c.computeLibraryElement(c.sourceFactory.forUri(uri)); |
| 5458 | 5461 |
| 5459 bool _isDartRuntime(LibraryElement l) => | 5462 bool _isDartRuntime(LibraryElement l) => |
| 5460 l.isInSdk && l.source.uri.toString() == 'dart:_runtime'; | 5463 l.isInSdk && l.source.uri.toString() == 'dart:_runtime'; |
| OLD | NEW |