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

Unified Diff: pkg/dev_compiler/lib/src/compiler/code_generator.dart

Issue 2362563004: re-land fix #27110 with proper DDC side of changes (Closed)
Patch Set: add tests Created 4 years, 3 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 | « pkg/dev_compiler/lib/js/legacy/dart_sdk.js ('k') | pkg/dev_compiler/lib/src/compiler/reify_coercions.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/dev_compiler/lib/src/compiler/code_generator.dart
diff --git a/pkg/dev_compiler/lib/src/compiler/code_generator.dart b/pkg/dev_compiler/lib/src/compiler/code_generator.dart
index c62aa11e635e922f45cb7278f7ae3701ea1a856d..54f4b6fd5741d5b8f1aecfdb910a2a55b657e225 100644
--- a/pkg/dev_compiler/lib/src/compiler/code_generator.dart
+++ b/pkg/dev_compiler/lib/src/compiler/code_generator.dart
@@ -1,4 +1,5 @@
// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
+
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
@@ -29,7 +30,7 @@ import 'package:analyzer/src/summary/summarize_elements.dart'
show PackageBundleAssembler;
import 'package:analyzer/src/summary/summary_sdk.dart';
import 'package:analyzer/src/task/strong/ast_properties.dart'
- show isDynamicInvoke, setIsDynamicInvoke;
+ show isDynamicInvoke, setIsDynamicInvoke, getImplicitAssignmentCast;
import 'package:path/path.dart' show separator;
import '../closure/closure_annotator.dart' show ClosureAnnotator;
@@ -559,19 +560,13 @@ class CodeGenerator extends GeneralizingAstVisitor
var type = _emitType(to,
nameType: options.nameTypeTests || options.hoistTypeTests,
hoistType: options.hoistTypeTests);
- if (isReifiedCoercion(node)) {
+ if (CoercionReifier.isImplicitCast(node)) {
return js.call('#._check(#)', [type, jsFrom]);
} else {
return js.call('#.as(#)', [type, jsFrom]);
}
}
- bool isReifiedCoercion(AstNode node) {
- // TODO(sra): Find a better way to recognize reified coercion, since we
- // can't set the isSynthetic attribute.
- return (node is AsExpression) && (node.asOperator.offset == 0);
- }
-
@override
visitIsExpression(IsExpression node) {
// Generate `is` as `dart.is` or `typeof` depending on the RHS type.
@@ -1930,8 +1925,8 @@ class CodeGenerator extends GeneralizingAstVisitor
var fun = new JS.Fun(
params,
- js.statement(
- '{ return $newKeyword #(#); }', [_visit(redirect), params]),
+ js.statement('{ return $newKeyword #(#); }',
+ [_visit(redirect) as JS.Node, params]),
returnType: returnType);
return annotate(
new JS.Method(name, fun, isStatic: true), node, node.element);
@@ -3014,9 +3009,12 @@ class CodeGenerator extends GeneralizingAstVisitor
// (for example, x is IndexExpression) we evaluate those once.
var vars = <JS.MetaLetVariable, JS.Expression>{};
var lhs = _bindLeftHandSide(vars, left, context: context);
- var inc = AstBuilder.binaryExpression(lhs, op, right);
- inc.staticElement = element;
- inc.staticType = getStaticType(left);
+ Expression inc = AstBuilder.binaryExpression(lhs, op, right)
+ ..staticElement = element
+ ..staticType = getStaticType(lhs);
+
+ var castTo = getImplicitAssignmentCast(left);
+ if (castTo != null) inc = CoercionReifier.castExpression(inc, castTo);
return new JS.MetaLet(vars, [_emitSet(lhs, inc)]);
}
@@ -4544,7 +4542,8 @@ class CodeGenerator extends GeneralizingAstVisitor
}
}
if (tail.isEmpty) return _visit(node);
- return js.call('dart.nullSafe(#, #)', [_visit(node), tail.reversed]);
+ return js.call(
+ 'dart.nullSafe(#, #)', [_visit(node) as JS.Expression, tail.reversed]);
}
static Token _getOperator(Expression node) {
@@ -4697,8 +4696,8 @@ class CodeGenerator extends GeneralizingAstVisitor
// dynamic dispatch
var dynamicHelper = const {'[]': 'dindex', '[]=': 'dsetindex'}[name];
if (dynamicHelper != null) {
- return js.call(
- 'dart.$dynamicHelper(#, #)', [_visit(target), _visitList(args)]);
+ return js.call('dart.$dynamicHelper(#, #)',
+ [_visit(target) as JS.Expression, _visitList(args)]);
} else {
return js.call('dart.dsend(#, #, #)',
[_visit(target), memberName, _visitList(args)]);
@@ -5052,7 +5051,7 @@ class CodeGenerator extends GeneralizingAstVisitor
// TODO(jmesserly): we can likely make these faster.
JS.Expression emitMap() {
var entries = node.entries;
- var mapArguments = null;
+ Object mapArguments = null;
var type = node.staticType as InterfaceType;
var typeArgs = type.typeArguments;
var reifyTypeArgs = typeArgs.any((t) => !t.isDynamic);
@@ -5174,10 +5173,9 @@ class CodeGenerator extends GeneralizingAstVisitor
if (op == '&&') return shortCircuit('# && #');
if (op == '||') return shortCircuit('# || #');
}
- if (isReifiedCoercion(node)) {
- AsExpression asNode = node;
- assert(asNode.staticType == types.boolType);
- return js.call('dart.test(#)', _visit(asNode.expression));
+ if (node is AsExpression && CoercionReifier.isImplicitCast(node)) {
+ assert(node.staticType == types.boolType);
+ return js.call('dart.test(#)', _visit(node.expression));
}
JS.Expression result = _visit(node);
if (isNullable(node)) result = js.call('dart.test(#)', result);
@@ -5458,7 +5456,8 @@ String jsLibraryName(String libraryRoot, LibraryElement library) {
uri.path.substring(libraryRoot.length).replaceAll('/', separator);
} else {
// We don't have a unique name.
- throw 'Invalid library root. $libraryRoot does not contain ${uri.toFilePath()}';
+ throw 'Invalid library root. $libraryRoot does not contain ${uri
+ .toFilePath()}';
}
return pathToJSIdentifier(qualifiedPath);
}
@@ -5479,10 +5478,12 @@ JS.LiteralString _propertyName(String name) => js.string(name, "'");
/// everywhere in the tree where they are treated as the same variable.
class TemporaryVariableElement extends LocalVariableElementImpl {
final JS.Expression jsVariable;
+
TemporaryVariableElement.forNode(Identifier name, this.jsVariable)
: super.forNode(name);
int get hashCode => identityHashCode(this);
+
bool operator ==(Object other) => identical(this, other);
}
« no previous file with comments | « pkg/dev_compiler/lib/js/legacy/dart_sdk.js ('k') | pkg/dev_compiler/lib/src/compiler/reify_coercions.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698