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

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

Issue 2850783002: Dart SDK Spelling b, c, and d. (Closed)
Patch Set: Created 3 years, 7 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
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 2
3 // for details. All rights reserved. Use of this source code is governed by a 3 // for details. All rights reserved. Use of this source code is governed by a
4 // BSD-style license that can be found in the LICENSE file. 4 // BSD-style license that can be found in the LICENSE file.
5 5
6 import 'dart:collection' show HashMap, HashSet; 6 import 'dart:collection' show HashMap, HashSet;
7 import 'dart:math' show min, max; 7 import 'dart:math' show min, max;
8 8
9 import 'package:analyzer/analyzer.dart' hide ConstantEvaluator; 9 import 'package:analyzer/analyzer.dart' hide ConstantEvaluator;
10 import 'package:analyzer/dart/ast/ast.dart'; 10 import 'package:analyzer/dart/ast/ast.dart';
(...skipping 3213 matching lines...) Expand 10 before | Expand all | Expand 10 after
3224 op = op.substring(0, op.length - 1); // remove trailing '=' 3224 op = op.substring(0, op.length - 1); // remove trailing '='
3225 return _emitOpAssign(left, right, op, node.staticElement, context: node); 3225 return _emitOpAssign(left, right, op, node.staticElement, context: node);
3226 } 3226 }
3227 3227
3228 JS.MetaLet _emitOpAssign( 3228 JS.MetaLet _emitOpAssign(
3229 Expression left, Expression right, String op, MethodElement element, 3229 Expression left, Expression right, String op, MethodElement element,
3230 {Expression context}) { 3230 {Expression context}) {
3231 if (op == '??') { 3231 if (op == '??') {
3232 // Desugar `l ??= r` as ((x) => x == null ? l = r : x)(l) 3232 // Desugar `l ??= r` as ((x) => x == null ? l = r : x)(l)
3233 // Note that if `x` contains subexpressions, we need to ensure those 3233 // Note that if `x` contains subexpressions, we need to ensure those
3234 // are also evaluated only once. This is similar to desguaring for 3234 // are also evaluated only once. This is similar to desugaring for
3235 // postfix expressions like `i++`. 3235 // postfix expressions like `i++`.
3236 3236
3237 // Handle the left hand side, to ensure each of its subexpressions are 3237 // Handle the left hand side, to ensure each of its subexpressions are
3238 // evaluated only once. 3238 // evaluated only once.
3239 var vars = <JS.MetaLetVariable, JS.Expression>{}; 3239 var vars = <JS.MetaLetVariable, JS.Expression>{};
3240 var x = _bindLeftHandSide(vars, left, context: left); 3240 var x = _bindLeftHandSide(vars, left, context: left);
3241 // Capture the result of evaluating the left hand side in a temp. 3241 // Capture the result of evaluating the left hand side in a temp.
3242 var t = _bindValue(vars, 't', x, context: x); 3242 var t = _bindValue(vars, 't', x, context: x);
3243 return new JS.MetaLet(vars, [ 3243 return new JS.MetaLet(vars, [
3244 js.call('# == null ? # : #', [_visit(t), _emitSet(x, right), _visit(t)]) 3244 js.call('# == null ? # : #', [_visit(t), _emitSet(x, right), _visit(t)])
(...skipping 1134 matching lines...) Expand 10 before | Expand all | Expand 10 after
4379 Expression node, JS.Expression uncoerced) { 4379 Expression node, JS.Expression uncoerced) {
4380 // Don't coerce if the parent will coerce. 4380 // Don't coerce if the parent will coerce.
4381 AstNode parent = _parentOperation(node); 4381 AstNode parent = _parentOperation(node);
4382 if (_nodeIsBitwiseOperation(parent)) return uncoerced; 4382 if (_nodeIsBitwiseOperation(parent)) return uncoerced;
4383 4383
4384 // Don't do a no-op coerce if the most significant bit is zero. 4384 // Don't do a no-op coerce if the most significant bit is zero.
4385 if (_is31BitUnsigned(node)) return uncoerced; 4385 if (_is31BitUnsigned(node)) return uncoerced;
4386 4386
4387 // If the consumer of the expression is '==' or '!=' with a constant that 4387 // If the consumer of the expression is '==' or '!=' with a constant that
4388 // fits in 31 bits, adding a coercion does not change the result of the 4388 // fits in 31 bits, adding a coercion does not change the result of the
4389 // comparision, e.g. `a & ~b == 0`. 4389 // comparison, e.g. `a & ~b == 0`.
4390 if (parent is BinaryExpression) { 4390 if (parent is BinaryExpression) {
4391 var tokenType = parent.operator.type; 4391 var tokenType = parent.operator.type;
4392 Expression left = parent.leftOperand; 4392 Expression left = parent.leftOperand;
4393 Expression right = parent.rightOperand; 4393 Expression right = parent.rightOperand;
4394 if (tokenType == TokenType.EQ_EQ || tokenType == TokenType.BANG_EQ) { 4394 if (tokenType == TokenType.EQ_EQ || tokenType == TokenType.BANG_EQ) {
4395 const int MAX = 0x7fffffff; 4395 const int MAX = 0x7fffffff;
4396 if (_asIntInRange(right, 0, MAX) != null) return uncoerced; 4396 if (_asIntInRange(right, 0, MAX) != null) return uncoerced;
4397 if (_asIntInRange(left, 0, MAX) != null) return uncoerced; 4397 if (_asIntInRange(left, 0, MAX) != null) return uncoerced;
4398 } else if (tokenType == TokenType.GT_GT) { 4398 } else if (tokenType == TokenType.GT_GT) {
4399 if (_isDefinitelyNonNegative(left) && 4399 if (_isDefinitelyNonNegative(left) &&
(...skipping 1728 matching lines...) Expand 10 before | Expand all | Expand 10 after
6128 if (targetIdentifier.staticElement is! PrefixElement) return false; 6128 if (targetIdentifier.staticElement is! PrefixElement) return false;
6129 var prefix = targetIdentifier.staticElement as PrefixElement; 6129 var prefix = targetIdentifier.staticElement as PrefixElement;
6130 6130
6131 // The library the prefix is referring to must come from a deferred import. 6131 // The library the prefix is referring to must come from a deferred import.
6132 var containingLibrary = resolutionMap 6132 var containingLibrary = resolutionMap
6133 .elementDeclaredByCompilationUnit(target.root as CompilationUnit) 6133 .elementDeclaredByCompilationUnit(target.root as CompilationUnit)
6134 .library; 6134 .library;
6135 var imports = containingLibrary.getImportsWithPrefix(prefix); 6135 var imports = containingLibrary.getImportsWithPrefix(prefix);
6136 return imports.length == 1 && imports[0].isDeferred; 6136 return imports.length == 1 && imports[0].isDeferred;
6137 } 6137 }
OLDNEW
« no previous file with comments | « pkg/dev_compiler/doc/GENERIC_METHODS.md ('k') | pkg/dev_compiler/test/codegen/BenchmarkBase.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698