Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(261)

Side by Side Diff: lib/type_propagation/builder.dart

Issue 2502343002: Store named parameters in sorted lists instead of using maps. (Closed)
Patch Set: Add testcase Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 library kernel.type_propagation.builder; 4 library kernel.type_propagation.builder;
5 5
6 import '../ast.dart'; 6 import '../ast.dart';
7 import '../class_hierarchy.dart'; 7 import '../class_hierarchy.dart';
8 import '../core_types.dart'; 8 import '../core_types.dart';
9 import 'canonicalizer.dart'; 9 import 'canonicalizer.dart';
10 import 'constraints.dart'; 10 import 'constraints.dart';
(...skipping 1818 matching lines...) Expand 10 before | Expand all | Expand 10 after
1829 1829
1830 int visitFunctionType(FunctionType node) { 1830 int visitFunctionType(FunctionType node) {
1831 // TODO: Handle arity range. 1831 // TODO: Handle arity range.
1832 int arity = node.positionalParameters.length; 1832 int arity = node.positionalParameters.length;
1833 int function = builder.functionValueNode; 1833 int function = builder.functionValueNode;
1834 for (int i = 0; i < node.positionalParameters.length; ++i) { 1834 for (int i = 0; i < node.positionalParameters.length; ++i) {
1835 int field = fieldNames.getPositionalParameterField(arity, i); 1835 int field = fieldNames.getPositionalParameterField(arity, i);
1836 int argument = environment.getLoad(function, field); 1836 int argument = environment.getLoad(function, field);
1837 visitContravariant(node.positionalParameters[i], argument); 1837 visitContravariant(node.positionalParameters[i], argument);
1838 } 1838 }
1839 node.namedParameters.forEach((String name, DartType type) { 1839 for (int i = 0; i < node.namedParameters.length; ++i) {
1840 int field = fieldNames.getNamedParameterField(arity, name); 1840 var parameter = node.namedParameters[i];
1841 int field = fieldNames.getNamedParameterField(arity, parameter.name);
1841 int argument = environment.getLoad(function, field); 1842 int argument = environment.getLoad(function, field);
1842 visitContravariant(type, argument); 1843 visitContravariant(parameter.type, argument);
1843 }); 1844 }
1844 int returnVariable = visit(node.returnType); 1845 int returnVariable = visit(node.returnType);
1845 environment.addStore( 1846 environment.addStore(
1846 function, fieldNames.getReturnField(arity), returnVariable); 1847 function, fieldNames.getReturnField(arity), returnVariable);
1847 return function; 1848 return function;
1848 } 1849 }
1849 1850
1850 /// Equivalent to visiting the FunctionType for the given function. 1851 /// Equivalent to visiting the FunctionType for the given function.
1851 int buildFunctionNode(FunctionNode node) { 1852 int buildFunctionNode(FunctionNode node) {
1852 int minArity = node.requiredParameterCount; 1853 int minArity = node.requiredParameterCount;
1853 int maxArity = node.positionalParameters.length; 1854 int maxArity = node.positionalParameters.length;
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
1927 visitFunctionType(FunctionType node) { 1928 visitFunctionType(FunctionType node) {
1928 int minArity = node.requiredParameterCount; 1929 int minArity = node.requiredParameterCount;
1929 int maxArity = node.positionalParameters.length; 1930 int maxArity = node.positionalParameters.length;
1930 for (int i = 0; i < node.positionalParameters.length; ++i) { 1931 for (int i = 0; i < node.positionalParameters.length; ++i) {
1931 int argument = visitCovariant(node.positionalParameters[i]); 1932 int argument = visitCovariant(node.positionalParameters[i]);
1932 for (int arity = minArity; arity <= maxArity; ++arity) { 1933 for (int arity = minArity; arity <= maxArity; ++arity) {
1933 int field = fieldNames.getPositionalParameterField(arity, i); 1934 int field = fieldNames.getPositionalParameterField(arity, i);
1934 environment.addStore(input, field, argument); 1935 environment.addStore(input, field, argument);
1935 } 1936 }
1936 } 1937 }
1937 node.namedParameters.forEach((String name, DartType type) { 1938 for (var parameter in node.namedParameters) {
1938 int argument = visitCovariant(type); 1939 int argument = visitCovariant(parameter.type);
1939 for (int arity = minArity; arity <= maxArity; ++arity) { 1940 for (int arity = minArity; arity <= maxArity; ++arity) {
1940 int field = fieldNames.getNamedParameterField(arity, name); 1941 int field = fieldNames.getNamedParameterField(arity, parameter.name);
1941 environment.addStore(input, field, argument); 1942 environment.addStore(input, field, argument);
1942 } 1943 }
1943 }); 1944 }
1944 for (int arity = minArity; arity <= maxArity; ++arity) { 1945 for (int arity = minArity; arity <= maxArity; ++arity) {
1945 int returnLocation = 1946 int returnLocation =
1946 environment.getLoad(input, fieldNames.getReturnField(arity)); 1947 environment.getLoad(input, fieldNames.getReturnField(arity));
1947 visitContravariant(node.returnType, returnLocation); 1948 visitContravariant(node.returnType, returnLocation);
1948 } 1949 }
1949 } 1950 }
1950 1951
1951 /// Equivalent to visiting the FunctionType for the given function. 1952 /// Equivalent to visiting the FunctionType for the given function.
1952 void buildFunctionNode(FunctionNode node) { 1953 void buildFunctionNode(FunctionNode node) {
1953 int minArity = node.requiredParameterCount; 1954 int minArity = node.requiredParameterCount;
(...skipping 13 matching lines...) Expand all
1967 environment.addStore(input, field, argument); 1968 environment.addStore(input, field, argument);
1968 } 1969 }
1969 } 1970 }
1970 for (int arity = minArity; arity <= maxArity; ++arity) { 1971 for (int arity = minArity; arity <= maxArity; ++arity) {
1971 int returnLocation = 1972 int returnLocation =
1972 environment.getLoad(input, fieldNames.getReturnField(arity)); 1973 environment.getLoad(input, fieldNames.getReturnField(arity));
1973 visitContravariant(node.returnType, returnLocation); 1974 visitContravariant(node.returnType, returnLocation);
1974 } 1975 }
1975 } 1976 }
1976 } 1977 }
OLDNEW
« lib/ast.dart ('K') | « lib/type_environment.dart ('k') | lib/visitor.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698