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

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: 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
« no previous file with comments | « no previous file | lib/ast.dart » ('j') | lib/ast.dart » ('J')
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 named.sort();
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 named.sort();
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 1573 matching lines...) Expand 10 before | Expand all | Expand 10 after
2143 .map((tp) => convertTypeParameter(tp, boundVariables)) 2149 .map((tp) => convertTypeParameter(tp, boundVariables))
2144 .toList(); 2150 .toList();
2145 } 2151 }
2146 2152
2147 List<ast.DartType> convertTypeList( 2153 List<ast.DartType> convertTypeList(
2148 Iterable<DartType> types, List<TypeParameterElement> boundVariables) { 2154 Iterable<DartType> types, List<TypeParameterElement> boundVariables) {
2149 if (types.isEmpty) return const <ast.DartType>[]; 2155 if (types.isEmpty) return const <ast.DartType>[];
2150 return types.map((t) => convertType(t, boundVariables)).toList(); 2156 return types.map((t) => convertType(t, boundVariables)).toList();
2151 } 2157 }
2152 2158
2153 Map<String, ast.DartType> convertTypeMap( 2159 List<ast.NamedType> convertTypeMap(
2154 Map<String, DartType> types, List<TypeParameterElement> boundVariables) { 2160 Map<String, DartType> types, List<TypeParameterElement> boundVariables) {
2155 if (types.isEmpty) return const <String, ast.DartType>{}; 2161 if (types.isEmpty) return const <ast.NamedType>[];
2156 var result = <String, ast.DartType>{}; 2162 List<ast.NamedType> result = <ast.NamedType>[];
2157 types.forEach((name, type) { 2163 types.forEach((name, type) {
2158 result[name] = convertType(type, boundVariables); 2164 result.add(new ast.NamedType(name, convertType(type, boundVariables)));
2159 }); 2165 });
2166 result.sort();
2160 return result; 2167 return result;
2161 } 2168 }
2162 2169
2163 ast.DartType visitSimpleIdentifier(SimpleIdentifier node) { 2170 ast.DartType visitSimpleIdentifier(SimpleIdentifier node) {
2164 Element element = node.staticElement; 2171 Element element = node.staticElement;
2165 switch (ElementKind.of(element)) { 2172 switch (ElementKind.of(element)) {
2166 case ElementKind.CLASS: 2173 case ElementKind.CLASS:
2167 return new ast.InterfaceType(scope.getClassReference(element)); 2174 return new ast.InterfaceType(scope.getClassReference(element));
2168 2175
2169 case ElementKind.DYNAMIC: 2176 case ElementKind.DYNAMIC:
(...skipping 606 matching lines...) Expand 10 before | Expand all | Expand 10 after
2776 if (element is FieldElement) return element.getter; 2783 if (element is FieldElement) return element.getter;
2777 return element; 2784 return element;
2778 } 2785 }
2779 2786
2780 Element desynthesizeSetter(Element element) { 2787 Element desynthesizeSetter(Element element) {
2781 if (element == null || !element.isSynthetic) return element; 2788 if (element == null || !element.isSynthetic) return element;
2782 if (element is PropertyAccessorElement) return element.variable; 2789 if (element is PropertyAccessorElement) return element.variable;
2783 if (element is FieldElement) return element.setter; 2790 if (element is FieldElement) return element.setter;
2784 return element; 2791 return element;
2785 } 2792 }
OLDNEW
« no previous file with comments | « no previous file | lib/ast.dart » ('j') | lib/ast.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698