| Index: sdk/lib/_internal/compiler/implementation/dart_backend/backend_ast_emitter.dart
|
| diff --git a/sdk/lib/_internal/compiler/implementation/dart_backend/backend_ast_emitter.dart b/sdk/lib/_internal/compiler/implementation/dart_backend/backend_ast_emitter.dart
|
| index c17eba4db1f56f94246461e30083b21680cdc44f..070ec761f2086b31d6428cbbcd999566d0f479b4 100644
|
| --- a/sdk/lib/_internal/compiler/implementation/dart_backend/backend_ast_emitter.dart
|
| +++ b/sdk/lib/_internal/compiler/implementation/dart_backend/backend_ast_emitter.dart
|
| @@ -672,7 +672,7 @@ class ConstantEmitter extends ConstExpVisitor<Expression> {
|
| ASTEmitter parent;
|
| ConstantEmitter(this.parent);
|
|
|
| - Expression visitPrimitive(PrimitiveConstExp exp) {
|
| + Expression handlePrimitiveConstant(dart2js.PrimitiveConstant value) {
|
| // Num constants may be negative, while literals must be non-negative:
|
| // Literals are non-negative in the specification, and a negated literal
|
| // parses as a call to unary `-`. The AST unparser assumes literals are
|
| @@ -680,13 +680,18 @@ class ConstantEmitter extends ConstExpVisitor<Expression> {
|
| // the predecrement operator.
|
| // Translate such constants into their positive value wrapped by
|
| // the unary minus operator.
|
| - if (exp.constant is dart2js.NumConstant) {
|
| - dart2js.NumConstant numConstant = exp.constant;
|
| + if (value is dart2js.NumConstant) {
|
| + dart2js.NumConstant numConstant = value;
|
| if (numConstant.value.isNegative) {
|
| return negatedLiteral(numConstant);
|
| }
|
| }
|
| - return new Literal(exp.constant);
|
| + return new Literal(value);
|
| + }
|
| +
|
| + @override
|
| + Expression visitPrimitive(PrimitiveConstExp exp) {
|
| + return handlePrimitiveConstant(exp.value);
|
| }
|
|
|
| /// Given a negative num constant, returns the corresponding positive
|
| @@ -704,6 +709,7 @@ class ConstantEmitter extends ConstExpVisitor<Expression> {
|
| return new UnaryOperator('-', new Literal(positiveConstant));
|
| }
|
|
|
| + @override
|
| Expression visitList(ListConstExp exp) {
|
| return new LiteralList(
|
| exp.values.map(visit).toList(growable: false),
|
| @@ -711,6 +717,7 @@ class ConstantEmitter extends ConstExpVisitor<Expression> {
|
| typeArgument: parent.emitOptionalType(exp.type.typeArguments.single));
|
| }
|
|
|
| + @override
|
| Expression visitMap(MapConstExp exp) {
|
| List<LiteralMapEntry> entries = new List<LiteralMapEntry>.generate(
|
| exp.values.length,
|
| @@ -722,6 +729,7 @@ class ConstantEmitter extends ConstExpVisitor<Expression> {
|
| return new LiteralMap(entries, isConst: true, typeArguments: typeArguments);
|
| }
|
|
|
| + @override
|
| Expression visitConstructor(ConstructorConstExp exp) {
|
| int positionalArgumentCount = exp.selector.positionalArgumentCount;
|
| List<Argument> args = new List<Argument>.generate(
|
| @@ -742,20 +750,24 @@ class ConstantEmitter extends ConstExpVisitor<Expression> {
|
| ..dartType = exp.type;
|
| }
|
|
|
| + @override
|
| Expression visitConcatenate(ConcatenateConstExp exp) {
|
| return new StringConcat(exp.arguments.map(visit).toList(growable: false));
|
| }
|
|
|
| + @override
|
| Expression visitSymbol(SymbolConstExp exp) {
|
| return new LiteralSymbol(exp.name);
|
| }
|
|
|
| + @override
|
| Expression visitType(TypeConstExp exp) {
|
| DartType type = exp.type;
|
| return new LiteralType(type.name)
|
| ..type = type;
|
| }
|
|
|
| + @override
|
| Expression visitVariable(VariableConstExp exp) {
|
| Element element = exp.element;
|
| if (element.kind != ElementKind.VARIABLE) {
|
| @@ -766,11 +778,30 @@ class ConstantEmitter extends ConstExpVisitor<Expression> {
|
| ..element = element;
|
| }
|
|
|
| + @override
|
| Expression visitFunction(FunctionConstExp exp) {
|
| return new Identifier(exp.element.name)
|
| ..element = exp.element;
|
| }
|
|
|
| + @override
|
| + Expression visitBinary(BinaryConstExp exp) {
|
| + return handlePrimitiveConstant(exp.value);
|
| + }
|
| +
|
| + @override
|
| + Expression visitConditional(ConditionalConstExp exp) {
|
| + if (exp.condition.value.isTrue) {
|
| + return exp.trueExp.accept(this);
|
| + } else {
|
| + return exp.falseExp.accept(this);
|
| + }
|
| + }
|
| +
|
| + @override
|
| + Expression visitUnary(UnaryConstExp exp) {
|
| + return handlePrimitiveConstant(exp.value);
|
| + }
|
| }
|
|
|
| /// Moves function parameters into a separate variable if one of its uses is
|
|
|