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

Side by Side Diff: lib/analyzer/ast_from_analyzer.dart

Issue 2502343002: Store named parameters in sorted lists instead of using maps. (Closed)
Patch Set: Remove duplicates from named parameter lists to recover from erroneous inputs 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
« no previous file with comments | « no previous file | lib/ast.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.analyzer.ast_from_analyzer; 4 library kernel.analyzer.ast_from_analyzer;
5 5
6 import '../ast.dart' as ast; 6 import '../ast.dart' as ast;
7 import '../frontend/accessors.dart'; 7 import '../frontend/accessors.dart';
8 import '../frontend/super_initializers.dart'; 8 import '../frontend/super_initializers.dart';
9 import '../log.dart'; 9 import '../log.dart';
10 import '../type_algebra.dart'; 10 import '../type_algebra.dart';
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 449
450 case ParameterKind.POSITIONAL: 450 case ParameterKind.POSITIONAL:
451 positional.add(parameterNode); 451 positional.add(parameterNode);
452 break; 452 break;
453 453
454 case ParameterKind.NAMED: 454 case ParameterKind.NAMED:
455 named.add(parameterNode); 455 named.add(parameterNode);
456 break; 456 break;
457 } 457 }
458 } 458 }
459 if (named.isNotEmpty) {
460 sortAndRemoveDuplicates(named);
461 }
459 var returnType = element is ConstructorElement 462 var returnType = element is ConstructorElement
460 ? const ast.VoidType() 463 ? const ast.VoidType()
461 : buildType(element.returnType); 464 : buildType(element.returnType);
462 return new ast.FunctionNode(null, 465 return new ast.FunctionNode(null,
463 typeParameters: typeParameters, 466 typeParameters: typeParameters,
464 positionalParameters: positional, 467 positionalParameters: positional,
465 namedParameters: named, 468 namedParameters: named,
466 requiredParameterCount: requiredParameterCount, 469 requiredParameterCount: requiredParameterCount,
467 returnType: returnType); 470 returnType: returnType);
468 } 471 }
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
550 553
551 case ParameterKind.POSITIONAL: 554 case ParameterKind.POSITIONAL:
552 positional.add(declaration); 555 positional.add(declaration);
553 break; 556 break;
554 557
555 case ParameterKind.NAMED: 558 case ParameterKind.NAMED:
556 named.add(declaration); 559 named.add(declaration);
557 break; 560 break;
558 } 561 }
559 } 562 }
563 if (named.isNotEmpty) {
564 sortAndRemoveDuplicates(named);
565 }
560 return new ast.FunctionNode(buildOptionalFunctionBody(body), 566 return new ast.FunctionNode(buildOptionalFunctionBody(body),
561 typeParameters: typeParameters, 567 typeParameters: typeParameters,
562 positionalParameters: positional, 568 positionalParameters: positional,
563 namedParameters: named, 569 namedParameters: named,
564 requiredParameterCount: requiredParameterCount, 570 requiredParameterCount: requiredParameterCount,
565 returnType: buildOptionalTypeAnnotation(returnType) ?? 571 returnType: buildOptionalTypeAnnotation(returnType) ??
566 inferredReturnType ?? 572 inferredReturnType ??
567 const ast.DynamicType(), 573 const ast.DynamicType(),
568 asyncMarker: getAsyncMarker( 574 asyncMarker: getAsyncMarker(
569 isAsync: body.isAsynchronous, isStar: body.isGenerator)); 575 isAsync: body.isAsynchronous, isStar: body.isGenerator));
(...skipping 1373 matching lines...) Expand 10 before | Expand all | Expand 10 after
1943 return new SuperPropertyAccessor( 1949 return new SuperPropertyAccessor(
1944 scope.buildName(node.propertyName), 1950 scope.buildName(node.propertyName),
1945 scope.resolveConcreteGet(element, auxiliary), 1951 scope.resolveConcreteGet(element, auxiliary),
1946 scope.resolveConcreteSet(element, auxiliary)); 1952 scope.resolveConcreteSet(element, auxiliary));
1947 } else if (target is Identifier && target.staticElement is ClassElement) { 1953 } else if (target is Identifier && target.staticElement is ClassElement) {
1948 // Note that this case also covers null-aware static access on a class, 1954 // Note that this case also covers null-aware static access on a class,
1949 // which is equivalent to a regular static access. 1955 // which is equivalent to a regular static access.
1950 return scope.staticAccess(node.propertyName.name, element, auxiliary); 1956 return scope.staticAccess(node.propertyName.name, element, auxiliary);
1951 } else if (node.operator.value() == '?.') { 1957 } else if (node.operator.value() == '?.') {
1952 return new NullAwarePropertyAccessor( 1958 return new NullAwarePropertyAccessor(
1953 build(target), scope.buildName(node.propertyName), getter, setter, 1959 build(target),
1960 scope.buildName(node.propertyName),
1961 getter,
1962 setter,
1954 scope.buildType(node.staticType)); 1963 scope.buildType(node.staticType));
1955 } else { 1964 } else {
1956 return PropertyAccessor.make( 1965 return PropertyAccessor.make(
1957 build(target), scope.buildName(node.propertyName), getter, setter); 1966 build(target), scope.buildName(node.propertyName), getter, setter);
1958 } 1967 }
1959 } 1968 }
1960 1969
1961 ast.Expression visitRethrowExpression(RethrowExpression node) { 1970 ast.Expression visitRethrowExpression(RethrowExpression node) {
1962 return new ast.Rethrow(); 1971 return new ast.Rethrow();
1963 } 1972 }
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
2143 .map((tp) => convertTypeParameter(tp, boundVariables)) 2152 .map((tp) => convertTypeParameter(tp, boundVariables))
2144 .toList(); 2153 .toList();
2145 } 2154 }
2146 2155
2147 List<ast.DartType> convertTypeList( 2156 List<ast.DartType> convertTypeList(
2148 Iterable<DartType> types, List<TypeParameterElement> boundVariables) { 2157 Iterable<DartType> types, List<TypeParameterElement> boundVariables) {
2149 if (types.isEmpty) return const <ast.DartType>[]; 2158 if (types.isEmpty) return const <ast.DartType>[];
2150 return types.map((t) => convertType(t, boundVariables)).toList(); 2159 return types.map((t) => convertType(t, boundVariables)).toList();
2151 } 2160 }
2152 2161
2153 Map<String, ast.DartType> convertTypeMap( 2162 List<ast.NamedType> convertTypeMap(
2154 Map<String, DartType> types, List<TypeParameterElement> boundVariables) { 2163 Map<String, DartType> types, List<TypeParameterElement> boundVariables) {
2155 if (types.isEmpty) return const <String, ast.DartType>{}; 2164 if (types.isEmpty) return const <ast.NamedType>[];
2156 var result = <String, ast.DartType>{}; 2165 List<ast.NamedType> result = <ast.NamedType>[];
2157 types.forEach((name, type) { 2166 types.forEach((name, type) {
2158 result[name] = convertType(type, boundVariables); 2167 result.add(new ast.NamedType(name, convertType(type, boundVariables)));
2159 }); 2168 });
2169 sortAndRemoveDuplicates(result);
2160 return result; 2170 return result;
2161 } 2171 }
2162 2172
2163 ast.DartType visitSimpleIdentifier(SimpleIdentifier node) { 2173 ast.DartType visitSimpleIdentifier(SimpleIdentifier node) {
2164 Element element = node.staticElement; 2174 Element element = node.staticElement;
2165 switch (ElementKind.of(element)) { 2175 switch (ElementKind.of(element)) {
2166 case ElementKind.CLASS: 2176 case ElementKind.CLASS:
2167 return new ast.InterfaceType(scope.getClassReference(element)); 2177 return new ast.InterfaceType(scope.getClassReference(element));
2168 2178
2169 case ElementKind.DYNAMIC: 2179 case ElementKind.DYNAMIC:
(...skipping 606 matching lines...) Expand 10 before | Expand all | Expand 10 after
2776 if (element is FieldElement) return element.getter; 2786 if (element is FieldElement) return element.getter;
2777 return element; 2787 return element;
2778 } 2788 }
2779 2789
2780 Element desynthesizeSetter(Element element) { 2790 Element desynthesizeSetter(Element element) {
2781 if (element == null || !element.isSynthetic) return element; 2791 if (element == null || !element.isSynthetic) return element;
2782 if (element is PropertyAccessorElement) return element.variable; 2792 if (element is PropertyAccessorElement) return element.variable;
2783 if (element is FieldElement) return element.setter; 2793 if (element is FieldElement) return element.setter;
2784 return element; 2794 return element;
2785 } 2795 }
2796
2797 void sortAndRemoveDuplicates/*<T extends Comparable<T>>*/(List/*<T>*/ list) {
2798 list.sort();
2799 int deleted = 0;
2800 for (int i = 1; i < list.length; ++i) {
2801 var item = list[i];
2802 if (list[i - 1].compareTo(item) == 0) {
2803 ++deleted;
2804 } else if (deleted > 0) {
2805 list[i - deleted] = item;
2806 }
2807 }
2808 if (deleted > 0) {
2809 list.length -= deleted;
2810 }
2811 }
OLDNEW
« no previous file with comments | « no previous file | lib/ast.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698