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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | lib/ast.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/analyzer/ast_from_analyzer.dart
diff --git a/lib/analyzer/ast_from_analyzer.dart b/lib/analyzer/ast_from_analyzer.dart
index 7dfba0d46ba7b83f20852efd4d1715f6ceb319ce..2aae68729ebe9cdb8ec0c4ee4f09913548b76257 100644
--- a/lib/analyzer/ast_from_analyzer.dart
+++ b/lib/analyzer/ast_from_analyzer.dart
@@ -456,6 +456,9 @@ class TypeScope extends ReferenceScope {
break;
}
}
+ if (named.isNotEmpty) {
+ sortAndRemoveDuplicates(named);
+ }
var returnType = element is ConstructorElement
? const ast.VoidType()
: buildType(element.returnType);
@@ -557,6 +560,9 @@ class ExpressionScope extends TypeScope {
break;
}
}
+ if (named.isNotEmpty) {
+ sortAndRemoveDuplicates(named);
+ }
return new ast.FunctionNode(buildOptionalFunctionBody(body),
typeParameters: typeParameters,
positionalParameters: positional,
@@ -1950,7 +1956,10 @@ class ExpressionBuilder
return scope.staticAccess(node.propertyName.name, element, auxiliary);
} else if (node.operator.value() == '?.') {
return new NullAwarePropertyAccessor(
- build(target), scope.buildName(node.propertyName), getter, setter,
+ build(target),
+ scope.buildName(node.propertyName),
+ getter,
+ setter,
scope.buildType(node.staticType));
} else {
return PropertyAccessor.make(
@@ -2150,13 +2159,14 @@ class TypeAnnotationBuilder extends GeneralizingAstVisitor<ast.DartType> {
return types.map((t) => convertType(t, boundVariables)).toList();
}
- Map<String, ast.DartType> convertTypeMap(
+ List<ast.NamedType> convertTypeMap(
Map<String, DartType> types, List<TypeParameterElement> boundVariables) {
- if (types.isEmpty) return const <String, ast.DartType>{};
- var result = <String, ast.DartType>{};
+ if (types.isEmpty) return const <ast.NamedType>[];
+ List<ast.NamedType> result = <ast.NamedType>[];
types.forEach((name, type) {
- result[name] = convertType(type, boundVariables);
+ result.add(new ast.NamedType(name, convertType(type, boundVariables)));
});
+ sortAndRemoveDuplicates(result);
return result;
}
@@ -2783,3 +2793,19 @@ Element desynthesizeSetter(Element element) {
if (element is FieldElement) return element.setter;
return element;
}
+
+void sortAndRemoveDuplicates/*<T extends Comparable<T>>*/(List/*<T>*/ list) {
+ list.sort();
+ int deleted = 0;
+ for (int i = 1; i < list.length; ++i) {
+ var item = list[i];
+ if (list[i - 1].compareTo(item) == 0) {
+ ++deleted;
+ } else if (deleted > 0) {
+ list[i - deleted] = item;
+ }
+ }
+ if (deleted > 0) {
+ list.length -= deleted;
+ }
+}
« 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