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

Side by Side Diff: lib/src/compiler/code_generator.dart

Issue 2042883004: Handle more boolean conversion cases. (Closed) Base URL: https://github.com/dart-lang/dev_compiler@master
Patch Set: Created 4 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
« no previous file with comments | « lib/runtime/dart_sdk.js ('k') | no next file » | 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) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 import 'dart:collection' show HashMap, HashSet; 5 import 'dart:collection' show HashMap, HashSet;
6 import 'dart:math' show min, max; 6 import 'dart:math' show min, max;
7 7
8 import 'package:analyzer/analyzer.dart' hide ConstantEvaluator; 8 import 'package:analyzer/analyzer.dart' hide ConstantEvaluator;
9 import 'package:analyzer/dart/ast/ast.dart'; 9 import 'package:analyzer/dart/ast/ast.dart';
10 import 'package:analyzer/dart/ast/token.dart' show Token, TokenType; 10 import 'package:analyzer/dart/ast/token.dart' show Token, TokenType;
(...skipping 3450 matching lines...) Expand 10 before | Expand all | Expand 10 after
3461 JS.Expression notNull(Expression expr) { 3461 JS.Expression notNull(Expression expr) {
3462 if (expr == null) return null; 3462 if (expr == null) return null;
3463 var jsExpr = _visit(expr); 3463 var jsExpr = _visit(expr);
3464 if (!isNullable(expr)) return jsExpr; 3464 if (!isNullable(expr)) return jsExpr;
3465 return js.call('dart.notNull(#)', jsExpr); 3465 return js.call('dart.notNull(#)', jsExpr);
3466 } 3466 }
3467 3467
3468 @override 3468 @override
3469 JS.Expression visitBinaryExpression(BinaryExpression node) { 3469 JS.Expression visitBinaryExpression(BinaryExpression node) {
3470 var op = node.operator; 3470 var op = node.operator;
3471
3472 // The operands of logical boolean operators are subject to boolean
3473 // conversion.
3474 if (op.type == TokenType.BAR_BAR ||
3475 op.type == TokenType.AMPERSAND_AMPERSAND) {
3476 return _visitTest(node);
Jennifer Messerly 2016/06/07 19:28:35 Reading this, I was confused ... my thought was "s
3477 }
3478
3471 var left = node.leftOperand; 3479 var left = node.leftOperand;
3472 var right = node.rightOperand; 3480 var right = node.rightOperand;
3473 3481
3474 var leftType = getStaticType(left); 3482 var leftType = getStaticType(left);
3475 var rightType = getStaticType(right); 3483 var rightType = getStaticType(right);
3476 3484
3477 var code; 3485 var code;
3478 if (op.type.isEqualityOperator) { 3486 if (op.type.isEqualityOperator) {
3479 // If we statically know LHS or RHS is null we can generate a clean check. 3487 // If we statically know LHS or RHS is null we can generate a clean check.
3480 // We can also do this if both sides are the same primitive type. 3488 // We can also do this if both sides are the same primitive type.
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after
3916 ..staticElement = node.staticElement 3924 ..staticElement = node.staticElement
3917 ..staticType = getStaticType(expr); 3925 ..staticType = getStaticType(expr);
3918 3926
3919 var body = <JS.Expression>[_emitSet(left, increment), _visit(x)]; 3927 var body = <JS.Expression>[_emitSet(left, increment), _visit(x)];
3920 return new JS.MetaLet(vars, body, statelessResult: true); 3928 return new JS.MetaLet(vars, body, statelessResult: true);
3921 } 3929 }
3922 3930
3923 @override 3931 @override
3924 JS.Expression visitPrefixExpression(PrefixExpression node) { 3932 JS.Expression visitPrefixExpression(PrefixExpression node) {
3925 var op = node.operator; 3933 var op = node.operator;
3934
3935 // Logical negation, `!e`, is a boolean conversion context since it is
3936 // defined as `e ? false : true`.
3937 if (op.lexeme == '!') return _visitTest(node);
3938
3926 var expr = node.operand; 3939 var expr = node.operand;
3927 3940
3928 var dispatchType = getStaticType(expr); 3941 var dispatchType = getStaticType(expr);
3929 if (unaryOperationIsPrimitive(dispatchType)) { 3942 if (unaryOperationIsPrimitive(dispatchType)) {
3930 if (op.lexeme == '~') { 3943 if (op.lexeme == '~') {
3931 if (_isNumberInJS(dispatchType)) { 3944 if (_isNumberInJS(dispatchType)) {
3932 JS.Expression jsExpr = js.call('~#', notNull(expr)); 3945 JS.Expression jsExpr = js.call('~#', notNull(expr));
3933 return _coerceBitOperationResultToUnsigned(node, jsExpr); 3946 return _coerceBitOperationResultToUnsigned(node, jsExpr);
3934 } 3947 }
3935 return _emitSend(expr, op.lexeme[0], []); 3948 return _emitSend(expr, op.lexeme[0], []);
(...skipping 1037 matching lines...) Expand 10 before | Expand all | Expand 10 after
4973 } 4986 }
4974 4987
4975 bool isLibraryPrefix(Expression node) => 4988 bool isLibraryPrefix(Expression node) =>
4976 node is SimpleIdentifier && node.staticElement is PrefixElement; 4989 node is SimpleIdentifier && node.staticElement is PrefixElement;
4977 4990
4978 LibraryElement _getLibrary(AnalysisContext c, String uri) => 4991 LibraryElement _getLibrary(AnalysisContext c, String uri) =>
4979 c.computeLibraryElement(c.sourceFactory.forUri(uri)); 4992 c.computeLibraryElement(c.sourceFactory.forUri(uri));
4980 4993
4981 bool _isDartRuntime(LibraryElement l) => 4994 bool _isDartRuntime(LibraryElement l) =>
4982 l.isInSdk && l.source.uri.toString() == 'dart:_runtime'; 4995 l.isInSdk && l.source.uri.toString() == 'dart:_runtime';
OLDNEW
« no previous file with comments | « lib/runtime/dart_sdk.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698