| Index: pkg/compiler/lib/src/js_backend/constant_emitter.dart
|
| diff --git a/pkg/compiler/lib/src/js_backend/constant_emitter.dart b/pkg/compiler/lib/src/js_backend/constant_emitter.dart
|
| index 4afb1359c30aa5bee56330b128b0f6a39ddf3052..0f97ea76e73a1fe2b969a0dc9f4b90a6ecd57407 100644
|
| --- a/pkg/compiler/lib/src/js_backend/constant_emitter.dart
|
| +++ b/pkg/compiler/lib/src/js_backend/constant_emitter.dart
|
| @@ -55,7 +55,7 @@ class ConstantEmitter {
|
| * Do not use directly, use methods from [ConstantEmitter].
|
| */
|
| class ConstantReferenceEmitter
|
| - implements ConstantValueVisitor<jsAst.Expression> {
|
| + implements ConstantValueVisitor<jsAst.Expression, Null> {
|
| final Compiler compiler;
|
| final Namer namer;
|
|
|
| @@ -68,7 +68,7 @@ class ConstantReferenceEmitter
|
| }
|
|
|
| jsAst.Expression _visit(ConstantValue constant) {
|
| - return constant.accept(this);
|
| + return constant.accept(this, null);
|
| }
|
|
|
| jsAst.Expression emitCanonicalVersion(ConstantValue constant) {
|
| @@ -81,27 +81,28 @@ class ConstantReferenceEmitter
|
| return constantEmitter.literal(constant);
|
| }
|
|
|
| - jsAst.Expression visitFunction(FunctionConstantValue constant) {
|
| + @override
|
| + jsAst.Expression visitFunction(FunctionConstantValue constant, [_]) {
|
| return namer.isolateStaticClosureAccess(constant.element);
|
| }
|
|
|
| - jsAst.Expression visitNull(NullConstantValue constant) {
|
| + @override
|
| + jsAst.Expression visitNull(NullConstantValue constant, [_]) {
|
| return literal(constant);
|
| }
|
|
|
| - jsAst.Expression visitInt(IntConstantValue constant) {
|
| + @override
|
| + jsAst.Expression visitInt(IntConstantValue constant, [_]) {
|
| return literal(constant);
|
| }
|
|
|
| - jsAst.Expression visitDouble(DoubleConstantValue constant) {
|
| + @override
|
| + jsAst.Expression visitDouble(DoubleConstantValue constant, [_]) {
|
| return literal(constant);
|
| }
|
|
|
| - jsAst.Expression visitTrue(TrueConstantValue constant) {
|
| - return literal(constant);
|
| - }
|
| -
|
| - jsAst.Expression visitFalse(FalseConstantValue constant) {
|
| + @override
|
| + jsAst.Expression visitBool(BoolConstantValue constant, [_]) {
|
| return literal(constant);
|
| }
|
|
|
| @@ -110,38 +111,46 @@ class ConstantReferenceEmitter
|
| * a form that is valid as JavaScript string literal content.
|
| * The string is assumed quoted by double quote characters.
|
| */
|
| - jsAst.Expression visitString(StringConstantValue constant) {
|
| + @override
|
| + jsAst.Expression visitString(StringConstantValue constant, [_]) {
|
| // TODO(sra): If the string is long *and repeated* (and not on a hot path)
|
| // then it should be assigned to a name. We don't have reference counts (or
|
| // profile information) here, so this is the wrong place.
|
| return literal(constant);
|
| }
|
|
|
| - jsAst.Expression visitList(ListConstantValue constant) {
|
| + @override
|
| + jsAst.Expression visitList(ListConstantValue constant, [_]) {
|
| return emitCanonicalVersion(constant);
|
| }
|
|
|
| - jsAst.Expression visitMap(MapConstantValue constant) {
|
| + @override
|
| + jsAst.Expression visitMap(MapConstantValue constant, [_]) {
|
| return emitCanonicalVersion(constant);
|
| }
|
|
|
| - jsAst.Expression visitType(TypeConstantValue constant) {
|
| + @override
|
| + jsAst.Expression visitType(TypeConstantValue constant, [_]) {
|
| return emitCanonicalVersion(constant);
|
| }
|
|
|
| - jsAst.Expression visitConstructed(ConstructedConstantValue constant) {
|
| + @override
|
| + jsAst.Expression visitConstructed(ConstructedConstantValue constant, [_]) {
|
| return emitCanonicalVersion(constant);
|
| }
|
|
|
| - jsAst.Expression visitInterceptor(InterceptorConstantValue constant) {
|
| + @override
|
| + jsAst.Expression visitInterceptor(InterceptorConstantValue constant, [_]) {
|
| return emitCanonicalVersion(constant);
|
| }
|
|
|
| - jsAst.Expression visitDummy(DummyConstantValue constant) {
|
| + @override
|
| + jsAst.Expression visitDummy(DummyConstantValue constant, [_]) {
|
| return literal(constant);
|
| }
|
|
|
| - jsAst.Expression visitDeferred(DeferredConstantValue constant) {
|
| + @override
|
| + jsAst.Expression visitDeferred(DeferredConstantValue constant, [_]) {
|
| return emitCanonicalVersion(constant);
|
| }
|
| }
|
| @@ -151,7 +160,8 @@ class ConstantReferenceEmitter
|
| * [ConstantValue]s. These can be used for inlining constants or in
|
| * initializers. Do not use directly, use methods from [ConstantEmitter].
|
| */
|
| -class ConstantLiteralEmitter implements ConstantValueVisitor<jsAst.Expression> {
|
| +class ConstantLiteralEmitter
|
| + implements ConstantValueVisitor<jsAst.Expression, Null> {
|
|
|
| // Matches blank lines, comment lines and trailing comments that can't be part
|
| // of a string.
|
| @@ -173,24 +183,28 @@ class ConstantLiteralEmitter implements ConstantValueVisitor<jsAst.Expression> {
|
| }
|
|
|
| jsAst.Expression _visit(ConstantValue constant) {
|
| - return constant.accept(this);
|
| + return constant.accept(this, null);
|
| }
|
|
|
| - jsAst.Expression visitFunction(FunctionConstantValue constant) {
|
| + @override
|
| + jsAst.Expression visitFunction(FunctionConstantValue constant, [_]) {
|
| compiler.internalError(NO_LOCATION_SPANNABLE,
|
| "The function constant does not need specific JS code.");
|
| return null;
|
| }
|
|
|
| - jsAst.Expression visitNull(NullConstantValue constant) {
|
| + @override
|
| + jsAst.Expression visitNull(NullConstantValue constant, [_]) {
|
| return new jsAst.LiteralNull();
|
| }
|
|
|
| - jsAst.Expression visitInt(IntConstantValue constant) {
|
| + @override
|
| + jsAst.Expression visitInt(IntConstantValue constant, [_]) {
|
| return new jsAst.LiteralNumber('${constant.primitiveValue}');
|
| }
|
|
|
| - jsAst.Expression visitDouble(DoubleConstantValue constant) {
|
| + @override
|
| + jsAst.Expression visitDouble(DoubleConstantValue constant, [_]) {
|
| double value = constant.primitiveValue;
|
| if (value.isNaN) {
|
| return js("0/0");
|
| @@ -203,21 +217,18 @@ class ConstantLiteralEmitter implements ConstantValueVisitor<jsAst.Expression> {
|
| }
|
| }
|
|
|
| - jsAst.Expression visitTrue(TrueConstantValue constant) {
|
| + @override
|
| + jsAst.Expression visitBool(BoolConstantValue constant, [_]) {
|
| if (compiler.enableMinification) {
|
| - // Use !0 for true.
|
| - return js("!0");
|
| - } else {
|
| - return js('true');
|
| - }
|
| - }
|
| -
|
| - jsAst.Expression visitFalse(FalseConstantValue constant) {
|
| - if (compiler.enableMinification) {
|
| - // Use !1 for false.
|
| - return js("!1");
|
| + if (constant.isTrue) {
|
| + // Use !0 for true.
|
| + return js("!0");
|
| + } else {
|
| + // Use !1 for false.
|
| + return js("!1");
|
| + }
|
| } else {
|
| - return js('false');
|
| + return constant.isTrue ? js('true') : js('false');
|
| }
|
| }
|
|
|
| @@ -226,13 +237,15 @@ class ConstantLiteralEmitter implements ConstantValueVisitor<jsAst.Expression> {
|
| * a form that is valid as JavaScript string literal content.
|
| * The string is assumed quoted by double quote characters.
|
| */
|
| - jsAst.Expression visitString(StringConstantValue constant) {
|
| + @override
|
| + jsAst.Expression visitString(StringConstantValue constant, [_]) {
|
| StringBuffer sb = new StringBuffer();
|
| writeJsonEscapedCharsOn(constant.primitiveValue.slowToString(), sb);
|
| return new jsAst.LiteralString('"$sb"');
|
| }
|
|
|
| - jsAst.Expression visitList(ListConstantValue constant) {
|
| + @override
|
| + jsAst.Expression visitList(ListConstantValue constant, [_]) {
|
| List<jsAst.Expression> elements = _array(constant.entries);
|
| jsAst.ArrayInitializer array = new jsAst.ArrayInitializer(elements);
|
| jsAst.Expression value = makeConstantListTemplate.instantiate([array]);
|
| @@ -243,7 +256,8 @@ class ConstantLiteralEmitter implements ConstantValueVisitor<jsAst.Expression> {
|
| return namer.elementAccess(element);
|
| }
|
|
|
| - jsAst.Expression visitMap(JavaScriptMapConstant constant) {
|
| + @override
|
| + jsAst.Expression visitMap(JavaScriptMapConstant constant, [_]) {
|
| jsAst.Expression jsMap() {
|
| List<jsAst.Property> properties = <jsAst.Property>[];
|
| for (int i = 0; i < constant.length; i++) {
|
| @@ -325,7 +339,8 @@ class ConstantLiteralEmitter implements ConstantValueVisitor<jsAst.Expression> {
|
| return backend.namer.elementAccess(helper);
|
| }
|
|
|
| - jsAst.Expression visitType(TypeConstantValue constant) {
|
| + @override
|
| + jsAst.Expression visitType(TypeConstantValue constant, [_]) {
|
| DartType type = constant.representedType;
|
| String name = namer.getRuntimeTypeName(type.element);
|
| jsAst.Expression typeName = new jsAst.LiteralString("'$name'");
|
| @@ -333,17 +348,20 @@ class ConstantLiteralEmitter implements ConstantValueVisitor<jsAst.Expression> {
|
| [typeName]);
|
| }
|
|
|
| - jsAst.Expression visitInterceptor(InterceptorConstantValue constant) {
|
| + @override
|
| + jsAst.Expression visitInterceptor(InterceptorConstantValue constant, [_]) {
|
| return new jsAst.PropertyAccess.field(
|
| getJsConstructor(constant.dispatchedType.element),
|
| 'prototype');
|
| }
|
|
|
| - jsAst.Expression visitDummy(DummyConstantValue constant) {
|
| + @override
|
| + jsAst.Expression visitDummy(DummyConstantValue constant, [_]) {
|
| return new jsAst.LiteralNumber('0');
|
| }
|
|
|
| - jsAst.Expression visitConstructed(ConstructedConstantValue constant) {
|
| + @override
|
| + jsAst.Expression visitConstructed(ConstructedConstantValue constant, [_]) {
|
| Element element = constant.type.element;
|
| if (element.isForeign(backend)
|
| && element.name == 'JS_CONST') {
|
| @@ -383,7 +401,8 @@ class ConstantLiteralEmitter implements ConstantValueVisitor<jsAst.Expression> {
|
| return value;
|
| }
|
|
|
| - jsAst.Expression visitDeferred(DeferredConstantValue constant) {
|
| + @override
|
| + jsAst.Expression visitDeferred(DeferredConstantValue constant, [_]) {
|
| return constantEmitter.reference(constant.referenced);
|
| }
|
| }
|
|
|