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

Side by Side Diff: sdk/lib/_internal/compiler/implementation/dart_backend/backend_ast_emitter.dart

Issue 658103003: Support map and list literals in analyzer2dart. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Use LiteralMapEntry to ensure build order Created 6 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 backend_ast_emitter; 5 library backend_ast_emitter;
6 6
7 import 'tree_ir_nodes.dart' as tree; 7 import 'tree_ir_nodes.dart' as tree;
8 import 'backend_ast_nodes.dart'; 8 import 'backend_ast_nodes.dart';
9 import '../constants/expressions.dart'; 9 import '../constants/expressions.dart';
10 import '../constants/values.dart'; 10 import '../constants/values.dart';
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 name = variable.element == null ? '$prefix$counter' : variable.element.name; 324 name = variable.element == null ? '$prefix$counter' : variable.element.name;
325 while (!usedVariableNames.add(name)) { 325 while (!usedVariableNames.add(name)) {
326 ++counter; 326 ++counter;
327 name = '$prefix$counter'; 327 name = '$prefix$counter';
328 } 328 }
329 variableNames[variable] = name; 329 variableNames[variable] = name;
330 330
331 // Synthesize an element for the variable 331 // Synthesize an element for the variable
332 if (variable.element == null || name != variable.element.name) { 332 if (variable.element == null || name != variable.element.name) {
333 // TODO(johnniwinther): Replace by synthetic [Entity]. 333 // TODO(johnniwinther): Replace by synthetic [Entity].
334 variable.element = new modelx.LocalVariableElementX.synthetic( 334 variable.element = new _SyntheticLocalVariableElement(
335 name, 335 name,
336 functionElement, 336 functionElement,
337 variableList); 337 variableList);
338 } 338 }
339 return name; 339 return name;
340 } 340 }
341 341
342 String getConstantName(VariableElement element) { 342 String getConstantName(VariableElement element) {
343 assert(element.kind == ElementKind.VARIABLE); 343 assert(element.kind == ElementKind.VARIABLE);
344 if (element.enclosingElement != functionElement) { 344 if (element.enclosingElement != functionElement) {
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 } 507 }
508 508
509 Expression visitLiteralList(tree.LiteralList exp) { 509 Expression visitLiteralList(tree.LiteralList exp) {
510 return new LiteralList( 510 return new LiteralList(
511 exp.values.map(visitExpression).toList(growable: false), 511 exp.values.map(visitExpression).toList(growable: false),
512 typeArgument: emitOptionalType(exp.type.typeArguments.single)); 512 typeArgument: emitOptionalType(exp.type.typeArguments.single));
513 } 513 }
514 514
515 Expression visitLiteralMap(tree.LiteralMap exp) { 515 Expression visitLiteralMap(tree.LiteralMap exp) {
516 List<LiteralMapEntry> entries = new List<LiteralMapEntry>.generate( 516 List<LiteralMapEntry> entries = new List<LiteralMapEntry>.generate(
517 exp.values.length, 517 exp.entries.length,
518 (i) => new LiteralMapEntry(visitExpression(exp.keys[i]), 518 (i) => new LiteralMapEntry(visitExpression(exp.entries[i].key),
519 visitExpression(exp.values[i]))); 519 visitExpression(exp.entries[i].value)));
520 List<TypeAnnotation> typeArguments = exp.type.treatAsRaw 520 List<TypeAnnotation> typeArguments = exp.type.treatAsRaw
521 ? null 521 ? null
522 : exp.type.typeArguments.map(createTypeAnnotation).toList(growable: fals e); 522 : exp.type.typeArguments.map(createTypeAnnotation)
523 .toList(growable: false);
523 return new LiteralMap(entries, typeArguments: typeArguments); 524 return new LiteralMap(entries, typeArguments: typeArguments);
524 } 525 }
525 526
526 Expression visitTypeOperator(tree.TypeOperator exp) { 527 Expression visitTypeOperator(tree.TypeOperator exp) {
527 return new TypeOperator(visitExpression(exp.receiver), 528 return new TypeOperator(visitExpression(exp.receiver),
528 exp.operator, 529 exp.operator,
529 createTypeAnnotation(exp.type)); 530 createTypeAnnotation(exp.type));
530 } 531 }
531 532
532 List<Argument> emitArguments(tree.Invoke exp) { 533 List<Argument> emitArguments(tree.Invoke exp) {
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after
890 } 891 }
891 } 892 }
892 893
893 visitVariable(tree.Variable variable) { 894 visitVariable(tree.Variable variable) {
894 if (shadowedParameters.contains(variable)) { 895 if (shadowedParameters.contains(variable)) {
895 hasShadowedUse.add(variable); 896 hasShadowedUse.add(variable);
896 } 897 }
897 } 898 }
898 899
899 } 900 }
901
902 // TODO(johnniwinther): Remove this when the dart `backend_ast` does not need
903 // [Element] for entities.
904 class _SyntheticLocalVariableElement extends modelx.VariableElementX
905 implements LocalVariableElement {
906
907 _SyntheticLocalVariableElement(String name,
908 ExecutableElement enclosingElement,
909 modelx.VariableList variables)
910 : super(name, ElementKind.VARIABLE, enclosingElement, variables, null);
911
912 ExecutableElement get executableContext => enclosingElement;
913
914 ExecutableElement get memberContext => executableContext.memberContext;
915
916 bool get isLocal => true;
917
918 LibraryElement get implementationLibrary => enclosingElement.library;
919 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698