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 700 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
711 CloneVisitor cloner = substitution.isEmpty | 711 CloneVisitor cloner = substitution.isEmpty |
712 ? this.cloner | 712 ? this.cloner |
713 : new CloneWithoutBody(typeSubstitution: substitution); | 713 : new CloneWithoutBody(typeSubstitution: substitution); |
714 FunctionNode function = procedure.function; | 714 FunctionNode function = procedure.function; |
715 List<TypeParameter> typeParameters = | 715 List<TypeParameter> typeParameters = |
716 function.typeParameters.map(cloner.clone).toList(); | 716 function.typeParameters.map(cloner.clone).toList(); |
717 List<VariableDeclaration> positionalParameters = | 717 List<VariableDeclaration> positionalParameters = |
718 function.positionalParameters.map(cloner.clone).toList(); | 718 function.positionalParameters.map(cloner.clone).toList(); |
719 List<VariableDeclaration> namedParameters = | 719 List<VariableDeclaration> namedParameters = |
720 function.namedParameters.map(cloner.clone).toList(); | 720 function.namedParameters.map(cloner.clone).toList(); |
721 // TODO(ahe): Clone or copy inferredReturnValue? | |
722 InferredValue inferredReturnValue = null; | |
723 | 721 |
724 List<DartType> types = typeParameters | 722 List<DartType> types = typeParameters |
725 .map((TypeParameter parameter) => new TypeParameterType(parameter)) | 723 .map((TypeParameter parameter) => new TypeParameterType(parameter)) |
726 .toList(); | 724 .toList(); |
727 List<Expression> positional = positionalParameters | 725 List<Expression> positional = positionalParameters |
728 .map((VariableDeclaration parameter) => new VariableGet(parameter)) | 726 .map((VariableDeclaration parameter) => new VariableGet(parameter)) |
729 .toList(); | 727 .toList(); |
730 List<NamedExpression> named = | 728 List<NamedExpression> named = |
731 namedParameters.map((VariableDeclaration parameter) { | 729 namedParameters.map((VariableDeclaration parameter) { |
732 return new NamedExpression(parameter.name, new VariableGet(parameter)); | 730 return new NamedExpression(parameter.name, new VariableGet(parameter)); |
733 }).toList(); | 731 }).toList(); |
734 | 732 |
735 Arguments arguments = new Arguments(positional, types: types, named: named); | 733 Arguments arguments = new Arguments(positional, types: types, named: named); |
736 InvocationExpression invocation = procedure.isInstanceMember | 734 InvocationExpression invocation = procedure.isInstanceMember |
737 ? new MethodInvocation(receiver, procedure.name, arguments, procedure) | 735 ? new MethodInvocation(receiver, procedure.name, arguments, procedure) |
738 : new StaticInvocation(procedure, arguments); | 736 : new StaticInvocation(procedure, arguments); |
739 return new FunctionNode(new ReturnStatement(invocation), | 737 return new FunctionNode(new ReturnStatement(invocation), |
740 typeParameters: typeParameters, | 738 typeParameters: typeParameters, |
741 positionalParameters: positionalParameters, | 739 positionalParameters: positionalParameters, |
742 namedParameters: namedParameters, | 740 namedParameters: namedParameters, |
743 requiredParameterCount: function.requiredParameterCount, | 741 requiredParameterCount: function.requiredParameterCount, |
744 returnType: substitute(function.returnType, cloner.typeSubstitution), | 742 returnType: substitute(function.returnType, cloner.typeSubstitution)); |
745 inferredReturnValue: inferredReturnValue); | |
746 } | 743 } |
747 | 744 |
748 /// Creates copies of the type variables in [original] and returns a | 745 /// Creates copies of the type variables in [original] and returns a |
749 /// substitution that can be passed to [substitute] to substitute all uses of | 746 /// substitution that can be passed to [substitute] to substitute all uses of |
750 /// [original] with their copies. | 747 /// [original] with their copies. |
751 Map<TypeParameter, DartType> copyTypeVariables( | 748 Map<TypeParameter, DartType> copyTypeVariables( |
752 Iterable<TypeParameter> original) { | 749 Iterable<TypeParameter> original) { |
753 if (original.isEmpty) return const <TypeParameter, DartType>{}; | 750 if (original.isEmpty) return const <TypeParameter, DartType>{}; |
754 Map<TypeParameter, DartType> substitution = <TypeParameter, DartType>{}; | 751 Map<TypeParameter, DartType> substitution = <TypeParameter, DartType>{}; |
755 for (TypeParameter t in original) { | 752 for (TypeParameter t in original) { |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
835 // TODO(ahe): Remove this method when we don't generate closure classes | 832 // TODO(ahe): Remove this method when we don't generate closure classes |
836 // anymore. | 833 // anymore. |
837 void addClosureClassNote(Class closureClass) { | 834 void addClosureClassNote(Class closureClass) { |
838 closureClass.addMember(new Field(new Name("note"), | 835 closureClass.addMember(new Field(new Name("note"), |
839 type: coreTypes.stringClass.rawType, | 836 type: coreTypes.stringClass.rawType, |
840 initializer: new StringLiteral( | 837 initializer: new StringLiteral( |
841 "This is temporary. The VM doesn't need closure classes."), | 838 "This is temporary. The VM doesn't need closure classes."), |
842 fileUri: currentFileUri)); | 839 fileUri: currentFileUri)); |
843 } | 840 } |
844 } | 841 } |
OLD | NEW |