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 && accessContext is NullLiteral) | |
jensj
2017/08/11 06:24:54
https://www.dartlang.org/guides/language/effective
sjindel
2017/08/11 09:21:06
Done.
| |
452 accessContext = new VectorCreation(1); | |
453 | |
448 return new ClosureCreation( | 454 return new ClosureCreation( |
449 closedTopLevelFunction, accessContext, closureType, fnTypeArgs); | 455 closedTopLevelFunction, accessContext, closureType, fnTypeArgs); |
450 } | 456 } |
451 | 457 |
452 TreeNode visitProcedure(Procedure node) { | 458 TreeNode visitProcedure(Procedure node) { |
453 assert(isEmptyContext); | 459 assert(isEmptyContext); |
454 | 460 |
455 currentMember = node; | 461 currentMember = node; |
456 | 462 |
457 FunctionNode function = node.function; | 463 FunctionNode function = node.function; |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
733 return new FunctionNode(new ReturnStatement(invocation), | 739 return new FunctionNode(new ReturnStatement(invocation), |
734 typeParameters: typeParameters, | 740 typeParameters: typeParameters, |
735 positionalParameters: positionalParameters, | 741 positionalParameters: positionalParameters, |
736 namedParameters: namedParameters, | 742 namedParameters: namedParameters, |
737 requiredParameterCount: requiredParameterCount, | 743 requiredParameterCount: requiredParameterCount, |
738 returnType: substitute(function.returnType, cloner.typeSubstitution)); | 744 returnType: substitute(function.returnType, cloner.typeSubstitution)); |
739 } | 745 } |
740 | 746 |
741 /// Creates copies of the type variables in [original] and returns a | 747 /// Creates copies of the type variables in [original] and returns a |
742 /// substitution that can be passed to [substitute] to substitute all uses of | 748 /// substitution that can be passed to [substitute] to substitute all uses of |
743 /// [original] with their copies. Additionally returns a list of new type | 749 /// [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 /// | 750 /// |
747 Map<TypeParameter, DartType> copyTypeVariables( | 751 Map<TypeParameter, DartType> copyTypeVariables( |
748 Iterable<TypeParameter> original) { | 752 Iterable<TypeParameter> original) { |
749 if (original.isEmpty) return const <TypeParameter, DartType>{}; | 753 if (original.isEmpty) return const <TypeParameter, DartType>{}; |
750 | 754 |
751 Map<TypeParameter, DartType> substitution = <TypeParameter, DartType>{}; | 755 Map<TypeParameter, DartType> substitution = <TypeParameter, DartType>{}; |
752 for (TypeParameter t in original) { | 756 for (TypeParameter t in original) { |
753 substitution[t] = new TypeParameterType(new TypeParameter(t.name)); | 757 substitution[t] = new TypeParameterType(new TypeParameter(t.name)); |
754 } | 758 } |
755 | 759 |
(...skipping 27 matching lines...) Expand all Loading... | |
783 copy.function.body.parent = copy.function; | 787 copy.function.body.parent = copy.function; |
784 return copy; | 788 return copy; |
785 } | 789 } |
786 | 790 |
787 void addGetterForwarder(Name name, Procedure getter) { | 791 void addGetterForwarder(Name name, Procedure getter) { |
788 assert(getter.isGetter); | 792 assert(getter.isGetter); |
789 newClassMembers | 793 newClassMembers |
790 .add(copyWithBody(getter, forwardToThisProperty(getter))..name = name); | 794 .add(copyWithBody(getter, forwardToThisProperty(getter))..name = name); |
791 } | 795 } |
792 } | 796 } |
OLD | NEW |