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

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

Issue 348053002: dart2dart: Support for all constants in new backend. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: SVN rebase + merge Created 6 years, 6 months 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
« no previous file with comments | « no previous file | sdk/lib/_internal/compiler/implementation/dart_backend/dart_tree.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) 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 dart_codegen; 5 library dart_codegen;
6 6
7 import 'dart_tree.dart' as tree; 7 import 'dart_tree.dart' as tree;
8 import 'dart_printer.dart'; 8 import 'dart_printer.dart';
9 import 'dart_tree_printer.dart' show TreePrinter; 9 import 'dart_tree_printer.dart' show TreePrinter;
10 import '../tree/tree.dart' as frontend; 10 import '../tree/tree.dart' as frontend;
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 328
329 visitStatement(stmt.next); 329 visitStatement(stmt.next);
330 } 330 }
331 331
332 Expression visitConstant(tree.Constant exp) { 332 Expression visitConstant(tree.Constant exp) {
333 return emitConstant(exp.value); 333 return emitConstant(exp.value);
334 } 334 }
335 335
336 Expression visitLiteralList(tree.LiteralList exp) { 336 Expression visitLiteralList(tree.LiteralList exp) {
337 return new LiteralList( 337 return new LiteralList(
338 exp.values.map(visitExpression).toList(growable: false)); 338 exp.values.map(visitExpression).toList(growable: false),
339 isConst: exp.constant != null,
340 typeArgument: emitOptionalType(exp.type.typeArguments.single));
339 } 341 }
340 342
341 Expression visitLiteralMap(tree.LiteralMap exp) { 343 Expression visitLiteralMap(tree.LiteralMap exp) {
342 List<LiteralMapEntry> entries = new List<LiteralMapEntry>.generate( 344 List<LiteralMapEntry> entries = new List<LiteralMapEntry>.generate(
343 exp.values.length, 345 exp.values.length,
344 (i) => new LiteralMapEntry(visitExpression(exp.keys[i]), 346 (i) => new LiteralMapEntry(visitExpression(exp.keys[i]),
345 visitExpression(exp.values[i]))); 347 visitExpression(exp.values[i])));
346 return new LiteralMap(entries); 348 List<TypeAnnotation> typeArguments = exp.type.treatAsRaw
349 ? null
350 : exp.type.typeArguments.mapToList(emitType);
351 return new LiteralMap(entries,
352 isConst: exp.constant != null,
353 typeArguments: typeArguments);
347 } 354 }
348 355
349 List<Argument> emitArguments(tree.Invoke exp) { 356 List<Argument> emitArguments(tree.Invoke exp) {
350 List<tree.Expression> args = exp.arguments; 357 List<tree.Expression> args = exp.arguments;
351 int positionalArgumentCount = exp.selector.positionalArgumentCount; 358 int positionalArgumentCount = exp.selector.positionalArgumentCount;
352 List<Argument> result = new List<Argument>.generate(positionalArgumentCount, 359 List<Argument> result = new List<Argument>.generate(positionalArgumentCount,
353 (i) => visitExpression(exp.arguments[i])); 360 (i) => visitExpression(exp.arguments[i]));
354 for (int i = 0; i < exp.selector.namedArgumentCount; ++i) { 361 for (int i = 0; i < exp.selector.namedArgumentCount; ++i) {
355 result.add(new NamedArgument(exp.selector.namedArguments[i], 362 result.add(new NamedArgument(exp.selector.namedArguments[i],
356 visitExpression(exp.arguments[positionalArgumentCount + i]))); 363 visitExpression(exp.arguments[positionalArgumentCount + i])));
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 422
416 default: 423 default:
417 throw "Unexpected selector in InvokeMethod: ${exp.selector.kind}"; 424 throw "Unexpected selector in InvokeMethod: ${exp.selector.kind}";
418 } 425 }
419 } 426 }
420 427
421 Expression visitInvokeConstructor(tree.InvokeConstructor exp) { 428 Expression visitInvokeConstructor(tree.InvokeConstructor exp) {
422 List args = emitArguments(exp); 429 List args = emitArguments(exp);
423 FunctionElement constructor = exp.target; 430 FunctionElement constructor = exp.target;
424 String name = constructor.name.isEmpty ? null : constructor.name; 431 String name = constructor.name.isEmpty ? null : constructor.name;
425 return new CallNew(emitType(exp.type), args, constructorName: name) 432 return new CallNew(emitType(exp.type),
433 args,
434 constructorName: name,
435 isConst: exp.constant != null)
426 ..constructor = constructor 436 ..constructor = constructor
427 ..dartType = exp.type; 437 ..dartType = exp.type;
428 } 438 }
429
430 Expression visitInvokeConstConstructor(tree.InvokeConstConstructor exp) {
431 List args = emitArguments(exp);
432 FunctionElement constructor = exp.target;
433 String name = constructor.name.isEmpty ? null : constructor.name;
434 return new CallNew(emitType(exp.type), args, constructorName: name,
435 isConst: true)
436 ..constructor = constructor
437 ..dartType = exp.type;
438 }
439 439
440 Expression visitConcatenateStrings(tree.ConcatenateStrings exp) { 440 Expression visitConcatenateStrings(tree.ConcatenateStrings exp) {
441 List args = exp.arguments.map(visitExpression).toList(growable:false); 441 List args = exp.arguments.map(visitExpression).toList(growable:false);
442 return new StringConcat(args); 442 return new StringConcat(args);
443 } 443 }
444 444
445 Expression visitConditional(tree.Conditional exp) { 445 Expression visitConditional(tree.Conditional exp) {
446 return new Conditional( 446 return new Conditional(
447 visitExpression(exp.condition), 447 visitExpression(exp.condition),
448 visitExpression(exp.thenExpression), 448 visitExpression(exp.thenExpression),
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 if (type.treatAsDynamic) { 493 if (type.treatAsDynamic) {
494 return null; 494 return null;
495 } else { 495 } else {
496 return emitType(type); 496 return emitType(type);
497 } 497 }
498 } 498 }
499 499
500 Expression emitConstant(dart2js.Constant constant) { 500 Expression emitConstant(dart2js.Constant constant) {
501 if (constant is dart2js.PrimitiveConstant) { 501 if (constant is dart2js.PrimitiveConstant) {
502 return new Literal(constant); 502 return new Literal(constant);
503 } else if (constant is dart2js.ListConstant) { 503 } else if (constant is dart2js.ConstructedConstant &&
504 return new LiteralList( 504 constant.isLiteralSymbol) {
505 constant.entries.map(emitConstant).toList(growable: false), 505 dart2js.StringConstant nameConstant = constant.fields[0];
506 isConst: true); 506 String nameString = nameConstant.value.slowToString();
507 } else if (constant is dart2js.MapConstant) { 507 return new LiteralSymbol(nameString);
508 List<LiteralMapEntry> entries = <LiteralMapEntry>[]; 508 } else if (constant is dart2js.FunctionConstant) {
509 for (var i = 0; i < constant.keys.length; i++) { 509 return new Identifier(constant.element.name)
510 entries.add(new LiteralMapEntry( 510 ..element = constant.element;
511 emitConstant(constant.keys.entries[i]), 511 } else if (constant is dart2js.TypeConstant) {
512 emitConstant(constant.values[i]))); 512 GenericType type = constant.representedType;
513 } 513 return new Identifier(type.name)
514 return new LiteralMap(entries, isConst: true); 514 ..element = type.element;
515 } else { 515 } else {
516 if (constant is dart2js.ConstructedConstant && constant.isLiteralSymbol) { 516 throw "Unsupported constant: $constant";
517 dart2js.StringConstant nameConstant = constant.fields[0];
518 String nameString = nameConstant.value.slowToString();
519 return new LiteralSymbol(nameString);
520 } else {
521 throw "Unsupported constant: $constant";
522 }
523 } 517 }
524 } 518 }
525 } 519 }
526 520
OLDNEW
« no previous file with comments | « no previous file | sdk/lib/_internal/compiler/implementation/dart_backend/dart_tree.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698