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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | sdk/lib/_internal/compiler/implementation/dart_backend/dart_tree.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/_internal/compiler/implementation/dart_backend/dart_codegen.dart
diff --git a/sdk/lib/_internal/compiler/implementation/dart_backend/dart_codegen.dart b/sdk/lib/_internal/compiler/implementation/dart_backend/dart_codegen.dart
index 83aef83abbd4a11c22c743142f926171bf8621df..97cc8cadb152afb60ff0c4f033576b817e23c236 100644
--- a/sdk/lib/_internal/compiler/implementation/dart_backend/dart_codegen.dart
+++ b/sdk/lib/_internal/compiler/implementation/dart_backend/dart_codegen.dart
@@ -335,7 +335,9 @@ class ASTEmitter extends tree.Visitor<dynamic, Expression> {
Expression visitLiteralList(tree.LiteralList exp) {
return new LiteralList(
- exp.values.map(visitExpression).toList(growable: false));
+ exp.values.map(visitExpression).toList(growable: false),
+ isConst: exp.constant != null,
+ typeArgument: emitOptionalType(exp.type.typeArguments.single));
}
Expression visitLiteralMap(tree.LiteralMap exp) {
@@ -343,7 +345,12 @@ class ASTEmitter extends tree.Visitor<dynamic, Expression> {
exp.values.length,
(i) => new LiteralMapEntry(visitExpression(exp.keys[i]),
visitExpression(exp.values[i])));
- return new LiteralMap(entries);
+ List<TypeAnnotation> typeArguments = exp.type.treatAsRaw
+ ? null
+ : exp.type.typeArguments.mapToList(emitType);
+ return new LiteralMap(entries,
+ isConst: exp.constant != null,
+ typeArguments: typeArguments);
}
List<Argument> emitArguments(tree.Invoke exp) {
@@ -422,17 +429,10 @@ class ASTEmitter extends tree.Visitor<dynamic, Expression> {
List args = emitArguments(exp);
FunctionElement constructor = exp.target;
String name = constructor.name.isEmpty ? null : constructor.name;
- return new CallNew(emitType(exp.type), args, constructorName: name)
- ..constructor = constructor
- ..dartType = exp.type;
- }
-
- Expression visitInvokeConstConstructor(tree.InvokeConstConstructor exp) {
- List args = emitArguments(exp);
- FunctionElement constructor = exp.target;
- String name = constructor.name.isEmpty ? null : constructor.name;
- return new CallNew(emitType(exp.type), args, constructorName: name,
- isConst: true)
+ return new CallNew(emitType(exp.type),
+ args,
+ constructorName: name,
+ isConst: exp.constant != null)
..constructor = constructor
..dartType = exp.type;
}
@@ -500,26 +500,20 @@ class ASTEmitter extends tree.Visitor<dynamic, Expression> {
Expression emitConstant(dart2js.Constant constant) {
if (constant is dart2js.PrimitiveConstant) {
return new Literal(constant);
- } else if (constant is dart2js.ListConstant) {
- return new LiteralList(
- constant.entries.map(emitConstant).toList(growable: false),
- isConst: true);
- } else if (constant is dart2js.MapConstant) {
- List<LiteralMapEntry> entries = <LiteralMapEntry>[];
- for (var i = 0; i < constant.keys.length; i++) {
- entries.add(new LiteralMapEntry(
- emitConstant(constant.keys.entries[i]),
- emitConstant(constant.values[i])));
- }
- return new LiteralMap(entries, isConst: true);
+ } else if (constant is dart2js.ConstructedConstant &&
+ constant.isLiteralSymbol) {
+ dart2js.StringConstant nameConstant = constant.fields[0];
+ String nameString = nameConstant.value.slowToString();
+ return new LiteralSymbol(nameString);
+ } else if (constant is dart2js.FunctionConstant) {
+ return new Identifier(constant.element.name)
+ ..element = constant.element;
+ } else if (constant is dart2js.TypeConstant) {
+ GenericType type = constant.representedType;
+ return new Identifier(type.name)
+ ..element = type.element;
} else {
- if (constant is dart2js.ConstructedConstant && constant.isLiteralSymbol) {
- dart2js.StringConstant nameConstant = constant.fields[0];
- String nameString = nameConstant.value.slowToString();
- return new LiteralSymbol(nameString);
- } else {
- throw "Unsupported constant: $constant";
- }
+ throw "Unsupported constant: $constant";
}
}
}
« 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