| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 library kernel.transformations.closure.converter; | 5 library kernel.transformations.closure.converter; |
| 6 | 6 |
| 7 import '../../ast.dart' | 7 import '../../ast.dart' |
| 8 show | 8 show |
| 9 Arguments, | 9 Arguments, |
| 10 Block, | 10 Block, |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 Statement, | 43 Statement, |
| 44 StaticInvocation, | 44 StaticInvocation, |
| 45 ThisExpression, | 45 ThisExpression, |
| 46 Transformer, | 46 Transformer, |
| 47 TreeNode, | 47 TreeNode, |
| 48 TypeParameter, | 48 TypeParameter, |
| 49 TypeParameterType, | 49 TypeParameterType, |
| 50 VariableDeclaration, | 50 VariableDeclaration, |
| 51 VariableGet, | 51 VariableGet, |
| 52 VariableSet, | 52 VariableSet, |
| 53 VectorCreation, |
| 53 VectorType, | 54 VectorType, |
| 54 transformList; | 55 transformList; |
| 55 | 56 |
| 56 import '../../frontend/accessors.dart' show VariableAccessor; | 57 import '../../frontend/accessors.dart' show VariableAccessor; |
| 57 | 58 |
| 58 import '../../clone.dart' show CloneVisitor; | 59 import '../../clone.dart' show CloneVisitor; |
| 59 | 60 |
| 60 import '../../core_types.dart' show CoreTypes; | 61 import '../../core_types.dart' show CoreTypes; |
| 61 | 62 |
| 62 import '../../type_algebra.dart' show substitute; | 63 import '../../type_algebra.dart' show substitute; |
| (...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 438 substitute(decl.type, closureTypeSubstitutionMap)) | 439 substitute(decl.type, closureTypeSubstitutionMap)) |
| 439 .toList(), | 440 .toList(), |
| 440 substitute(function.returnType, closureTypeSubstitutionMap), | 441 substitute(function.returnType, closureTypeSubstitutionMap), |
| 441 namedParameters: function.namedParameters | 442 namedParameters: function.namedParameters |
| 442 .map((VariableDeclaration decl) => new NamedType( | 443 .map((VariableDeclaration decl) => new NamedType( |
| 443 decl.name, substitute(decl.type, closureTypeSubstitutionMap))) | 444 decl.name, substitute(decl.type, closureTypeSubstitutionMap))) |
| 444 .toList(), | 445 .toList(), |
| 445 typeParameters: closureTypeParams, | 446 typeParameters: closureTypeParams, |
| 446 requiredParameterCount: function.requiredParameterCount - 1); | 447 requiredParameterCount: function.requiredParameterCount - 1); |
| 447 | 448 |
| 449 // If we capture type parameters but not regular variables, we still need to |
| 450 // make a context. |
| 451 if (capturedTypeVariables[function] != null && |
| 452 accessContext is NullLiteral) { |
| 453 accessContext = new VectorCreation(1); |
| 454 } |
| 455 |
| 448 return new ClosureCreation( | 456 return new ClosureCreation( |
| 449 closedTopLevelFunction, accessContext, closureType, fnTypeArgs); | 457 closedTopLevelFunction, accessContext, closureType, fnTypeArgs); |
| 450 } | 458 } |
| 451 | 459 |
| 452 TreeNode visitProcedure(Procedure node) { | 460 TreeNode visitProcedure(Procedure node) { |
| 453 assert(isEmptyContext); | 461 assert(isEmptyContext); |
| 454 | 462 |
| 455 currentMember = node; | 463 currentMember = node; |
| 456 | 464 |
| 457 FunctionNode function = node.function; | 465 FunctionNode function = node.function; |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 733 return new FunctionNode(new ReturnStatement(invocation), | 741 return new FunctionNode(new ReturnStatement(invocation), |
| 734 typeParameters: typeParameters, | 742 typeParameters: typeParameters, |
| 735 positionalParameters: positionalParameters, | 743 positionalParameters: positionalParameters, |
| 736 namedParameters: namedParameters, | 744 namedParameters: namedParameters, |
| 737 requiredParameterCount: requiredParameterCount, | 745 requiredParameterCount: requiredParameterCount, |
| 738 returnType: substitute(function.returnType, cloner.typeSubstitution)); | 746 returnType: substitute(function.returnType, cloner.typeSubstitution)); |
| 739 } | 747 } |
| 740 | 748 |
| 741 /// Creates copies of the type variables in [original] and returns a | 749 /// Creates copies of the type variables in [original] and returns a |
| 742 /// substitution that can be passed to [substitute] to substitute all uses of | 750 /// substitution that can be passed to [substitute] to substitute all uses of |
| 743 /// [original] with their copies. Additionally returns a list of new type | 751 /// [original] with their copies. |
| 744 /// parameters to prefix to the enclosing function's type parameters and the | |
| 745 /// arguments to be passed for those parameters. | |
| 746 /// | 752 /// |
| 747 Map<TypeParameter, DartType> copyTypeVariables( | 753 Map<TypeParameter, DartType> copyTypeVariables( |
| 748 Iterable<TypeParameter> original) { | 754 Iterable<TypeParameter> original) { |
| 749 if (original.isEmpty) return const <TypeParameter, DartType>{}; | 755 if (original.isEmpty) return const <TypeParameter, DartType>{}; |
| 750 | 756 |
| 751 Map<TypeParameter, DartType> substitution = <TypeParameter, DartType>{}; | 757 Map<TypeParameter, DartType> substitution = <TypeParameter, DartType>{}; |
| 752 for (TypeParameter t in original) { | 758 for (TypeParameter t in original) { |
| 753 substitution[t] = new TypeParameterType(new TypeParameter(t.name)); | 759 substitution[t] = new TypeParameterType(new TypeParameter(t.name)); |
| 754 } | 760 } |
| 755 | 761 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 783 copy.function.body.parent = copy.function; | 789 copy.function.body.parent = copy.function; |
| 784 return copy; | 790 return copy; |
| 785 } | 791 } |
| 786 | 792 |
| 787 void addGetterForwarder(Name name, Procedure getter) { | 793 void addGetterForwarder(Name name, Procedure getter) { |
| 788 assert(getter.isGetter); | 794 assert(getter.isGetter); |
| 789 newClassMembers | 795 newClassMembers |
| 790 .add(copyWithBody(getter, forwardToThisProperty(getter))..name = name); | 796 .add(copyWithBody(getter, forwardToThisProperty(getter))..name = name); |
| 791 } | 797 } |
| 792 } | 798 } |
| OLD | NEW |