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

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

Issue 2022213002: _visitTest should look through parentheses (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 4372 matching lines...) Expand 10 before | Expand all | Expand 10 after
4383 /// to give a more helpful message. 4383 /// to give a more helpful message.
4384 // TODO(sra): When nullablility is available earlier, it would be cleaner to 4384 // TODO(sra): When nullablility is available earlier, it would be cleaner to
4385 // build an input AST where the boolean conversion is a single AST node. 4385 // build an input AST where the boolean conversion is a single AST node.
4386 JS.Expression _visitTest(Expression node) { 4386 JS.Expression _visitTest(Expression node) {
4387 JS.Expression finish(JS.Expression result) { 4387 JS.Expression finish(JS.Expression result) {
4388 return annotate(result, node); 4388 return annotate(result, node);
4389 } 4389 }
4390 if (node is PrefixExpression && node.operator.lexeme == '!') { 4390 if (node is PrefixExpression && node.operator.lexeme == '!') {
4391 return finish(js.call('!#', _visitTest(node.operand))); 4391 return finish(js.call('!#', _visitTest(node.operand)));
4392 } 4392 }
4393 if (node is ParenthesizedExpression) {
4394 return finish(_visitTest(node.expression));
4395 }
4393 if (node is BinaryExpression) { 4396 if (node is BinaryExpression) {
4394 JS.Expression shortCircuit(String code) { 4397 JS.Expression shortCircuit(String code) {
4395 return finish(js.call(code, 4398 return finish(js.call(code,
4396 [_visitTest(node.leftOperand), _visitTest(node.rightOperand)])); 4399 [_visitTest(node.leftOperand), _visitTest(node.rightOperand)]));
4397 } 4400 }
4398 var op = node.operator.type.lexeme; 4401 var op = node.operator.type.lexeme;
4399 if (op == '&&') return shortCircuit('# && #'); 4402 if (op == '&&') return shortCircuit('# && #');
4400 if (op == '||') return shortCircuit('# || #'); 4403 if (op == '||') return shortCircuit('# || #');
4401 } 4404 }
4402 // Offset 0 from start of file is syntactically impossible for normal code. 4405 // Offset 0 from start of file is syntactically impossible for normal code.
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
4661 } 4664 }
4662 4665
4663 bool isLibraryPrefix(Expression node) => 4666 bool isLibraryPrefix(Expression node) =>
4664 node is SimpleIdentifier && node.staticElement is PrefixElement; 4667 node is SimpleIdentifier && node.staticElement is PrefixElement;
4665 4668
4666 LibraryElement _getLibrary(AnalysisContext c, String uri) => 4669 LibraryElement _getLibrary(AnalysisContext c, String uri) =>
4667 c.computeLibraryElement(c.sourceFactory.forUri(uri)); 4670 c.computeLibraryElement(c.sourceFactory.forUri(uri));
4668 4671
4669 bool _isDartRuntime(LibraryElement l) => 4672 bool _isDartRuntime(LibraryElement l) =>
4670 l.isInSdk && l.source.uri.toString() == 'dart:_runtime'; 4673 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